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 const HTTP_PROTOCOL_RGX = /https?:\/\//;
23 class ApplicationsHomeCtrl {
24 constructor(applicationsService, $log, $window, userProfileService, $scope,$cookies, utilsService) {
26 this.isLoading = true;
27 $scope.getUserAppsIsDone = false;
28 this.userProfileService = userProfileService;
29 //get all user's applications on init
30 $scope.buildNumber = "OpenECOMP Portal Version: 1.0.0"
32 userProfileService.getUserProfile()
34 $log.info('ApplicationsHomeCtrl::getUserProfile', profile);
35 $scope.userId = profile.orgUserId;
36 //$scope.appsViewData = ['notempty']; // initialize with length != 0
37 $scope.appsViewData = [];
40 //redirect to login.htm, if the EPService cookie is missing and logged in user is not a guest.
41 if (!$cookies.get('EPService') && !profile.guestSession) {
42 this.isLoading = false;
44 myHostName = location.host;
45 $log.info("EPService cookie is missing, so attempting to redirecting to login page.");
46 if (utilsService.isRunningInLocalDevEnv()) {
47 $log.info("Portal is running in local development and redirecting to 'http://localhost:8080/ecompportal/login.htm'.");
48 $window.location.href = "http://localhost:8080/ecompportal/login.htm";
50 $log.info("Redirecting to 'login.htm'.");
51 $window.location.href = "login.htm";
55 applicationsService.getUserApps()
57 $log.info('ApplicationsHomeCtrl::getUserApps: ', res);
60 for (let i = 0; i < this.apps.length; i++) {
61 $scope.appsView[i] = {
70 $scope.appsView[i].headerText = this.apps[i].name;
71 $scope.appsView[i].subHeaderText = this.apps[i].notes;
72 $scope.appsView[i].imageLink = this.apps[i].thumbnail || this.apps[i].imageUrl;
73 $scope.appsView[i].order = this.apps[i].order;
74 $scope.appsView[i].url = this.apps[i].url;
75 $scope.appsView[i].restrictedApp = this.apps[i].restrictedApp;
77 $log.info('ApplicationsHomeCtrl::getUserApps: apps count : ' + $scope.appsView.length);
79 if ($cookies.getObject($scope.userId+'_apps') == undefined || $cookies.getObject($scope.userId+'_apps') == null || $cookies.getObject($scope.userId+'_apps').length == 0) {
80 if (($scope.appsView != undefined) && ($scope.appsView != null) && ($scope.appsView.length > 0)){
81 $scope.appsViewData = $scope.appsView;
82 $cookies.putObject($scope.userId + '_apps', $scope.appsView);
86 this.listChanged = false;
87 this.appsListFromCookie = $cookies.getObject($scope.userId+'_apps');
88 this.finalAppsList = [];
90 // If an app is still valid for this user from backend(appsView) and
91 // it was in the cookie already, put it in the list in the same order
92 // it was in within the cookie.
95 for (let i = 0; i < this.appsListFromCookie.length; i++) {
96 this.foundAppInListFromBackend = false;
97 for (let j = 0; j < $scope.appsView.length; j++) {
98 if (this.appsListFromCookie[i].url == $scope.appsView[j].url) {
99 this.finalAppsList[finalCount] = {
108 this.finalAppsList[finalCount].headerText = this.appsListFromCookie[i].headerText;
109 this.finalAppsList[finalCount].subHeaderText = this.appsListFromCookie[i].subHeaderText;
110 this.finalAppsList[finalCount].imageLink = this.appsListFromCookie[i].imageLink;
111 this.finalAppsList[finalCount].order = this.appsListFromCookie[i].order;
112 this.finalAppsList[finalCount].url = this.appsListFromCookie[i].url;
113 this.finalAppsList[finalCount].restrictedApp = this.appsListFromCookie[i].restrictedApp;
115 this.foundAppInListFromBackend = true;
119 if (this.foundAppInListFromBackend == false) {
120 this.listChanged = true;
125 // Fill in the rest of the list with the Apps retrieved from the backend that we did not already add. There could have been
126 // new Apps configured for the user that are not in the cookie.
128 for (let i = 0; i < $scope.appsView.length; i++) {
130 for (let j = 0; j < this.finalAppsList.length; j++) {
131 if ($scope.appsView[i].url == this.finalAppsList[j].url) {
137 if (this.found == false) {
138 this.finalAppsList[finalCount] = {
147 this.finalAppsList[finalCount].headerText = $scope.appsView[i].headerText;
148 this.finalAppsList[finalCount].subHeaderText = $scope.appsView[i].subHeaderText;
149 this.finalAppsList[finalCount].imageLink = $scope.appsView[i].imageLink;
150 this.finalAppsList[finalCount].order = $scope.appsView[i].order;
151 this.finalAppsList[finalCount].url = $scope.appsView[i].url;
152 this.finalAppsList[finalCount].restrictedApp = $scope.appsView[i].restrictedApp;
154 this.listChanged = true;
158 if ((this.finalAppsList != undefined) && (this.finalAppsList != null) && (this.finalAppsList.length > 0)) {
159 if (this.listChanged) {
160 $scope.appsViewData = this.finalAppsList;
161 $cookies.putObject($scope.userId + '_apps', this.finalAppsList);
163 $scope.appsViewData = $cookies.getObject($scope.userId+'_apps');
166 this.isLoading = false;
167 $scope.getUserAppsIsDone = true;
170 $log.error('oh no! couldnt get applications list...', err);
171 this.isLoading = false;
172 $scope.getUserAppsIsDone = true;
177 this.gridsterOpts = {
188 $cookies.putObject($scope.userId + '_apps', $scope.appsViewData);
193 //navigate to application url in new tab
194 this.goToPortal = (item) => {
195 $log.info("goToPortal called with item: " + item);
197 let restrictedApp = item.restrictedApp;
199 $log.info('No url found for this application, doing nothing..');
202 if (!HTTP_PROTOCOL_RGX.test(url)) {
203 url = 'http://' + url;
206 $window.open(url, '_blank');
208 var tabContent = { id: new Date(), title: item.headerText, url:item.url.split('#')[0] + '?' + (new Date).getTime() + "#" + item.url.split('#')[1]};
209 $cookies.putObject('addTab', tabContent );
214 // userProfileService.getUserProfile()
216 // if (profile.roles.indexOf('superAdmin') > -1) {
217 // $scope.buildNumber = "ECOMP Portal Version: 1610.0.2058"
220 // $log.error('Applications Home:: getUserProfile() failed: ' + err);
223 // $log.error('Applications Home:: getUserProfile() failed: ' + err);
225 if(getParameterByName('noUserError')!=null){
226 if(getParameterByName('noUserError')=="Show"){
227 $("#errorInfo").show();
232 ApplicationsHomeCtrl.$inject = ['applicationsService', '$log', '$window', 'userProfileService', '$scope','$cookies', 'utilsService'];
233 angular.module('ecompApp').controller('ApplicationsHomeCtrl', ApplicationsHomeCtrl);
236 function getParameterByName(name, url) {
237 if (!url) url = window.location.href;
238 name = name.replace(/[\[\]]/g, "\\$&");
239 var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
240 results = regex.exec(url);
241 if (!results) return '';
242 if (!results[2]) return '';
243 return (results[2].replace(/\+/g, " "));