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?:\/\//;
24 constructor(applicationsService, $log, $window, conf, userProfileService, userbarUpdateService, $scope,$cookies,$rootScope,confirmBoxService,auditLogService) {
29 var cookieDomain = this.conf.cookieDomain;
30 // Array to store the tabs
32 $scope.notificationShow=true;
33 $rootScope.showFooter = "";
34 $cookies.putObject('show_app_header', false,{domain: cookieDomain, path : '/'});
36 let getCookieDomain = function() {
37 return window.location.hostname;
39 let getContextPath=function() {
40 return window.location.pathname.substring( 0, window.location.pathname.lastIndexOf( '/' ) + 1 );
43 let noRefresh = function () {
44 window.onbeforeunload = function(e) {
46 var isQtoHref = false;
48 isQtoHref = e.srcElement.activeElement.href.includes("to");
53 if ($scope.tabs.length > 1 && isQtoHref == false) {
54 return "Changes you made may not be saved. Are you sure you want to refresh?";
60 // Add tab to the end of the array
61 var addTab = function (title, content) {
62 if($scope.tabs.length===tabLimit){
64 confirmBoxService.showInformation('You have reached your maximum limit of tabs allowed.').then(isConfirmed => {});
66 // console.log(window.performance.memory);
67 // var usedperc = (window.performance.memory.usedJSHeapSize/window.performance.memory.jsHeapSizeLimit)*100;
68 // console.log('Current memory usage: '+usedperc+'%');
69 if(title!=='Home' && content.indexOf('https') == -1){
70 console.log('App URL: '+content+'. The application URL you are trying to open is not HTTPS. We recommend to use secured HTTPS URL while on-boarding the application.');
71 //confirmBoxService.showInformation('The application URL you are trying to open is not HTTPS. We recommend to use secured HTTPS URL while on-boarding the application.').then(isConfirmed => {});
74 $scope.tabs.push({ title: title, content: content });
76 //$scope.tabs[$scope.tabs.length - 1].disabled = false;
77 $scope.selectedIndex = $scope.tabs.length - 1;
78 if ($scope.tabs.length > 1) {
81 $cookies.putObject('cookieTabs', $scope.tabs,{domain: getCookieDomain(), path : getContextPath()});
82 $cookies.putObject('visInVisCookieTabs', $scope.tabs,{domain: getCookieDomain(), path : getContextPath()});
88 var addTab = function (title, content, appId) {
89 if($scope.tabs.length===tabLimit){
91 confirmBoxService.showInformation('You have reached your maximum limit of tabs allowed.').then(isConfirmed => {});
93 if(title!=='Home' && content.indexOf('https') === -1){
94 console.log('App URL: '+content+'. The application URL you are trying to open is not HTTPS. We recommend to use secured HTTPS URL while on-boarding the application.');
96 $scope.tabs.push({ title: title, content: content, appId:appId });
98 $scope.selectedIndex = $scope.tabs.length - 1;
99 if ($scope.tabs.length > 1) {
102 $cookies.putObject('cookieTabs', $scope.tabs,{domain: getCookieDomain(), path : getContextPath()});
103 $cookies.putObject('visInVisCookieTabs', $scope.tabs,{domain: getCookieDomain(), path : getContextPath()});
107 // adjust title - trim the title and append ...
108 var adjustTitle = function (title) {
110 var nonEmptyCharPattern = /(\s|\w)/;
111 var adjustedTitle = title.substring(0,index);
112 var ext = title.charAt(index).replace(nonEmptyCharPattern,'...');
113 return adjustedTitle.concat(ext);
119 $scope.auditLog = function(app) {
120 $log.debug('auditLog::auditLog: auditLog.ping() = ' + app);
122 if(app.content==null || app.content=='')
125 comment = app.content;
126 auditLogService.storeAudit(app.appId, 'tab', comment);
129 // Remove tab by index
130 var removeTab = function (event, index) {
131 event.preventDefault();
132 event.stopPropagation();
133 $scope.tabs.splice(index, 1);
134 $cookies.putObject('cookieTabs', $scope.tabs,{domain: getCookieDomain(), path : getContextPath()});
137 //adjust height of the tab due to the search popup being hidden
138 $scope.adjustTabStyle = function(title){
140 $(".w-ecomp-tabs").css('height',"50px");
142 $(".w-ecomp-tabs").css('height',"100%");
147 var selectTab = function (title) {
148 $scope.adjustTabStyle(title);
150 $rootScope.ContentModel.IsVisible=true;
151 $rootScope.showFooter = true;
152 $rootScope.tabBottom = 75;
153 userbarUpdateService.setRefreshCount(userbarUpdateService.maxCount);
156 $rootScope.ContentModel.IsVisible=false;
157 $rootScope.showFooter = false;
158 $rootScope.tabBottom = 0;
162 // Initialize the scope functions
163 $scope.addTab = addTab;
164 $scope.removeTab = removeTab;
165 $scope.selectTab = selectTab;
166 $scope.adjustTitle = adjustTitle;
169 $rootScope.ContentModel = {
175 var sessionActive = applicationsService.ping()
176 .then(sessionActive => {
177 // $log.debug('TabsCtrl::addTab: applicationsService.ping() = ' + JSON.stringify(sessionActive));
178 // For demonstration add 5 tabs
180 var cookieTabs = $cookies.getObject('cookieTabs');
181 if(cookieTabs!=null){
182 for(var t in cookieTabs){
183 // console.log('TabsCtrl::addTab: cookieTabs title: '+cookieTabs[t].title);
184 if(cookieTabs[t].title!=null && cookieTabs[t].title==='Home'){
185 cookieTabs[t].content = "";
186 $rootScope.ContentModel.IsVisible=true;
187 addTab( cookieTabs[t].title, cookieTabs[t].content,1) ;
189 addTab( cookieTabs[t].title, cookieTabs[t].content,cookieTabs[t].appId) ;
194 for (var i = 0; i < 1; i++) {
200 $rootScope.ContentModel.IsVisible=true;
201 addTab(title, content,1);
203 addTab(title, content,appId);
210 //$scope.tabs[$scope.tabs.length - 1].active = false;
211 //$scope.tabs[0].disabled = false;
212 $scope.selectedIndex = 0;
215 $scope.$watchCollection(function() { return $cookies.getObject('addTab'); }, function(newValue) {
216 // $log.log('Cookie string: ' + $cookies.get('test'))
217 var tabContent = $cookies.getObject('addTab');
218 if(tabContent!=null && tabContent.url!=null){
219 var tabExists = false;
220 for(var x in $scope.tabs){
221 // console.log($scope.tabs[x].content);
222 if($scope.tabs[x].title==tabContent.title){
224 //$scope.tabs[x].disabled = false;
225 $scope.selectedIndex = x;
226 // added dummy variable to get iframe reloded if tab is already opened.
227 if(tabContent.url.indexOf('?')===-1){
228 $scope.tabs[x].content=tabContent.url+'?dummyVar='+(new Date()).getTime();
231 $scope.tabs[x].content=tabContent.url+'&dummyVar='+(new Date()).getTime();
236 addTab( tabContent.title, tabContent.url,tabContent.appId) ;
238 $cookies.remove('addTab');
243 TabsCtrl.$inject = ['applicationsService', '$log', '$window', 'conf', 'userProfileService', 'userbarUpdateService', '$scope','$cookies','$rootScope','confirmBoxService','auditLogService'];
244 angular.module('ecompApp').controller('TabsCtrl', TabsCtrl);
246 angular.module('ecompApp').directive('mainArea', function() {
249 templateUrl: 'app/views/tabs/tabframe.html',
250 link: function(scope, element) {
252 //var iframeId = "#tabframe-" + scope.$parent.tab.title.split(' ').join('-');
253 // jQuery(iframeId).load(function() {
255 // }); //.attr("src",'{{tab.content | trusted}}' ); //src='{{tab.content | trusted}}'
256 // jQuery(iframeId).attr('src', '{{tab.content | trusted}}');
258 //element.childNodes[0].on('load', function() {
267 angular.module('ecompApp').directive('tabHighlight', [function () {
270 link: function (scope, element) {
271 // Here is the major jQuery usage where we add the event
272 // listeners mousemove and mouseout on the tabs to initalize
273 // the moving highlight for the inactive tabs
274 var x, y, initial_background = '#c3d5e6';
278 .mousemove(function (e) {
279 // Add highlight effect on inactive tabs
280 if(!element.hasClass('md-active'))
282 x = e.pageX - this.offsetLeft;
283 y = e.pageY - this.offsetTop;
285 // Set the background when mouse moves over inactive tabs
287 .css({ background: '-moz-radial-gradient(circle at ' + x + 'px ' + y + 'px, rgba(255,255,255,0.4) 0px, rgba(255,255,255,0.0) 45px), ' + initial_background })
288 .css({ background: '-webkit-radial-gradient(circle at ' + x + 'px ' + y + 'px, rgba(255,255,255,0.4) 0px, rgba(255,255,255,0.0) 45px), ' + initial_background })
289 .css({ background: 'radial-gradient(circle at ' + x + 'px ' + y + 'px, rgba(255,255,255,0.4) 0px, rgba(255,255,255,0.0) 45px), ' + initial_background });
292 .mouseout(function () {
293 // Return the inital background color of the tab
294 element.removeAttr('style');
304 function getParameterByName(name, url) {
305 if (!url) url = window.location.href;
306 name = name.replace(/[\[\]]/g, "\\$&");
307 var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
308 results = regex.exec(url);
309 if (!results) return '';
310 if (!results[2]) return '';
311 return (results[2].replace(/\+/g, " "));
314 function isCascadeFrame(ref) {
317 var e = document.body;
318 e.parentNode.removeChild(e);
319 window.location = "unKnownError";