NG-UI Added support for the OSM Repository
[osm/NG-UI.git] / src / app / utilities / osm-repositories-action / OsmRepositoriesActionComponent.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 OsmRepositoriesActionComponent.ts
20  */
21 import { Component, Injector, OnInit } from '@angular/core';
22 import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
23 import { MODALCLOSERESPONSEDATA } from 'CommonModel';
24 import { DeleteComponent } from 'DeleteComponent';
25 import { OsmRepoCreateUpdateComponent } from 'OsmRepoCreateUpdate';
26 import { OSMRepoData } from 'OsmRepoModel';
27 import { SharedService } from 'SharedService';
28 /**
29  * Creating Component
30  * @Component takes OsmRepositoriesActionComponent.html as template url
31  */
32 @Component({
33   selector: 'app-osm-repositories-action',
34   templateUrl: './OsmRepositoriesActionComponent.html',
35   styleUrls: ['./OsmRepositoriesActionComponent.scss']
36 })
37 /** Exporting a class @exports OsmRepositoriesActionComponent */
38 export class OsmRepositoriesActionComponent implements OnInit {
39   /** To get the value from the osm repo via valuePrepareFunction default Property of ng-smarttable @public */
40   public value: OSMRepoData;
41
42   /** To inject services @public */
43   public injector: Injector;
44
45   /** Variables holds OSM repo name @public */
46   public osmrepoName: string;
47
48   /** Variables holds OSM repo id @public */
49   public identifier: string;
50
51   /** Instance of the modal service @private */
52   private modalService: NgbModal;
53
54   /** Contains all methods related to shared @private */
55   private sharedService: SharedService;
56
57   constructor(injector: Injector) {
58     this.injector = injector;
59     this.sharedService = this.injector.get(SharedService);
60     this.modalService = this.injector.get(NgbModal);
61   }
62
63   /** Lifecyle Hooks the trigger before component is instantiate @public */
64   public ngOnInit(): void {
65     this.osmrepoName = this.value.name;
66     this.identifier = this.value.identifier;
67   }
68
69   /** Delete OSM Repository @public */
70   public deleteOsmRepository(): void {
71     const modalRef: NgbModalRef = this.modalService.open(DeleteComponent, { backdrop: 'static' });
72     modalRef.result.then((result: MODALCLOSERESPONSEDATA) => {
73       if (result) {
74         this.sharedService.callData();
75       }
76     }).catch();
77   }
78
79   /** Edit a osm repo @public */
80   public editOsmrepo(id: string): void {
81     const modalRef: NgbModalRef = this.modalService.open(OsmRepoCreateUpdateComponent, { backdrop: 'static' });
82     modalRef.componentInstance.createupdateType = 'Edit';
83     modalRef.componentInstance.osmrepoid = id;
84     modalRef.result.then((result: MODALCLOSERESPONSEDATA) => {
85       if (result) {
86         this.sharedService.callData();
87       }
88     }).catch();
89   }
90 }