-/*-\r
- * ================================================================================\r
- * ECOMP Portal\r
- * ================================================================================\r
- * Copyright (C) 2017 AT&T Intellectual Property\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ================================================================================\r
- */\r
-'use strict';\r
-(function () {\r
- class WidgetOnboardingCtrl {\r
- constructor($log, applicationsService, widgetsCatalogService, ngDialog, confirmBoxService,\r
- userProfileService, $cookies, $scope) {\r
- $scope.infoMessage = true;\r
-\r
- let populateAvailableApps = widgets => {\r
- let allPortalsFilterObject = {index: 0, title: 'All applications', value: ''};\r
- this.availableApps = [allPortalsFilterObject];\r
- this.filterByApp = this.availableApps[0];\r
- applicationsService.getAppsForSuperAdminAndAccountAdmin().then(myApps => {\r
- var reSortedApp = myApps.sort(getSortOrder("name"));\r
- var realAppIndex = 1;\r
- for (let i = 1; i <= reSortedApp.length; i++) {\r
- if (!reSortedApp[i-1].restrictedApp) {\r
- this.availableApps.push({\r
- index: realAppIndex,\r
- title: reSortedApp[i - 1].name,\r
- value: reSortedApp[i - 1].name\r
- })\r
- realAppIndex = realAppIndex + 1;\r
- }\r
- }\r
- }).catch(err => {\r
- $log.error('WidgetOnboardingCtrl:getAppsForSuperAdmin failed', err);\r
- });\r
- };\r
- \r
- let getOnboardingWidgets = () => {\r
- this.isLoadingTable = true;\r
- this.isCommError = false;\r
- widgetsCatalogService.getManagedWidgets().then(res => {\r
- if(!(res instanceof Array)){\r
- this.isCommError = true;\r
- return;\r
- }\r
- \r
- var reSortedWidget = res.sort(getSortOrder("name"));\r
- $scope.widgetsList = reSortedWidget;\r
- for(var i = 0; i < $scope.widgetsList.length; i++){\r
- let set = new Set();\r
- var info = "";\r
- var appContent = [];\r
- var appName = []; \r
- for(var n = 0; n < $scope.widgetsList[i].widgetRoles.length; n++){\r
- set.add($scope.widgetsList[i].widgetRoles[n].app.appName);\r
- }\r
- if($scope.widgetsList[i].allowAllUser == "Y"){\r
- info = "All Applications";\r
- appContent.push("All Applications");\r
- appName.push("All Applications");\r
- }\r
- \r
- set.forEach(function (item) {\r
- info = item.toString() + " - ";\r
- for(var n = 0; n < $scope.widgetsList[i].widgetRoles.length; n++){\r
- if(item.toString() == $scope.widgetsList[i].widgetRoles[n].app.appName){\r
- info += $scope.widgetsList[i].widgetRoles[n].roleName + "; ";\r
- }\r
- }\r
- appContent.push(info);\r
- appName.push(item.toString());\r
- });\r
- $scope.widgetsList[i].appContent = appContent;\r
- $scope.widgetsList[i].appName = appName;\r
- }\r
- populateAvailableApps(reSortedWidget);\r
- }).catch(err => {\r
- // Land here when the micro service is down\r
- $log.error('WidgetOnboardingCtrl::getOnboardingWidgets caught error', err);\r
- }).finally(()=> {\r
- this.isLoadingTable = false;\r
- });\r
- \r
- };\r
- \r
- \r
- // Refactor this into a directive\r
- let getSortOrder = (prop) => {\r
- return function(a, b) {\r
- if (a[prop].toLowerCase() > b[prop].toLowerCase()) {\r
- return 1;\r
- } else if (a[prop].toLowerCase() < b[prop].toLowerCase()) {\r
- return -1;\r
- }\r
- return 0;\r
- }\r
- }\r
-\r
- $scope.hideMe = function () {\r
- $scope.infoMessage = false;\r
- }\r
-\r
- let init = () => {\r
- this.isLoadingTable = false;\r
- getOnboardingWidgets();\r
- this.searchString = '';\r
- this.widgetsTableHeaders = [\r
- {name: 'Widget Name', value: 'name', isSortable: false}\r
- ];\r
- $scope.widgetsList = [];\r
- };\r
- \r
- this.filterByDropdownValue = item => { \r
- if(this.filterByApp.value === '')\r
- return true;\r
- \r
- for(var i = 0; i < item.appName.length; i++){\r
- if(item.appName[i] == this.filterByApp.value\r
- || item.appName[i] == 'All Applications'){\r
- return true;\r
- }\r
- }\r
- return false;\r
- };\r
-\r
- this.openWidgetCatalogDetailsModal = (selectedWidget) => {\r
- let data = null;\r
- if(selectedWidget){\r
- if(!selectedWidget.id){\r
- $log.error('WidgetOnboardingCtrl:openWidgetCatalogDetailModal: widget id not found');\r
- return;\r
- }\r
- data = {\r
- widget: selectedWidget\r
- }\r
- }\r
- ngDialog.open({\r
- templateUrl: 'app/views/widget-onboarding/widget-details-dialog/widget-details.modal.html',\r
- controller: 'WidgetOnboardingDetailsModalCtrl',\r
- controllerAs: 'widgetOnboardingDetails',\r
- data: data\r
- }).closePromise.then(needUpdate => {\r
- if(needUpdate.value === true){\r
- getOnboardingWidgets();\r
- }\r
- });\r
- };\r
-\r
- this.deleteWidget = widget => { \r
- \r
- confirmBoxService.deleteItem(widget.name).then(isConfirmed => {\r
- if(isConfirmed){\r
- if(!widget || !widget.id){\r
- $log.error('WidgetOnboardingCtrl::deleteWidget: No widget or ID... cannot delete');\r
- return;\r
- }\r
- widgetsCatalogService.deleteWidget(widget.id).then(() => {\r
- $scope.widgetsList.splice($scope.widgetsList.indexOf(widget), 1);\r
- }).catch(err => {\r
- $log.error('WidgetOnboardingCtrl::deleteWidget error:',err);\r
- });\r
- }\r
- }).catch(err => {\r
- $log.error('WidgetOnboardingCtrl::deleteWidget error:',err);\r
- });\r
- \r
- };\r
- \r
- \r
- this.downloadWidget = widget => {\r
- widgetsCatalogService.downloadWidgetFile(widget.id).then(res => {\r
- var data = res;\r
- var filename = widget.name + ".zip";\r
- \r
- if (data == undefined || data == null){\r
- confirmBoxService.showInformation("Could not download. Please retry.");\r
- return; \r
- }\r
- var a = document.createElement('a');\r
- var blob = new Blob([data], {type: 'application/octet-stream'});\r
- a.href = URL.createObjectURL(blob);\r
- a.download = filename;\r
- a.click();\r
- });\r
- };\r
- \r
- init();\r
- }\r
- }\r
- WidgetOnboardingCtrl.$inject = ['$log', 'applicationsService', 'widgetsCatalogService', 'ngDialog', 'confirmBoxService',\r
- 'userProfileService','$cookies', '$scope'];\r
- angular.module('ecompApp').controller('WidgetOnboardingCtrl', WidgetOnboardingCtrl);\r
-})();\r
+/*-
+ * ================================================================================
+ * ECOMP Portal
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ================================================================================
+ */
+'use strict';
+(function () {
+ class WidgetOnboardingCtrl {
+ constructor($log, applicationsService, widgetsCatalogService, ngDialog, confirmBoxService,
+ userProfileService, $cookies, $scope) {
+ $scope.infoMessage = true;
+
+ let populateAvailableApps = widgets => {
+ let allPortalsFilterObject = {index: 0, title: 'All applications', value: ''};
+ this.availableApps = [allPortalsFilterObject];
+ this.filterByApp = this.availableApps[0];
+ applicationsService.getAppsForSuperAdminAndAccountAdmin().then(myApps => {
+ var reSortedApp = myApps.sort(getSortOrder("name"));
+ var realAppIndex = 1;
+ for (let i = 1; i <= reSortedApp.length; i++) {
+ if (!reSortedApp[i-1].restrictedApp) {
+ this.availableApps.push({
+ index: realAppIndex,
+ title: reSortedApp[i - 1].name,
+ value: reSortedApp[i - 1].name
+ })
+ realAppIndex = realAppIndex + 1;
+ }
+ }
+ }).catch(err => {
+ $log.error('WidgetOnboardingCtrl:getAppsForSuperAdmin failed', err);
+ });
+ };
+
+ let getOnboardingWidgets = () => {
+ this.isLoadingTable = true;
+ this.isCommError = false;
+ widgetsCatalogService.getManagedWidgets().then(res => {
+ if(!(res instanceof Array)){
+ this.isCommError = true;
+ return;
+ }
+
+ var reSortedWidget = res.sort(getSortOrder("name"));
+ $scope.widgetsList = reSortedWidget;
+ for(var i = 0; i < $scope.widgetsList.length; i++){
+ let set = new Set();
+ var info = "";
+ var appContent = [];
+ var appName = [];
+ for(var n = 0; n < $scope.widgetsList[i].widgetRoles.length; n++){
+ set.add($scope.widgetsList[i].widgetRoles[n].app.appName);
+ }
+ if($scope.widgetsList[i].allowAllUser == "Y"){
+ info = "All Applications";
+ appContent.push("All Applications");
+ appName.push("All Applications");
+ }
+
+ set.forEach(function (item) {
+ info = item.toString() + " - ";
+ for(var n = 0; n < $scope.widgetsList[i].widgetRoles.length; n++){
+ if(item.toString() == $scope.widgetsList[i].widgetRoles[n].app.appName){
+ info += $scope.widgetsList[i].widgetRoles[n].roleName + "; ";
+ }
+ }
+ appContent.push(info);
+ appName.push(item.toString());
+ });
+ $scope.widgetsList[i].appContent = appContent;
+ $scope.widgetsList[i].appName = appName;
+ }
+ populateAvailableApps(reSortedWidget);
+ }).catch(err => {
+ // Land here when the micro service is down
+ $log.error('WidgetOnboardingCtrl::getOnboardingWidgets caught error', err);
+ }).finally(()=> {
+ this.isLoadingTable = false;
+ });
+
+ };
+
+
+ // Refactor this into a directive
+ let getSortOrder = (prop) => {
+ return function(a, b) {
+ if (a[prop].toLowerCase() > b[prop].toLowerCase()) {
+ return 1;
+ } else if (a[prop].toLowerCase() < b[prop].toLowerCase()) {
+ return -1;
+ }
+ return 0;
+ }
+ }
+
+ $scope.hideMe = function () {
+ $scope.infoMessage = false;
+ }
+
+ let init = () => {
+ this.isLoadingTable = false;
+ getOnboardingWidgets();
+ this.searchString = '';
+ this.widgetsTableHeaders = [
+ {name: 'Widget Name', value: 'name', isSortable: false}
+ ];
+ $scope.widgetsList = [];
+ };
+
+ this.filterByDropdownValue = item => {
+ if(this.filterByApp.value === '')
+ return true;
+
+ for(var i = 0; i < item.appName.length; i++){
+ if(item.appName[i] == this.filterByApp.value
+ || item.appName[i] == 'All Applications'){
+ return true;
+ }
+ }
+ return false;
+ };
+
+ this.openWidgetCatalogDetailsModal = (selectedWidget) => {
+ let data = null;
+ if(selectedWidget){
+ if(!selectedWidget.id){
+ $log.error('WidgetOnboardingCtrl:openWidgetCatalogDetailModal: widget id not found');
+ return;
+ }
+ data = {
+ widget: selectedWidget
+ }
+ }
+ ngDialog.open({
+ templateUrl: 'app/views/widget-onboarding/widget-details-dialog/widget-details.modal.html',
+ controller: 'WidgetOnboardingDetailsModalCtrl',
+ controllerAs: 'widgetOnboardingDetails',
+ data: data
+ }).closePromise.then(needUpdate => {
+ if(needUpdate.value === true){
+ getOnboardingWidgets();
+ }
+ });
+ };
+
+ this.deleteWidget = widget => {
+
+ confirmBoxService.deleteItem(widget.name).then(isConfirmed => {
+ if(isConfirmed){
+ if(!widget || !widget.id){
+ $log.error('WidgetOnboardingCtrl::deleteWidget: No widget or ID... cannot delete');
+ return;
+ }
+ widgetsCatalogService.deleteWidget(widget.id).then(() => {
+ $scope.widgetsList.splice($scope.widgetsList.indexOf(widget), 1);
+ }).catch(err => {
+ $log.error('WidgetOnboardingCtrl::deleteWidget error:',err);
+ });
+ }
+ }).catch(err => {
+ $log.error('WidgetOnboardingCtrl::deleteWidget error:',err);
+ });
+
+ };
+
+
+ this.downloadWidget = widget => {
+ widgetsCatalogService.downloadWidgetFile(widget.id).then(res => {
+ var data = res;
+ var filename = widget.name + ".zip";
+
+ if (data == undefined || data == null){
+ confirmBoxService.showInformation("Could not download. Please retry.");
+ return;
+ }
+ var a = document.createElement('a');
+ var blob = new Blob([data], {type: 'application/octet-stream'});
+ a.href = URL.createObjectURL(blob);
+ a.download = filename;
+ a.click();
+ });
+ };
+
+ init();
+ }
+ }
+ WidgetOnboardingCtrl.$inject = ['$log', 'applicationsService', 'widgetsCatalogService', 'ngDialog', 'confirmBoxService',
+ 'userProfileService','$cookies', '$scope'];
+ angular.module('ecompApp').controller('WidgetOnboardingCtrl', WidgetOnboardingCtrl);
+})();