diff options
author | shentao <shentao@chinamobile.com> | 2017-09-01 11:57:47 +0800 |
---|---|---|
committer | shentao <shentao@chinamobile.com> | 2017-09-01 11:57:58 +0800 |
commit | 57dbba269d19bc59fad89160200bb2dbcccb9003 (patch) | |
tree | d466041ceffa2161124ca79a48b3e077777c74b8 /usecaseui-common/src/main/webapp/app/fusion/scripts/directives | |
parent | 4ff32341a0af1972b44a7410e76e9b231131e7ab (diff) |
Upload Monitor function code
Change-Id: I33ad76221b4cb771a298ff240245fc24be664efb
Issue-Id: USECASEUI-6
Signed-off-by: shentao <shentao@chinamobile.com>
Diffstat (limited to 'usecaseui-common/src/main/webapp/app/fusion/scripts/directives')
4 files changed, 674 insertions, 0 deletions
diff --git a/usecaseui-common/src/main/webapp/app/fusion/scripts/directives/dummy.txt b/usecaseui-common/src/main/webapp/app/fusion/scripts/directives/dummy.txt new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/usecaseui-common/src/main/webapp/app/fusion/scripts/directives/dummy.txt diff --git a/usecaseui-common/src/main/webapp/app/fusion/scripts/directives/footer.js b/usecaseui-common/src/main/webapp/app/fusion/scripts/directives/footer.js new file mode 100644 index 00000000..d49f5980 --- /dev/null +++ b/usecaseui-common/src/main/webapp/app/fusion/scripts/directives/footer.js @@ -0,0 +1,11 @@ +app.directive('qFooter', function () { + return { + restrict: 'A', //This menas that it will be used as an attribute and NOT as an element. I don't like creating custom HTML elements + replace: false, + templateUrl: "app/fusion/scripts/view-models/footer.html", + controller: ['$scope', '$filter', function ($scope, $filter) { + // Your behaviour goes here :) + }] + } +}); + diff --git a/usecaseui-common/src/main/webapp/app/fusion/scripts/directives/header.js b/usecaseui-common/src/main/webapp/app/fusion/scripts/directives/header.js new file mode 100644 index 00000000..ef0a8fd2 --- /dev/null +++ b/usecaseui-common/src/main/webapp/app/fusion/scripts/directives/header.js @@ -0,0 +1,479 @@ +app.directive('qHeader', function () { + return { + restrict: 'A', //This menas that it will be used as an attribute and NOT as an element. I don't like creating custom HTML elements + replace: false, + templateUrl: "app/fusion/scripts/view-models/header.html", + controller: ['$scope', '$filter','$http','$timeout', '$log','UserInfoService', '$window', '$cookies', function ($scope, $filter, $http, $timeout, $log,UserInfoService, $window, $cookies) { + + /*Define fields*/ + $scope.userName; + $scope.userFirstName; + $scope.redirectUrl; + $scope.contactUsUrl; + $scope.getAccessUrl; + $scope.childData=[]; + $scope.parentData=[]; + $scope.menuItems = []; + $scope.loadMenufail=false; + $scope.megaMenuDataObject=[]; + $scope.activeClickSubMenu = { + x: '' + }; + $scope.activeClickMenu = { + x: '' + }; + $scope.favoritesMenuItems = []; + $scope.favoriteItemsCount = 0; + $scope.showFavorites = false; + $scope.emptyFavorites = false; + $scope.favoritesWindow = false; + + /*Menu Structure*/ + var menuStructureConvert = function(menuItems) { + // console.log(menuItems); + $scope.megaMenuDataObjectTemp = + [ + { + text: "ECOMP", + children: menuItems + }, + { + text: "Help", + children: [ + { + text:"Contact Us", + url:$scope.contactUsUrl + }, + { + text:"Get Access", + url:$scope.getAccessUrl + }] + } + ]; + return $scope.megaMenuDataObjectTemp; + }; + + /***************functions**************/ + /*Put user info into fields*/ + $scope.inputUserInfo = function(userInfo){ + if (typeof(userInfo) != "undefined" && userInfo!=null && userInfo!=''){ + if(typeof(userInfo.USER_FIRST_NAME) != "undefined" && userInfo.USER_FIRST_NAME!=null){ + $scope.userFirstName = userInfo.USER_FIRST_NAME; + } + } + } + /*getting user info from session*/ + $scope.getUserNameFromSession = function(){ + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (res) { + $scope.contactUsUrl=res.contactUsLink; + $scope.userName = res.userName; + $scope.userFirstName = res.firstName; + $scope.redirectUrl = res.portalUrl; + $scope.getAccessUrl = res.getAccessUrl; + }); + } + $scope.getTopMenuStaticInfo=function() { + var promise = UserInfoService.getFunctionalMenuStaticDetailShareContext(); + promise.then( + function(res) { + if(res==null || res==''){ + $log.error('failed to get static User information'); + $scope.getUserNameFromSession(); + }else{ + // $log.info('Received static User information'); + var resData = res; + // console.log(resData); + $scope.inputUserInfo(resData); + $scope.userName = $scope.firstName+ ' '+ $scope.lastName; + } + }, + function(err) { + $log.error('getFunctionalMenuStaticDetailShareContext failed', err); + } + ); + } + + $scope.returnToPortal=function(){ + window.location.href = $scope.redirectUrl; + } + + var unflatten = function( array, parent, tree ){ + tree = typeof tree !== 'undefined' ? tree : []; + parent = typeof parent !== 'undefined' ? parent : { menuId: null }; + var children = _.filter( array, function(child){ return child.parentMenuId == parent.menuId; }); + if( !_.isEmpty( children ) ){ + if( parent.menuId === null ){ + tree = children; + }else{ + parent['children'] = children + } + _.each( children, function( child ){ unflatten( array, child ) } ); + } + return tree; + } + + $scope.getMenu=function() { + $scope.getTopMenuStaticInfo(); + $http({ + method: "GET", + url: 'get_functional_menu', +// TIMEOUT USED FOR LOCAL TESTING ONLY +// timeout: 100 + }).success(function (response) { + + if (response == '101: Timeout') { + $log.debug('Timeout attempting to get_functional_menu'); + $scope.megaMenuDataObject = menuStructureConvert(""); +// $scope.createErrorMenu(); + //$scope.loadMenufail=true; + } else { + if(typeof response != 'undefined' && response.length!=0 && typeof response[0] != 'undefined' && typeof response[0].error!="undefined"){ + $log.debug('Timeout attempting to get_functional_menu'); + $scope.menuItems = unflatten( response); + $scope.megaMenuDataObject = menuStructureConvert($scope.menuItems); +// $scope.createErrorMenu(); + //$scope.loadMenufail=true; + }else{ + $scope.loadMenufail=false; + $scope.contactUsURL = response.contactUsLink; + $log.debug('functional_menu',response); + $scope.megaMenuDataObject = menuStructureConvert(""); + } + } + }).error(function (response){ + $scope.megaMenuDataObject = menuStructureConvert(""); +// $scope.createErrorMenu(); + //$scope.loadMenufail=true; + $log.debug('REST API failed get_functional_menu...'); + }); + + } + + $scope.adjustHeader=function() { + $scope.showHeader = ($cookies.show_app_header == undefined ? true : $cookies.show_app_header); + + if($scope.showHeader == true) { + $scope.drawer_margin_top = 70; + $scope.drawer_custom_top = 54; + $scope.toggle_drawer_top = 55; + } + else { + + $scope.drawer_margin_top = 60; + $scope.drawer_custom_top = 0; + $scope.toggle_drawer_top = 10; + } + + } + + $scope.getMenu(); + $scope.adjustHeader(); + +/* **************************************************************************/ +/* Logic for the favorite menus is here */ + + $scope.loadFavorites = function () { + $log.debug('loadFavorites has happened.'); + if ($scope.favoritesMenuItems == '') { + $scope.generateFavoriteItems(); + $log.debug('loadFavorites is calling generateFavoriteItems()'); + } else { + $log.debug('loadFavorites is NOT calling generateFavoriteItems()'); + } + } + + $scope.goToUrl = function (item) { + $log.debug("goToUrl called", item); + + var url = item.url; + var restrictedApp = item.restrictedApp; + // $log.debug('Restricted app status is: ' + restrictedApp); + if (!url) { + $log.error('No url found for this application, doing nothing..'); + return; + } + if (restrictedApp) { + $window.open(url, '_blank'); + } else { + $window.open(url, '_self'); + } + + } + + $scope.submenuLevelAction = function(index, column) { + if ($scope.favoritesMenuItems == '') { + $scope.generateFavoriteItems(); + $log.debug('submenuLevelAction is calling generateFavoriteItems()'); + } + $log.debug('item hovered/clicked: ' + index + '; column = ' + column); + if (column == 2) { // 2 is Design + $scope.favoritesWindow = false; + $scope.showFavorites = false; + $scope.emptyFavorites = false; + } + if (index=='Favorites' && $scope.favoriteItemsCount != 0) { + $log.debug('Showing Favorites window'); + $scope.favoritesWindow = true; + $scope.showFavorites = true; + $scope.emptyFavorites = false; + } + if (index=='Favorites' && $scope.favoriteItemsCount == 0) { + $log.debug('Hiding Favorites window in favor of No Favorites Window'); + $scope.favoritesWindow = true; + $scope.showFavorites = false; + $scope.emptyFavorites = true; + } + if (column > 2) { + $scope.favoritesWindow = false; + $scope.showFavorites = false; + $scope.emptyFavorites = false; + } + }; + + $scope.hideFavoritesWindow = function() { + $log.debug('$scope.hideFavoritesWindow has been called'); + $scope.showFavorites = false; + $scope.emptyFavorites = false; + } + + $scope.isUrlFavorite = function (menuId) { +// $log.debug('array objects in menu favorites = ' + $scope.favoriteItemsCount + '; menuId=' + menuId); + var jsonMenu = JSON.stringify($scope.favoritesMenuItems); + var isMenuFavorite = jsonMenu.indexOf('menuId\":' + menuId); + if (isMenuFavorite==-1) { + return false; + } else { + return true; + } + + } + + $scope.generateFavoriteItems = function() { + $http({ + method: "GET", + url: 'get_favorites', +// TIMEOUT USED FOR LOCAL TESTING ONLY +// timeout: 100 + }).success(function (response) { + if (response == '101: Timeout') { + $log.error('Timeout attempting to get_favorites_menu'); + } else { + if(typeof response != 'undefined' && response.length!=0 && typeof response[0] != 'undefined' && typeof response[0].error!="undefined"){ + $log.error('REST API failed get_favorites' + response); + }else{ + $log.debug('get_favorites = ' + JSON.stringify(response)); + $scope.favoritesMenuItems = response; + $scope.favoriteItemsCount = Object.keys($scope.favoritesMenuItems).length; + // $log.info('number of favorite menus: ' + $scope.favoriteItemsCount); + } + } + }).error(function (response){ + $log.error('REST API failed get_favorites' + response); +//createFavoriteErrorMenu() USED FOR LOCAL TESTING ONLY +// $scope.createFavoriteErrorMenu(); + }); + } + + $scope.createFavoriteErrorMenu=function() { + $scope.favoritesMenuItems = []; + $scope.favoriteItemsCount = Object.keys($scope.favoritesMenuItems).length; + // $log.info('number of favorite menus: ' + $scope.favoriteItemsCount); + } + + /* end of Favorite Menu code */ + /* **************************************************************************/ + + + /* **************************************************************************/ + // THIS IS USED FOR LOCAL TESTING ONLY + /* **************************************************************************/ + $scope.createErrorMenu=function() { + $log.debug('Creating fake menu now...'); +// $scope.loadMenufail=true; + $scope.menuItems = [ + { + "menuId": 1, + "column": 2, + "text": "Design", + "parentMenuId": null, + "url": "" + }, + { + "menuId": 2, + "column": 3, + "text": "Infrastructure Ordering", + "parentMenuId": null, + "url": "" + }, + { + "menuId": 3, + "column": 4, + "text": "Service Creation", + "parentMenuId": null, + "url": "" + }, + { + "menuId": 4, + "column": 5, + "text": "Service Mgmt", + "parentMenuId": null, + "url": "" + }, + { + "menuId": 90, + "column": 1, + "text": "Google", + "parentMenuId": 1, + "url": "http://google.com" + }, + { + "menuId": 91, + "column": 1, + "text": "Mike Little's Coffee Cup", + "parentMenuId": 2, + "url": "http://coffee.com" + }, + { + "menuId": 92, + "column": 2, + "text": "Andy and his Astrophotgraphy", + "parentMenuId": 3, + "url": "http://nightskypix.com" + }, + { + "menuId": 93, + "column": 1, + "text": "JSONLint", + "parentMenuId": 4, + "url": "http://http://jsonlint.com" + }, + { + "menuId": 94, + "column": 2, + "text": "ONAP test link", + "parentMenuId": 4, + "url": "http://tbd.onap.org/testlink" + }, + { + "menuId": 95, + "column": 2, + "text": "4th Level App4a R16", + "parentMenuId": 4, + "url": "http://app4ar16.onap.org/testlink" + }, + { + "menuId": 96, + "column": 3, + "text": "3rd Level App1c R200", + "parentMenuId": 4, + "url": "http://app1c.com" + }, + { + "menuId": 97, + "column": 1, + "text": "3rd Level App4b R16", + "parentMenuId": 5, + "url": "http://app4b.com" + }, + { + "menuId": 98, + "column": 2, + "text": "3rd Level App2b R16", + "parentMenuId": 5, + "url": "http://app2b.com" + }, + { + "menuId": 99, + "column": 1, + "text": "Favorites", + "parentMenuId": null, + "url": "" + } + ]; + $scope.menuItems = unflatten( $scope.menuItems ); + //remove this + $scope.megaMenuDataObject = menuStructureConvert($scope.menuItems); + } + }] + } +}); + +app.filter("ellipsis", function(){ + return function(text, length){ + if (text) { + var ellipsis = text.length > length ? "..." : ""; + return text.slice(0, length) + ellipsis; + }; + return text; + } +}); + +function reloadPageOnce() { + if( window.localStorage ) + { + if( !localStorage.getItem('firstLoad') ) + { + localStorage['firstLoad'] = true; + window.location.reload(); + } + else + localStorage.removeItem('firstLoad'); + } +} +app.controller('loginSnippetCtrl', function ($scope,$http, $log,UserInfoService){ + /*Define fields*/ + $scope.userProfile={ + firstName:'', + lastName:'', + fullName:'', + email:'', + } + /*Put user info into fields*/ + $scope.inputUserInfo = function(userInfo){ + if (typeof(userInfo) != "undefined" && userInfo!=null && userInfo!=''){ + if (typeof(userInfo.USER_FIRST_NAME) != "undefined" && userInfo.USER_FIRST_NAME!=null && userInfo.USER_FIRST_NAME!='') + $scope.userProfile.firstName = userInfo.USER_FIRST_NAME; + if (typeof(userInfo.USER_LAST_NAME) != "undefined" && userInfo.USER_LAST_NAME!=null && userInfo.USER_LAST_NAME!='') + $scope.userProfile.lastName = userInfo.USER_LAST_NAME; + if (typeof(userInfo.USER_EMAIL) != "undefined" && userInfo.USER_EMAIL!=null && userInfo.USER_EMAIL!='') + $scope.userProfile.email = userInfo.USER_EMAIL; + + } + } + /*getting user info from session*/ + $scope.getUserNameFromSession = function(){ + UserInfoService.getFunctionalMenuStaticDetailSession() + .then(function (response) { + $scope.userProfile.fullName = response.userName; + $scope.userProfile.email = response.email; + }); + } + /*getting user info from shared context*/ + $scope.getUserName=function() { + var promise = UserInfoService.getFunctionalMenuStaticDetailShareContext(); + promise.then( + function(res) { + if(res==null || res==''){ + $log.error('getFunctionalMenuStaticDetailShareContext failed'); + $scope.getUserNameFromSession(); + }else{ + // $log.info('Received User information from shared context',res); + var resData = res; + // console.log(resData); + $scope.inputUserInfo(resData); + $scope.userProfile.fullName = $scope.userProfile.firstName+ ' '+ $scope.userProfile.lastName; + } + }, + function(err) { + console.log('getFunctionalMenuStaticDetailShareContext failed', err); + } + ); + }; + /*call the get user info function*/ + try{ + $scope.getUserName(); + }catch(err){ + $log.info('getUserName failed', err); + } +}); diff --git a/usecaseui-common/src/main/webapp/app/fusion/scripts/directives/leftMenu.js b/usecaseui-common/src/main/webapp/app/fusion/scripts/directives/leftMenu.js new file mode 100644 index 00000000..f42276fe --- /dev/null +++ b/usecaseui-common/src/main/webapp/app/fusion/scripts/directives/leftMenu.js @@ -0,0 +1,184 @@ + +app.directive('qMenu', function () { + return { + restrict: 'A', //This menas that it will be used as an attribute and NOT as an element. I don't like creating custom HTML elements + replace: false, + templateUrl: "app/fusion/scripts/view-models/left_menu.html", + controller: ['$scope', '$filter','$http','$timeout','$cookies','LeftMenuService', function ($scope, $filter, $http,$timeout,$cookies,LeftMenuService) { + + $scope.leftChildData=[]; + $scope.leftParentData=[]; + $scope.leftMenuItems = []; + $scope.app_name = ""; + $scope.app_name_full; + LeftMenuService.getLeftMenu().then(function(response){ + var j = response; + try{ + if(j && j !== "null" && j!== "undefined"){ + $scope.leftParentData = JSON.parse(j.data); + $scope.leftChildData = JSON.parse(j.data2); + }else{ + throw "Get Left Menu response is not an object/is empty"; + } + try{ + var leftChildItemList = $scope.leftChildData; + var pageUrl = window.location.href.split('/')[window.location.href.split('/').length-1]; + var leftParentList =$scope.leftParentData; + for (var i = 0; i < leftParentList.length; i++) { + $scope.item = { + parentLabel : leftParentList[i].label, + parentAction : leftParentList[i].action, + parentImageSrc : leftParentList[i].imageSrc, + open:pageUrl==leftParentList[i].action?true:false, + childItemList : leftChildItemList[i] + } + $scope.leftMenuItems.push($scope.item); + }; + }catch(err){ + console.log("failed to set left menu structure", err); + } + }catch (e) { + console.log("failed to get left menu items", e); + reloadPageOnce(); + return; + } + },function(error){ + console.log("error happened while calling getLeftMenu", error); + }); + + LeftMenuService.getAppName().then(function(response){ + var j = response; + try{ + if(j && j !== "null" && j!== "undefined"){ + // console.log("app name is " + $scope.app_name); + $scope.app_name_full = j.data; + var processed_app_name = j.data; + var n = processed_app_name.length; + if (n > 15) { + n = 15; + } + $scope.app_name = processed_app_name.substr(0, n); + }else{ + throw "Get app_name respsone is not an object/is empty"; + } + }catch (e) { + console.log("failed to get app name", e); + return; + } + },function(error){ + console.log("failed in getAppName", error); + }); + + $scope.adjustHeader=function() { + $scope.showHeader = ($cookies.show_app_header == undefined ? true : $cookies.show_app_header); + + if($scope.showHeader == true) { + $scope.drawer_margin_top = 50; + $scope.drawer_custom_top = 54; + $scope.toggle_drawer_top = 55; + } + else { + + $scope.drawer_margin_top = 40; + $scope.drawer_custom_top = 0; + $scope.toggle_drawer_top = 10; + } + + + }; + + $scope.adjustHLeftMenu = function (type){ + $scope.showHeader = ($cookies.show_app_header == undefined ? true : $cookies.show_app_header); + + if($scope.showHeader == true) { + $scope.drawer_margin_top = 60; + $scope.drawer_custom_top = 54; + $scope.toggle_drawer_top = 55; + } + else { + + $scope.drawer_margin_top = 50; + $scope.drawer_custom_top = 0; + $scope.toggle_drawer_top = 10; + } + if(type=='burgerIcon'){ + return { "top": $scope.toggle_drawer_top+"px"}; + }else if(type=='leftMenu'){ + return { "margin-top": $scope.drawer_margin_top+"px"}; + }else + return; + } + $scope.adjustHeader(); + $scope.drawerOpen = true; + + $scope.toggleDrawer = function() { + $scope.drawerOpen = !($scope.drawerOpen); + if ($scope.drawerOpen) { + // setCookie('drawerOpen','open',30); + $scope.arrowShow = true; + + + if (document.getElementById('fnMenueContent')!=null) + document.getElementById('fnMenueContent').style.marginLeft = "0px"; + + if (document.getElementById('rightContentAdmin')!=null) + document.getElementById('rightContentAdmin').style.marginLeft = "210px"; + + else if (document.getElementById('rightContentProfile')!=null) + document.getElementById('rightContentProfile').style.marginLeft = "210px"; + + + + } else { + + $scope.arrowShow = false; + + if (document.getElementById('fnMenueContent')!=null) + document.getElementById('fnMenueContent').style.marginLeft = "-150px"; + + if (document.getElementById('rightContentAdmin')!=null) { + document.getElementById('rightContentAdmin').style.marginLeft = "50px"; + + } + + else if (document.getElementById('rightContentProfile')!=null) + document.getElementById('rightContentProfile').style.marginLeft = "50px"; + + + + + } + }; + + $timeout(function() { + detectScrollEvent(); + }, 800); + }] + } + +}); +$(window).scroll(function() { + if ($('.att-drawer').is(':visible')) { + detectScrollEvent(); + } + +}); + +function detectScrollEvent() { + try{ + var footerOff = $('#footerContainer').offset().top; + var headOff = $('#headerContainer').offset().top; + var winHeight = $(window).height(); + if ((footerOff - headOff) <= winHeight) { + $('.att-drawer').css({ + "height" : footerOff - headOff - 55 + }); + } else { + $('.att-drawer').css({ + "height" : "94vh" + }); + } + }catch(err){ + console.log('detectScrollEvent failed', err) + } +} |