Initial Commit - NG UI
[osm/NG-UI.git] / src / app / utilities / confirmation-topology / ConfirmationTopologyComponent.ts
1 /*
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: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in)
17 */
18 /**
19  * @file Delete Topology Model
20  */
21 import { Component, Injector, Input, OnInit } from '@angular/core';
22 import { FormBuilder, FormGroup, Validators } from '@angular/forms';
23 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
24 import { TranslateService } from '@ngx-translate/core';
25 import { MODALCLOSERESPONSEWITHCP } from 'CommonModel';
26 /**
27  * Creating component
28  * @Component takes ConfirmationTopologyComponent.html as template url
29  */
30 @Component({
31   selector: 'app-confirmation-topology',
32   templateUrl: './ConfirmationTopologyComponent.html',
33   styleUrls: ['./ConfirmationTopologyComponent.scss']
34 })
35 /** Exporting a class @exports ConfirmationTopologyComponent */
36 export class ConfirmationTopologyComponent implements OnInit {
37   /** Form valid on submit trigger @public */
38   public submitted: boolean = false;
39   /** To inject services @public */
40   public injector: Injector;
41   /** Instance for active modal service @public */
42   public activeModal: NgbActiveModal;
43   /** FormGroup instance added to the form @ html @public */
44   public addConfirmationForm: FormGroup;
45   /** Input contains Modal dialog componentInstance @private */
46   @Input() public topologytitle: string;
47   /** Input contains Modal dialog componentInstance @private */
48   @Input() public topologyname: string;
49   /** Input contains Modal dialog componentInstance @private */
50   @Input() public topologyType: string;
51   /** Input contains Modal dialog componentInstance @private */
52   @Input() public cpDetails: {}[];
53
54   /** Contains connectionpoint @public */
55   public connectionPointInput: string;
56
57   /** Contains tranlsate instance @private */
58   private translateService: TranslateService;
59   /** FormBuilder instance added to the formBuilder @private */
60   private formBuilder: FormBuilder;
61   constructor(injector: Injector) {
62     this.injector = injector;
63     this.activeModal = this.injector.get(NgbActiveModal);
64     this.translateService = this.injector.get(TranslateService);
65     this.formBuilder = this.injector.get(FormBuilder);
66   }
67
68   /**
69    * Lifecyle Hooks the trigger before component is instantiate
70    */
71   public ngOnInit(): void {
72     this.initializeForm();
73   }
74   /** convenience getter for easy access to form fields */
75   get f(): FormGroup['controls'] { return this.addConfirmationForm.controls; }
76
77   /** initialize Forms @public */
78   public initializeForm(): void {
79     this.addConfirmationForm = this.formBuilder.group({
80       cpName: [null, [Validators.required]]
81     });
82   }
83
84   /** add confirmation to be handled in this function @public */
85   public addConfirmation(): void {
86     this.submitted = true;
87     if (this.addConfirmationForm.invalid) { return; } // Proceed, onces form is valid
88     const modalData: MODALCLOSERESPONSEWITHCP = {
89       message: 'Done',
90       connection_point: this.connectionPointInput
91     };
92     this.activeModal.close(modalData);
93   }
94   /** confirmation to be handled in this function @public */
95   public confirmation(): void {
96     const modalData: MODALCLOSERESPONSEWITHCP = {
97       message: 'Done'
98     };
99     this.activeModal.close(modalData);
100   }
101
102 }