File

src/app/pages/containers/global-configs/global-configs.component.ts

Implements

OnInit

Metadata

selector app-global-configs
templateUrl ./global-configs.component.html

Index

Properties
Methods

Constructor

constructor(clientService: ClientService, configService: ConfigService, activatedRoute: ActivatedRoute, router: Router, toastService: ToastService)
Parameters :
Name Type Optional
clientService ClientService No
configService ConfigService No
activatedRoute ActivatedRoute No
router Router No
toastService ToastService No

Methods

getClients
getClients()
Returns : any
makeBackButton
makeBackButton()
Returns : { routerLink: {}; queryParams: {}; name: string; }
Async ngOnInit
ngOnInit()
Returns : any
onClientChange
onClientChange(event)
Parameters :
Name Optional
event No
Returns : void
onSave
onSave(event)
Parameters :
Name Optional
event No
Returns : void
Async updateConfigs
updateConfigs()
Returns : any

Properties

__
Default value : strings
clientId
Type : string
clients
Type : | null
configs
loading
Default value : true
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import {Client} from '@app/pages/models/client';
import {ConfigService} from '@app/pages/services/config.service';
import {ToastService} from '@app/shared/services/toast.service';
import {ClientService} from '@app/pages/services/client.service';

import strings from '@i18n/strings.json';

@Component({
  selector: 'app-global-configs',
  templateUrl: './global-configs.component.html',
  // styleUrls: ['./global-configs.component.scss']
})

export class GlobalConfigsComponent implements OnInit {
  __ = strings;

  clientId: string;
  configs;
  clients: [Client] | null;
  loading = true;
  // private backButtonObject;

  constructor(
    private clientService: ClientService,
    private configService: ConfigService,
    private activatedRoute: ActivatedRoute,
    private router: Router,
    private toastService: ToastService) {}

  async ngOnInit() {
    this.clientId = this.activatedRoute.snapshot.queryParams.client;
    this.clients = await this.getClients();
    this.updateConfigs();
  }

  getClients() {
    if (!this.clientId) { return; }
    const {clients} = history.state;
    return (clients ? clients : this.clientService.getAllClients());
  }

  onClientChange(event) {
    console.log("change", event);
    this.clientId = event.id;
    this.updateConfigs();
    this.router.navigate(['/global-configs'], {queryParams: {client: this.clientId}}).then(() => {});
  }

  async updateConfigs() {
    this.loading = true;
    this.configs = await this.configService.getGlobalConfigByClientId(this.clientId);
    this.loading = false;
  }

  onSave(event) {
    const newConfigArray = event.config.map(c => ({name: c.name, value: c.value}));
    this.configService.postGlobalConfigByClientId(this.clientId, {config: newConfigArray}).subscribe(() => {
      this.toastService.showSuccess(`Global Configurations of App: ${this.clientId} changed.`);
    });
  }

  makeBackButton() {
    if (!this.clientId) { return; }
    return {routerLink: ['/global-clients'], queryParams: {}, 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">
        <a class="btn btn-secondary btn-block tab-button active" [routerLink]="['/global-clients']">Global Configurations</a>
        <a class="btn btn-secondary btn-block tab-button" [routerLink]="['/projects']">Projects</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]="clients" [selected]="clientId" [label]="__.application" [field]="'id'" (change)="onClientChange($event)"></app-dropdown>
          </div>
        </div>
        <div class="col-md-2"></div>
      </div>
      <h1>{{__.globalConfigurations}}</h1>
      <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" [global]="true" [configObject]="configs" (save)="onSave($event)"></app-configs-table>
      </div>
    </div>
  </div>
</div>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""