1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-24 07:49:41 +02:00

fix(app): use deps injection in router correctly (#4049)

* fix(app): use deps injection in router correctly

* feat(app): guard against using wrong endpoint type

* feat(sidebar): supply endpoint id

* feat(templates): move custom templates to docker
This commit is contained in:
Chaim Lev-Ari 2020-07-21 00:06:37 +03:00 committed by GitHub
parent 66a3104805
commit 4b97cf738e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 135 additions and 101 deletions

View file

@ -7,51 +7,56 @@ angular.module('portainer.docker', ['portainer.app']).config([
name: 'docker',
parent: 'endpoint',
abstract: true,
/* ngInject */
async onEnter(endpoint, $state, EndpointService, EndpointProvider, LegacyExtensionManager, Notifications, StateManager, SystemService) {
try {
const status = await checkEndpointStatus(endpoint);
if (endpoint.Type !== 4) {
await updateEndpointStatus(endpoint, status);
}
endpoint.Status = status;
if (status === 2) {
if (!endpoint.Snapshots[0]) {
throw new Error('Endpoint is unreachable and there is no snapshot available for offline browsing.');
}
if (endpoint.Snapshots[0].Swarm) {
throw new Error('Endpoint is unreachable. Connect to another swarm manager.');
}
}
EndpointProvider.setEndpointID(endpoint.Id);
EndpointProvider.setEndpointPublicURL(endpoint.PublicURL);
EndpointProvider.setOfflineModeFromStatus(endpoint.Status);
const extensions = await LegacyExtensionManager.initEndpointExtensions(endpoint);
await StateManager.updateEndpointState(endpoint, extensions);
} catch (e) {
Notifications.error('Failed loading endpoint', e);
$state.go('portainer.home', {}, { reload: true });
}
async function checkEndpointStatus(endpoint) {
try {
await SystemService.ping(endpoint.Id);
return 1;
} catch (e) {
return 2;
}
}
async function updateEndpointStatus(endpoint, status) {
if (endpoint.Status === status) {
onEnter: /* @ngInject */ function onEnter(endpoint, $async, $state, EndpointService, EndpointProvider, LegacyExtensionManager, Notifications, StateManager, SystemService) {
return $async(async () => {
if (![1, 2, 4].includes(endpoint.Type)) {
$state.go('portainer.home');
return;
}
await EndpointService.updateEndpoint(endpoint.Id, { Status: status });
}
try {
const status = await checkEndpointStatus(endpoint);
if (endpoint.Type !== 4) {
await updateEndpointStatus(endpoint, status);
}
endpoint.Status = status;
if (status === 2) {
if (!endpoint.Snapshots[0]) {
throw new Error('Endpoint is unreachable and there is no snapshot available for offline browsing.');
}
if (endpoint.Snapshots[0].Swarm) {
throw new Error('Endpoint is unreachable. Connect to another swarm manager.');
}
}
EndpointProvider.setEndpointID(endpoint.Id);
EndpointProvider.setEndpointPublicURL(endpoint.PublicURL);
EndpointProvider.setOfflineModeFromStatus(endpoint.Status);
const extensions = await LegacyExtensionManager.initEndpointExtensions(endpoint);
await StateManager.updateEndpointState(endpoint, extensions);
} catch (e) {
Notifications.error('Failed loading endpoint', e);
$state.go('portainer.home', {}, { reload: true });
}
async function checkEndpointStatus(endpoint) {
try {
await SystemService.ping(endpoint.Id);
return 1;
} catch (e) {
return 2;
}
}
async function updateEndpointStatus(endpoint, status) {
if (endpoint.Status === status) {
return;
}
await EndpointService.updateEndpoint(endpoint.Id, { Status: status });
}
});
},
};
@ -179,7 +184,7 @@ angular.module('portainer.docker', ['portainer.app']).config([
};
const customTemplates = {
name: 'portainer.templates.custom',
name: 'docker.templates.custom',
url: '/custom',
views: {
@ -190,7 +195,7 @@ angular.module('portainer.docker', ['portainer.app']).config([
};
const customTemplatesNew = {
name: 'portainer.templates.custom.new',
name: 'docker.templates.custom.new',
url: '/new?fileContent&type',
views: {
@ -205,7 +210,7 @@ angular.module('portainer.docker', ['portainer.app']).config([
};
const customTemplatesEdit = {
name: 'portainer.templates.custom.edit',
name: 'docker.templates.custom.edit',
url: '/:id',
views: {