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 : '/'});
37 let noRefresh = function () {
38 window.onbeforeunload = function(e) {
40 var isQtoHref = false;
42 isQtoHref = e.srcElement.activeElement.href.includes("to");
47 if ($scope.tabs.length > 1 && isQtoHref == false) {
48 return "Changes you made may not be saved. Are you sure you want to refresh?";
54 // Add tab to the end of the array
55 var addTab = function (title, content) {
56 if($scope.tabs.length===tabLimit){
58 confirmBoxService.showInformation('You have reached your maximum limit of tabs allowed.').then(isConfirmed => {});
60 // console.log(window.performance.memory);
61 // var usedperc = (window.performance.memory.usedJSHeapSize/window.performance.memory.jsHeapSizeLimit)*100;
62 // console.log('Current memory usage: '+usedperc+'%');
63 if(title!=='Home' && content.indexOf('https') == -1){
64 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.');
65 //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 => {});
68 $scope.tabs.push({ title: title, content: content });
70 //$scope.tabs[$scope.tabs.length - 1].disabled = false;
71 $scope.selectedIndex = $scope.tabs.length - 1;
72 if ($scope.tabs.length > 1) {
75 $cookies.putObject('cookieTabs', $scope.tabs,{domain: cookieDomain, path : '/'});
76 $cookies.putObject('visInVisCookieTabs', $scope.tabs,{domain: cookieDomain, path : '/'});
81 var addTab = function (title, content, appId) {
82 if($scope.tabs.length===tabLimit){
84 confirmBoxService.showInformation('You have reached your maximum limit of tabs allowed.').then(isConfirmed => {});
86 if(title!=='Home' && content.indexOf('https') === -1){
87 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.');
89 $scope.tabs.push({ title: title, content: content, appId:appId });
91 $scope.selectedIndex = $scope.tabs.length - 1;
92 if ($scope.tabs.length > 1) {
95 $cookies.putObject('cookieTabs', $scope.tabs,{domain: cookieDomain, path : '/'});
96 $cookies.putObject('visInVisCookieTabs', $scope.tabs,{domain: cookieDomain, path : '/'});
100 // adjust title - trim the title and append ...
101 var adjustTitle = function (title) {
103 var nonEmptyCharPattern = /(\s|\w)/;
104 var adjustedTitle = title.substring(0,index);
105 var ext = title.charAt(index).replace(nonEmptyCharPattern,'...');
106 return adjustedTitle.concat(ext);
112 $scope.auditLog = function(app) {
113 $log.debug('auditLog::auditLog: auditLog.ping() = ' + app);
115 if(app.content==null || app.content=='')
118 comment = app.content;
119 auditLogService.storeAudit(app.appId, 'tab', comment);
122 // Remove tab by index
123 var removeTab = function (event, index) {
124 event.preventDefault();
125 event.stopPropagation();
126 $scope.tabs.splice(index, 1);
127 $cookies.putObject('cookieTabs', $scope.tabs,{domain: cookieDomain, path : '/'});
130 //adjust height of the tab due to the search popup being hidden
131 $scope.adjustTabStyle = function(title){
133 $(".w-ecomp-tabs").css('height',"50px");
135 $(".w-ecomp-tabs").css('height',"100%");
140 var selectTab = function (title) {
141 $scope.adjustTabStyle(title);
143 $rootScope.ContentModel.IsVisible=true;
144 $rootScope.showFooter = true;
145 $rootScope.tabBottom = 75;
146 userbarUpdateService.setRefreshCount(userbarUpdateService.maxCount);
149 $rootScope.ContentModel.IsVisible=false;
150 $rootScope.showFooter = false;
151 $rootScope.tabBottom = 0;
155 // Initialize the scope functions
156 $scope.addTab = addTab;
157 $scope.removeTab = removeTab;
158 $scope.selectTab = selectTab;
159 $scope.adjustTitle = adjustTitle;
162 $rootScope.ContentModel = {
168 var sessionActive = applicationsService.ping()
169 .then(sessionActive => {
170 // $log.debug('TabsCtrl::addTab: applicationsService.ping() = ' + JSON.stringify(sessionActive));
171 // For demonstration add 5 tabs
173 var cookieTabs = $cookies.getObject('cookieTabs');
174 if(cookieTabs!=null){
175 for(var t in cookieTabs){
176 // console.log('TabsCtrl::addTab: cookieTabs title: '+cookieTabs[t].title);
177 if(cookieTabs[t].title!=null && cookieTabs[t].title==='Home'){
178 cookieTabs[t].content = "";
179 $rootScope.ContentModel.IsVisible=true;
180 addTab( cookieTabs[t].title, cookieTabs[t].content,1) ;
182 addTab( cookieTabs[t].title, cookieTabs[t].content,cookieTabs[t].appId) ;
187 for (var i = 0; i < 1; i++) {
193 $rootScope.ContentModel.IsVisible=true;
194 addTab(title, content,1);
196 addTab(title, content,appId);
203 //$scope.tabs[$scope.tabs.length - 1].active = false;
204 //$scope.tabs[0].disabled = false;
205 $scope.selectedIndex = 0;
208 $scope.$watchCollection(function() { return $cookies.getObject('addTab'); }, function(newValue) {
209 // $log.log('Cookie string: ' + $cookies.get('test'))
210 var tabContent = $cookies.getObject('addTab');
211 if(tabContent!=null && tabContent.url!=null){
212 var tabExists = false;
213 for(var x in $scope.tabs){
214 // console.log($scope.tabs[x].content);
215 if($scope.tabs[x].title==tabContent.title){
217 //$scope.tabs[x].disabled = false;
218 $scope.selectedIndex = x;
219 // added dummy variable to get iframe reloded if tab is already opened.
220 if(tabContent.url.indexOf('?')===-1){
221 $scope.tabs[x].content=tabContent.url+'?dummyVar='+(new Date()).getTime();
224 $scope.tabs[x].content=tabContent.url+'&dummyVar='+(new Date()).getTime();
229 addTab( tabContent.title, tabContent.url,tabContent.appId) ;
231 $cookies.remove('addTab');
236 TabsCtrl.$inject = ['applicationsService', '$log', '$window', 'conf', 'userProfileService', 'userbarUpdateService', '$scope','$cookies','$rootScope','confirmBoxService','auditLogService'];
237 angular.module('ecompApp').controller('TabsCtrl', TabsCtrl);
239 angular.module('ecompApp').directive('mainArea', function() {
242 templateUrl: 'app/views/tabs/tabframe.html',
243 link: function(scope, element) {
245 //var iframeId = "#tabframe-" + scope.$parent.tab.title.split(' ').join('-');
246 // jQuery(iframeId).load(function() {
248 // }); //.attr("src",'{{tab.content | trusted}}' ); //src='{{tab.content | trusted}}'
249 // jQuery(iframeId).attr('src', '{{tab.content | trusted}}');
251 //element.childNodes[0].on('load', function() {
260 angular.module('ecompApp').directive('tabHighlight', [function () {
263 link: function (scope, element) {
264 // Here is the major jQuery usage where we add the event
265 // listeners mousemove and mouseout on the tabs to initalize
266 // the moving highlight for the inactive tabs
267 var x, y, initial_background = '#c3d5e6';
271 .mousemove(function (e) {
272 // Add highlight effect on inactive tabs
273 if(!element.hasClass('md-active'))
275 x = e.pageX - this.offsetLeft;
276 y = e.pageY - this.offsetTop;
278 // Set the background when mouse moves over inactive tabs
280 .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 })
281 .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 })
282 .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 });
285 .mouseout(function () {
286 // Return the inital background color of the tab
287 element.removeAttr('style');
297 function getParameterByName(name, url) {
298 if (!url) url = window.location.href;
299 name = name.replace(/[\[\]]/g, "\\$&");
300 var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
301 results = regex.exec(url);
302 if (!results) return '';
303 if (!results[2]) return '';
304 return (results[2].replace(/\+/g, " "));
307 function isCascadeFrame(ref) {
310 var e = document.body;
311 e.parentNode.removeChild(e);
312 window.location = "unKnownError";