mirror of https://github.com/portainer/portainer
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 dockerpull/4076/head
parent
66a3104805
commit
4b97cf738e
|
@ -8,17 +8,22 @@ angular.module('portainer.azure', ['portainer.app']).config([
|
|||
url: '/azure',
|
||||
parent: 'endpoint',
|
||||
abstract: true,
|
||||
/* ngInject */
|
||||
async onEnter($state, endpoint, EndpointProvider, Notifications, StateManager) {
|
||||
try {
|
||||
EndpointProvider.setEndpointID(endpoint.Id);
|
||||
EndpointProvider.setEndpointPublicURL(endpoint.PublicURL);
|
||||
EndpointProvider.setOfflineModeFromStatus(endpoint.Status);
|
||||
await StateManager.updateEndpointState(endpoint, []);
|
||||
} catch (e) {
|
||||
Notifications.error('Failed loading endpoint', e);
|
||||
$state.go('portainer.home', {}, { reload: true });
|
||||
}
|
||||
onEnter: /* @ngInject */ function onEnter($async, $state, endpoint, EndpointProvider, Notifications, StateManager) {
|
||||
return $async(async () => {
|
||||
if (endpoint.Type !== 3) {
|
||||
$state.go('portainer.home');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
EndpointProvider.setEndpointID(endpoint.Id);
|
||||
EndpointProvider.setEndpointPublicURL(endpoint.PublicURL);
|
||||
EndpointProvider.setOfflineModeFromStatus(endpoint.Status);
|
||||
await StateManager.updateEndpointState(endpoint, []);
|
||||
} catch (e) {
|
||||
Notifications.error('Failed loading endpoint', e);
|
||||
$state.go('portainer.home', {}, { reload: true });
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
import angular from 'angular';
|
||||
|
||||
angular.module('portainer.azure').component('azureSidebarContent', {
|
||||
templateUrl: './azureSidebarContent.html',
|
||||
bindings: {
|
||||
endpointId: '<',
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<li class="sidebar-list">
|
||||
<a ui-sref="azure.dashboard" ui-sref-active="active">Dashboard <span class="menu-icon fa fa-tachometer-alt fa-fw"></span></a>
|
||||
<a ui-sref="azure.dashboard({endpointId: $ctrl.endpointId})" ui-sref-active="active">Dashboard <span class="menu-icon fa fa-tachometer-alt fa-fw"></span></a>
|
||||
</li>
|
||||
<li class="sidebar-list">
|
||||
<a ui-sref="azure.containerinstances" ui-sref-active="active">Container instances <span class="menu-icon fa fa-cubes fa-fw"></span></a>
|
||||
<a ui-sref="azure.containerinstances({endpointId: $ctrl.endpointId})" ui-sref-active="active">Container instances <span class="menu-icon fa fa-cubes fa-fw"></span></a>
|
||||
</li>
|
||||
|
|
|
@ -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: {
|
||||
|
|
|
@ -8,5 +8,6 @@ angular.module('portainer.docker').component('dockerSidebarContent', {
|
|||
offlineMode: '<',
|
||||
toggle: '<',
|
||||
currentRouteName: '<',
|
||||
endpointId: '<',
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1,43 +1,43 @@
|
|||
<li class="sidebar-list">
|
||||
<a ui-sref="docker.dashboard" ui-sref-active="active">Dashboard <span class="menu-icon fa fa-tachometer-alt fa-fw"></span></a>
|
||||
<a ui-sref="docker.dashboard({endpointId: $ctrl.endpointId})" ui-sref-active="active">Dashboard <span class="menu-icon fa fa-tachometer-alt fa-fw"></span></a>
|
||||
</li>
|
||||
<li class="sidebar-list" ng-if="!$ctrl.offlineMode" authorization="DockerContainerCreate, PortainerStackCreate">
|
||||
<a ui-sref="docker.templates" ui-sref-active="active">App Templates <span class="menu-icon fa fa-rocket fa-fw"></span></a>
|
||||
<a ui-sref="docker.templates({endpointId: $ctrl.endpointId})" ui-sref-active="active">App Templates <span class="menu-icon fa fa-rocket fa-fw"></span></a>
|
||||
|
||||
<div class="sidebar-sublist" ng-if="$ctrl.toggle && $ctrl.currentRouteName.includes('docker.templates')">
|
||||
<a ui-sref="docker.templates.custom" ui-sref-active="active">Custom Templates</a>
|
||||
<a ui-sref="docker.templates.custom({endpointId: $ctrl.endpointId})" ui-sref-active="active">Custom Templates</a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="sidebar-list">
|
||||
<a ui-sref="docker.stacks" ui-sref-active="active">Stacks <span class="menu-icon fa fa-th-list fa-fw"></span></a>
|
||||
<a ui-sref="docker.stacks({endpointId: $ctrl.endpointId})" ui-sref-active="active">Stacks <span class="menu-icon fa fa-th-list fa-fw"></span></a>
|
||||
</li>
|
||||
<li class="sidebar-list" ng-if="$ctrl.swarmManagement">
|
||||
<a ui-sref="docker.services" ui-sref-active="active">Services <span class="menu-icon fa fa-list-alt fa-fw"></span></a>
|
||||
<a ui-sref="docker.services({endpointId: $ctrl.endpointId})" ui-sref-active="active">Services <span class="menu-icon fa fa-list-alt fa-fw"></span></a>
|
||||
</li>
|
||||
<li class="sidebar-list">
|
||||
<a ui-sref="docker.containers" ui-sref-active="active">Containers <span class="menu-icon fa fa-cubes fa-fw"></span></a>
|
||||
<a ui-sref="docker.containers({endpointId: $ctrl.endpointId})" ui-sref-active="active">Containers <span class="menu-icon fa fa-cubes fa-fw"></span></a>
|
||||
</li>
|
||||
<li class="sidebar-list">
|
||||
<a ui-sref="docker.images" ui-sref-active="active">Images <span class="menu-icon fa fa-clone fa-fw"></span></a>
|
||||
<a ui-sref="docker.images({endpointId: $ctrl.endpointId})" ui-sref-active="active">Images <span class="menu-icon fa fa-clone fa-fw"></span></a>
|
||||
</li>
|
||||
<li class="sidebar-list">
|
||||
<a ui-sref="docker.networks" ui-sref-active="active">Networks <span class="menu-icon fa fa-sitemap fa-fw"></span></a>
|
||||
<a ui-sref="docker.networks({endpointId: $ctrl.endpointId})" ui-sref-active="active">Networks <span class="menu-icon fa fa-sitemap fa-fw"></span></a>
|
||||
</li>
|
||||
<li class="sidebar-list">
|
||||
<a ui-sref="docker.volumes" ui-sref-active="active">Volumes <span class="menu-icon fa fa-hdd fa-fw"></span></a>
|
||||
<a ui-sref="docker.volumes({endpointId: $ctrl.endpointId})" ui-sref-active="active">Volumes <span class="menu-icon fa fa-hdd fa-fw"></span></a>
|
||||
</li>
|
||||
<li class="sidebar-list" ng-if="$ctrl.endpointApiVersion >= 1.3 && $ctrl.swarmManagement">
|
||||
<a ui-sref="docker.configs" ui-sref-active="active">Configs <span class="menu-icon fa fa-file-code fa-fw"></span></a>
|
||||
<a ui-sref="docker.configs({endpointId: $ctrl.endpointId})" ui-sref-active="active">Configs <span class="menu-icon fa fa-file-code fa-fw"></span></a>
|
||||
</li>
|
||||
<li class="sidebar-list" ng-if="$ctrl.endpointApiVersion >= 1.25 && $ctrl.swarmManagement">
|
||||
<a ui-sref="docker.secrets" ui-sref-active="active">Secrets <span class="menu-icon fa fa-user-secret fa-fw"></span></a>
|
||||
<a ui-sref="docker.secrets({endpointId: $ctrl.endpointId})" ui-sref-active="active">Secrets <span class="menu-icon fa fa-user-secret fa-fw"></span></a>
|
||||
</li>
|
||||
<li class="sidebar-list" ng-if="$ctrl.standaloneManagement && $ctrl.adminAccess && !$ctrl.offlineMode">
|
||||
<a ui-sref="docker.events" ui-sref-active="active">Events <span class="menu-icon fa fa-history fa-fw"></span></a>
|
||||
<a ui-sref="docker.events({endpointId: $ctrl.endpointId})" ui-sref-active="active">Events <span class="menu-icon fa fa-history fa-fw"></span></a>
|
||||
</li>
|
||||
<li class="sidebar-list" ng-if="$ctrl.swarmManagement">
|
||||
<a ui-sref="docker.swarm" ui-sref-active="active">Swarm <span class="menu-icon fa fa-object-group fa-fw"></span></a>
|
||||
<a ui-sref="docker.swarm({endpointId: $ctrl.endpointId})" ui-sref-active="active">Swarm <span class="menu-icon fa fa-object-group fa-fw"></span></a>
|
||||
</li>
|
||||
<li class="sidebar-list" ng-if="$ctrl.standaloneManagement">
|
||||
<a ui-sref="docker.host" ui-sref-active="active">Host <span class="menu-icon fa fa-th fa-fw"></span></a>
|
||||
<a ui-sref="docker.host({endpointId: $ctrl.endpointId})" ui-sref-active="active">Host <span class="menu-icon fa fa-th fa-fw"></span></a>
|
||||
</li>
|
||||
|
|
|
@ -8,24 +8,30 @@ angular.module('portainer.kubernetes', ['portainer.app']).config([
|
|||
url: '/kubernetes',
|
||||
parent: 'endpoint',
|
||||
abstract: true,
|
||||
/* @ngInject */
|
||||
async onEnter($state, endpoint, EndpointProvider, KubernetesHealthService, Notifications, StateManager) {
|
||||
try {
|
||||
if (endpoint.Type === 7) {
|
||||
try {
|
||||
await KubernetesHealthService.ping();
|
||||
endpoint.Status = 1;
|
||||
} catch (e) {
|
||||
endpoint.Status = 2;
|
||||
}
|
||||
}
|
||||
|
||||
EndpointProvider.setEndpointID(endpoint.Id);
|
||||
await StateManager.updateEndpointState(endpoint, []);
|
||||
} catch (e) {
|
||||
Notifications.error('Failed loading endpoint', e);
|
||||
$state.go('portainer.home', {}, { reload: true });
|
||||
}
|
||||
onEnter: /* @ngInject */ function onEnter($async, $state, endpoint, EndpointProvider, KubernetesHealthService, Notifications, StateManager) {
|
||||
return $async(async () => {
|
||||
if (![5, 6, 7].includes(endpoint.Type)) {
|
||||
$state.go('portainer.home');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (endpoint.Type === 7) {
|
||||
try {
|
||||
await KubernetesHealthService.ping();
|
||||
endpoint.Status = 1;
|
||||
} catch (e) {
|
||||
endpoint.Status = 2;
|
||||
}
|
||||
}
|
||||
|
||||
EndpointProvider.setEndpointID(endpoint.Id);
|
||||
await StateManager.updateEndpointState(endpoint, []);
|
||||
} catch (e) {
|
||||
Notifications.error('Failed loading endpoint', e);
|
||||
$state.go('portainer.home', {}, { reload: true });
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
<li class="sidebar-list">
|
||||
<a ui-sref="kubernetes.dashboard" ui-sref-active="active">Dashboard <span class="menu-icon fa fa-tachometer-alt fa-fw"></span></a>
|
||||
<a ui-sref="kubernetes.dashboard({endpointId: $ctrl.endpointId})" ui-sref-active="active">Dashboard <span class="menu-icon fa fa-tachometer-alt fa-fw"></span></a>
|
||||
</li>
|
||||
<li class="sidebar-list">
|
||||
<a ui-sref="kubernetes.resourcePools" ui-sref-active="active">Resource pools <span class="menu-icon fa fa-layer-group fa-fw"></span></a>
|
||||
<a ui-sref="kubernetes.resourcePools({endpointId: $ctrl.endpointId})" ui-sref-active="active">Resource pools <span class="menu-icon fa fa-layer-group fa-fw"></span></a>
|
||||
</li>
|
||||
<li class="sidebar-list">
|
||||
<a ui-sref="kubernetes.applications" ui-sref-active="active">Applications <span class="menu-icon fa fa-laptop-code fa-fw"></span></a>
|
||||
<a ui-sref="kubernetes.applications({endpointId: $ctrl.endpointId})" ui-sref-active="active">Applications <span class="menu-icon fa fa-laptop-code fa-fw"></span></a>
|
||||
</li>
|
||||
<li class="sidebar-list">
|
||||
<a ui-sref="kubernetes.configurations" ui-sref-active="active">Configurations <span class="menu-icon fa fa-file-code fa-fw"></span></a>
|
||||
<a ui-sref="kubernetes.configurations({endpointId: $ctrl.endpointId})" ui-sref-active="active">Configurations <span class="menu-icon fa fa-file-code fa-fw"></span></a>
|
||||
</li>
|
||||
<li class="sidebar-list">
|
||||
<a ui-sref="kubernetes.volumes" ui-sref-active="active">Volumes <span class="menu-icon fa fa-database fa-fw"></span></a>
|
||||
<a ui-sref="kubernetes.volumes({endpointId: $ctrl.endpointId})" ui-sref-active="active">Volumes <span class="menu-icon fa fa-database fa-fw"></span></a>
|
||||
</li>
|
||||
<li class="sidebar-list">
|
||||
<a ui-sref="kubernetes.cluster" ui-sref-active="active">Cluster <span class="menu-icon fa fa-server fa-fw"></span></a>
|
||||
<a ui-sref="kubernetes.cluster({endpointId: $ctrl.endpointId})" ui-sref-active="active">Cluster <span class="menu-icon fa fa-server fa-fw"></span></a>
|
||||
</li>
|
||||
|
|
|
@ -2,5 +2,6 @@ angular.module('portainer.kubernetes').component('kubernetesSidebarContent', {
|
|||
templateUrl: './kubernetesSidebarContent.html',
|
||||
bindings: {
|
||||
adminAccess: '<',
|
||||
endpointId: '<',
|
||||
},
|
||||
});
|
||||
|
|
|
@ -81,8 +81,7 @@ angular.module('portainer.app', []).config([
|
|||
parent: 'root',
|
||||
abstract: true,
|
||||
resolve: {
|
||||
/* @ngInject */
|
||||
endpoint($async, $state, $transition$, EndpointService, Notifications) {
|
||||
endpoint: /* @ngInject */ function endpoint($async, $state, $transition$, EndpointService, Notifications) {
|
||||
return $async(async () => {
|
||||
try {
|
||||
const endpointId = +$transition$.params().endpointId;
|
||||
|
|
|
@ -13,9 +13,13 @@
|
|||
<a ui-sref="portainer.home" ui-sref-active="active">Home <span class="menu-icon fa fa-home fa-fw"></span></a>
|
||||
</li>
|
||||
<li class="sidebar-title endpoint-name" ng-if="applicationState.endpoint.name"> <span class="fa fa-plug space-right"></span>{{ applicationState.endpoint.name }} </li>
|
||||
<kubernetes-sidebar-content ng-if="applicationState.endpoint.mode && applicationState.endpoint.mode.provider === 'KUBERNETES'" admin-access="isAdmin">
|
||||
<kubernetes-sidebar-content
|
||||
ng-if="applicationState.endpoint.mode && applicationState.endpoint.mode.provider === 'KUBERNETES'"
|
||||
admin-access="isAdmin"
|
||||
endpoint-id="endpointId"
|
||||
>
|
||||
</kubernetes-sidebar-content>
|
||||
<azure-sidebar-content ng-if="applicationState.endpoint.mode && applicationState.endpoint.mode.provider === 'AZURE'"> </azure-sidebar-content>
|
||||
<azure-sidebar-content ng-if="applicationState.endpoint.mode && applicationState.endpoint.mode.provider === 'AZURE'" endpoint-id="endpointId"> </azure-sidebar-content>
|
||||
<docker-sidebar-content
|
||||
ng-if="applicationState.endpoint.mode && applicationState.endpoint.mode.provider !== 'AZURE' && applicationState.endpoint.mode.provider !== 'KUBERNETES'"
|
||||
current-route-name="$state.current.name"
|
||||
|
@ -25,6 +29,7 @@
|
|||
standalone-management="applicationState.endpoint.mode.provider === 'DOCKER_STANDALONE'"
|
||||
admin-access="isAdmin"
|
||||
offline-mode="endpointState.OfflineMode"
|
||||
endpoint-id="endpointId"
|
||||
></docker-sidebar-content>
|
||||
<li class="sidebar-title" authorization="IntegrationStoridgeAdmin" ng-if="applicationState.endpoint.mode && applicationState.endpoint.extensions.length > 0">
|
||||
<span>Integrations</span>
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
angular.module('portainer.app').controller('SidebarController', [
|
||||
'$q',
|
||||
'$scope',
|
||||
'$transitions',
|
||||
'StateManager',
|
||||
'Notifications',
|
||||
'Authentication',
|
||||
'UserService',
|
||||
function ($q, $scope, StateManager, Notifications, Authentication, UserService) {
|
||||
'EndpointProvider',
|
||||
function ($q, $scope, $transitions, StateManager, Notifications, Authentication, UserService, EndpointProvider) {
|
||||
function checkPermissions(memberships) {
|
||||
var isLeader = false;
|
||||
angular.forEach(memberships, function (membership) {
|
||||
|
@ -23,6 +25,7 @@ angular.module('portainer.app').controller('SidebarController', [
|
|||
let userDetails = Authentication.getUserDetails();
|
||||
let isAdmin = Authentication.isAdmin();
|
||||
$scope.isAdmin = isAdmin;
|
||||
$scope.endpointId = EndpointProvider.endpointID();
|
||||
|
||||
$q.when(!isAdmin ? UserService.userMemberships(userDetails.ID) : [])
|
||||
.then(function success(data) {
|
||||
|
@ -31,6 +34,10 @@ angular.module('portainer.app').controller('SidebarController', [
|
|||
.catch(function error(err) {
|
||||
Notifications.error('Failure', err, 'Unable to retrieve user memberships');
|
||||
});
|
||||
|
||||
$transitions.onEnter({}, () => {
|
||||
$scope.endpointId = EndpointProvider.endpointID();
|
||||
});
|
||||
}
|
||||
|
||||
initView();
|
||||
|
|
Loading…
Reference in New Issue