2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
39 import { Component, OnInit, ViewChild, Input} from '@angular/core';
40 import { MatTableDataSource } from '@angular/material';
41 import { MatSort, MatPaginator } from '@angular/material';
42 import { ApplicationsService } from '../../shared/services/index';
43 import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
44 import { IApplications } from 'src/app/shared/model/applications-onboarding/applications';
45 import { environment } from '../../../environments/environment';
46 import { ApplicationDetailsDialogComponent } from './application-details-dialog/application-details-dialog.component';
47 import { ConfirmationModalComponent } from 'src/app/modals/confirmation-modal/confirmation-modal.component';
48 import { InformationModalComponent } from 'src/app/modals/information-modal/information-modal.component';
51 selector: 'app-application-onboarding',
52 templateUrl: './application-onboarding.component.html',
53 styleUrls: ['./application-onboarding.component.scss']
55 export class ApplicationOnboardingComponent implements OnInit {
57 api = environment.api;
58 appsList: Array<IApplications> = [];
60 isEditMode: boolean = false;
61 emptyImgForPreview: string;
62 isUserSuperAdmin: boolean = false;
63 displayedColumns: string[] = ['thumbnail', 'applicationName','active',
64 'integrationType', 'modeOfIntegration', 'guestAccess', 'landingPage','restURL',
65 'communicationKey', 'applicationNamespace', 'centralAuthAccess'];
66 dataSource = new MatTableDataSource(this.appsList);
67 @ViewChild(MatSort) sort: MatSort;
68 @ViewChild(MatPaginator) paginator: MatPaginator;
69 showEcompSpinner:boolean = false;
71 constructor(public applicationsService: ApplicationsService, public ngbModal: NgbModal) { }
74 this.emptyImgForPreview = '../../../assets/images/default_app_image.gif';
75 this.checkIfUserIsSuperAdmin();
76 this.getOnboardingApps();
80 //console.log("getOnboardingApps called");
81 this.showEcompSpinner = true;
82 this.applicationsService.getOnboardingApps()
85 if (this.result == null || this.result == 'undefined') {
86 console.log('WidgetOnboardingService::getOnboardingWidgets Failed: Result or result.data is null');
87 this.showEcompSpinner = false;
89 this.appsList = _data;
90 for (var i = 0; i < this.appsList.length; i++) {
91 this.appsList[i].imageLink = '';
92 if (this.appsList[i].imageUrl){
93 this.appsList[i].imageLink = this.api.appThumbnail.replace(':appId', this.appsList[i].id);
94 this.appsList[i].imageLink = this.appsList[i].imageLink+'?' + new Date().getTime();
96 this.appsList[i].imageLink = this.emptyImgForPreview;
99 this.populateTableData(this.appsList);
100 this.showEcompSpinner = false;
104 this.showEcompSpinner = false;
105 this.openConfirmationModal('Error', error.message);
107 this.showEcompSpinner = false;
110 applyFilter(filterValue: string) {
111 this.dataSource.filter = filterValue.trim().toLowerCase();
115 populateTableData(appsList: Array<IApplications>){
116 this.dataSource = new MatTableDataSource(appsList);
117 this.dataSource.sort = this.sort;
118 this.dataSource.paginator = this.paginator;
121 openAddApplicationModal(rowData: any, action:any) {
122 console.log("Action : ", action);
123 const modalRef = this.ngbModal.open(ApplicationDetailsDialogComponent, { size: 'lg', backdrop: 'static', keyboard: false });
124 modalRef.componentInstance.title = 'Application Details';
125 modalRef.componentInstance.action = action;
126 //console.log("selectedData in parent",rowData);
127 if(rowData != 'undefined' && rowData){
128 modalRef.componentInstance.applicationObj = rowData;
129 this.isEditMode = true;
131 modalRef.componentInstance.applicationObj = {};
132 this.isEditMode = false;
134 modalRef.componentInstance.passEntry.subscribe((receivedEntry: any) => {
135 //console.log("receivedEntry >>> ",receivedEntry);
137 this.appsList.push(receivedEntry);
138 //this.populateTableData(this.appsList);
139 this.getOnboardingApps();
144 deleteApplication(application: IApplications){
145 let confirmationMsg = 'You are about to delete this App : ' + application.appName+ '. Click OK to continue.';
146 this.openInformationModal("Confirmation",confirmationMsg).result.then((result) => {
147 if (result === 'Ok') {
148 if(!application || application == null){
149 console.log('ApplicationOnboardingCtrl::deleteApplication: No apllication or ID... cannot delete');
152 this.showEcompSpinner = true;
153 this.appsList.splice(this.appsList.indexOf(application), 1);
154 this.applicationsService.deleteOnboardingApp(application.id)
155 .subscribe( data => {
157 this.getOnboardingApps();
158 this.showEcompSpinner = false;
161 this.showEcompSpinner = false;
162 if(error && error.status == 405){
163 this.openConfirmationModal('', 'Application : ' + application.appName+ ' can not be deleted as it is associsted with one of the Microservices.');
165 this.openConfirmationModal('Error', error.message);
174 checkIfUserIsSuperAdmin(){
175 this.applicationsService.checkIfUserIsSuperAdmin()
178 this.isUserSuperAdmin = true;
179 this.displayedColumns = ['thumbnail', 'applicationName','active',
180 'integrationType', 'modeOfIntegration', 'guestAccess', 'landingPage','restURL',
181 'communicationKey', 'applicationNamespace', 'centralAuthAccess', 'delete'];
183 //console.log("isUserSuperAdmin :: ",this.isUserSuperAdmin);
186 this.openConfirmationModal('Error', 'ApplicationsCtrl.checkIfUserIsSuperAdmin:: Failed '+error.message);
190 openConfirmationModal(_title: string, _message: string) {
191 const modalInfoRef = this.ngbModal.open(ConfirmationModalComponent);
192 modalInfoRef.componentInstance.title = _title;
193 modalInfoRef.componentInstance.message = _message;
196 openInformationModal(_title: string, _message: string){
197 const modalInfoRef = this.ngbModal.open(InformationModalComponent);
198 modalInfoRef.componentInstance.title = _title;
199 modalInfoRef.componentInstance.message = _message;