File
Description
Users Component
Implements
Metadata
| selector |
app-users |
| templateUrl |
./users.component.html |
Methods
|
getProjects
|
getProjects()
|
|
|
|
|
|
makeBackButton
|
makeBackButton()
|
|
|
|
Returns : { routerLink: {}; queryParams: { project: any; }; name: string; }
|
|
makeQueryParams
|
makeQueryParams(userId)
|
|
|
|
Returns : { project: any; client: any; user: any; }
|
|
makeState
|
makeState()
|
|
|
|
Returns : { projects: [any]; clients: [any]; users: void | [any]; }
|
|
Async
ngOnInit
|
ngOnInit()
|
|
|
|
|
|
onClientChange
|
onClientChange(event)
|
|
|
|
|
|
onProjectChange
|
onProjectChange(event)
|
|
|
|
|
|
Async
updateUsers
|
updateUsers()
|
|
|
|
|
|
__
|
Default value : strings
|
|
|
|
loading
|
Default value : true
|
|
|
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import {ProjectService} from '@app/pages/services/project.service';
import {ClientService} from '@app/pages/services/client.service';
import {UserService} from '@app/pages/services/user.service';
import {Project} from '@app/pages/models/project';
import {Client} from '@app/pages/models/client';
import {User} from '@app/pages/models/user';
import strings from '@i18n/strings.json';
/**
* Users Component
*/
@Component({
selector: 'app-users',
templateUrl: './users.component.html',
// styleUrls: ['./users.component.scss']
})
export class UsersComponent implements OnInit {
__ = strings;
projectId;
clientId;
projects: [Project];
clients: [Client];
users: [User] | void;
loading = true;
constructor(
private userService: UserService,
private clientService: ClientService,
private projectService: ProjectService,
private activatedRoute: ActivatedRoute,
private router: Router) {}
async ngOnInit() {
this.projectId = this.activatedRoute.snapshot.queryParams.project;
this.clientId = this.activatedRoute.snapshot.queryParams.client;
this.projects = await this.getProjects();
this.clients = await this.getClients();
this.updateUsers();
}
getProjects() {
if (!this.projectId) { return; }
const {projects} = history.state;
return (projects ? projects : this.projectService.getAllProjects());
}
getClients() {
if (!this.clientId) { return; }
const {clients} = history.state;
return (clients ? clients : this.clientService.getAllClients());
}
onProjectChange(event) {
this.projectId = event.name;
const tempObject = {...this.activatedRoute.snapshot.queryParams};
tempObject.project = this.projectId;
this.updateUsers();
this.router.navigate(['/users'], {queryParams: tempObject});
}
onClientChange(event) {
this.clientId = event.id;
const tempObject = {...this.activatedRoute.snapshot.queryParams};
tempObject.client = this.clientId;
this.updateUsers();
this.router.navigate(['/users'], {queryParams: tempObject});
}
async updateUsers() {
this.loading = true;
this.users = await this.userService.getUsersByProjectId(this.projectId);
this.loading = false;
}
makeState() {
return {projects: this.projects, clients: this.clients, users: this.users};
}
makeQueryParams(userId) {
return {project: this.projectId, client: this.clientId, user: userId};
}
makeBackButton() {
if (!this.clientId || !this.projectId) { return; }
return {routerLink: ['/clients'], queryParams: {project: this.projectId}, name: 'Applications'};
}
}
<div class="my-3 my-md-5">
<div class="row">
<div class="col-md-2">
<app-left-sidebar [backButton]="makeBackButton()"></app-left-sidebar>
<div class="btn-group-vertical w-100 mb-3 mb-md-0" role="group" aria-label="Button group with nested dropdown">
<a class="btn btn-secondary btn-block tab-button" [routerLink]="['/global-clients']">Global Configurations</a>
<a class="btn btn-secondary btn-block tab-button active" [routerLink]="['/projects']">Projects</a>
</div>
<div class="btn-group-vertical w-100 mb-3 mb-md-0" role="group" aria-label="Button group with nested dropdown">
<a class="btn btn-secondary btn-block tab-button" [routerLink]="['/configs']" [queryParams]="makeQueryParams()" [state]="makeState()">All groups and users</a>
<a class="btn btn-secondary btn-block tab-button" [routerLink]="['/groups']" [queryParams]="makeQueryParams()" [state]="makeState()">Groups</a>
<a class="btn btn-secondary btn-block tab-button active" [routerLink]="['/users']" [queryParams]="makeQueryParams()" [state]="makeState()">Users</a>
</div>
</div>
<div class="col-md-8">
<div class="row mb-3">
<app-dropdown class="col-md-6" [data]="projects" [field]="'projectName'" [label]="__.project" [selected]="projectId" (change)="onProjectChange($event)"></app-dropdown>
<app-dropdown class="col-md-6" [data]="clients" [field]="'id'" [label]="__.application" [selected]="clientId" (change)="onClientChange($event)"></app-dropdown>
</div>
<h2>{{__.selectAUser}}</h2>
<div class="row my-5" *ngIf="loading"><h2>{{__.loading}}</h2></div>
<div *ngIf="!loading" class="row my-3">
<div *ngFor="let user of users" class="col-lg-4 mb-3">
<div class="card">
<a [routerLink]="['/configs']" [queryParams]="makeQueryParams(user.id)" [state]="makeState()">
<div class="card-body">
<!--<h5 class="card-title">{{user.name}}</h5>-->
<h5 class="card-title">{{user.id}}</h5>
</div>
</a>
</div>
</div>
</div>
</div>
<div class="col-md-2"></div>
</div>
</div>
Legend
Html element with directive