[PORTAL-16 PORTAL-18] Widget ms; staging
[portal.git] / ecomp-portal-FE-common / client / app / views / catalog / catalog.controller.js
index ad34b08..150a305 100644 (file)
-/*-\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
-\r
-function _classCallCheck(instance, Constructor) {\r
-       if (!(instance instanceof Constructor)) {\r
-               throw new TypeError('Cannot call a class as a function');\r
-       }\r
-}\r
-\r
-(function() {\r
-       var HTTP_PROTOCOL_RGX = /https?:\/\//;\r
-\r
-       var CatalogCtrl = function CatalogCtrl(conf, catalogService, confirmBoxService, ExternalRequestAccessService,\r
-                       $log, $window, userProfileService, applicationsService, $scope, $state, \r
-                       $timeout, $interval, $modal, ngDialog) {\r
-\r
-               this.conf = conf;       \r
-               var _this = this;\r
-               _classCallCheck(this, CatalogCtrl);\r
-\r
-               // activate spinner\r
-               this.isLoading = true;\r
-               $scope.getAppCatalogIsDone = false;\r
-               $scope.radioValue = 'All';\r
-               $scope.$watch('radioValue', function(newValue, oldValue) {\r
-                       var appCatalog = $scope.appCatalog;\r
-                       $scope.appCatalog = [];\r
-                       $scope.appCatalog = appCatalog;\r
-\r
-                       \r
-               });\r
-               \r
-               this.catalogService = catalogService;\r
-               this.userProfileService = userProfileService;\r
-               this.applicationsService = applicationsService;\r
-               var resultAccessValue = null;\r
-               $scope.demoNum = 1;\r
-               $scope.appRoles = [];\r
-               \r
-        let init = () => {\r
-            getExternalAccess();\r
-        };\r
-        \r
-        var getExternalAccess = () => {\r
-               ExternalRequestAccessService.getExternalRequestAccessServiceInfo().then(\r
-                               function(property) {\r
-               resultAccessValue = property.accessValue;\r
-                                       // $log.info(res);\r
-                               }).catch(err => {\r
-                        $log.error('CatalogCtrl: failed getExternalRequestAccessServiceInfo: ' + JSON.stringify(err));\r
-                    });    \r
-        };\r
-        \r
-\r
-       \r
-               $scope.applyPresentationDetailsToAppsCatalog = function(res, value) {\r
-                       \r
-                       _this.apps = res;\r
-                       var rowNo = 0;\r
-\r
-                       // defend against error string result -\r
-                       // a huge list that should never happen.\r
-                       var maxItems = 333;\r
-                       if (_this.apps.length < maxItems)\r
-                               maxItems = _this.apps.length;\r
-                       for (var i = 0; i < maxItems; i++) {                                                                                            \r
-                               let imgLnk = '';\r
-                               if (_this.apps[i].imageUrl)\r
-                                       imgLnk = conf.api.appThumbnail.replace(':appId', _this.apps[i].id);\r
-                               //$log.debug('CatalogCtlr::applyPresn: imgLink = ' + imgLnk);\r
-                               $scope.appCatalog[i] = {\r
-                                       sizeX : 2,\r
-                                       sizeY : 2,\r
-                                       id : _this.apps[i].id,\r
-                                       headerText : _this.apps[i].name,\r
-                                       imageLink : imgLnk,\r
-                                       restricted : _this.apps[i].restricted,  \r
-                                       select : _this.apps[i].select,\r
-                                       access : _this.apps[i].access,\r
-                                       pending: _this.apps[i].pending,\r
-                                       mlproperty: value\r
-                               };\r
-                       }\r
-                       //$log.debug('CatalogCtrl: getAppCatalog count : '\r
-                       //                              + $scope.appCatalog.length);\r
-                       _this.isLoading = false;\r
-                       $scope.getAppCatalogIsDone = true;\r
-               }\r
-               \r
-        let getAppsCatalog = () => {\r
-            catalogService.getAppCatalog()\r
-                .then(appsList => {\r
-                       $scope.applyPresentationDetailsToAppsCatalog(appsList);\r
-                }).catch(err => {\r
-                    confirmBoxService.showInformation('There was a problem retrieving the Applications. ' +\r
-                        'Please try again later. Error Status: '+ err.status).then(isConfirmed => {});\r
-                    $log.error('CatalogCtrl:openAddRoleModal: Error: ', err);\r
-                });\r
-        };\r
-        \r
-        this.openAddRoleModal = (item) => { \r
-               let data = null;\r
-\r
-            if((!item.restricted) && (item.mlproperty)){\r
-                data = {\r
-                    dialogState: 2,\r
-                    selectedUser:{\r
-                        attuid: $scope.attuid,\r
-                        firstName: $scope.firstName,\r
-                        lastName: $scope.lastName,\r
-                        headerText: item.headerText,\r
-                       item: item\r
-                        \r
-                    }\r
-                }\r
-            ngDialog.open({\r
-                templateUrl: 'app/views/catalog/add-catalog-dialogs/new-catalog.modal.html',\r
-                controller: 'NewCatalogModalCtrl',\r
-                controllerAs: 'userInfo',\r
-                data: data\r
-            }).closePromise.then(needUpdate => {\r
-                if(needUpdate.value === true){\r
-                       getAppsCatalog();\r
-                }\r
-               \r
-            });\r
-          }\r
-        };\r
-\r
-               // Run this function when user clicks on checkbox.\r
-               this.storeSelection = function(item) {\r
-                       // $log.debug('CatalogCtrl:storeSelection: item.id is ' + item.id + ', select is ' + item.select);\r
-                       var pendingFlag = false;\r
-                       \r
-                       if(item.access) \r
-                               pendingFlag = false;\r
-                       else\r
-                               pendingFlag =  item.pending;\r
-                                                       \r
-                       var appData = { \r
-                                       appId   : item.id,\r
-                                       select  : item.select,\r
-                                       pending : pendingFlag   // TODO\r
-                       };\r
-                       \r
-                       catalogService.updateManualAppSort(appData).then(\r
-                                       function(result) {\r
-                                               // $log.debug('CatalogCtrl:storeSelection result is ', result);\r
-                                       })['catch'](function(err) {\r
-                                               $log.error('CatalogCtrl:storeSelection: exception: ', err);\r
-                                       });\r
-                       catalogService.updateAppCatalog(appData).then(\r
-                               function(result) {\r
-                                       // $log.debug('CatalogCtrl:storeSelection result is ', result);\r
-                               })['catch'](function(err) {\r
-                                       $log.error('CatalogCtrl:storeSelection: exception: ', err);\r
-                               });\r
-               };\r
-               \r
-               userProfileService\r
-                               .getUserProfile()\r
-                               .then(\r
-                                               function(profile) {\r
-                                                       $scope.attuid = profile.orgUserId;\r
-                                                       $scope.firstName = profile.firstName;\r
-                                                       $scope.lastName = profile.lastName;\r
-                                                       $scope.appCatalog = [];\r
-                                                       \r
-                                                       catalogService.getAppCatalog().then(\r
-                                                                                       function(res) { \r
-                                                                       $scope.applyPresentationDetailsToAppsCatalog(res, resultAccessValue);\r
-                                                                                       })['catch'](function(err) {\r
-                                                                       $log.error('CatalogCtrl: failed getAppCatalog: ', JSON.stringify(err));\r
-                                                                       _this.isLoading = false;\r
-                                                                       $scope.getAppCatalogIsDone = true;\r
-                                                 });\r
-                                               });\r
-\r
-                                                       // applicationsService.getUserApps()\r
-\r
-\r
-               this.gridsterOpts = {\r
-                       columns : 12,\r
-                       colWidth : 95,\r
-                       rowHeight : 95,\r
-                       margins : [ 20, 20 ],\r
-                       outerMargin : true,\r
-                       pushing : true,\r
-                       floating : true,\r
-                       swapping : true,\r
-               };\r
-\r
-               if (getParameterByName('noUserError') != null) {\r
-                       if (getParameterByName('noUserError') == "Show") {\r
-                               $("#errorInfo").show();\r
-                       }\r
-\r
-               }\r
-               \r
-               init();\r
-       };\r
-\r
-       CatalogCtrl.$inject = [ 'conf', 'catalogService', 'confirmBoxService', 'ExternalRequestAccessService', '$log',\r
-                       '$window', 'userProfileService', 'applicationsService', '$scope', \r
-                       '$state', '$timeout', '$interval', '$modal', 'ngDialog' ];\r
-       angular.module('ecompApp').controller('CatalogCtrl', CatalogCtrl);\r
-})();\r
-\r
-function getParameterByName(name, url) {\r
-       if (!url)\r
-               url = window.location.href;\r
-       name = name.replace(/[\[\]]/g, "\\$&");\r
-       var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex\r
-                       .exec(url);\r
-       if (!results)\r
-               return '';\r
-       if (!results[2])\r
-               return '';\r
-       return results[2].replace(/\+/g, " ");\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 _classCallCheck(instance, Constructor) {
+       if (!(instance instanceof Constructor)) {
+               throw new TypeError('Cannot call a class as a function');
+       }
+}
+
+(function() {
+       var HTTP_PROTOCOL_RGX = /https?:\/\//;
+
+       var CatalogCtrl = function CatalogCtrl(conf, catalogService, confirmBoxService, ExternalRequestAccessService,
+                       $log, $window, userProfileService, applicationsService, $scope, $state, 
+                       $timeout, $interval, $modal, ngDialog) {
+
+               this.conf = conf;       
+               var _this = this;
+               var externalRequest = true;
+               _classCallCheck(this, CatalogCtrl);
+
+               // activate spinner
+               this.isLoading = true;
+               $scope.getAppCatalogIsDone = false;
+               $scope.radioValue = 'All';
+               $scope.$watch('radioValue', function(newValue, oldValue) {
+                       var appCatalog = $scope.appCatalog;
+                       $scope.appCatalog = [];
+                       $scope.appCatalog = appCatalog;
+
+                       
+               });
+               
+               this.catalogService = catalogService;
+               this.userProfileService = userProfileService;
+               this.applicationsService = applicationsService;
+               var resultAccessValue = null;
+               $scope.demoNum = 1;
+               $scope.appRoles = [];
+               
+        let init = () => {
+            getExternalAccess();
+        };
+        
+        var getExternalAccess = () => {
+               ExternalRequestAccessService.getExternalRequestAccessServiceInfo().then(
+                               function(property) {
+               resultAccessValue = property.accessValue;
+                                       // $log.info(res);
+                               }).catch(err => {
+                        $log.error('CatalogCtrl: failed getExternalRequestAccessServiceInfo: ' + JSON.stringify(err));
+                    });    
+        };
+        
+
+       
+               $scope.applyPresentationDetailsToAppsCatalog = function(res, value) {
+                       
+                       _this.apps = res;
+                       var rowNo = 0;
+
+                       // defend against error string result -
+                       // a huge list that should never happen.
+                       var maxItems = 333;
+                       if (_this.apps.length < maxItems)
+                               maxItems = _this.apps.length;
+                       for (var i = 0; i < maxItems; i++) {                                                                                            
+                               let imgLnk = '';
+                               if (_this.apps[i].imageUrl)
+                                       imgLnk = conf.api.appThumbnail.replace(':appId', _this.apps[i].id);
+                               //$log.debug('CatalogCtlr::applyPresn: imgLink = ' + imgLnk);
+                               $scope.appCatalog[i] = {
+                                       sizeX : 2,
+                                       sizeY : 2,
+                                       id : _this.apps[i].id,
+                                       headerText : _this.apps[i].name,
+                                       mlAppName: _this.apps[i].mlAppName,
+                                       imageLink : imgLnk,
+                                       restricted : _this.apps[i].restricted,  
+                                       select : _this.apps[i].select,
+                                       access : _this.apps[i].access,
+                                       pending: _this.apps[i].pending,
+                                       mlproperty: value
+                               };
+                       }
+                       //$log.debug('CatalogCtrl: getAppCatalog count : '
+                       //                              + $scope.appCatalog.length);
+                       _this.isLoading = false;
+                       $scope.getAppCatalogIsDone = true;
+               }
+               
+        let getAppsCatalog = () => {
+            catalogService.getAppCatalog()
+                .then(appsList => {
+                       $scope.applyPresentationDetailsToAppsCatalog(appsList);
+                }).catch(err => {
+                    confirmBoxService.showInformation('There was a problem retrieving the Applications. ' +
+                        'Please try again later. Error Status: '+ err.status).then(isConfirmed => {});
+                    $log.error('CatalogCtrl:openAddRoleModal: Error: ', err);
+                });
+        };
+        
+        this.openAddRoleModal = (item) => { 
+               let data = null;
+
+            if((!item.restricted) && (item.mlproperty)){
+                data = {
+                    dialogState: 2,
+                    selectedUser:{
+                        attuid: $scope.attuid,
+                        firstName: $scope.firstName,
+                        lastName: $scope.lastName,
+                        headerText: item.headerText,
+                        haloAppName : item.mlAppName,
+                       item: item,
+                       extReqValue : externalRequest
+                        
+                    }
+                }
+            ngDialog.open({
+                templateUrl: 'app/views/catalog/add-catalog-dialogs/new-catalog.modal.html',
+                controller: 'NewCatalogModalCtrl',
+                controllerAs: 'userInfo',
+                data: data
+            }).closePromise.then(needUpdate => {
+                if(needUpdate.value === true){
+                       getAppsCatalog();
+                }
+               
+            });
+          }
+        };
+
+               // Run this function when user clicks on checkbox.
+               this.storeSelection = function(item) {
+                       // $log.debug('CatalogCtrl:storeSelection: item.id is ' + item.id + ', select is ' + item.select);
+                       var pendingFlag = false;
+                       
+                       if(item.access) 
+                               pendingFlag = false;
+                       else
+                               pendingFlag =  item.pending;
+                                                       
+                       var appData = { 
+                                       appId   : item.id,
+                                       select  : item.select,
+                                       pending : pendingFlag   // TODO
+                       };
+                       
+                       catalogService.updateManualAppSort(appData).then(
+                                       function(result) {
+                                               // $log.debug('CatalogCtrl:storeSelection result is ', result);
+                                       })['catch'](function(err) {
+                                               $log.error('CatalogCtrl:storeSelection: exception: ', err);
+                                       });
+                       catalogService.updateAppCatalog(appData).then(
+                               function(result) {
+                                       // $log.debug('CatalogCtrl:storeSelection result is ', result);
+                               })['catch'](function(err) {
+                                       $log.error('CatalogCtrl:storeSelection: exception: ', err);
+                               });
+               };
+               
+               userProfileService
+                               .getUserProfile()
+                               .then(
+                                               function(profile) {
+                                                       $scope.attuid = profile.orgUserId;
+                                                       $scope.firstName = profile.firstName;
+                                                       $scope.lastName = profile.lastName;
+                                                       $scope.appCatalog = [];
+                                                       
+                                                       catalogService.getAppCatalog().then(
+                                                                                       function(res) { 
+                                                                       $scope.applyPresentationDetailsToAppsCatalog(res, resultAccessValue);
+                                                                                       })['catch'](function(err) {
+                                                                       $log.error('CatalogCtrl: failed getAppCatalog: ', JSON.stringify(err));
+                                                                       _this.isLoading = false;
+                                                                       $scope.getAppCatalogIsDone = true;
+                                                 });
+                                               });
+
+                                                       // applicationsService.getUserApps()
+
+
+               this.gridsterOpts = {
+                       columns : 12,
+                       colWidth : 95,
+                       rowHeight : 95,
+                       margins : [ 20, 20 ],
+                       outerMargin : true,
+                       pushing : true,
+                       floating : true,
+                       swapping : true,
+                       resizable: {
+                               enabled: false,
+                       },
+               };
+
+               if (getParameterByName('noUserError') != null) {
+                       if (getParameterByName('noUserError') == "Show") {
+                               $("#errorInfo").show();
+                       }
+
+               }
+               
+               init();
+       };
+
+       CatalogCtrl.$inject = [ 'conf', 'catalogService', 'confirmBoxService', 'ExternalRequestAccessService', '$log',
+                       '$window', 'userProfileService', 'applicationsService', '$scope', 
+                       '$state', '$timeout', '$interval', '$modal', 'ngDialog' ];
+       angular.module('ecompApp').controller('CatalogCtrl', CatalogCtrl);
+})();
+
+function getParameterByName(name, url) {
+       if (!url)
+               url = window.location.href;
+       name = name.replace(/[\[\]]/g, "\\$&");
+       var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex
+                       .exec(url);
+       if (!results)
+               return '';
+       if (!results[2])
+               return '';
+       return results[2].replace(/\+/g, " ");
+}