2 Copyright 2020 TATA ELXSI
4 Licensed under the Apache License, Version 2.0 (the 'License');
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
16 Author: SANDHYA JS (sandhya.j@tataelxsi.co.in)
19 * @file WarningConfiguration Model
21 import { HttpHeaders } from '@angular/common/http';
22 import { Component, Injector, Input } from '@angular/core';
23 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
24 import { TranslateService } from '@ngx-translate/core';
25 import { NotifierService } from 'angular-notifier';
26 import { APIURLHEADER, ERRORDATA, MODALCLOSERESPONSEDATA, UNLOCKPARAMS } from 'CommonModel';
27 import { environment } from 'environment';
28 import { RestService } from 'RestService';
31 * @Component takes WarningComponent.html as template url
34 selector: 'app-warning',
35 templateUrl: './WarningComponent.html',
36 styleUrls: ['./WarningComponent.scss']
38 /** Exporting a class @exports WarningComponent */
39 export class WarningComponent {
40 /** To inject services @public */
41 public injector: Injector;
43 /** Instance for active modal service @public */
44 public activeModal: NgbActiveModal;
46 /** Check the loading results @public */
47 public isLoad: Boolean = false;
49 /** Contains title data @public */
51 public heading: string;
53 /** Contains body data @public */
55 public confirmationMessage: string;
57 /** Contains footer data @public */
59 public submitMessage: string;
61 /** Give the message for the loading @public */
62 public message: string = 'PLEASEWAIT';
64 /** Contains id of the admin user @public */
68 /** Holds which action to perform @public */
70 public action: boolean = false;
72 /** Contains editType data @public */
74 public editType: string;
76 /** handle translate @public */
77 public translateService: TranslateService;
79 /** Controls the header form @private */
80 private headers: HttpHeaders;
82 /** Instance of the rest service @private */
83 private restService: RestService;
85 /** Notifier service to popup notification @private */
86 private notifierService: NotifierService;
88 constructor(injector: Injector) {
89 this.injector = injector;
90 this.activeModal = this.injector.get(NgbActiveModal);
91 this.restService = this.injector.get(RestService);
92 this.translateService = this.injector.get(TranslateService);
93 this.notifierService = this.injector.get(NotifierService);
97 * Lifecyle Hooks the trigger before component is instantiate
99 public ngOnInit(): void {
103 /** Close the modal @public */
104 public closeModal(getMessage: string): void {
105 this.activeModal.close({ message: getMessage });
109 * called on submit @private onSubmit
111 public onSubmit(): void {
113 const modalData: MODALCLOSERESPONSEDATA = {
116 const id: string = sessionStorage.getItem('user_id');
117 const payLoad: UNLOCKPARAMS = {};
118 if (this.editType === 'unlock') {
119 payLoad.system_admin_id = id;
120 payLoad.unlock = true;
122 payLoad.system_admin_id = id;
123 payLoad.renew = true;
125 const apiURLHeader: APIURLHEADER = {
126 url: environment.USERS_URL + '/' + this.id,
127 httpOptions: { headers: this.headers }
129 this.restService.patchResource(apiURLHeader, payLoad).subscribe((result: {}): void => {
130 this.activeModal.close(modalData);
132 if (this.editType === 'unlock') {
133 this.notifierService.notify('success', this.translateService.instant('PAGE.USERS.UNLOCKUSER'));
135 this.notifierService.notify('success', this.translateService.instant('PAGE.USERS.RENEWUSER'));
137 }, (error: ERRORDATA): void => {
138 this.restService.handleError(error, 'put');