mirror of
https://github.com/portainer/portainer.git
synced 2025-08-09 15:55:23 +02:00
refactor(endpoints): remove endpointProvider from views [EE-1136] (#5359)
[EE-1136]
This commit is contained in:
parent
7088da5157
commit
eb9f6c77f4
56 changed files with 408 additions and 429 deletions
|
@ -35,3 +35,7 @@ export default class EndpointHelper {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function isOfflineEndpoint(endpoint) {
|
||||
return endpoint.Status !== 1;
|
||||
}
|
||||
|
|
|
@ -1,26 +1,25 @@
|
|||
angular.module('portainer.app').factory('Stack', [
|
||||
'$resource',
|
||||
'EndpointProvider',
|
||||
'API_ENDPOINT_STACKS',
|
||||
function StackFactory($resource, EndpointProvider, API_ENDPOINT_STACKS) {
|
||||
'use strict';
|
||||
return $resource(
|
||||
API_ENDPOINT_STACKS + '/:id/:action/:subaction',
|
||||
{},
|
||||
{
|
||||
get: { method: 'GET', params: { id: '@id' } },
|
||||
query: { method: 'GET', isArray: true },
|
||||
create: { method: 'POST', ignoreLoadingBar: true },
|
||||
update: { method: 'PUT', params: { id: '@id' }, ignoreLoadingBar: true },
|
||||
associate: { method: 'PUT', params: { id: '@id', swarmId: '@swarmId', endpointId: '@endpointId', orphanedRunning: '@orphanedRunning', action: 'associate' } },
|
||||
remove: { method: 'DELETE', params: { id: '@id', external: '@external', endpointId: '@endpointId' } },
|
||||
getStackFile: { method: 'GET', params: { id: '@id', action: 'file' } },
|
||||
migrate: { method: 'POST', params: { id: '@id', action: 'migrate', endpointId: '@endpointId' }, ignoreLoadingBar: true },
|
||||
start: { method: 'POST', params: { id: '@id', action: 'start' } },
|
||||
stop: { method: 'POST', params: { id: '@id', action: 'stop' } },
|
||||
updateGit: { method: 'PUT', params: { id: '@id', action: 'git', subaction: 'redeploy' } },
|
||||
updateGitStackSettings: { method: 'POST', params: { id: '@id', action: 'git' }, ignoreLoadingBar: true },
|
||||
}
|
||||
);
|
||||
},
|
||||
]);
|
||||
import angular from 'angular';
|
||||
|
||||
angular.module('portainer.app').factory('Stack', StackFactory);
|
||||
|
||||
/* @ngInject */
|
||||
function StackFactory($resource, API_ENDPOINT_STACKS) {
|
||||
return $resource(
|
||||
API_ENDPOINT_STACKS + '/:id/:action',
|
||||
{},
|
||||
{
|
||||
get: { method: 'GET', params: { id: '@id' } },
|
||||
query: { method: 'GET', isArray: true },
|
||||
create: { method: 'POST', ignoreLoadingBar: true },
|
||||
update: { method: 'PUT', params: { id: '@id' }, ignoreLoadingBar: true },
|
||||
associate: { method: 'PUT', params: { id: '@id', swarmId: '@swarmId', endpointId: '@endpointId', orphanedRunning: '@orphanedRunning', action: 'associate' } },
|
||||
remove: { method: 'DELETE', params: { id: '@id', external: '@external', endpointId: '@endpointId' } },
|
||||
getStackFile: { method: 'GET', params: { id: '@id', action: 'file' } },
|
||||
migrate: { method: 'POST', params: { id: '@id', action: 'migrate', endpointId: '@endpointId' }, ignoreLoadingBar: true },
|
||||
start: { method: 'POST', params: { id: '@id', action: 'start' } },
|
||||
stop: { method: 'POST', params: { id: '@id', action: 'stop' } },
|
||||
updateGit: { method: 'PUT', params: { id: '@id', action: 'git', subaction: 'redeploy' } },
|
||||
updateGitStackSettings: { method: 'POST', params: { id: '@id', action: 'git' }, ignoreLoadingBar: true },
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -4,12 +4,13 @@ import { TemplateViewModel } from '../../models/template';
|
|||
angular.module('portainer.app').factory('TemplateService', TemplateServiceFactory);
|
||||
|
||||
/* @ngInject */
|
||||
function TemplateServiceFactory($q, Templates, TemplateHelper, EndpointProvider, ImageHelper, ContainerHelper, EndpointService) {
|
||||
var service = {};
|
||||
function TemplateServiceFactory($q, Templates, TemplateHelper, ImageHelper, ContainerHelper, EndpointService) {
|
||||
var service = {
|
||||
templates,
|
||||
};
|
||||
|
||||
service.templates = function () {
|
||||
function templates(endpointId) {
|
||||
const deferred = $q.defer();
|
||||
const endpointId = EndpointProvider.currentEndpoint().Id;
|
||||
|
||||
$q.all({
|
||||
templates: Templates.query().$promise,
|
||||
|
@ -36,7 +37,7 @@ function TemplateServiceFactory($q, Templates, TemplateHelper, EndpointProvider,
|
|||
});
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
}
|
||||
|
||||
service.templateFile = templateFile;
|
||||
function templateFile(repositoryUrl, composeFilePathInRepository) {
|
||||
|
|
|
@ -1,236 +1,226 @@
|
|||
import moment from 'moment';
|
||||
|
||||
angular.module('portainer.app').factory('StateManager', [
|
||||
'$q',
|
||||
'$async',
|
||||
'SystemService',
|
||||
'InfoHelper',
|
||||
'LocalStorage',
|
||||
'SettingsService',
|
||||
'StatusService',
|
||||
'APPLICATION_CACHE_VALIDITY',
|
||||
'AgentPingService',
|
||||
'$analytics',
|
||||
'EndpointProvider',
|
||||
function StateManagerFactory(
|
||||
$q,
|
||||
$async,
|
||||
SystemService,
|
||||
InfoHelper,
|
||||
LocalStorage,
|
||||
SettingsService,
|
||||
StatusService,
|
||||
APPLICATION_CACHE_VALIDITY,
|
||||
AgentPingService,
|
||||
$analytics,
|
||||
EndpointProvider
|
||||
) {
|
||||
var manager = {};
|
||||
angular.module('portainer.app').factory('StateManager', StateManagerFactory);
|
||||
|
||||
var state = {
|
||||
loading: true,
|
||||
application: {},
|
||||
endpoint: {},
|
||||
UI: {
|
||||
dismissedInfoPanels: {},
|
||||
dismissedInfoHash: '',
|
||||
},
|
||||
extensions: [],
|
||||
};
|
||||
/* @ngInject */
|
||||
function StateManagerFactory(
|
||||
$async,
|
||||
$q,
|
||||
SystemService,
|
||||
InfoHelper,
|
||||
LocalStorage,
|
||||
SettingsService,
|
||||
StatusService,
|
||||
APPLICATION_CACHE_VALIDITY,
|
||||
AgentPingService,
|
||||
$analytics,
|
||||
EndpointProvider
|
||||
) {
|
||||
var manager = {};
|
||||
|
||||
manager.setVersionInfo = function (versionInfo) {
|
||||
state.application.versionStatus = versionInfo;
|
||||
LocalStorage.storeApplicationState(state.application);
|
||||
};
|
||||
var state = {
|
||||
loading: true,
|
||||
application: {},
|
||||
endpoint: {},
|
||||
UI: {
|
||||
dismissedInfoPanels: {},
|
||||
dismissedInfoHash: '',
|
||||
},
|
||||
extensions: [],
|
||||
};
|
||||
|
||||
manager.dismissInformationPanel = function (id) {
|
||||
state.UI.dismissedInfoPanels[id] = true;
|
||||
LocalStorage.storeUIState(state.UI);
|
||||
};
|
||||
manager.setVersionInfo = function (versionInfo) {
|
||||
state.application.versionStatus = versionInfo;
|
||||
LocalStorage.storeApplicationState(state.application);
|
||||
};
|
||||
|
||||
manager.dismissImportantInformation = function (hash) {
|
||||
state.UI.dismissedInfoHash = hash;
|
||||
LocalStorage.storeUIState(state.UI);
|
||||
};
|
||||
manager.dismissInformationPanel = function (id) {
|
||||
state.UI.dismissedInfoPanels[id] = true;
|
||||
LocalStorage.storeUIState(state.UI);
|
||||
};
|
||||
|
||||
manager.getState = function () {
|
||||
return state;
|
||||
};
|
||||
manager.dismissImportantInformation = function (hash) {
|
||||
state.UI.dismissedInfoHash = hash;
|
||||
LocalStorage.storeUIState(state.UI);
|
||||
};
|
||||
|
||||
manager.clean = function () {
|
||||
state.endpoint = {};
|
||||
state.application = {};
|
||||
};
|
||||
manager.getState = function () {
|
||||
return state;
|
||||
};
|
||||
|
||||
manager.cleanEndpoint = function () {
|
||||
state.endpoint = {};
|
||||
EndpointProvider.clean();
|
||||
};
|
||||
manager.clean = function () {
|
||||
state.endpoint = {};
|
||||
state.application = {};
|
||||
};
|
||||
|
||||
manager.updateLogo = function (logoURL) {
|
||||
state.application.logo = logoURL;
|
||||
LocalStorage.storeApplicationState(state.application);
|
||||
};
|
||||
manager.cleanEndpoint = function () {
|
||||
state.endpoint = {};
|
||||
EndpointProvider.clean();
|
||||
};
|
||||
|
||||
manager.updateTheme = function (theme) {
|
||||
state.application.theme = theme;
|
||||
LocalStorage.storeApplicationState(state.application);
|
||||
};
|
||||
manager.updateLogo = function (logoURL) {
|
||||
state.application.logo = logoURL;
|
||||
LocalStorage.storeApplicationState(state.application);
|
||||
};
|
||||
|
||||
manager.updateSnapshotInterval = function (interval) {
|
||||
state.application.snapshotInterval = interval;
|
||||
LocalStorage.storeApplicationState(state.application);
|
||||
};
|
||||
manager.updateTheme = function (theme) {
|
||||
state.application.theme = theme;
|
||||
LocalStorage.storeApplicationState(state.application);
|
||||
};
|
||||
|
||||
manager.updateEnableEdgeComputeFeatures = function updateEnableEdgeComputeFeatures(enableEdgeComputeFeatures) {
|
||||
state.application.enableEdgeComputeFeatures = enableEdgeComputeFeatures;
|
||||
LocalStorage.storeApplicationState(state.application);
|
||||
};
|
||||
manager.updateSnapshotInterval = function (interval) {
|
||||
state.application.snapshotInterval = interval;
|
||||
LocalStorage.storeApplicationState(state.application);
|
||||
};
|
||||
|
||||
manager.updateEnableTelemetry = function updateEnableTelemetry(enableTelemetry) {
|
||||
state.application.enableTelemetry = enableTelemetry;
|
||||
$analytics.setOptOut(!enableTelemetry);
|
||||
LocalStorage.storeApplicationState(state.application);
|
||||
};
|
||||
manager.updateEnableEdgeComputeFeatures = function updateEnableEdgeComputeFeatures(enableEdgeComputeFeatures) {
|
||||
state.application.enableEdgeComputeFeatures = enableEdgeComputeFeatures;
|
||||
LocalStorage.storeApplicationState(state.application);
|
||||
};
|
||||
|
||||
function assignStateFromStatusAndSettings(status, settings) {
|
||||
state.application.version = status.Version;
|
||||
state.application.edition = status.Edition;
|
||||
state.application.instanceId = status.InstanceID;
|
||||
manager.updateEnableTelemetry = function updateEnableTelemetry(enableTelemetry) {
|
||||
state.application.enableTelemetry = enableTelemetry;
|
||||
$analytics.setOptOut(!enableTelemetry);
|
||||
LocalStorage.storeApplicationState(state.application);
|
||||
};
|
||||
|
||||
state.application.enableTelemetry = settings.EnableTelemetry;
|
||||
state.application.logo = settings.LogoURL;
|
||||
state.application.snapshotInterval = settings.SnapshotInterval;
|
||||
state.application.enableEdgeComputeFeatures = settings.EnableEdgeComputeFeatures;
|
||||
state.application.validity = moment().unix();
|
||||
}
|
||||
function assignStateFromStatusAndSettings(status, settings) {
|
||||
state.application.version = status.Version;
|
||||
state.application.edition = status.Edition;
|
||||
state.application.instanceId = status.InstanceID;
|
||||
|
||||
function loadApplicationState() {
|
||||
var deferred = $q.defer();
|
||||
state.application.enableTelemetry = settings.EnableTelemetry;
|
||||
state.application.logo = settings.LogoURL;
|
||||
state.application.snapshotInterval = settings.SnapshotInterval;
|
||||
state.application.enableEdgeComputeFeatures = settings.EnableEdgeComputeFeatures;
|
||||
state.application.validity = moment().unix();
|
||||
}
|
||||
|
||||
$q.all({
|
||||
settings: SettingsService.publicSettings(),
|
||||
status: StatusService.status(),
|
||||
function loadApplicationState() {
|
||||
var deferred = $q.defer();
|
||||
|
||||
$q.all({
|
||||
settings: SettingsService.publicSettings(),
|
||||
status: StatusService.status(),
|
||||
})
|
||||
.then(function success(data) {
|
||||
var status = data.status;
|
||||
var settings = data.settings;
|
||||
assignStateFromStatusAndSettings(status, settings);
|
||||
LocalStorage.storeApplicationState(state.application);
|
||||
deferred.resolve(state);
|
||||
})
|
||||
.then(function success(data) {
|
||||
var status = data.status;
|
||||
var settings = data.settings;
|
||||
assignStateFromStatusAndSettings(status, settings);
|
||||
LocalStorage.storeApplicationState(state.application);
|
||||
deferred.resolve(state);
|
||||
})
|
||||
.catch(function error(err) {
|
||||
deferred.reject({ msg: 'Unable to retrieve server settings and status', err: err });
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
manager.initialize = initialize;
|
||||
async function initialize() {
|
||||
return $async(async () => {
|
||||
const UIState = LocalStorage.getUIState();
|
||||
if (UIState) {
|
||||
state.UI = UIState;
|
||||
}
|
||||
|
||||
const endpointState = LocalStorage.getEndpointState();
|
||||
if (endpointState) {
|
||||
state.endpoint = endpointState;
|
||||
}
|
||||
|
||||
const applicationState = LocalStorage.getApplicationState();
|
||||
if (isAppStateValid(applicationState)) {
|
||||
state.application = applicationState;
|
||||
} else {
|
||||
await loadApplicationState();
|
||||
}
|
||||
|
||||
state.loading = false;
|
||||
$analytics.setPortainerStatus(state.application.instanceId, state.application.version);
|
||||
$analytics.setOptOut(!state.application.enableTelemetry);
|
||||
return state;
|
||||
.catch(function error(err) {
|
||||
deferred.reject({ msg: 'Unable to retrieve server settings and status', err: err });
|
||||
});
|
||||
}
|
||||
|
||||
function isAppStateValid(appState) {
|
||||
if (!appState || !appState.validity) {
|
||||
return false;
|
||||
}
|
||||
const now = moment().unix();
|
||||
const cacheValidity = now - appState.validity;
|
||||
return cacheValidity < APPLICATION_CACHE_VALIDITY;
|
||||
}
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function assignExtensions(endpointExtensions) {
|
||||
var extensions = [];
|
||||
|
||||
for (var i = 0; i < endpointExtensions.length; i++) {
|
||||
var extension = endpointExtensions[i];
|
||||
if (extension.Type === 1) {
|
||||
extensions.push('storidge');
|
||||
}
|
||||
manager.initialize = initialize;
|
||||
async function initialize() {
|
||||
return $async(async () => {
|
||||
const UIState = LocalStorage.getUIState();
|
||||
if (UIState) {
|
||||
state.UI = UIState;
|
||||
}
|
||||
|
||||
return extensions;
|
||||
}
|
||||
|
||||
manager.updateEndpointState = function (endpoint, extensions) {
|
||||
var deferred = $q.defer();
|
||||
|
||||
if (endpoint.Type === 3) {
|
||||
state.endpoint.name = endpoint.Name;
|
||||
state.endpoint.mode = { provider: 'AZURE' };
|
||||
LocalStorage.storeEndpointState(state.endpoint);
|
||||
deferred.resolve();
|
||||
return deferred.promise;
|
||||
} else if (endpoint.Type === 5 || endpoint.Type === 6 || endpoint.Type === 7) {
|
||||
state.endpoint.name = endpoint.Name;
|
||||
state.endpoint.mode = { provider: 'KUBERNETES' };
|
||||
LocalStorage.storeEndpointState(state.endpoint);
|
||||
deferred.resolve();
|
||||
return deferred.promise;
|
||||
const endpointState = LocalStorage.getEndpointState();
|
||||
if (endpointState) {
|
||||
state.endpoint = endpointState;
|
||||
}
|
||||
|
||||
const reload = endpoint.Status === 1 || !endpoint.Snaphosts || !endpoint.Snaphosts.length || !endpoint.Snapshots[0].SnapshotRaw;
|
||||
const applicationState = LocalStorage.getApplicationState();
|
||||
if (isAppStateValid(applicationState)) {
|
||||
state.application = applicationState;
|
||||
} else {
|
||||
await loadApplicationState();
|
||||
}
|
||||
|
||||
$q.all({
|
||||
version: reload ? SystemService.version() : $q.when(endpoint.Snapshots[0].SnapshotRaw.Version),
|
||||
info: reload ? SystemService.info() : $q.when(endpoint.Snapshots[0].SnapshotRaw.Info),
|
||||
})
|
||||
.then(function success(data) {
|
||||
var endpointMode = InfoHelper.determineEndpointMode(data.info, endpoint.Type);
|
||||
var endpointAPIVersion = parseFloat(data.version.ApiVersion);
|
||||
state.endpoint.mode = endpointMode;
|
||||
state.endpoint.name = endpoint.Name;
|
||||
state.endpoint.type = endpoint.Type;
|
||||
state.endpoint.apiVersion = endpointAPIVersion;
|
||||
state.endpoint.extensions = assignExtensions(extensions);
|
||||
state.loading = false;
|
||||
$analytics.setPortainerStatus(state.application.instanceId, state.application.version);
|
||||
$analytics.setOptOut(!state.application.enableTelemetry);
|
||||
return state;
|
||||
});
|
||||
}
|
||||
|
||||
if (endpointMode.agentProxy && endpoint.Status === 1) {
|
||||
return AgentPingService.ping().then(function onPingSuccess(data) {
|
||||
state.endpoint.agentApiVersion = data.version;
|
||||
});
|
||||
}
|
||||
})
|
||||
.then(function () {
|
||||
LocalStorage.storeEndpointState(state.endpoint);
|
||||
deferred.resolve();
|
||||
})
|
||||
.catch(function error(err) {
|
||||
deferred.reject({ msg: 'Unable to connect to the Docker environment', err: err });
|
||||
})
|
||||
.finally(function final() {
|
||||
state.loading = false;
|
||||
});
|
||||
function isAppStateValid(appState) {
|
||||
if (!appState || !appState.validity) {
|
||||
return false;
|
||||
}
|
||||
const now = moment().unix();
|
||||
const cacheValidity = now - appState.validity;
|
||||
return cacheValidity < APPLICATION_CACHE_VALIDITY;
|
||||
}
|
||||
|
||||
function assignExtensions(endpointExtensions) {
|
||||
var extensions = [];
|
||||
|
||||
for (var i = 0; i < endpointExtensions.length; i++) {
|
||||
var extension = endpointExtensions[i];
|
||||
if (extension.Type === 1) {
|
||||
extensions.push('storidge');
|
||||
}
|
||||
}
|
||||
|
||||
return extensions;
|
||||
}
|
||||
|
||||
manager.updateEndpointState = function (endpoint, extensions) {
|
||||
var deferred = $q.defer();
|
||||
|
||||
if (endpoint.Type === 3) {
|
||||
state.endpoint.name = endpoint.Name;
|
||||
state.endpoint.mode = { provider: 'AZURE' };
|
||||
LocalStorage.storeEndpointState(state.endpoint);
|
||||
deferred.resolve();
|
||||
return deferred.promise;
|
||||
};
|
||||
} else if (endpoint.Type === 5 || endpoint.Type === 6 || endpoint.Type === 7) {
|
||||
state.endpoint.name = endpoint.Name;
|
||||
state.endpoint.mode = { provider: 'KUBERNETES' };
|
||||
LocalStorage.storeEndpointState(state.endpoint);
|
||||
deferred.resolve();
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
manager.getAgentApiVersion = function getAgentApiVersion() {
|
||||
return state.endpoint.agentApiVersion;
|
||||
};
|
||||
const reload = endpoint.Status === 1 || !endpoint.Snaphosts || !endpoint.Snaphosts.length || !endpoint.Snapshots[0].SnapshotRaw;
|
||||
|
||||
return manager;
|
||||
},
|
||||
]);
|
||||
$q.all({
|
||||
version: reload ? SystemService.version() : $q.when(endpoint.Snapshots[0].SnapshotRaw.Version),
|
||||
info: reload ? SystemService.info() : $q.when(endpoint.Snapshots[0].SnapshotRaw.Info),
|
||||
})
|
||||
.then(function success(data) {
|
||||
var endpointMode = InfoHelper.determineEndpointMode(data.info, endpoint.Type);
|
||||
var endpointAPIVersion = parseFloat(data.version.ApiVersion);
|
||||
state.endpoint.mode = endpointMode;
|
||||
state.endpoint.name = endpoint.Name;
|
||||
state.endpoint.type = endpoint.Type;
|
||||
state.endpoint.apiVersion = endpointAPIVersion;
|
||||
state.endpoint.extensions = assignExtensions(extensions);
|
||||
|
||||
if (endpointMode.agentProxy && endpoint.Status === 1) {
|
||||
return AgentPingService.ping().then(function onPingSuccess(data) {
|
||||
state.endpoint.agentApiVersion = data.version;
|
||||
});
|
||||
}
|
||||
})
|
||||
.then(function () {
|
||||
LocalStorage.storeEndpointState(state.endpoint);
|
||||
deferred.resolve();
|
||||
})
|
||||
.catch(function error(err) {
|
||||
deferred.reject({ msg: 'Unable to connect to the Docker environment', err: err });
|
||||
})
|
||||
.finally(function final() {
|
||||
state.loading = false;
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
manager.getAgentApiVersion = function getAgentApiVersion() {
|
||||
return state.endpoint.agentApiVersion;
|
||||
};
|
||||
|
||||
return manager;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ class CustomTemplatesViewController {
|
|||
$state,
|
||||
Authentication,
|
||||
CustomTemplateService,
|
||||
EndpointProvider,
|
||||
FormValidator,
|
||||
ModalService,
|
||||
NetworkService,
|
||||
|
@ -26,7 +25,6 @@ class CustomTemplatesViewController {
|
|||
this.$state = $state;
|
||||
this.Authentication = Authentication;
|
||||
this.CustomTemplateService = CustomTemplateService;
|
||||
this.EndpointProvider = EndpointProvider;
|
||||
this.FormValidator = FormValidator;
|
||||
this.ModalService = ModalService;
|
||||
this.NetworkService = NetworkService;
|
||||
|
@ -132,7 +130,7 @@ class CustomTemplatesViewController {
|
|||
}
|
||||
const stackName = this.formValues.name;
|
||||
|
||||
const endpointId = this.EndpointProvider.endpointID();
|
||||
const endpointId = this.endpoint.Id;
|
||||
|
||||
this.state.actionInProgress = true;
|
||||
|
||||
|
|
|
@ -3,4 +3,7 @@ import CustomTemplatesViewController from './customTemplatesViewController.js';
|
|||
angular.module('portainer.app').component('customTemplatesView', {
|
||||
templateUrl: './customTemplatesView.html',
|
||||
controller: CustomTemplatesViewController,
|
||||
bindings: {
|
||||
endpoint: '<',
|
||||
},
|
||||
});
|
||||
|
|
|
@ -19,7 +19,6 @@ function EndpointController(
|
|||
EndpointService,
|
||||
GroupService,
|
||||
TagService,
|
||||
EndpointProvider,
|
||||
Notifications,
|
||||
Authentication,
|
||||
SettingsService,
|
||||
|
@ -191,7 +190,6 @@ function EndpointController(
|
|||
EndpointService.updateEndpoint(endpoint.Id, payload).then(
|
||||
function success() {
|
||||
Notifications.success('Environment updated', $scope.endpoint.Name);
|
||||
EndpointProvider.setEndpointPublicURL(endpoint.PublicURL);
|
||||
$state.go('portainer.endpoints', {}, { reload: true });
|
||||
},
|
||||
function error(err) {
|
||||
|
|
|
@ -9,12 +9,11 @@ require('./includes/agent.html');
|
|||
|
||||
class InitEndpointController {
|
||||
/* @ngInject */
|
||||
constructor($async, $scope, $state, EndpointService, EndpointProvider, StateManager, Notifications) {
|
||||
constructor($async, $scope, $state, EndpointService, StateManager, Notifications) {
|
||||
this.$async = $async;
|
||||
this.$scope = $scope;
|
||||
this.$state = $state;
|
||||
this.EndpointService = EndpointService;
|
||||
this.EndpointProvider = EndpointProvider;
|
||||
this.StateManager = StateManager;
|
||||
this.Notifications = Notifications;
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@ import { RegistryCreateFormValues } from 'Portainer/models/registry';
|
|||
|
||||
class CreateRegistryController {
|
||||
/* @ngInject */
|
||||
constructor($async, $state, EndpointProvider, Notifications, RegistryService, RegistryGitlabService) {
|
||||
Object.assign(this, { $async, $state, EndpointProvider, Notifications, RegistryService, RegistryGitlabService });
|
||||
constructor($async, $state, Notifications, RegistryService, RegistryGitlabService) {
|
||||
Object.assign(this, { $async, $state, Notifications, RegistryService, RegistryGitlabService });
|
||||
|
||||
this.RegistryTypes = RegistryTypes;
|
||||
this.state = {
|
||||
|
@ -17,6 +17,7 @@ class CreateRegistryController {
|
|||
selectedItems: [],
|
||||
},
|
||||
originViewReference: 'portainer.registries',
|
||||
originalEndpointId: null,
|
||||
};
|
||||
|
||||
this.createRegistry = this.createRegistry.bind(this);
|
||||
|
@ -105,7 +106,7 @@ class CreateRegistryController {
|
|||
this.state.actionInProgress = true;
|
||||
await this.RegistryService.createGitlabRegistries(this.model, this.state.gitlab.selectedItems);
|
||||
this.Notifications.success('Registries successfully created');
|
||||
this.$state.go(this.state.originViewReference, { endpointId: this.EndpointProvider.endpointID() });
|
||||
this.$state.go(this.state.originViewReference, { endpointId: this.state.originalEndpointId });
|
||||
} catch (err) {
|
||||
this.Notifications.error('Failure', err, 'Unable to create registries');
|
||||
this.state.actionInProgress = false;
|
||||
|
@ -119,7 +120,7 @@ class CreateRegistryController {
|
|||
this.state.actionInProgress = true;
|
||||
await this.RegistryService.createRegistry(this.model);
|
||||
this.Notifications.success('Registry successfully created');
|
||||
this.$state.go(this.state.originViewReference, { endpointId: this.EndpointProvider.endpointID() });
|
||||
this.$state.go(this.state.originViewReference, { endpointId: this.state.originalEndpointId });
|
||||
} catch (err) {
|
||||
this.Notifications.error('Failure', err, 'Unable to create registry');
|
||||
this.state.actionInProgress = false;
|
||||
|
@ -130,9 +131,12 @@ class CreateRegistryController {
|
|||
$onInit() {
|
||||
this.model = new RegistryCreateFormValues();
|
||||
|
||||
const origin = this.$transition$.originalTransition().from();
|
||||
if (origin.name && /^[a-z]+\.registries$/.test(origin.name)) {
|
||||
this.state.originViewReference = origin;
|
||||
const from = this.$transition$.from();
|
||||
const params = this.$transition$.params('from');
|
||||
|
||||
if (from.name && /^[a-z]+\.registries$/.test(from.name)) {
|
||||
this.state.originViewReference = from;
|
||||
this.state.originalEndpointId = params.endpointId || null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,13 +19,13 @@ angular
|
|||
FormValidator,
|
||||
ResourceControlService,
|
||||
FormHelper,
|
||||
EndpointProvider,
|
||||
StackHelper,
|
||||
ContainerHelper,
|
||||
CustomTemplateService,
|
||||
ContainerService,
|
||||
WebhookHelper,
|
||||
clipboard
|
||||
clipboard,
|
||||
endpoint
|
||||
) {
|
||||
$scope.onChangeTemplateId = onChangeTemplateId;
|
||||
$scope.buildAnalyticsProperties = buildAnalyticsProperties;
|
||||
|
@ -307,12 +307,7 @@ angular
|
|||
$scope.state.StackType = 1;
|
||||
}
|
||||
|
||||
try {
|
||||
const endpoint = EndpointProvider.currentEndpoint();
|
||||
$scope.composeSyntaxMaxVersion = endpoint.ComposeSyntaxMaxVersion;
|
||||
} catch (err) {
|
||||
Notifications.error('Failure', err, 'Unable to retrieve the ComposeSyntaxMaxVersion');
|
||||
}
|
||||
$scope.composeSyntaxMaxVersion = endpoint.ComposeSyntaxMaxVersion;
|
||||
|
||||
try {
|
||||
const containers = await ContainerService.containers(true);
|
||||
|
|
|
@ -116,7 +116,7 @@
|
|||
ng-if="regular && endpoints.length > 0"
|
||||
endpoints="endpoints"
|
||||
groups="groups"
|
||||
current-endpoint-id="currentEndpointId"
|
||||
current-endpoint-id="endpoint.Id"
|
||||
on-duplicate="duplicateStack(name, endpointId)"
|
||||
on-migrate="migrateStack(name, endpointId)"
|
||||
yaml-error="state.yamlError"
|
||||
|
@ -216,6 +216,7 @@
|
|||
show-host-column="false"
|
||||
show-add-action="false"
|
||||
not-auto-focus="true"
|
||||
endpoint-public-url="endpoint.PublicURL"
|
||||
></containers-datatable>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -236,6 +237,8 @@
|
|||
show-add-action="false"
|
||||
show-stack-column="false"
|
||||
not-auto-focus="true"
|
||||
endpoint-public-url="endpoint.PublicURL"
|
||||
endpoint-id="endpoint.Id"
|
||||
></services-datatable>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -24,6 +24,7 @@ angular.module('portainer.app').controller('StackController', [
|
|||
'ResourceControlService',
|
||||
'Authentication',
|
||||
'ContainerHelper',
|
||||
'endpoint',
|
||||
function (
|
||||
$async,
|
||||
$q,
|
||||
|
@ -47,8 +48,10 @@ angular.module('portainer.app').controller('StackController', [
|
|||
StackHelper,
|
||||
ResourceControlService,
|
||||
Authentication,
|
||||
ContainerHelper
|
||||
ContainerHelper,
|
||||
endpoint
|
||||
) {
|
||||
$scope.endpoint = endpoint;
|
||||
$scope.state = {
|
||||
actionInProgress: false,
|
||||
migrationInProgress: false,
|
||||
|
@ -79,16 +82,18 @@ angular.module('portainer.app').controller('StackController', [
|
|||
$scope.formValues.Env = value;
|
||||
}
|
||||
|
||||
$scope.duplicateStack = function duplicateStack(name, endpointId) {
|
||||
$scope.duplicateStack = function duplicateStack(name, targetEndpointId) {
|
||||
var stack = $scope.stack;
|
||||
var env = FormHelper.removeInvalidEnvVars($scope.formValues.Env);
|
||||
EndpointProvider.setEndpointID(endpointId);
|
||||
// sets the targetEndpointID as global for interceptors
|
||||
EndpointProvider.setEndpointID(targetEndpointId);
|
||||
|
||||
return StackService.duplicateStack(name, $scope.stackFileContent, env, endpointId, stack.Type).then(onDuplicationSuccess).catch(notifyOnError);
|
||||
return StackService.duplicateStack(name, $scope.stackFileContent, env, targetEndpointId, stack.Type).then(onDuplicationSuccess).catch(notifyOnError);
|
||||
|
||||
function onDuplicationSuccess() {
|
||||
Notifications.success('Stack successfully duplicated');
|
||||
$state.go('docker.stacks', {}, { reload: true });
|
||||
// sets back the original endpointID as global for interceptors
|
||||
EndpointProvider.setEndpointID(stack.EndpointId);
|
||||
}
|
||||
|
||||
|
@ -132,11 +137,10 @@ angular.module('portainer.app').controller('StackController', [
|
|||
});
|
||||
};
|
||||
|
||||
function migrateStack(name, endpointId) {
|
||||
var stack = $scope.stack;
|
||||
var targetEndpointId = endpointId;
|
||||
function migrateStack(name, targetEndpointId) {
|
||||
const stack = $scope.stack;
|
||||
|
||||
var migrateRequest = StackService.migrateSwarmStack;
|
||||
let migrateRequest = StackService.migrateSwarmStack;
|
||||
if (stack.Type === 2) {
|
||||
migrateRequest = StackService.migrateComposeStack;
|
||||
}
|
||||
|
@ -145,9 +149,8 @@ angular.module('portainer.app').controller('StackController', [
|
|||
// The EndpointID property is not available for these stacks, we can pass
|
||||
// the current endpoint identifier as a part of the migrate request. It will be used if
|
||||
// the EndpointID property is not defined on the stack.
|
||||
var originalEndpointId = EndpointProvider.endpointID();
|
||||
if (stack.EndpointId === 0) {
|
||||
stack.EndpointId = originalEndpointId;
|
||||
stack.EndpointId = endpoint.Id;
|
||||
}
|
||||
|
||||
$scope.state.migrationInProgress = true;
|
||||
|
@ -213,9 +216,8 @@ angular.module('portainer.app').controller('StackController', [
|
|||
// The EndpointID property is not available for these stacks, we can pass
|
||||
// the current endpoint identifier as a part of the update request. It will be used if
|
||||
// the EndpointID property is not defined on the stack.
|
||||
var endpointId = EndpointProvider.endpointID();
|
||||
if (stack.EndpointId === 0) {
|
||||
stack.EndpointId = endpointId;
|
||||
stack.EndpointId = endpoint.Id;
|
||||
}
|
||||
|
||||
$scope.state.actionInProgress = true;
|
||||
|
@ -433,8 +435,6 @@ angular.module('portainer.app').controller('StackController', [
|
|||
var stackName = $transition$.params().name;
|
||||
$scope.stackName = stackName;
|
||||
|
||||
$scope.currentEndpointId = EndpointProvider.endpointID();
|
||||
|
||||
const regular = $transition$.params().regular == 'true';
|
||||
$scope.regular = regular;
|
||||
|
||||
|
@ -456,12 +456,7 @@ angular.module('portainer.app').controller('StackController', [
|
|||
loadStack(stackId);
|
||||
}
|
||||
|
||||
try {
|
||||
const endpoint = EndpointProvider.currentEndpoint();
|
||||
$scope.composeSyntaxMaxVersion = endpoint.ComposeSyntaxMaxVersion;
|
||||
} catch (err) {
|
||||
Notifications.error('Failure', err, 'Unable to retrieve the ComposeSyntaxMaxVersion');
|
||||
}
|
||||
$scope.composeSyntaxMaxVersion = endpoint.ComposeSyntaxMaxVersion;
|
||||
|
||||
$scope.stackType = $transition$.params().type;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import { isOfflineEndpoint } from '@/portainer/helpers/endpointHelper';
|
||||
|
||||
angular.module('portainer.app').controller('StacksController', StacksController);
|
||||
|
||||
/* @ngInject */
|
||||
function StacksController($scope, $state, Notifications, StackService, ModalService, EndpointProvider, Authentication, endpoint) {
|
||||
function StacksController($scope, $state, Notifications, StackService, ModalService, Authentication, endpoint) {
|
||||
$scope.removeAction = function (selectedItems) {
|
||||
ModalService.confirmDeletion('Do you want to remove the selected stack(s)? Associated services will be removed as well.', function onConfirm(confirmed) {
|
||||
if (!confirmed) {
|
||||
|
@ -12,8 +14,8 @@ function StacksController($scope, $state, Notifications, StackService, ModalServ
|
|||
};
|
||||
|
||||
function deleteSelectedStacks(stacks) {
|
||||
var endpointId = EndpointProvider.endpointID();
|
||||
var actionCount = stacks.length;
|
||||
const endpointId = endpoint.Id;
|
||||
let actionCount = stacks.length;
|
||||
angular.forEach(stacks, function (stack) {
|
||||
StackService.remove(stack, stack.External, endpointId)
|
||||
.then(function success() {
|
||||
|
@ -39,15 +41,14 @@ function StacksController($scope, $state, Notifications, StackService, ModalServ
|
|||
$scope.getStacks = getStacks;
|
||||
|
||||
function getStacks() {
|
||||
var endpointMode = $scope.applicationState.endpoint.mode;
|
||||
var endpointId = EndpointProvider.endpointID();
|
||||
const endpointMode = $scope.applicationState.endpoint.mode;
|
||||
const endpointId = endpoint.Id;
|
||||
|
||||
const includeOrphanedStacks = Authentication.isAdmin();
|
||||
StackService.stacks(true, endpointMode.provider === 'DOCKER_SWARM_MODE' && endpointMode.role === 'MANAGER', endpointId, includeOrphanedStacks)
|
||||
.then(function success(data) {
|
||||
var stacks = data;
|
||||
.then(function success(stacks) {
|
||||
$scope.stacks = stacks;
|
||||
$scope.offlineMode = EndpointProvider.offlineMode();
|
||||
$scope.offlineMode = isOfflineEndpoint(endpoint);
|
||||
})
|
||||
.catch(function error(err) {
|
||||
$scope.stacks = [];
|
||||
|
|
|
@ -276,9 +276,10 @@ angular.module('portainer.app').controller('TemplatesController', [
|
|||
|
||||
var endpointMode = $scope.applicationState.endpoint.mode;
|
||||
var apiVersion = $scope.applicationState.endpoint.apiVersion;
|
||||
const endpointId = +$state.params.endpointId;
|
||||
|
||||
$q.all({
|
||||
templates: TemplateService.templates(),
|
||||
templates: TemplateService.templates(endpointId),
|
||||
volumes: VolumeService.getVolumes(),
|
||||
networks: NetworkService.networks(
|
||||
endpointMode.provider === 'DOCKER_STANDALONE' || endpointMode.provider === 'DOCKER_SWARM_MODE',
|
||||
|
@ -296,7 +297,7 @@ angular.module('portainer.app').controller('TemplatesController', [
|
|||
})
|
||||
.catch(function error(err) {
|
||||
$scope.templates = [];
|
||||
Notifications.error('Failure', err, 'An error occured during apps initialization.');
|
||||
Notifications.error('Failure', err, 'An error occurred during apps initialization.');
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue