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', 'guestAccess', 'url','restURL',
65 'communicationKey', 'applicationNamespace', 'centralAuthAccess'];
66 dataSource = new MatTableDataSource(this.appsList);
67 @ViewChild(MatSort) sort: MatSort;
68 @ViewChild(MatPaginator) paginator: MatPaginator;
70 constructor(public applicationsService: ApplicationsService, public ngbModal: NgbModal) { }
73 this.emptyImgForPreview = '../../../assets/images/default_app_image.gif';
74 this.checkIfUserIsSuperAdmin();
75 this.getOnboardingApps();
79 //console.log("getOnboardingApps called");
80 this.applicationsService.getOnboardingApps()
83 if (this.result == null || this.result == 'undefined') {
84 console.log('WidgetOnboardingService::getOnboardingWidgets Failed: Result or result.data is null');
86 this.appsList = _data;
87 for (var i = 0; i < this.appsList.length; i++) {
88 this.appsList[i].imageLink = '';
89 if (this.appsList[i].imageUrl){
90 this.appsList[i].imageLink = this.api.appThumbnail.replace(':appId', this.appsList[i].id);
91 this.appsList[i].imageLink = this.appsList[i].imageLink+'?' + new Date().getTime();
93 this.appsList[i].imageLink = this.emptyImgForPreview;
96 this.populateTableData(this.appsList);
100 this.openConfirmationModal('Error', error.message);
104 applyFilter(filterValue: string) {
105 this.dataSource.filter = filterValue.trim().toLowerCase();
109 populateTableData(appsList: Array<IApplications>){
110 this.dataSource = new MatTableDataSource(appsList);
111 this.dataSource.sort = this.sort;
112 this.dataSource.paginator = this.paginator;
115 openAddApplicationModal(rowData: any) {
116 const modalRef = this.ngbModal.open(ApplicationDetailsDialogComponent, { size: 'lg' });
117 modalRef.componentInstance.title = 'Application Details';
118 //console.log("selectedData in parent",rowData);
119 if(rowData != 'undefined' && rowData){
120 modalRef.componentInstance.applicationObj = rowData;
121 this.isEditMode = true;
123 modalRef.componentInstance.applicationObj = {};
124 this.isEditMode = false;
126 modalRef.componentInstance.passEntry.subscribe((receivedEntry: any) => {
127 //console.log("receivedEntry >>> ",receivedEntry);
129 this.appsList.push(receivedEntry);
130 //this.populateTableData(this.appsList);
131 this.getOnboardingApps();
136 deleteApplication(application: IApplications){
137 let confirmationMsg = 'You are about to delete this App : ' + application.name+ '. Click OK to continue.';
138 this.openInformationModal("Confirmation",confirmationMsg).result.then((result) => {
139 if (result === 'Ok') {
140 if(!application || application == null){
141 console.log('ApplicationOnboardingCtrl::deleteApplication: No apllication or ID... cannot delete');
144 this.appsList.splice(this.appsList.indexOf(application), 1);
145 this.applicationsService.deleteOnboardingApp(application.id)
146 .subscribe( data => {
148 this.getOnboardingApps();
151 this.openConfirmationModal('Error', error);
159 checkIfUserIsSuperAdmin(){
160 this.applicationsService.checkIfUserIsSuperAdmin()
163 this.isUserSuperAdmin = true;
164 this.displayedColumns = ['thumbnail', 'applicationName','active',
165 'integrationType', 'guestAccess', 'url','restURL',
166 'communicationKey', 'applicationNamespace', 'centralAuthAccess', 'delete'];
168 //console.log("isUserSuperAdmin :: ",this.isUserSuperAdmin);
171 this.openConfirmationModal('Error', 'ApplicationsCtrl.checkIfUserIsSuperAdmin:: Failed '+error.message);
175 openConfirmationModal(_title: string, _message: string) {
176 const modalInfoRef = this.ngbModal.open(ConfirmationModalComponent);
177 modalInfoRef.componentInstance.title = _title;
178 modalInfoRef.componentInstance.message = _message;
181 openInformationModal(_title: string, _message: string){
182 const modalInfoRef = this.ngbModal.open(InformationModalComponent);
183 modalInfoRef.componentInstance.title = _title;
184 modalInfoRef.componentInstance.message = _message;