nexus site path corrected
[portal.git] / ecomp-portal-FE / client / app / views / catalog / catalog.controller.js
1 /*-
2  * ================================================================================
3  * eCOMP Portal
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ================================================================================
19  */
20
21 'use strict';
22
23 function _classCallCheck(instance, Constructor) {
24         if (!(instance instanceof Constructor)) {
25                 throw new TypeError('Cannot call a class as a function');
26         }
27 }
28
29 (function() {
30         var HTTP_PROTOCOL_RGX = /https?:\/\//;
31
32         var CatalogCtrl = function CatalogCtrl(catalogService, confirmBoxService, 
33                         $log, $window, userProfileService, $scope, $timeout, $interval,
34                         $modal, ngDialog) {
35
36                 var _this = this;
37
38                 _classCallCheck(this, CatalogCtrl);
39
40                 // activate spinner
41                 this.isLoading = true;
42                 $scope.getAppCatalogIsDone = false;
43                 $scope.radioValue = 'All';
44                 $scope.$watch('radioValue', function(newValue, oldValue) {
45                         var appCatalog = $scope.appCatalog;
46                         $scope.appCatalog = [];
47                         $scope.appCatalog = appCatalog;
48
49                         
50                 });
51                 
52                 this.catalogService = catalogService;
53                 this.userProfileService = userProfileService;
54                 $scope.demoNum = 1;
55
56                 this.getAccess = function(item) {
57                         if(!item.access)
58                                 confirmBoxService.showDynamicInformation(item,
59                                         'app/views/catalog/information-box.tpl.html','CatalogConfirmationBoxCtrl'
60                                 ).then(isConfirmed => {});
61                 };
62                 
63                 // Run this function when user clicks on checkbox.
64                 this.storeSelection = function(item) {
65                         // $log.debug('CatalogCtrl:storeSelection: item.id is ' + item.id + ', select is ' + item.select);
66                         var pendingFlag = false;
67                         
68                         if(item.access) 
69                                 pendingFlag = false;
70                         else
71                                 pendingFlag =  item.pending;
72                                 
73                         
74                         
75                         
76                         var appData = { 
77                                         appId   : item.id,
78                                         select  : item.select,
79                                         pending : pendingFlag   // TODO
80                         };
81                         catalogService.updateAppCatalog(appData).then(
82                                 function(result) {
83                                         // $log.debug('CatalogCtrl:storeSelection result is ', result);
84                                 })['catch'](function(err) {
85                                         $log.error('CatalogCtrl:storeSelection: exception: ', err);
86                                 });
87                 };
88                 
89                 userProfileService
90                                 .getUserProfile()
91                                 .then(
92                                                 function(profile) {
93                                                         $scope.attuid = profile.attuid;
94                                                         $scope.appCatalog = [];
95
96                                                         // applicationsService.getUserApps()
97                                                         catalogService
98                                                                         .getAppCatalog()
99                                                                         .then(
100                                                                                         function(res) {
101                                                                                                 // $log.info(res);
102                                                                                                 _this.apps = res;
103                                                                                                 var rowNo = 0;
104                                                                                                 for (var i = 0; i < _this.apps.length; i++) {
105                                                                                                         $scope.appCatalog[i] = {
106                                                                                                                 sizeX : 2,
107                                                                                                                 sizeY : 2,
108                                                                                                                 id : _this.apps[i].id,
109                                                                                                                 headerText : _this.apps[i].name,
110                                                                                                                 imageLink : _this.apps[i].thumbnail
111                                                                                                                                 || _this.apps[i].imageUrl,
112                                                                                                                 url : _this.apps[i].url,
113                                                                                                                 restricted : _this.apps[i].restricted,  
114                                                                                                                 select : (_this.apps[i].select || (_this.apps[i].access && _this.apps[i].pending)), 
115                                                                                                                 access : _this.apps[i].access,
116                                                                                                                 pending: _this.apps[i].pending
117                                                                                                         };
118                                                                                                 }
119                                                                                                 //$log.debug('CatalogCtrl: getAppCatalog count : '
120                                                                                                 //                              + $scope.appCatalog.length);
121                                                                                                 _this.isLoading = false;
122                                                                                                 $scope.getAppCatalogIsDone = true;
123                                                                                         })['catch'](function(err) {
124                                                                 $log.error('CatalogCtrl: failed to get app list: ', err);
125                                                                 _this.isLoading = false;
126                                                                 $scope.getAppCatalogIsDone = true;
127                                                         });
128                                                 });
129
130                 this.gridsterOpts = {
131                         columns : 12,
132                         colWidth : 95,
133                         rowHeight : 95,
134                         margins : [ 20, 20 ],
135                         outerMargin : true,
136                         pushing : true,
137                         floating : true,
138                         swapping : true,
139                 };
140
141                 if (getParameterByName('noUserError') != null) {
142                         if (getParameterByName('noUserError') == "Show") {
143                                 $("#errorInfo").show();
144                         }
145
146                 }
147         };
148
149         CatalogCtrl.$inject = [ 'catalogService', 'confirmBoxService', '$log',
150                         '$window', 'userProfileService', '$scope', '$timeout', '$interval',
151                         '$modal', 'ngDialog' ];
152         angular.module('ecompApp').controller('CatalogCtrl', CatalogCtrl);
153 })();
154
155 function getParameterByName(name, url) {
156         if (!url)
157                 url = window.location.href;
158         name = name.replace(/[\[\]]/g, "\\$&");
159         var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex
160                         .exec(url);
161         if (!results)
162                 return '';
163         if (!results[2])
164                 return '';
165         return results[2].replace(/\+/g, " ");
166 }