Show More
app.js
248 lines
| 10.1 KiB
| application/javascript
|
JavascriptLexer
r0 | // # Copyright (C) 2010-2016 RhodeCode GmbH | |||
// # | ||||
// # This program is free software: you can redistribute it and/or modify | ||||
// # it under the terms of the GNU Affero General Public License, version 3 | ||||
// # (only), as published by the Free Software Foundation. | ||||
// # | ||||
// # This program is distributed in the hope that it will be useful, | ||||
// # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
// # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
// # GNU General Public License for more details. | ||||
// # | ||||
// # You should have received a copy of the GNU Affero General Public License | ||||
// # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
// # | ||||
// # This program is dual-licensed. If you wish to learn more about the | ||||
r28 | // # AppEnlight Enterprise Edition, including its added features, Support | |||
r0 | // # services, and proprietary license terms, please see | |||
// # https://rhodecode.com/licenses/ | ||||
'use strict'; | ||||
// Declare app level module which depends on filters, and services | ||||
angular.module('appenlight.base', [ | ||||
'ngRoute', | ||||
'ui.router', | ||||
'ui.router.router', | ||||
'underscore', | ||||
'ui.bootstrap', | ||||
'ngResource', | ||||
'ngAnimate', | ||||
'ngCookies', | ||||
'smart-table', | ||||
'angular-toArrayFilter', | ||||
'mentio' | ||||
]); | ||||
angular.module('appenlight.filters', []); | ||||
angular.module('appenlight.templates', []); | ||||
r64 | angular.module('appenlight.controllers', [ | |||
'appenlight.base' | ||||
]); | ||||
angular.module('appenlight.components', [ | ||||
r71 | 'appenlight.components.channelstream', | |||
'appenlight.components.appenlightApp', | ||||
r75 | 'appenlight.components.appenlightHeader', | |||
r76 | 'appenlight.components.indexDashboardView', | |||
'appenlight.components.logsBrowserView', | ||||
r84 | 'appenlight.components.reportView', | |||
'appenlight.components.reportsBrowserView', | ||||
'appenlight.components.reportsSlowBrowserView', | ||||
r78 | 'appenlight.components.eventBrowserView', | |||
'appenlight.components.userProfileView', | ||||
'appenlight.components.userIdentitiesView', | ||||
r81 | 'appenlight.components.userPasswordView', | |||
'appenlight.components.userAuthTokensView', | ||||
'appenlight.components.userAlertChannelsListView', | ||||
'appenlight.components.userAlertChannelsEmailNewView', | ||||
r83 | 'appenlight.components.applicationsListView', | |||
'appenlight.components.applicationsPurgeLogsView', | ||||
'appenlight.components.applicationsUpdateView', | ||||
'appenlight.components.integrationsListView', | ||||
'appenlight.components.bitbucketIntegrationConfigView', | ||||
'appenlight.components.campfireIntegrationConfigView', | ||||
'appenlight.components.flowdockIntegrationConfigView', | ||||
'appenlight.components.githubIntegrationConfigView', | ||||
'appenlight.components.hipchatIntegrationConfigView', | ||||
'appenlight.components.jiraIntegrationConfigView', | ||||
'appenlight.components.slackIntegrationConfigView', | ||||
'appenlight.components.webhooksIntegrationConfigView', | ||||
r85 | 'appenlight.components.adminView', | |||
'appenlight.components.adminApplicationsListView', | ||||
'appenlight.components.adminUsersListView', | ||||
'appenlight.components.adminUsersCreateView', | ||||
'appenlight.components.adminGroupsListView', | ||||
'appenlight.components.adminGroupsCreateView', | ||||
'appenlight.components.adminConfigurationView', | ||||
'appenlight.components.adminSystemView', | ||||
'appenlight.components.adminPartitionsView', | ||||
r78 | 'appenlight.components.settingsView' | |||
r64 | ]); | |||
r0 | angular.module('appenlight.directives', [ | |||
'appenlight.directives.c3chart', | ||||
'appenlight.directives.confirmValidate', | ||||
'appenlight.directives.focus', | ||||
'appenlight.directives.formErrors', | ||||
'appenlight.directives.humanFormat', | ||||
'appenlight.directives.isoToRelativeTime', | ||||
'appenlight.directives.permissionsForm', | ||||
'appenlight.directives.smallReportGroupList', | ||||
'appenlight.directives.smallReportList', | ||||
'appenlight.directives.pluginConfig', | ||||
'appenlight.directives.recursive', | ||||
'appenlight.directives.reportAlertAction', | ||||
'appenlight.directives.postProcessAction', | ||||
'appenlight.directives.rule', | ||||
'appenlight.directives.ruleReadOnly' | ||||
]); | ||||
angular.module('appenlight.services', [ | ||||
'appenlight.services.chartResultParser', | ||||
'appenlight.services.resources', | ||||
'appenlight.services.stateHolder', | ||||
'appenlight.services.typeAheadTagHelper', | ||||
'appenlight.services.UUIDProvider' | ||||
]).value('version', '0.1'); | ||||
var pluginsToLoad = _.map(decodeEncodedJSON(window.AE.plugins), | ||||
function(item){ | ||||
r98 | return item.config.javascript.angular_module | |||
r0 | }); | |||
r91 | console.info(pluginsToLoad); | |||
r0 | angular.module('appenlight.plugins', pluginsToLoad); | |||
var app = angular.module('appenlight', [ | ||||
'appenlight.base', | ||||
'appenlight.config', | ||||
'appenlight.templates', | ||||
'appenlight.filters', | ||||
'appenlight.services', | ||||
'appenlight.directives', | ||||
'appenlight.controllers', | ||||
r64 | 'appenlight.components', | |||
r0 | 'appenlight.plugins' | |||
]); | ||||
r62 | // needs manual execution because of plugin files | |||
function kickstartAE(initialUserData) { | ||||
r0 | app.config(['$httpProvider', '$uibTooltipProvider', '$locationProvider', function ($httpProvider, $uibTooltipProvider, $locationProvider) { | |||
$locationProvider.html5Mode(true); | ||||
$httpProvider.interceptors.push(['$q', '$rootScope', '$timeout', 'stateHolder', function ($q, $rootScope, $timeout, stateHolder) { | ||||
return { | ||||
'response': function (response) { | ||||
var flashMessages = angular.fromJson(response.headers('x-flash-messages')); | ||||
if (flashMessages && flashMessages.length > 0) { | ||||
stateHolder.flashMessages.extend(flashMessages); | ||||
} | ||||
return response; | ||||
}, | ||||
'responseError': function (rejection) { | ||||
if (rejection.status > 299 && rejection.status !== 422) { | ||||
stateHolder.flashMessages.extend([{ | ||||
msg: 'Response status code: ' + rejection.status + ', "' + rejection.statusText + '", url: ' + rejection.config.url, | ||||
type: 'error' | ||||
}]); | ||||
} | ||||
if (rejection.status == 0) { | ||||
stateHolder.flashMessages.extend([{ | ||||
msg: 'Response timeout', | ||||
type: 'error' | ||||
}]); | ||||
} | ||||
var flashMessages = angular.fromJson(rejection.headers('x-flash-messages')); | ||||
if (flashMessages && flashMessages.length > 0) { | ||||
stateHolder.flashMessages.extend(flashMessages); | ||||
} | ||||
return $q.reject(rejection); | ||||
} | ||||
} | ||||
}]); | ||||
$uibTooltipProvider.options({appendToBody: true}); | ||||
}]); | ||||
app.config(function ($provide) { | ||||
$provide.decorator("$exceptionHandler", function ($delegate) { | ||||
return function (exception, cause) { | ||||
$delegate(exception, cause); | ||||
if (typeof AppEnlight !== 'undefined') { | ||||
AppEnlight.grabError(exception); | ||||
} | ||||
}; | ||||
}); | ||||
}); | ||||
r62 | app.run(['$rootScope', '$timeout', 'stateHolder', '$state', '$location', '$transitions', '$window', 'AeConfig', | |||
function ($rootScope, $timeout, stateHolder, $state, $location, $transitions, $window, AeConfig) { | ||||
r100 | console.log('appenlight run()'); | |||
r63 | if (initialUserData){ | |||
stateHolder.AeUser.update(initialUserData); | ||||
r91 | ||||
if (stateHolder.AeUser.hasAppPermission('root_administration' | ||||
)){ | ||||
AeConfig.topNav.menuAdminItems.push( | ||||
{'sref': 'admin', 'label': 'Admin Settings'} | ||||
) | ||||
} | ||||
r63 | } | |||
r0 | $rootScope.$state = $state; | |||
$rootScope.stateHolder = stateHolder; | ||||
$rootScope.flash = stateHolder.flashMessages.list; | ||||
$rootScope.closeAlert = stateHolder.flashMessages.closeAlert; | ||||
$rootScope.AeConfig = AeConfig; | ||||
var transitionApp = function($transition$, $state) { | ||||
// redirect user to /register unless its one of open views | ||||
var isGuestState = [ | ||||
'report.view_detail', | ||||
'report.view_group', | ||||
'dashboard.view' | ||||
].indexOf($transition$.to().name) !== -1; | ||||
var path = $window.location.pathname; | ||||
// strip trailing slash | ||||
if (path.substr(path.length - 1) === '/') { | ||||
path = path.substr(0, path.length - 1); | ||||
} | ||||
var isOpenView = false; | ||||
var openViews = [ | ||||
AeConfig.urls.otherRoutes.lostPassword, | ||||
AeConfig.urls.otherRoutes.lostPasswordGenerate | ||||
]; | ||||
console.log('$transitions.onBefore', path, $transition$.to().name, $state); | ||||
_.each(openViews, function (url) { | ||||
var url = '/' + url.split('/').slice(3).join('/'); | ||||
if (url === path) { | ||||
isOpenView = true; | ||||
} | ||||
}); | ||||
r62 | if (stateHolder.AeUser.id === null && !isGuestState && !isOpenView) { | |||
r0 | if (window.location.toString().indexOf(AeConfig.urls.otherRoutes.register) === -1) { | |||
console.log('redirect to register'); | ||||
r62 | var newLocation = AeConfig.urls.otherRoutes.register + '?came_from=' + encodeURIComponent(window.location); | |||
// fix infinite digest here | ||||
$rootScope.$on('$locationChangeStart', | ||||
function(event, toState, toParams, fromState, fromParams, options){ | ||||
event.preventDefault(); | ||||
$window.location = newLocation; | ||||
}); | ||||
$window.location = newLocation; | ||||
r0 | return false; | |||
} | ||||
return false; | ||||
} | ||||
r62 | return true; | |||
r0 | }; | |||
r100 | for (var i=0; i < stateHolder.plugins.callables.length; i++){ | |||
stateHolder.plugins.callables[i](); | ||||
} | ||||
$transitions.onBefore({}, transitionApp); | ||||
r0 | }]); | |||
} | ||||