File

src/app/pages/containers/users/users.component.ts

Description

Users Component

Implements

OnInit

Metadata

selector app-users
templateUrl ./users.component.html

Index

Properties
Methods

Constructor

constructor(userService: UserService, clientService: ClientService, projectService: ProjectService, activatedRoute: ActivatedRoute, router: Router)
Parameters :
Name Type Optional
userService UserService No
clientService ClientService No
projectService ProjectService No
activatedRoute ActivatedRoute No
router Router No

Methods

getClients
getClients()
Returns : any
getProjects
getProjects()
Returns : any
makeBackButton
makeBackButton()
Returns : { routerLink: {}; queryParams: { project: any; }; name: string; }
makeQueryParams
makeQueryParams(userId)
Parameters :
Name Optional
userId No
Returns : { project: any; client: any; user: any; }
makeState
makeState()
Returns : { projects: [any]; clients: [any]; users: void | [any]; }
Async ngOnInit
ngOnInit()
Returns : any
onClientChange
onClientChange(event)
Parameters :
Name Optional
event No
Returns : void
onProjectChange
onProjectChange(event)
Parameters :
Name Optional
event No
Returns : void
Async updateUsers
updateUsers()
Returns : any

Properties

__
Default value : strings
clientId
clients
Type : [Client]
loading
Default value : true
projectId
projects
Type : [Project]
users
Type : | void
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
Component
Html element with directive

result-matching ""

    No results matching ""