2 * ================================================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ================================================================================
22 function _classCallCheck(instance, Constructor) {
23 if (!(instance instanceof Constructor)) {
24 throw new TypeError('Cannot call a class as a function');
29 var HTTP_PROTOCOL_RGX = /https?:\/\//;
31 var CatalogCtrl = function CatalogCtrl(conf, catalogService, confirmBoxService, ExternalRequestAccessService,
32 $log, $window, userProfileService, applicationsService, $scope, $state,
33 $timeout, $interval, $modal, ngDialog) {
37 var externalRequest = true;
38 _classCallCheck(this, CatalogCtrl);
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;
52 this.catalogService = catalogService;
53 this.userProfileService = userProfileService;
54 this.applicationsService = applicationsService;
55 var resultAccessValue = null;
63 this.getAccess = function(item) {
65 confirmBoxService.showDynamicInformation(item,
66 'app/views/catalog/information-box.tpl.html','CatalogConfirmationBoxCtrl'
67 ).then(isConfirmed => {});
70 var getExternalAccess = () => {
71 ExternalRequestAccessService.getExternalRequestAccessServiceInfo().then(
73 resultAccessValue = property.accessValue;
76 $log.error('CatalogCtrl: failed getExternalRequestAccessServiceInfo: ' + JSON.stringify(err));
82 $scope.applyPresentationDetailsToAppsCatalog = function(res, value) {
87 // defend against error string result -
88 // a huge list that should never happen.
90 if (_this.apps.length < maxItems)
91 maxItems = _this.apps.length;
92 for (var i = 0; i < maxItems; i++) {
94 if (_this.apps[i].imageUrl)
95 imgLnk = conf.api.appThumbnail.replace(':appId', _this.apps[i].id);
96 //$log.debug('CatalogCtlr::applyPresn: imgLink = ' + imgLnk);
97 $scope.appCatalog[i] = {
100 id : _this.apps[i].id,
101 headerText : _this.apps[i].name,
102 mlAppName: _this.apps[i].mlAppName,
104 restricted : _this.apps[i].restricted,
105 select : _this.apps[i].select,
106 access : _this.apps[i].access,
107 pending: _this.apps[i].pending,
111 //$log.debug('CatalogCtrl: getAppCatalog count : '
112 // + $scope.appCatalog.length);
113 _this.isLoading = false;
114 $scope.getAppCatalogIsDone = true;
117 let getAppsCatalog = () => {
118 catalogService.getAppCatalog()
120 $scope.applyPresentationDetailsToAppsCatalog(appsList);
122 confirmBoxService.showInformation('There was a problem retrieving the Applications. ' +
123 'Please try again later. Error Status: '+ err.status).then(isConfirmed => {});
124 $log.error('CatalogCtrl:openAddRoleModal: Error: ', err);
128 this.openAddRoleModal = (item) => {
131 if((!item.restricted) && (item.mlproperty)){
135 orgUserId: $scope.orgUserId,
136 firstName: $scope.firstName,
137 lastName: $scope.lastName,
138 headerText: item.headerText,
139 haloAppName : item.mlAppName,
145 templateUrl: 'app/views/catalog/request-access-catalog-dialogs/request-access-catalog.modal.html',
146 controller: 'ExternalRequestAccessCtrl',
147 controllerAs: 'userInfo',
149 }).closePromise.then(needUpdate => {
150 if(needUpdate.value === true){
158 // Run this function when user clicks on checkbox.
159 this.storeSelection = function(item) {
160 // $log.debug('CatalogCtrl:storeSelection: item.id is ' + item.id + ', select is ' + item.select);
161 var pendingFlag = false;
166 pendingFlag = item.pending;
170 select : item.select,
171 pending : pendingFlag // TODO
174 catalogService.updateManualAppSort(appData).then(
176 // $log.debug('CatalogCtrl:storeSelection result is ', result);
177 })['catch'](function(err) {
178 $log.error('CatalogCtrl:storeSelection: exception: ', err);
180 catalogService.updateAppCatalog(appData).then(
182 // $log.debug('CatalogCtrl:storeSelection result is ', result);
183 })['catch'](function(err) {
184 $log.error('CatalogCtrl:storeSelection: exception: ', err);
192 $scope.orgUserId = profile.orgUserId;
193 $scope.firstName = profile.firstName;
194 $scope.lastName = profile.lastName;
195 $scope.appCatalog = [];
197 catalogService.getAppCatalog().then(
199 $scope.applyPresentationDetailsToAppsCatalog(res, resultAccessValue);
200 })['catch'](function(err) {
201 $log.error('CatalogCtrl: failed getAppCatalog: ', JSON.stringify(err));
202 _this.isLoading = false;
203 $scope.getAppCatalogIsDone = true;
207 // applicationsService.getUserApps()
210 this.gridsterOpts = {
214 margins : [ 20, 20 ],
224 if (getParameterByName('noUserError') != null) {
225 if (getParameterByName('noUserError') == "Show") {
226 $("#errorInfo").show();
234 CatalogCtrl.$inject = [ 'conf', 'catalogService', 'confirmBoxService', 'ExternalRequestAccessService', '$log',
235 '$window', 'userProfileService', 'applicationsService', '$scope',
236 '$state', '$timeout', '$interval', '$modal', 'ngDialog' ];
237 angular.module('ecompApp').controller('CatalogCtrl', CatalogCtrl);
240 function getParameterByName(name, url) {
242 url = window.location.href;
243 name = name.replace(/[\[\]]/g, "\\$&");
244 var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex
250 return results[2].replace(/\+/g, " ");