mirror of https://github.com/portainer/portainer
refactor(app): convert root folder files to es6 (#4159)
parent
f864b1bf69
commit
8f32517baa
|
@ -1,55 +0,0 @@
|
|||
import './assets/css';
|
||||
import '@babel/polyfill';
|
||||
|
||||
import angular from 'angular';
|
||||
import { UI_ROUTER_REACT_HYBRID } from '@uirouter/react-hybrid';
|
||||
|
||||
import './matomo-setup';
|
||||
import analyticsModule from './angulartics.matomo';
|
||||
|
||||
import './agent';
|
||||
import './azure/_module';
|
||||
import './docker/__module';
|
||||
import './edge/__module';
|
||||
import './portainer/__module';
|
||||
|
||||
angular.module('portainer', [
|
||||
'ui.bootstrap',
|
||||
'ui.router',
|
||||
UI_ROUTER_REACT_HYBRID,
|
||||
'ui.select',
|
||||
'isteven-multi-select',
|
||||
'ngSanitize',
|
||||
'ngFileUpload',
|
||||
'ngMessages',
|
||||
'ngResource',
|
||||
'angularUtils.directives.dirPagination',
|
||||
'LocalStorageModule',
|
||||
'angular-jwt',
|
||||
'angular-json-tree',
|
||||
'angular-loading-bar',
|
||||
'angular-clipboard',
|
||||
'ngFileSaver',
|
||||
'luegg.directives',
|
||||
'portainer.app',
|
||||
'portainer.agent',
|
||||
'portainer.azure',
|
||||
'portainer.docker',
|
||||
'portainer.kubernetes',
|
||||
'portainer.edge',
|
||||
'portainer.integrations',
|
||||
'rzModule',
|
||||
'moment-picker',
|
||||
'angulartics',
|
||||
analyticsModule,
|
||||
]);
|
||||
|
||||
if (require) {
|
||||
var req = require.context('./', true, /^(.*\.(js$))[^.]*$/im);
|
||||
req
|
||||
.keys()
|
||||
.filter((path) => !path.includes('.test'))
|
||||
.forEach(function (key) {
|
||||
req(key);
|
||||
});
|
||||
}
|
72
app/app.js
72
app/app.js
|
@ -1,55 +1,43 @@
|
|||
import $ from 'jquery';
|
||||
import { PortainerEndpointTypes } from 'Portainer/models/endpoint/models';
|
||||
|
||||
angular.module('portainer').run([
|
||||
'$rootScope',
|
||||
'$state',
|
||||
'$interval',
|
||||
'LocalStorage',
|
||||
'EndpointProvider',
|
||||
'SystemService',
|
||||
'cfpLoadingBar',
|
||||
'$transitions',
|
||||
'HttpRequestHelper',
|
||||
function ($rootScope, $state, $interval, LocalStorage, EndpointProvider, SystemService, cfpLoadingBar, $transitions, HttpRequestHelper) {
|
||||
'use strict';
|
||||
/* @ngInject */
|
||||
export function onStartupAngular($rootScope, $state, $interval, LocalStorage, EndpointProvider, SystemService, cfpLoadingBar, $transitions, HttpRequestHelper) {
|
||||
EndpointProvider.initialize();
|
||||
|
||||
EndpointProvider.initialize();
|
||||
$rootScope.$state = $state;
|
||||
$rootScope.defaultTitle = document.title;
|
||||
|
||||
$rootScope.$state = $state;
|
||||
$rootScope.defaultTitle = document.title;
|
||||
// Workaround to prevent the loading bar from going backward
|
||||
// https://github.com/chieffancypants/angular-loading-bar/issues/273
|
||||
const originalSet = cfpLoadingBar.set;
|
||||
cfpLoadingBar.set = function overrideSet(n) {
|
||||
if (n > cfpLoadingBar.status()) {
|
||||
originalSet.apply(cfpLoadingBar, arguments);
|
||||
}
|
||||
};
|
||||
|
||||
// Workaround to prevent the loading bar from going backward
|
||||
// https://github.com/chieffancypants/angular-loading-bar/issues/273
|
||||
var originalSet = cfpLoadingBar.set;
|
||||
cfpLoadingBar.set = function overrideSet(n) {
|
||||
if (n > cfpLoadingBar.status()) {
|
||||
originalSet.apply(cfpLoadingBar, arguments);
|
||||
}
|
||||
};
|
||||
$transitions.onBefore({}, () => {
|
||||
HttpRequestHelper.resetAgentHeaders();
|
||||
});
|
||||
|
||||
$transitions.onBefore({}, function () {
|
||||
HttpRequestHelper.resetAgentHeaders();
|
||||
});
|
||||
// Keep-alive Edge endpoints by sending a ping request every minute
|
||||
$interval(() => {
|
||||
ping(EndpointProvider, SystemService);
|
||||
}, 60 * 1000);
|
||||
|
||||
// Keep-alive Edge endpoints by sending a ping request every minute
|
||||
$interval(function () {
|
||||
ping(EndpointProvider, SystemService);
|
||||
}, 60 * 1000);
|
||||
|
||||
$(document).ajaxSend(function (event, jqXhr, jqOpts) {
|
||||
const type = jqOpts.type === 'POST' || jqOpts.type === 'PUT' || jqOpts.type === 'PATCH';
|
||||
const hasNoContentType = jqOpts.contentType !== 'application/json' && jqOpts.headers && !jqOpts.headers['Content-Type'];
|
||||
if (type && hasNoContentType) {
|
||||
jqXhr.setRequestHeader('Content-Type', 'application/json');
|
||||
}
|
||||
jqXhr.setRequestHeader('Authorization', 'Bearer ' + LocalStorage.getJWT());
|
||||
});
|
||||
},
|
||||
]);
|
||||
$(document).ajaxSend((event, jqXhr, jqOpts) => {
|
||||
const type = jqOpts.type === 'POST' || jqOpts.type === 'PUT' || jqOpts.type === 'PATCH';
|
||||
const hasNoContentType = jqOpts.contentType !== 'application/json' && jqOpts.headers && !jqOpts.headers['Content-Type'];
|
||||
if (type && hasNoContentType) {
|
||||
jqXhr.setRequestHeader('Content-Type', 'application/json');
|
||||
}
|
||||
jqXhr.setRequestHeader('Authorization', 'Bearer ' + LocalStorage.getJWT());
|
||||
});
|
||||
}
|
||||
|
||||
function ping(EndpointProvider, SystemService) {
|
||||
let endpoint = EndpointProvider.currentEndpoint();
|
||||
const endpoint = EndpointProvider.currentEndpoint();
|
||||
if (endpoint !== undefined && endpoint.Type == PortainerEndpointTypes.EdgeAgentOnDockerEnvironment) {
|
||||
SystemService.ping(endpoint.Id);
|
||||
}
|
||||
|
|
110
app/config.js
110
app/config.js
|
@ -2,74 +2,60 @@ import toastr from 'toastr';
|
|||
import { Terminal } from 'xterm';
|
||||
import * as fit from 'xterm/lib/addons/fit/fit';
|
||||
|
||||
angular.module('portainer').config([
|
||||
'$urlRouterProvider',
|
||||
'$httpProvider',
|
||||
'localStorageServiceProvider',
|
||||
'jwtOptionsProvider',
|
||||
'$uibTooltipProvider',
|
||||
'$compileProvider',
|
||||
'cfpLoadingBarProvider',
|
||||
function ($urlRouterProvider, $httpProvider, localStorageServiceProvider, jwtOptionsProvider, $uibTooltipProvider, $compileProvider, cfpLoadingBarProvider) {
|
||||
'use strict';
|
||||
/* @ngInject */
|
||||
export function configApp($urlRouterProvider, $httpProvider, localStorageServiceProvider, jwtOptionsProvider, $uibTooltipProvider, $compileProvider, cfpLoadingBarProvider) {
|
||||
if (process.env.NODE_ENV === 'testing') {
|
||||
$compileProvider.debugInfoEnabled(false);
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV === 'testing') {
|
||||
$compileProvider.debugInfoEnabled(false);
|
||||
}
|
||||
localStorageServiceProvider.setPrefix('portainer');
|
||||
|
||||
localStorageServiceProvider.setPrefix('portainer');
|
||||
jwtOptionsProvider.config({
|
||||
tokenGetter: /* @ngInject */ function tokenGetter(LocalStorage) {
|
||||
return LocalStorage.getJWT();
|
||||
},
|
||||
});
|
||||
$httpProvider.interceptors.push('jwtInterceptor');
|
||||
$httpProvider.interceptors.push('EndpointStatusInterceptor');
|
||||
$httpProvider.defaults.headers.post['Content-Type'] = 'application/json';
|
||||
$httpProvider.defaults.headers.put['Content-Type'] = 'application/json';
|
||||
$httpProvider.defaults.headers.patch['Content-Type'] = 'application/json';
|
||||
|
||||
jwtOptionsProvider.config({
|
||||
tokenGetter: [
|
||||
'LocalStorage',
|
||||
function (LocalStorage) {
|
||||
return LocalStorage.getJWT();
|
||||
},
|
||||
],
|
||||
});
|
||||
$httpProvider.interceptors.push('jwtInterceptor');
|
||||
$httpProvider.interceptors.push('EndpointStatusInterceptor');
|
||||
$httpProvider.defaults.headers.post['Content-Type'] = 'application/json';
|
||||
$httpProvider.defaults.headers.put['Content-Type'] = 'application/json';
|
||||
$httpProvider.defaults.headers.patch['Content-Type'] = 'application/json';
|
||||
|
||||
$httpProvider.interceptors.push([
|
||||
'HttpRequestHelper',
|
||||
function (HttpRequestHelper) {
|
||||
return {
|
||||
request: function (config) {
|
||||
if (config.url.indexOf('/docker/') > -1) {
|
||||
config.headers['X-PortainerAgent-Target'] = HttpRequestHelper.portainerAgentTargetHeader();
|
||||
if (HttpRequestHelper.portainerAgentManagerOperation()) {
|
||||
config.headers['X-PortainerAgent-ManagerOperation'] = '1';
|
||||
}
|
||||
$httpProvider.interceptors.push(
|
||||
/* @ngInject */ function (HttpRequestHelper) {
|
||||
return {
|
||||
request(config) {
|
||||
if (config.url.indexOf('/docker/') > -1) {
|
||||
config.headers['X-PortainerAgent-Target'] = HttpRequestHelper.portainerAgentTargetHeader();
|
||||
if (HttpRequestHelper.portainerAgentManagerOperation()) {
|
||||
config.headers['X-PortainerAgent-ManagerOperation'] = '1';
|
||||
}
|
||||
return config;
|
||||
},
|
||||
};
|
||||
},
|
||||
]);
|
||||
}
|
||||
return config;
|
||||
},
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
toastr.options = {
|
||||
timeOut: 3000,
|
||||
closeButton: true,
|
||||
progressBar: true,
|
||||
tapToDismiss: false,
|
||||
};
|
||||
toastr.options = {
|
||||
timeOut: 3000,
|
||||
closeButton: true,
|
||||
progressBar: true,
|
||||
tapToDismiss: false,
|
||||
};
|
||||
|
||||
Terminal.applyAddon(fit);
|
||||
Terminal.applyAddon(fit);
|
||||
|
||||
$uibTooltipProvider.setTriggers({
|
||||
mouseenter: 'mouseleave',
|
||||
click: 'click',
|
||||
focus: 'blur',
|
||||
outsideClick: 'outsideClick',
|
||||
});
|
||||
$uibTooltipProvider.setTriggers({
|
||||
mouseenter: 'mouseleave',
|
||||
click: 'click',
|
||||
focus: 'blur',
|
||||
outsideClick: 'outsideClick',
|
||||
});
|
||||
|
||||
cfpLoadingBarProvider.includeSpinner = false;
|
||||
cfpLoadingBarProvider.parentSelector = '#loadingbar-placeholder';
|
||||
cfpLoadingBarProvider.latencyThreshold = 600;
|
||||
cfpLoadingBarProvider.includeSpinner = false;
|
||||
cfpLoadingBarProvider.parentSelector = '#loadingbar-placeholder';
|
||||
cfpLoadingBarProvider.latencyThreshold = 600;
|
||||
|
||||
$urlRouterProvider.otherwise('/auth');
|
||||
},
|
||||
]);
|
||||
$urlRouterProvider.otherwise('/auth');
|
||||
}
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
import './assets/css';
|
||||
import '@babel/polyfill';
|
||||
|
||||
import angular from 'angular';
|
||||
import { UI_ROUTER_REACT_HYBRID } from '@uirouter/react-hybrid';
|
||||
|
||||
import './matomo-setup';
|
||||
import analyticsModule from './angulartics.matomo';
|
||||
|
||||
import './agent';
|
||||
import './azure/_module';
|
||||
import './docker/__module';
|
||||
import './edge/__module';
|
||||
import './portainer/__module';
|
||||
|
||||
import { onStartupAngular } from './app';
|
||||
import { configApp } from './config';
|
||||
|
||||
angular
|
||||
.module('portainer', [
|
||||
'ui.bootstrap',
|
||||
'ui.router',
|
||||
UI_ROUTER_REACT_HYBRID,
|
||||
'ui.select',
|
||||
'isteven-multi-select',
|
||||
'ngSanitize',
|
||||
'ngFileUpload',
|
||||
'ngMessages',
|
||||
'ngResource',
|
||||
'angularUtils.directives.dirPagination',
|
||||
'LocalStorageModule',
|
||||
'angular-jwt',
|
||||
'angular-json-tree',
|
||||
'angular-loading-bar',
|
||||
'angular-clipboard',
|
||||
'ngFileSaver',
|
||||
'luegg.directives',
|
||||
'portainer.app',
|
||||
'portainer.agent',
|
||||
'portainer.azure',
|
||||
'portainer.docker',
|
||||
'portainer.kubernetes',
|
||||
'portainer.edge',
|
||||
'portainer.integrations',
|
||||
'rzModule',
|
||||
'moment-picker',
|
||||
'angulartics',
|
||||
analyticsModule,
|
||||
])
|
||||
.run(onStartupAngular)
|
||||
.config(configApp);
|
||||
|
||||
if (require) {
|
||||
const req = require.context('./', true, /^(.*\.(js$))[^.]*$/im);
|
||||
req
|
||||
.keys()
|
||||
.filter((path) => !path.includes('.test'))
|
||||
.forEach(function (key) {
|
||||
req(key);
|
||||
});
|
||||
}
|
|
@ -14,7 +14,7 @@ const projectRoot = path.resolve(__dirname, '..');
|
|||
|
||||
module.exports = {
|
||||
entry: {
|
||||
main: './app/__module.js',
|
||||
main: './app',
|
||||
},
|
||||
output: {
|
||||
filename: '[name].[hash].js',
|
||||
|
|
Loading…
Reference in New Issue