[PORTAL-16 PORTAL-18] Widget ms; staging
[portal.git] / ecomp-portal-FE-common / client / app / views / dashboard / dashboard.controller.js
index 5a763e2..87558fa 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 DashboardCtrl = function DashboardCtrl(conf, applicationsService, $log,\r
-                       $window, userProfileService, $scope, $cookies, $timeout, $interval, \r
-                       $modal, $state, beReaderService, dashboardService, confirmBoxService, \r
-                       auditLogService,ngDialog, $compile, widgetsCatalogService) {\r
-\r
-               this.conf = conf;       \r
-               var _this = this;\r
-\r
-               _classCallCheck(this, DashboardCtrl);\r
-\r
-               // activate spinner\r
-               this.isLoading = true;\r
-               this.isCommError = false;\r
-               $scope.getUserAppsIsDone = false;\r
-               this.userProfileService = userProfileService;\r
-               $scope.demoNum = 1;\r
-               $scope.event_content_show = false;\r
-               $scope.widgetData = [];\r
-               $scope.activateThis = function(ele){\r
-                        $compile(ele.contents())($scope);\r
-                        $scope.$apply();\r
-               };\r
-\r
-               $scope.editWidgetModalPopup = function(availableData, resourceType) {\r
-                       $scope.editData = JSON.stringify(availableData);\r
-                       $scope.availableDataTemp = $scope.availableData;\r
-                       ngDialog.open({\r
-                                       templateUrl : 'app/views/dashboard/dashboard-widget-manage.html',\r
-                                       controller : 'CommonWidgetController',\r
-                                       resolve : {\r
-                                               message : function message() {\r
-                                                       var message = {\r
-                                                               type : resourceType,\r
-                                                               availableData : $scope.editData\r
-                                                       };\r
-                                                       return message;\r
-                                               }\r
-                                       }\r
-                               }).closePromise.then(needUpdate => {    \r
-                                       if(resourceType=='NEWS'){\r
-                                               $scope.updateNews();\r
-                                       }else if(resourceType=='EVENTS'){\r
-                                               $scope.updateEvents();\r
-                                       }else if(resourceType=='IMPORTANTRESOURCES'){\r
-                                               $scope.updateImportRes();\r
-                                       }\r
-                 });           \r
-               };\r
-               \r
-               $scope.editWidgetParameters = function(widgetId) {\r
-                       let data = {\r
-               widgetId: widgetId\r
-            }\r
-                       ngDialog.open({\r
-                                       templateUrl : 'app/views/dashboard/dashboard-widget-parameter-manage.html',\r
-                                       controller : 'WidgetParameterController',\r
-                                       data: data\r
-                               }).closePromise.then(needUpdate => {    \r
-                                               \r
-                 });           \r
-               };\r
-               \r
-               $scope.sort_options = [        \r
-                                      {index: 0, value: 'N', title: 'Name'},\r
-                                      {index: 1, value: 'L', title: 'Last used'},\r
-                                      {index: 2, value: 'F', title: 'Most used'},\r
-                                      {index: 3, value: 'M', title: 'Manual'}                                 \r
-                                  ]; \r
-               \r
-               $scope.selectedSortTypeChanged = function(userAppSortTypePref) {\r
-                       $scope.appsViewData = [];\r
-                       $scope.appsView = [];\r
-                       \r
-                       $scope.sort_type = userAppSortTypePref;\r
-                       \r
-                       applicationsService\r
-                       .getAppsOrderBySortPref(userAppSortTypePref)\r
-                               .then(function(res) {\r
-                                       _this.apps = res;                       \r
-                                       $scope.applyPresentationDetailsToApps(_this.apps);                              \r
-                       })      \r
-                       applicationsService\r
-                       .saveAppsSortTypePreference($scope.selectedSortType)\r
-                               .then(function(res) {\r
-                                       // Nothing to do\r
-                               })\r
-               \r
-               }\r
-               $scope.$watch('selectedSortType.value', (newVal, oldVal) => {\r
-                       for(var i=0;i<$scope.sort_options.length;i++){\r
-                       if($scope.sort_options[i].value==newVal){\r
-                       $scope.selectedSortType=angular.copy($scope.sort_options[i]);;\r
-                       }\r
-                       }\r
-                       });\r
-               \r
-               $scope.restoreSortSelected = function(){\r
-                       confirmBoxService.confirm("Restore the default size and position of all widgets?").then(\r
-                               function(confirmed){\r
-                                       var checkConfirm = confirmed;\r
-                                       if(checkConfirm === true){\r
-                                       applicationsService\r
-                                       .delWidgetsSortPref($scope.widgetsViewData).then(function(){\r
-                                               $state.reload();\r
-                                       });\r
-                                       }\r
-                               });\r
-               /*      if(confirm('Restore the default size and position of all widgets?') == true)\r
-                               {\r
-                       applicationsService\r
-                       .delWidgetsSortPref($scope.widgetsViewData).then(function(){\r
-                               $state.reload();\r
-                       })\r
-                               }*/\r
-                               \r
-               }\r
-               \r
-               $scope.applyPresentationDetailsToApps = function(appsReturned) {\r
-                       var rowNo = 0;\r
-                       for (var i = 0; i < _this.apps.length; i++) {\r
-                               $scope.appsView[i] = {\r
-                                       sizeX : 1,\r
-                                       sizeY : 1,\r
-                                       headerText : '',\r
-                                       subHeaderText : '',\r
-                                       imageLink : '',\r
-                                       order : '',\r
-                                       url : '',\r
-                                       appid: '',\r
-                               };\r
-                               $scope.appsView[i].headerText = appsReturned[i].name;\r
-                               $scope.appsView[i].subHeaderText = appsReturned[i].notes;\r
-                               let imgLnk = '';\r
-                               if (appsReturned[i].imageUrl)\r
-                                       imgLnk = conf.api.appThumbnail.replace(':appId', appsReturned[i].id);\r
-                               //$log.debug('DashboardCtlr::applyPresn: imgLink = ' + imgLnk);\r
-                               $scope.appsView[i].imageLink = imgLnk;\r
-                               $scope.appsView[i].order = appsReturned[i].order;\r
-                               $scope.appsView[i].url = appsReturned[i].url;\r
-                               $scope.appsView[i].restrictedApp = appsReturned[i].restrictedApp;\r
-                               $scope.appsView[i].appid = appsReturned[i].id;\r
-                       }\r
-                       $scope.appsView[_this.apps.length] = {\r
-                                       addRemoveApps : true,\r
-                                       sizeX : 1,\r
-                                       sizeY : 1,\r
-                                       headerText : 'Add/Remove Applications',\r
-                                       subHeaderText : '',\r
-                                       imageLink : 'assets/images/cloud.png',\r
-                                       order : '',\r
-                                       restrictedApp : false,\r
-                                       url : '',\r
-                       };\r
-                       if($scope.appsView.length>6){                                                                                                   \r
-                               $(".dashboard-boarder").css({\r
-                                       "height" : "400px"\r
-                               });\r
-                       }else{\r
-                               $(".dashboard-boarder").css({\r
-                                       "height" : "210px"\r
-                               });\r
-                       }\r
-                       \r
-                       if ($scope.appsView != undefined\r
-                                       && $scope.appsView != null\r
-                                       && $scope.appsView.length > 0) {\r
-                               $scope.appsViewData = $scope.appsView;\r
-                       }\r
-               }\r
-               \r
-$scope.widgetsView = [];\r
-               \r
-               $scope.applyPresentationDetailsToWidgets = function(widgetsReturned){\r
-                var rowNo = 0;\r
-                for (var i = 0; i < widgetsReturned.length; i++) {\r
-                               $scope.widgetsView[i] = {\r
-                                       sizeX : '',\r
-                                       sizeY :'',\r
-                                       headerText:'',\r
-                                       widgetText:'',\r
-                                       widgetIdentifier : '',\r
-                                       url : '',\r
-                                       widgetid: '',\r
-                                       attrb:'',\r
-                                       row:'',\r
-                                       col:'',\r
-                               };\r
-                               $scope.widgetsView[i].widgetid = widgetsReturned[i].id;\r
-                               $scope.widgetsView[i].headerText = widgetsReturned[i].headerName;\r
-                               $scope.widgetsView[i].widgetText = widgetsReturned[i].name;\r
-                               \r
-                               if(widgetsReturned[i].headerName.toLowerCase() === 'news'){\r
-                                       $scope.widgetsView[i].widgetIdentifier = 'NEWS';\r
-                               }\r
-                               else\r
-                               if(widgetsReturned[i].headerName.toLowerCase() === 'resources'){\r
-                                       $scope.widgetsView[i].widgetIdentifier = 'IMPORTANTRESOURCES';\r
-                               }\r
-                               else\r
-                               if(widgetsReturned[i].headerName.toLowerCase() === 'events'){\r
-                                       $scope.widgetsView[i].widgetIdentifier = 'EVENTS';\r
-                               }\r
-\r
-                               $scope.widgetsView[i].url = widgetsReturned[i].url;\r
-                               $scope.widgetsView[i].attrb = widgetsReturned[i].attrs;\r
-                               if(widgetsReturned[i].width === null){\r
-                                       $scope.widgetsView[i].sizeX = 2;\r
-                               }else{\r
-                                       $scope.widgetsView[i].sizeX = widgetsReturned[i].width;\r
-                               }\r
-                               if(widgetsReturned[i].height === null){\r
-                                       $scope.widgetsView[i].sizeY = 2;\r
-                               }else{\r
-                                       $scope.widgetsView[i].sizeY = widgetsReturned[i].height;\r
-                               }\r
-                               $scope.widgetsView[i].row = widgetsReturned[i].x;\r
-                               $scope.widgetsView[i].col = widgetsReturned[i].y;\r
-                       }\r
-               if ($scope.widgetsView != undefined\r
-                               && $scope.widgetsView != null\r
-                               && $scope.widgetsView.length > 0) {\r
-                       $scope.widgetsViewData = $scope.widgetsView;\r
-               }\r
-               }\r
-\r
-       applicationsService\r
-       .getUserAppsSortTypePreference().then(function(res) {\r
-                       var resJson = {};\r
-                   resJson.value = res;\r
-                       if (resJson.value==="N" || resJson.value==="") {\r
-                               resJson.index = 0;\r
-                               resJson.title = 'Name';\r
-                       }else if (resJson.value==="L") {\r
-                               resJson.index = 1;\r
-                               resJson.title = 'Last used';\r
-                       }else if(resJson.value==="F"){\r
-                               resJson.index = 2;\r
-                               resJson.title = 'Most used';\r
-                       }else {\r
-                               resJson.index = 3;\r
-                               resJson.title = 'Manual';\r
-                       }       \r
-                       $scope.selectedSortType = resJson;\r
-                       $scope.selectedSortTypeChanged(res);\r
-\r
-               \r
-               });\r
-               \r
-       $scope.widgetsList = [];\r
-       \r
-       let getUserWidgets = (loginName) => {\r
-        var conf = this.conf;\r
-                widgetsCatalogService.getUserWidgets(loginName).then(res => {\r
-                        if(!(res instanceof Array)){\r
-                                this.isCommError = true;\r
-                                return;\r
-                        }\r
-                        for(var i = 0; i < res.length; i++){    \r
-                                var widget_id = res[i][0];\r
-                                var widget_name = res[i][1];\r
-                                let url = this.conf.api.widgetCommon + "/" + widget_id + "/framework.js";\r
-                                var header_name = widget_name;\r
-                                if(res[i][7] == 1){\r
-                                       header_name = (widget_name.length > 9) ?widget_name.substring(0, 8) + '...' : widget_name;\r
-                                }\r
-                                if(res[i][4] === "S" || res[i][4] === null ){\r
-                                $scope.widgetsList.push({\r
-                                          id: widget_id,\r
-                                          headerName: header_name,\r
-                                  name: widget_name,\r
-                                  url: url,\r
-                                  attrs: [{attr: 'data-' + res[i][0], value: ''}],\r
-                                  x: res[i][3], \r
-                                  y: res[i][5],\r
-                                  height: res[i][6],\r
-                                  width: res[i][7]\r
-                                });\r
-                                }\r
-                                var script = document\r
-                                        .createElement('script');\r
-                                        script.src = url;\r
-                                        script.async = false;\r
-                                        var entry = document\r
-                                               .getElementsByTagName('script')[0];\r
-                                        entry.parentNode\r
-                                               .insertBefore(script, entry);\r
-                        } \r
-               $scope.applyPresentationDetailsToWidgets($scope.widgetsList);\r
-        }).catch(err => {\r
-            $log.error('WidgetsHomeCtrl::getUserWidgets error: ' + err);\r
-        }).finally(()=> {\r
-                \r
-        });\r
-   };\r
-\r
-      userProfileService.getUserProfile().then(\r
-                       function(profile) {\r
-                               $scope.orgUserId = profile.orgUserId;\r
-                               getUserWidgets($scope.orgUserId);\r
-         });\r
-               \r
-               /* Widget Gridster Section */\r
-               $scope.newsGridsterItem = {\r
-                       sizeX : 1,\r
-                       sizeY : 1,\r
-                       headerText : 'News',\r
-                       subHeaderText : '',\r
-                       imageLink : '',\r
-                       order : '',\r
-                       url : ''\r
-               };\r
-\r
-               $scope.eventsGridsterItem = {\r
-                       sizeX : 1,\r
-                       sizeY : 1,\r
-                       headerText : 'Events',\r
-                       subHeaderText : '',\r
-                       imageLink : '',\r
-                       order : '',\r
-                       url : ''\r
-               };\r
-\r
-               $scope.impoResGridsterItem = {\r
-                       sizeX : 1,\r
-                       sizeY : 1,\r
-                       headerText : 'Resources',\r
-                       subHeaderText : '',\r
-                       imageLink : '',\r
-                       order : '',\r
-                       url : ''\r
-               };\r
-               \r
-               this.gridsterAppOpts = {\r
-                               columns : 6,\r
-                               colWidth : 190,\r
-                               rowHeight : 190,\r
-                               margins : [ 20, 20 ],\r
-                               outerMargin : true,\r
-                               pushing : true,\r
-                               floating : true,\r
-                               swapping : true,\r
-                               resizable: {\r
-                                       enabled: false,\r
-                               },\r
-                               draggable : {\r
-                                       handle:'.icon-content-gridguide',\r
-                                       stop: function stop() { \r
-                                               $scope.defaultSortBy = function() {\r
-                                                       var resJson = {};\r
-                                                       resJson.value = 'M';\r
-                                                       resJson.index = 3;\r
-                                                       resJson.title = 'Manual';\r
-                                                       $scope.selectedSortType = resJson;\r
-                                                       applicationsService.saveAppsSortTypeManual($scope.appsViewData) \r
-                                                       applicationsService.saveAppsSortTypePreference($scope.selectedSortType)\r
-                                               }\r
-                                               $scope.defaultSortBy();                 \r
-                                       }\r
-                               }\r
-                       };\r
-                       \r
-                       this.gridsterWidgetOpts = {\r
-                                       columns : 6,\r
-                                       colWidth : 190,\r
-                                       rowHeight : 190,\r
-                                       margins : [ 20, 20 ],\r
-                                       outerMargin : true,\r
-                                       pushing : true,\r
-                                       floating : true,\r
-                                       swapping : true,\r
-                                       resizable: {\r
-                                               enabled: true,\r
-                                               stop: function stop(event, uiWidget, $element){\r
-                                                       if($element.sizeX == 1)\r
-                                                               $element.headerText = ($element.widgetText.length > 9) ? $element.widgetText.substring(0, 8) + '...' : $element.widgetText;\r
-                                                       if($element.sizeX >= 2)\r
-                                                               $element.headerText = $element.widgetText;\r
-                                                       \r
-                                                       applicationsService\r
-                                                       .saveWidgetsSortManual($scope.widgetsViewData)\r
-                                       \r
-                                               }\r
-                                       },\r
-                                       draggable : {\r
-                                               handle:'.icon-content-gridguide',\r
-                                               stop: function stop(){\r
-                                                       applicationsService\r
-                                                       .saveWidgetsSortManual($scope.widgetsViewData)\r
-                                       \r
-                                               }\r
-                                       }\r
-                       };\r
-               \r
-               this.goToCatalog = function(item) {\r
-                       $state.go('root.appCatalog');\r
-               } \r
-               \r
-               this.goToWidgetCatLog = function(item) {\r
-                       $state.go('root.widgetCatalog');\r
-               } \r
-               \r
-               // navigate to application url in new tab\r
-               this.goToPortal = function(item) {\r
-                       if (!item.url) {\r
-                               $log.error('No URL found for this application, doing nothing!');\r
-                               return;\r
-                       }\r
-                       if (item.restrictedApp) {\r
-                               // Link-based apps open in their own browser tab\r
-                               $window.open(item.url, '_blank');\r
-                       } else {\r
-                               // cache control so browsers load app page every time\r
-                               var ccParam = 'cc=' + new Date().getTime();\r
-                               var urlParts = item.url.split('#');\r
-                               var appUrl = null;\r
-                               if (urlParts.length < 2) {\r
-                                       // no #\r
-                                       let urlLastChar = item.url.charAt(item.url.length - 1);\r
-                                       if (item.url.includes("?"))\r
-                                               appUrl = (urlLastChar === '&' ? item.url + ccParam : item.url + '&' + ccParam);\r
-                                       else \r
-                                               appUrl = item.url + '?' + ccParam;\r
-                               } else {\r
-                                       // has #\r
-                                       let urlLastChar = urlParts[0].charAt(urlParts[0].length - 1);\r
-                                       if (item.url.includes("?"))\r
-                                               appUrl = (urlLastChar === '&' ? urlParts[0] + ccParam + '#' + urlParts[1]  :  urlParts[0] + '&' + ccParam + '#' + urlParts[1]);\r
-                                       else\r
-                                               appUrl = urlParts[0] + '?' + ccParam + "#" + urlParts[1];\r
-                               }\r
-                               // $log.debug('DashboardCtrlr::goToPortal: opening tab with URL\r
-                               // ' + appUrl);\r
-                               var tabContent = {\r
-                                       id: new Date(),\r
-                                       title: item.headerText,\r
-                                       url: appUrl,\r
-                                       appId: item.appId\r
-                               };\r
-                               $cookies.putObject('addTab', tabContent);\r
-                       }\r
-\r
-               };\r
-               \r
-               this.auditLog = function(app) {\r
-                       console.log(app);\r
-                       auditLogService.storeAudit(app.appid,'app',app.url);\r
-               };\r
-               \r
-               if (getParameterByName('noUserError') != null) {\r
-                       if (getParameterByName('noUserError') == "Show") {\r
-                               $("#errorInfo").show();\r
-                       }\r
-               }               \r
-       };\r
-\r
-       DashboardCtrl.$inject = [ 'conf', 'applicationsService', '$log', '$window',\r
-                       'userProfileService', '$scope', '$cookies', '$timeout', '$interval', \r
-                       '$modal',  '$state', 'beReaderService', 'dashboardService', 'confirmBoxService', \r
-                       'auditLogService', 'ngDialog', '$compile', 'widgetsCatalogService' ];\r
-       angular.module('ecompApp').controller('DashboardCtrl', DashboardCtrl);\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 DashboardCtrl = function DashboardCtrl(conf, applicationsService, $log,
+                       $window, userProfileService, $scope, $cookies, $timeout, $interval, 
+                       $modal, $state, beReaderService, dashboardService, confirmBoxService, 
+                       auditLogService,ngDialog, $compile, widgetsCatalogService) {
+
+               this.conf = conf;       
+               var _this = this;
+
+               _classCallCheck(this, DashboardCtrl);
+
+               // activate spinner
+               this.isLoading = true;
+               this.isCommError = false;
+               $scope.getUserAppsIsDone = false;
+               this.userProfileService = userProfileService;
+               $scope.demoNum = 1;
+               $scope.event_content_show = false;
+               $scope.widgetData = [];
+               $scope.activateThis = function(ele){
+                        $compile(ele.contents())($scope);
+                        $scope.$apply();
+               };
+
+               $scope.editWidgetModalPopup = function(availableData, resourceType) {
+                       $scope.editData = JSON.stringify(availableData);
+                       $scope.availableDataTemp = $scope.availableData;
+                       ngDialog.open({
+                                       templateUrl : 'app/views/dashboard/dashboard-widget-manage.html',
+                                       controller : 'CommonWidgetController',
+                                       resolve : {
+                                               message : function message() {
+                                                       var message = {
+                                                               type : resourceType,
+                                                               availableData : $scope.editData
+                                                       };
+                                                       return message;
+                                               }
+                                       }
+                               }).closePromise.then(needUpdate => {    
+                                       if(resourceType=='NEWS'){
+                                               $scope.updateNews();
+                                       }else if(resourceType=='EVENTS'){
+                                               $scope.updateEvents();
+                                       }else if(resourceType=='IMPORTANTRESOURCES'){
+                                               $scope.updateImportRes();
+                                       }
+                 });           
+               };
+               
+               $scope.editWidgetParameters = function(widgetId) {
+                       let data = {
+               widgetId: widgetId
+            }
+                       ngDialog.open({
+                                       templateUrl : 'app/views/dashboard/dashboard-widget-parameter-manage.html',
+                                       controller : 'WidgetParameterController',
+                                       data: data
+                               }).closePromise.then(needUpdate => {    
+                                               
+                 });           
+               };
+               
+               $scope.sort_options = [        
+                                      {index: 0, value: 'N', title: 'Name'},
+                                      {index: 1, value: 'L', title: 'Last used'},
+                                      {index: 2, value: 'F', title: 'Most used'},
+                                      {index: 3, value: 'M', title: 'Manual'}                                 
+                                  ]; 
+               
+               $scope.selectedSortTypeChanged = function(userAppSortTypePref) {
+                       $scope.appsViewData = [];
+                       $scope.appsView = [];
+                       
+                       $scope.sort_type = userAppSortTypePref;
+                       
+                       applicationsService
+                       .getAppsOrderBySortPref(userAppSortTypePref)
+                               .then(function(res) {
+                                       _this.apps = res;                       
+                                       $scope.applyPresentationDetailsToApps(_this.apps);                              
+                       })      
+                       applicationsService
+                       .saveAppsSortTypePreference($scope.selectedSortType)
+                               .then(function(res) {
+                                       // Nothing to do
+                               })
+               
+               }
+               $scope.$watch('selectedSortType.value', (newVal, oldVal) => {
+                       for(var i=0;i<$scope.sort_options.length;i++){
+                       if($scope.sort_options[i].value==newVal){
+                       $scope.selectedSortType=angular.copy($scope.sort_options[i]);;
+                       }
+                       }
+                       });
+               
+               $scope.restoreSortSelected = function(){
+                       confirmBoxService.confirm("Restore the default size and position of all widgets?").then(
+                               function(confirmed){
+                                       var checkConfirm = confirmed;
+                                       if(checkConfirm === true){
+                                       applicationsService
+                                       .delWidgetsSortPref($scope.widgetsViewData).then(function(){
+                                               $state.reload();
+                                       });
+                                       }
+                               });
+               /*      if(confirm('Restore the default size and position of all widgets?') == true)
+                               {
+                       applicationsService
+                       .delWidgetsSortPref($scope.widgetsViewData).then(function(){
+                               $state.reload();
+                       })
+                               }*/
+                               
+               }
+               
+               $scope.applyPresentationDetailsToApps = function(appsReturned) {
+                       var rowNo = 0;
+                       for (var i = 0; i < _this.apps.length; i++) {
+                               $scope.appsView[i] = {
+                                       sizeX : 1,
+                                       sizeY : 1,
+                                       headerText : '',
+                                       subHeaderText : '',
+                                       imageLink : '',
+                                       order : '',
+                                       url : '',
+                                       appid: '',
+                               };
+                               $scope.appsView[i].headerText = appsReturned[i].name;
+                               $scope.appsView[i].subHeaderText = appsReturned[i].notes;
+                               let imgLnk = '';
+                               if (appsReturned[i].imageUrl)
+                                       imgLnk = conf.api.appThumbnail.replace(':appId', appsReturned[i].id);
+                               //$log.debug('DashboardCtlr::applyPresn: imgLink = ' + imgLnk);
+                               $scope.appsView[i].imageLink = imgLnk;
+                               $scope.appsView[i].order = appsReturned[i].order;
+                               $scope.appsView[i].url = appsReturned[i].url;
+                               $scope.appsView[i].restrictedApp = appsReturned[i].restrictedApp;
+                               $scope.appsView[i].appid = appsReturned[i].id;
+                       }
+                       $scope.appsView[_this.apps.length] = {
+                                       addRemoveApps : true,
+                                       sizeX : 1,
+                                       sizeY : 1,
+                                       headerText : 'Add/Remove Applications',
+                                       subHeaderText : '',
+                                       imageLink : 'assets/images/cloud.png',
+                                       order : '',
+                                       restrictedApp : false,
+                                       url : '',
+                       };
+                       if($scope.appsView.length>6){                                                                                                   
+                               $(".dashboard-boarder").css({
+                                       "height" : "400px"
+                               });
+                       }else{
+                               $(".dashboard-boarder").css({
+                                       "height" : "210px"
+                               });
+                       }
+                       
+                       if ($scope.appsView != undefined
+                                       && $scope.appsView != null
+                                       && $scope.appsView.length > 0) {
+                               $scope.appsViewData = $scope.appsView;
+                       }
+               }
+               
+$scope.widgetsView = [];
+               
+               $scope.applyPresentationDetailsToWidgets = function(widgetsReturned){
+                var rowNo = 0;
+                for (var i = 0; i < widgetsReturned.length; i++) {
+                               $scope.widgetsView[i] = {
+                                       sizeX : '',
+                                       sizeY :'',
+                                       headerText:'',
+                                       widgetText:'',
+                                       widgetIdentifier : '',
+                                       url : '',
+                                       widgetid: '',
+                                       attrb:'',
+                                       row:'',
+                                       col:'',
+                               };
+                               $scope.widgetsView[i].widgetid = widgetsReturned[i].id;
+                               $scope.widgetsView[i].headerText = widgetsReturned[i].headerName;
+                               $scope.widgetsView[i].widgetText = widgetsReturned[i].name;
+                               
+                               if(widgetsReturned[i].headerName.toLowerCase() === 'news'){
+                                       $scope.widgetsView[i].widgetIdentifier = 'NEWS';
+                               }
+                               else
+                               if(widgetsReturned[i].headerName.toLowerCase() === 'resources'){
+                                       $scope.widgetsView[i].widgetIdentifier = 'IMPORTANTRESOURCES';
+                               }
+                               else
+                               if(widgetsReturned[i].headerName.toLowerCase() === 'events'){
+                                       $scope.widgetsView[i].widgetIdentifier = 'EVENTS';
+                               }
+
+                               $scope.widgetsView[i].url = widgetsReturned[i].url;
+                               $scope.widgetsView[i].attrb = widgetsReturned[i].attrs;
+                               if(widgetsReturned[i].width === null){
+                                       $scope.widgetsView[i].sizeX = 2;
+                               }else{
+                                       $scope.widgetsView[i].sizeX = widgetsReturned[i].width;
+                               }
+                               if(widgetsReturned[i].height === null){
+                                       $scope.widgetsView[i].sizeY = 2;
+                               }else{
+                                       $scope.widgetsView[i].sizeY = widgetsReturned[i].height;
+                               }
+                               $scope.widgetsView[i].row = widgetsReturned[i].x;
+                               $scope.widgetsView[i].col = widgetsReturned[i].y;
+                       }
+               if ($scope.widgetsView != undefined
+                               && $scope.widgetsView != null
+                               && $scope.widgetsView.length > 0) {
+                       $scope.widgetsViewData = $scope.widgetsView;
+               }
+               }
+
+       applicationsService
+       .getUserAppsSortTypePreference().then(function(res) {
+                       var resJson = {};
+                   resJson.value = res;
+                       if (resJson.value==="N" || resJson.value==="") {
+                               resJson.index = 0;
+                               resJson.title = 'Name';
+                       }else if (resJson.value==="L") {
+                               resJson.index = 1;
+                               resJson.title = 'Last used';
+                       }else if(resJson.value==="F"){
+                               resJson.index = 2;
+                               resJson.title = 'Most used';
+                       }else {
+                               resJson.index = 3;
+                               resJson.title = 'Manual';
+                       }       
+                       $scope.selectedSortType = resJson;
+                       $scope.selectedSortTypeChanged(res);
+
+               
+               });
+               
+       $scope.widgetsList = [];
+       
+       let getUserWidgets = (loginName) => {
+        var conf = this.conf;
+                widgetsCatalogService.getUserWidgets(loginName).then(res => {
+                        if(!(res instanceof Array)){
+                                this.isCommError = true;
+                                return;
+                        }
+                        for(var i = 0; i < res.length; i++){    
+                                var widget_id = res[i][0];
+                                var widget_name = res[i][1];
+                                let url = this.conf.api.widgetCommon + "/" + widget_id + "/framework.js";
+                                var header_name = widget_name;
+                                if(res[i][7] == 1){
+                                       header_name = (widget_name.length > 9) ?widget_name.substring(0, 8) + '...' : widget_name;
+                                }
+                                if(res[i][4] === "S" || res[i][4] === null ){
+                                $scope.widgetsList.push({
+                                          id: widget_id,
+                                          headerName: header_name,
+                                  name: widget_name,
+                                  url: url,
+                                  attrs: [{attr: 'data-' + res[i][0], value: ''}],
+                                  x: res[i][3], 
+                                  y: res[i][5],
+                                  height: res[i][6],
+                                  width: res[i][7]
+                                });
+                                }
+                                var script = document
+                                        .createElement('script');
+                                        script.src = url;
+                                        script.async = false;
+                                        var entry = document
+                                               .getElementsByTagName('script')[0];
+                                        entry.parentNode
+                                               .insertBefore(script, entry);
+                        } 
+               $scope.applyPresentationDetailsToWidgets($scope.widgetsList);
+        }).catch(err => {
+            $log.error('WidgetsHomeCtrl::getUserWidgets error: ' + err);
+        }).finally(()=> {
+                
+        });
+   };
+
+      userProfileService.getUserProfile().then(
+                       function(profile) {
+                               $scope.orgUserId = profile.orgUserId;
+                               getUserWidgets($scope.orgUserId);
+         });
+               
+               /* Widget Gridster Section */
+               $scope.newsGridsterItem = {
+                       sizeX : 1,
+                       sizeY : 1,
+                       headerText : 'News',
+                       subHeaderText : '',
+                       imageLink : '',
+                       order : '',
+                       url : ''
+               };
+
+               $scope.eventsGridsterItem = {
+                       sizeX : 1,
+                       sizeY : 1,
+                       headerText : 'Events',
+                       subHeaderText : '',
+                       imageLink : '',
+                       order : '',
+                       url : ''
+               };
+
+               $scope.impoResGridsterItem = {
+                       sizeX : 1,
+                       sizeY : 1,
+                       headerText : 'Resources',
+                       subHeaderText : '',
+                       imageLink : '',
+                       order : '',
+                       url : ''
+               };
+               
+               this.gridsterAppOpts = {
+                               columns : 6,
+                               colWidth : 190,
+                               rowHeight : 190,
+                               margins : [ 20, 20 ],
+                               outerMargin : true,
+                               pushing : true,
+                               floating : true,
+                               swapping : true,
+                               resizable: {
+                                       enabled: false,
+                               },
+                               draggable : {
+                                       handle:'.icon-content-gridguide',
+                                       stop: function stop() { 
+                                               $scope.defaultSortBy = function() {
+                                                       var resJson = {};
+                                                       resJson.value = 'M';
+                                                       resJson.index = 3;
+                                                       resJson.title = 'Manual';
+                                                       $scope.selectedSortType = resJson;
+                                                       applicationsService.saveAppsSortTypeManual($scope.appsViewData) 
+                                                       applicationsService.saveAppsSortTypePreference($scope.selectedSortType)
+                                               }
+                                               $scope.defaultSortBy();                 
+                                       }
+                               }
+                       };
+                       
+                       this.gridsterWidgetOpts = {
+                                       columns : 6,
+                                       colWidth : 190,
+                                       rowHeight : 190,
+                                       margins : [ 20, 20 ],
+                                       outerMargin : true,
+                                       pushing : true,
+                                       floating : true,
+                                       swapping : true,
+                                       resizable: {
+                                               enabled: true,
+                                               stop: function stop(event, uiWidget, $element){
+                                                       if($element.sizeX == 1)
+                                                               $element.headerText = ($element.widgetText.length > 9) ? $element.widgetText.substring(0, 8) + '...' : $element.widgetText;
+                                                       if($element.sizeX >= 2)
+                                                               $element.headerText = $element.widgetText;
+                                                       
+                                                       applicationsService
+                                                       .saveWidgetsSortManual($scope.widgetsViewData)
+                                       
+                                               }
+                                       },
+                                       draggable : {
+                                               handle:'.icon-content-gridguide',
+                                               stop: function stop(){
+                                                       applicationsService
+                                                       .saveWidgetsSortManual($scope.widgetsViewData)
+                                       
+                                               }
+                                       }
+                       };
+               
+               this.goToCatalog = function(item) {
+                       $state.go('root.appCatalog');
+               } 
+               
+               this.goToWidgetCatLog = function(item) {
+                       $state.go('root.widgetCatalog');
+               } 
+               
+               // navigate to application url in new tab
+               this.goToPortal = function(item) {
+                       userProfileService.getUserRolesForApplication($scope.orgUserId,item.appid)
+                 .then(res=>{
+                         var count = 0;
+                         for(var i=0;i<res.length;i++){
+                                if(!res[i].isApplied)
+                                        {
+                                        count++;
+                                        }
+                                  }
+                         if((count>0 && res.length == count)||res.length==0)
+                                 {
+                               confirmBoxService.showInformation('You have no roles assigned to this application to access.').then(isConfirmed => {});
+
+                                 }
+                         else{
+                                       if (!item.url) {
+                                               $log.error('No URL found for this application, doing nothing!');
+                                               return;
+                                       }
+                                       if (item.restrictedApp) {
+                                               // Link-based apps open in their own browser tab
+                                               $window.open(item.url, '_blank');
+                                       } else {
+                                               // cache control so browsers load app page every time
+                                               var ccParam = 'cc=' + new Date().getTime();
+                                               var urlParts = item.url.split('#');
+                                               var appUrl = null;
+                                               if (urlParts.length < 2) {
+                                                       // no #
+                                                       let urlLastChar = item.url.charAt(item.url.length - 1);
+                                                       if (item.url.includes("?"))
+                                                               appUrl = (urlLastChar === '&' ? item.url + ccParam : item.url + '&' + ccParam);
+                                                       else 
+                                                               appUrl = item.url + '?' + ccParam;
+                                               } else {
+                                                       // has #
+                                                       let urlLastChar = urlParts[0].charAt(urlParts[0].length - 1);
+                                                       if (item.url.includes("?"))
+                                                               appUrl = (urlLastChar === '&' ? urlParts[0] + ccParam + '#' + urlParts[1]  :  urlParts[0] + '&' + ccParam + '#' + urlParts[1]);
+                                                       else
+                                                               appUrl = urlParts[0] + '?' + ccParam + "#" + urlParts[1];
+                                               }
+                                               // $log.debug('DashboardCtrlr::goToPortal: opening tab with URL
+                                               // ' + appUrl);
+                                               var tabContent = {
+                                                       id: new Date(),
+                                                       title: item.headerText,
+                                                       url: appUrl,
+                                                       appId: item.appId
+                                               };
+                                               $cookies.putObject('addTab', tabContent);
+                                       }
+                                 
+                         }
+                });
+               
+                       
+               
+
+               };
+               
+               this.auditLog = function(app) {
+                       console.log(app);
+                       auditLogService.storeAudit(app.appid,'app',app.url);
+               };
+               
+               if (getParameterByName('noUserError') != null) {
+                       if (getParameterByName('noUserError') == "Show") {
+                               $("#errorInfo").show();
+                       }
+               }               
+       };
+
+       DashboardCtrl.$inject = [ 'conf', 'applicationsService', '$log', '$window',
+                       'userProfileService', '$scope', '$cookies', '$timeout', '$interval', 
+                       '$modal',  '$state', 'beReaderService', 'dashboardService', 'confirmBoxService', 
+                       'auditLogService', 'ngDialog', '$compile', 'widgetsCatalogService' ];
+       angular.module('ecompApp').controller('DashboardCtrl', DashboardCtrl);
+})();
+
+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, " ");
+}