blob: d52e98941ef6f10e0fc624fc868148c723ef253f [file] [log] [blame]
SANDHYA.JS99144582022-04-27 17:22:35 +05301/*
2 Copyright 2020 TATA ELXSI
3
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
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
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.
15
16 Author: SANDHYA JS (sandhya.j@tataelxsi.co.in)
17*/
18/**
19 * @file WarningConfiguration Model
20 */
SANDHYA.JS1b17c432023-04-26 17:54:57 +053021import { HttpHeaders } from '@angular/common/http';
SANDHYA.JS99144582022-04-27 17:22:35 +053022import { Component, Injector, Input } from '@angular/core';
23import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
SANDHYA.JS1b17c432023-04-26 17:54:57 +053024import { TranslateService } from '@ngx-translate/core';
25import { NotifierService } from 'angular-notifier';
26import { APIURLHEADER, ERRORDATA, MODALCLOSERESPONSEDATA, UNLOCKPARAMS } from 'CommonModel';
27import { environment } from 'environment';
28import { RestService } from 'RestService';
SANDHYA.JS99144582022-04-27 17:22:35 +053029/**
30 * Creating component
31 * @Component takes WarningComponent.html as template url
32 */
33@Component({
34 selector: 'app-warning',
35 templateUrl: './WarningComponent.html',
36 styleUrls: ['./WarningComponent.scss']
37})
38/** Exporting a class @exports WarningComponent */
39export class WarningComponent {
40 /** To inject services @public */
41 public injector: Injector;
42
43 /** Instance for active modal service @public */
44 public activeModal: NgbActiveModal;
45
46 /** Check the loading results @public */
47 public isLoad: Boolean = false;
48
49 /** Contains title data @public */
50 @Input()
51 public heading: string;
52
53 /** Contains body data @public */
54 @Input()
55 public confirmationMessage: string;
56
57 /** Contains footer data @public */
58 @Input()
59 public submitMessage: string;
60
61 /** Give the message for the loading @public */
62 public message: string = 'PLEASEWAIT';
63
SANDHYA.JS1b17c432023-04-26 17:54:57 +053064 /** Contains id of the admin user @public */
65 @Input()
66 public id: string;
67
68 /** Holds which action to perform @public */
69 @Input()
70 public action: boolean = false;
71
72 /** Contains editType data @public */
73 @Input()
74 public editType: string;
75
76 /** handle translate @public */
77 public translateService: TranslateService;
78
79 /** Controls the header form @private */
80 private headers: HttpHeaders;
81
82 /** Instance of the rest service @private */
83 private restService: RestService;
84
85 /** Notifier service to popup notification @private */
86 private notifierService: NotifierService;
87
SANDHYA.JS99144582022-04-27 17:22:35 +053088 constructor(injector: Injector) {
89 this.injector = injector;
90 this.activeModal = this.injector.get(NgbActiveModal);
SANDHYA.JS1b17c432023-04-26 17:54:57 +053091 this.restService = this.injector.get(RestService);
92 this.translateService = this.injector.get(TranslateService);
93 this.notifierService = this.injector.get(NotifierService);
SANDHYA.JS99144582022-04-27 17:22:35 +053094 }
95
96 /**
97 * Lifecyle Hooks the trigger before component is instantiate
98 */
99 public ngOnInit(): void {
100 //empty
101 }
102
103 /** Close the modal @public */
104 public closeModal(getMessage: string): void {
105 this.activeModal.close({ message: getMessage });
106 }
SANDHYA.JS1b17c432023-04-26 17:54:57 +0530107
108 /**
109 * called on submit @private onSubmit
110 */
111 public onSubmit(): void {
112 this.isLoad = true;
113 const modalData: MODALCLOSERESPONSEDATA = {
114 message: 'Done'
115 };
SANDHYA.JS5b35bcd2023-04-27 15:11:06 +0530116 const id: string = sessionStorage.getItem('user_id');
SANDHYA.JS1b17c432023-04-26 17:54:57 +0530117 const payLoad: UNLOCKPARAMS = {};
118 if (this.editType === 'unlock') {
119 payLoad.system_admin_id = id;
120 payLoad.unlock = true;
121 } else {
122 payLoad.system_admin_id = id;
123 payLoad.renew = true;
124 }
125 const apiURLHeader: APIURLHEADER = {
126 url: environment.USERS_URL + '/' + this.id,
127 httpOptions: { headers: this.headers }
128 };
129 this.restService.patchResource(apiURLHeader, payLoad).subscribe((result: {}): void => {
130 this.activeModal.close(modalData);
131 this.isLoad = false;
132 if (this.editType === 'unlock') {
133 this.notifierService.notify('success', this.translateService.instant('PAGE.USERS.UNLOCKUSER'));
134 } else {
135 this.notifierService.notify('success', this.translateService.instant('PAGE.USERS.RENEWUSER'));
136 }
137 }, (error: ERRORDATA): void => {
138 this.restService.handleError(error, 'put');
139 this.isLoad = false;
140 }, (): void => {
141 this.isLoad = false;
142 });
143 }
SANDHYA.JS99144582022-04-27 17:22:35 +0530144}