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 $ from 'jquery';
|
||||||
import { PortainerEndpointTypes } from 'Portainer/models/endpoint/models';
|
import { PortainerEndpointTypes } from 'Portainer/models/endpoint/models';
|
||||||
|
|
||||||
angular.module('portainer').run([
|
/* @ngInject */
|
||||||
'$rootScope',
|
export function onStartupAngular($rootScope, $state, $interval, LocalStorage, EndpointProvider, SystemService, cfpLoadingBar, $transitions, HttpRequestHelper) {
|
||||||
'$state',
|
EndpointProvider.initialize();
|
||||||
'$interval',
|
|
||||||
'LocalStorage',
|
|
||||||
'EndpointProvider',
|
|
||||||
'SystemService',
|
|
||||||
'cfpLoadingBar',
|
|
||||||
'$transitions',
|
|
||||||
'HttpRequestHelper',
|
|
||||||
function ($rootScope, $state, $interval, LocalStorage, EndpointProvider, SystemService, cfpLoadingBar, $transitions, HttpRequestHelper) {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
EndpointProvider.initialize();
|
$rootScope.$state = $state;
|
||||||
|
$rootScope.defaultTitle = document.title;
|
||||||
|
|
||||||
$rootScope.$state = $state;
|
// Workaround to prevent the loading bar from going backward
|
||||||
$rootScope.defaultTitle = document.title;
|
// 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
|
$transitions.onBefore({}, () => {
|
||||||
// https://github.com/chieffancypants/angular-loading-bar/issues/273
|
HttpRequestHelper.resetAgentHeaders();
|
||||||
var originalSet = cfpLoadingBar.set;
|
});
|
||||||
cfpLoadingBar.set = function overrideSet(n) {
|
|
||||||
if (n > cfpLoadingBar.status()) {
|
|
||||||
originalSet.apply(cfpLoadingBar, arguments);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
$transitions.onBefore({}, function () {
|
// Keep-alive Edge endpoints by sending a ping request every minute
|
||||||
HttpRequestHelper.resetAgentHeaders();
|
$interval(() => {
|
||||||
});
|
ping(EndpointProvider, SystemService);
|
||||||
|
}, 60 * 1000);
|
||||||
|
|
||||||
// Keep-alive Edge endpoints by sending a ping request every minute
|
$(document).ajaxSend((event, jqXhr, jqOpts) => {
|
||||||
$interval(function () {
|
const type = jqOpts.type === 'POST' || jqOpts.type === 'PUT' || jqOpts.type === 'PATCH';
|
||||||
ping(EndpointProvider, SystemService);
|
const hasNoContentType = jqOpts.contentType !== 'application/json' && jqOpts.headers && !jqOpts.headers['Content-Type'];
|
||||||
}, 60 * 1000);
|
if (type && hasNoContentType) {
|
||||||
|
jqXhr.setRequestHeader('Content-Type', 'application/json');
|
||||||
$(document).ajaxSend(function (event, jqXhr, jqOpts) {
|
}
|
||||||
const type = jqOpts.type === 'POST' || jqOpts.type === 'PUT' || jqOpts.type === 'PATCH';
|
jqXhr.setRequestHeader('Authorization', 'Bearer ' + LocalStorage.getJWT());
|
||||||
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) {
|
function ping(EndpointProvider, SystemService) {
|
||||||
let endpoint = EndpointProvider.currentEndpoint();
|
const endpoint = EndpointProvider.currentEndpoint();
|
||||||
if (endpoint !== undefined && endpoint.Type == PortainerEndpointTypes.EdgeAgentOnDockerEnvironment) {
|
if (endpoint !== undefined && endpoint.Type == PortainerEndpointTypes.EdgeAgentOnDockerEnvironment) {
|
||||||
SystemService.ping(endpoint.Id);
|
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 { Terminal } from 'xterm';
|
||||||
import * as fit from 'xterm/lib/addons/fit/fit';
|
import * as fit from 'xterm/lib/addons/fit/fit';
|
||||||
|
|
||||||
angular.module('portainer').config([
|
/* @ngInject */
|
||||||
'$urlRouterProvider',
|
export function configApp($urlRouterProvider, $httpProvider, localStorageServiceProvider, jwtOptionsProvider, $uibTooltipProvider, $compileProvider, cfpLoadingBarProvider) {
|
||||||
'$httpProvider',
|
if (process.env.NODE_ENV === 'testing') {
|
||||||
'localStorageServiceProvider',
|
$compileProvider.debugInfoEnabled(false);
|
||||||
'jwtOptionsProvider',
|
}
|
||||||
'$uibTooltipProvider',
|
|
||||||
'$compileProvider',
|
|
||||||
'cfpLoadingBarProvider',
|
|
||||||
function ($urlRouterProvider, $httpProvider, localStorageServiceProvider, jwtOptionsProvider, $uibTooltipProvider, $compileProvider, cfpLoadingBarProvider) {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
if (process.env.NODE_ENV === 'testing') {
|
localStorageServiceProvider.setPrefix('portainer');
|
||||||
$compileProvider.debugInfoEnabled(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
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({
|
$httpProvider.interceptors.push(
|
||||||
tokenGetter: [
|
/* @ngInject */ function (HttpRequestHelper) {
|
||||||
'LocalStorage',
|
return {
|
||||||
function (LocalStorage) {
|
request(config) {
|
||||||
return LocalStorage.getJWT();
|
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('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';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return config;
|
}
|
||||||
},
|
return config;
|
||||||
};
|
},
|
||||||
},
|
};
|
||||||
]);
|
}
|
||||||
|
);
|
||||||
|
|
||||||
toastr.options = {
|
toastr.options = {
|
||||||
timeOut: 3000,
|
timeOut: 3000,
|
||||||
closeButton: true,
|
closeButton: true,
|
||||||
progressBar: true,
|
progressBar: true,
|
||||||
tapToDismiss: false,
|
tapToDismiss: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
Terminal.applyAddon(fit);
|
Terminal.applyAddon(fit);
|
||||||
|
|
||||||
$uibTooltipProvider.setTriggers({
|
$uibTooltipProvider.setTriggers({
|
||||||
mouseenter: 'mouseleave',
|
mouseenter: 'mouseleave',
|
||||||
click: 'click',
|
click: 'click',
|
||||||
focus: 'blur',
|
focus: 'blur',
|
||||||
outsideClick: 'outsideClick',
|
outsideClick: 'outsideClick',
|
||||||
});
|
});
|
||||||
|
|
||||||
cfpLoadingBarProvider.includeSpinner = false;
|
cfpLoadingBarProvider.includeSpinner = false;
|
||||||
cfpLoadingBarProvider.parentSelector = '#loadingbar-placeholder';
|
cfpLoadingBarProvider.parentSelector = '#loadingbar-placeholder';
|
||||||
cfpLoadingBarProvider.latencyThreshold = 600;
|
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 = {
|
module.exports = {
|
||||||
entry: {
|
entry: {
|
||||||
main: './app/__module.js',
|
main: './app',
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
filename: '[name].[hash].js',
|
filename: '[name].[hash].js',
|
||||||
|
|
Loading…
Reference in New Issue