File
Implements
Metadata
| selector |
app-configs |
| templateUrl |
./configs.component.html |
Methods
|
getProjects
|
getProjects()
|
|
|
|
|
|
makeBackButton
|
makeBackButton()
|
|
|
|
Returns : { routerLink: {}; queryParams: { project: any; }; name: string; }
|
|
makeQueryParams
|
makeQueryParams()
|
|
|
|
Returns : { project: any; client: any; }
|
|
makeState
|
makeState()
|
|
|
|
Returns : { projects: [any]; clients: [any]; }
|
|
Async
ngOnInit
|
ngOnInit()
|
|
|
|
|
|
onClientChange
|
onClientChange(event)
|
|
|
|
|
|
onProjectChange
|
onProjectChange(event)
|
|
|
|
|
|
onUserChange
|
onUserChange(event)
|
|
|
|
|
|
Async
updateConfigs
|
updateConfigs()
|
|
|
|
|
|
__
|
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 {ConfigService} from '@app/pages/services/config.service';
import {Project} from '@app/pages/models/project';
import {Client} from '@app/pages/models/client';
import {ToastService} from '@app/shared/services/toast.service';
import strings from '@i18n/strings.json';
import {User} from "@app/pages/models/user";
@Component({
selector: 'app-configs',
templateUrl: './configs.component.html',
// styleUrls: ['./configs.component.scss']
})
export class ConfigsComponent implements OnInit {
__ = strings;
projectId;
clientId;
userId;
configs;
projects: [Project] | null;
clients: [Client] | null;
users: [User] | null;
loading = true;
constructor(
private projectService: ProjectService,
private clientService: ClientService,
private userService: UserService,
private configService: ConfigService,
private activatedRoute: ActivatedRoute,
private router: Router,
private toastService: ToastService) {console.log('cons');}
async ngOnInit() {
this.activatedRoute.queryParams.subscribe(() => {
this.init();
});
}
async init(){
this.projectId = this.activatedRoute.snapshot.queryParams.project;
this.clientId = this.activatedRoute.snapshot.queryParams.client;
this.userId = this.activatedRoute.snapshot.queryParams.user;
this.projects = await this.getProjects();
this.clients = await this.getClients();
this.users = await this.getUsers();
this.updateConfigs();
}
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());
}
getUsers() {
if (!this.userId) { return; }
const {users} = history.state;
return (users ? users : this.userService.getUsersByProjectId(this.projectId));
}
onProjectChange(event) {
this.projectId = event.name;
const tempObject = {...this.activatedRoute.snapshot.queryParams};
tempObject.project = this.projectId;
this.updateConfigs();
this.router.navigate(['/configs'], {queryParams: tempObject});
}
onClientChange(event) {
this.clientId = event.id;
const tempObject = {...this.activatedRoute.snapshot.queryParams};
tempObject.client = this.clientId;
this.updateConfigs();
this.router.navigate(['/configs'], {queryParams: tempObject});
}
onUserChange(event) {
this.clientId = event.id;
const tempObject = {...this.activatedRoute.snapshot.queryParams};
tempObject.client = this.clientId;
this.updateConfigs();
this.router.navigate(['/configs'], {queryParams: tempObject});
}
async updateConfigs() {
this.loading = true;
this.configs = await this.configService.getConfigByProjectIdClientId(this.projectId, this.clientId);
this.loading = false;
}
onSave(event) {
const newConfigArray = event.config.map(c => ({name: c.name, value: c.value}));
if (this.projectId && this.clientId && this.userId) {
this.configService.postConfigByProjectIdAndClientIdAndUserId(this.projectId, this.clientId, this.userId, {config: newConfigArray})
.subscribe(() => {
// tslint:disable-next-line:max-line-length
this.toastService.showSuccess(`Configurations of Project: ${this.projectId} - Application: ${this.clientId} - User: ${this.userId} changed.`);
});
} else if (this.projectId && this.clientId && !this.userId) {
this.configService.postConfigByProjectIdAndClientId(this.projectId, this.clientId, {config: newConfigArray})
.subscribe(() => {
this.toastService.showSuccess(`Configurations of Project: ${this.projectId} - Application: ${this.clientId} changed.`);
});
}
}
isActive(name){
switch (name){
case 'group':
return false;
case 'user':
return !!this.userId;
case 'config':
return !!(!this.userId && this.clientId && this.projectId);
}
}
makeState() {
return {projects: this.projects, clients: this.clients};
}
makeQueryParams() {
return {project: this.projectId, client: this.clientId};
}
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-3" role="group" aria-label="Button group">
<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-3" role="group" aria-label="Button group with nested dropdown">
<a class="btn btn-secondary btn tab-button" [ngClass]="{'active': isActive('config')}" [routerLink]="['/configs']" [queryParams]="makeQueryParams()" [state]="makeState()">All groups and users</a>
<a class="btn btn-secondary btn tab-button" [ngClass]="{'active': isActive('group')}" [routerLink]="['/groups']" [queryParams]="makeQueryParams()" [state]="makeState()">Groups</a>
<a class="btn btn-secondary btn tab-button" [ngClass]="{'active': isActive('user')}" [routerLink]="['/users']" [queryParams]="makeQueryParams()" [state]="makeState()">Users</a>
</div>
</div>
<div class="col-md-10">
<div class="row">
<div class="col-md-10">
<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>
<div class="row mb-3">
<app-dropdown class="col-md-6" [data]="users" [field]="'id'" [label]="__.user" [selected]="userId" (change)="onUserChange($event)"></app-dropdown>
</div>
</div>
<div class="col-md-2"></div>
</div>
<h2>{{__.configurations}}</h2>
<div class="row my-5" *ngIf="loading"><h2>{{__.loading}}</h2></div>
<div *ngIf="!loading" class="row my-3">
<app-configs-table class="w-100" *ngIf="!loading && configs" [global]="false" [configObject]="configs" (save)="onSave($event)"></app-configs-table>
</div>
</div>
</div>
</div>
Legend
Html element with directive