1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-05 05:45:22 +02:00

refactor(endpoints): remove endpointProvider from views [EE-1136] (#5359)

[EE-1136]
This commit is contained in:
Chaim Lev-Ari 2021-12-14 09:34:54 +02:00 committed by GitHub
parent 7088da5157
commit eb9f6c77f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
56 changed files with 408 additions and 429 deletions

View file

@ -264,7 +264,7 @@
ng-if="item.Ports.length > 0"
ng-repeat="p in item.Ports | unique: 'public'"
class="image-tag"
ng-href="http://{{ $ctrl.state.publicURL || p.host }}:{{ p.public }}"
ng-href="http://{{ $ctrl.endpointPublicUrl || p.host }}:{{ p.public }}"
target="_blank"
>
<i class="fa fa-external-link-alt" aria-hidden="true"></i> {{ p.public }}:{{ p.private }}

View file

@ -13,5 +13,6 @@ angular.module('portainer.docker').component('containersDatatable', {
offlineMode: '<',
refreshCallback: '<',
notAutoFocus: '<',
endpointPublicUrl: '<',
},
});

View file

@ -4,8 +4,7 @@ angular.module('portainer.docker').controller('ContainersDatatableController', [
'$scope',
'$controller',
'DatatableService',
'EndpointProvider',
function ($scope, $controller, DatatableService, EndpointProvider) {
function ($scope, $controller, DatatableService) {
angular.extend(this, $controller('GenericDatatableController', { $scope: $scope }));
var ctrl = this;
@ -14,7 +13,6 @@ angular.module('portainer.docker').controller('ContainersDatatableController', [
noStoppedItemsSelected: true,
noRunningItemsSelected: true,
noPausedItemsSelected: true,
publicURL: EndpointProvider.endpointPublicURL(),
});
this.settings = Object.assign(this.settings, {

View file

@ -6,5 +6,6 @@ angular.module('portainer.docker').component('servicesDatatableActions', {
selectedItemCount: '=',
showUpdateAction: '<',
showAddAction: '<',
endpointId: '<',
},
});

View file

@ -7,8 +7,9 @@ angular.module('portainer.docker').controller('ServicesDatatableActionsControlle
'ModalService',
'ImageHelper',
'WebhookService',
'EndpointProvider',
function ($q, $state, ServiceService, ServiceHelper, Notifications, ModalService, ImageHelper, WebhookService, EndpointProvider) {
function ($q, $state, ServiceService, ServiceHelper, Notifications, ModalService, ImageHelper, WebhookService) {
const ctrl = this;
this.scaleAction = function scaleService(service) {
var config = ServiceHelper.serviceToConfig(service.Model);
config.Mode.Replicated.Replicas = service.Replicas;
@ -84,7 +85,7 @@ angular.module('portainer.docker').controller('ServicesDatatableActionsControlle
angular.forEach(services, function (service) {
ServiceService.remove(service)
.then(function success() {
return WebhookService.webhooks(service.Id, EndpointProvider.endpointID());
return WebhookService.webhooks(service.Id, ctrl.endpointId);
})
.then(function success(data) {
return $q.when(data.length !== 0 && WebhookService.deleteWebhook(data[0].Id));

View file

@ -47,6 +47,7 @@
selected-item-count="$ctrl.state.selectedItemCount"
show-add-action="$ctrl.showAddAction"
show-update-action="$ctrl.showUpdateAction"
endpoint-id="$ctrl.endpointId"
></services-datatable-actions>
<div class="searchBar">
<i class="fa fa-search searchIcon" aria-hidden="true"></i>
@ -171,7 +172,7 @@
ng-if="item.Ports && item.Ports.length > 0 && p.PublishedPort"
ng-repeat="p in item.Ports"
class="image-tag"
ng-href="http://{{ $ctrl.state.publicURL }}:{{ p.PublishedPort }}"
ng-href="http://{{ $ctrl.endpointPublicUrl }}:{{ p.PublishedPort }}"
target="_blank"
ng-click="$event.stopPropagation();"
>

View file

@ -16,5 +16,7 @@ angular.module('portainer.docker').component('servicesDatatable', {
showTaskLogsButton: '<',
refreshCallback: '<',
notAutoFocus: '<',
endpointPublicUrl: '<',
endpointId: '<',
},
});

View file

@ -4,8 +4,7 @@ angular.module('portainer.docker').controller('ServicesDatatableController', [
'$scope',
'$controller',
'DatatableService',
'EndpointProvider',
function ($scope, $controller, DatatableService, EndpointProvider) {
function ($scope, $controller, DatatableService) {
angular.extend(this, $controller('GenericDatatableController', { $scope: $scope }));
var ctrl = this;
@ -13,7 +12,6 @@ angular.module('portainer.docker').controller('ServicesDatatableController', [
this.state = Object.assign(this.state, {
expandAll: false,
expandedItems: [],
publicURL: EndpointProvider.endpointPublicURL(),
});
this.expandAll = function () {

View file

@ -3,10 +3,10 @@ import { baseHref } from '@/portainer/helpers/pathHelper';
angular.module('portainer.docker').controller('ContainerConsoleController', [
'$scope',
'$state',
'$transition$',
'ContainerService',
'ImageService',
'EndpointProvider',
'Notifications',
'ContainerHelper',
'ExecService',
@ -15,10 +15,10 @@ angular.module('portainer.docker').controller('ContainerConsoleController', [
'CONSOLE_COMMANDS_LABEL_PREFIX',
function (
$scope,
$state,
$transition$,
ContainerService,
ImageService,
EndpointProvider,
Notifications,
ContainerHelper,
ExecService,
@ -65,7 +65,7 @@ angular.module('portainer.docker').controller('ContainerConsoleController', [
const params = {
token: LocalStorage.getJWT(),
endpointId: EndpointProvider.endpointID(),
endpointId: $state.params.endpointId,
id: attachId,
};
@ -106,7 +106,7 @@ angular.module('portainer.docker').controller('ContainerConsoleController', [
.then(function success(data) {
const params = {
token: LocalStorage.getJWT(),
endpointId: EndpointProvider.endpointID(),
endpointId: $state.params.endpointId,
id: data.Id,
};

View file

@ -19,6 +19,7 @@
show-add-action="true"
offline-mode="offlineMode"
refresh-callback="getContainers"
endpoint-public-url="endpoint.PublicURL"
></containers-datatable>
</div>
</div>

View file

@ -1,29 +1,26 @@
angular.module('portainer.docker').controller('ContainersController', [
'$scope',
'ContainerService',
'Notifications',
'EndpointProvider',
function ($scope, ContainerService, Notifications, EndpointProvider) {
$scope.offlineMode = false;
angular.module('portainer.docker').controller('ContainersController', ContainersController);
$scope.getContainers = getContainers;
/* @ngInject */
function ContainersController($scope, ContainerService, Notifications, endpoint) {
$scope.offlineMode = endpoint.Status !== 1;
$scope.endpoint = endpoint;
function getContainers() {
ContainerService.containers(1)
.then(function success(data) {
$scope.containers = data;
$scope.offlineMode = EndpointProvider.offlineMode();
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to retrieve containers');
$scope.containers = [];
});
}
$scope.getContainers = getContainers;
function initView() {
getContainers();
}
function getContainers() {
ContainerService.containers(1)
.then(function success(data) {
$scope.containers = data;
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to retrieve containers');
$scope.containers = [];
});
}
initView();
},
]);
function initView() {
getContainers();
}
initView();
}

View file

@ -1,6 +1,8 @@
import angular from 'angular';
import _ from 'lodash';
import { isOfflineEndpoint } from '@/portainer/helpers/endpointHelper';
angular.module('portainer.docker').controller('DashboardController', [
'$scope',
'$q',
@ -12,9 +14,7 @@ angular.module('portainer.docker').controller('DashboardController', [
'SystemService',
'ServiceService',
'StackService',
'EndpointService',
'Notifications',
'EndpointProvider',
'StateManager',
'TagService',
'endpoint',
@ -29,9 +29,7 @@ angular.module('portainer.docker').controller('DashboardController', [
SystemService,
ServiceService,
StackService,
EndpointService,
Notifications,
EndpointProvider,
StateManager,
TagService,
endpoint
@ -45,8 +43,7 @@ angular.module('portainer.docker').controller('DashboardController', [
async function initView() {
const endpointMode = $scope.applicationState.endpoint.mode;
const endpointId = EndpointProvider.endpointID();
$scope.endpointId = endpointId;
$scope.endpoint = endpoint;
$scope.showStacks = await shouldShowStacks();
@ -56,9 +53,8 @@ angular.module('portainer.docker').controller('DashboardController', [
volumes: VolumeService.volumes(),
networks: NetworkService.networks(true, true, true),
services: endpointMode.provider === 'DOCKER_SWARM_MODE' && endpointMode.role === 'MANAGER' ? ServiceService.services() : [],
stacks: StackService.stacks(true, endpointMode.provider === 'DOCKER_SWARM_MODE' && endpointMode.role === 'MANAGER', endpointId),
stacks: StackService.stacks(true, endpointMode.provider === 'DOCKER_SWARM_MODE' && endpointMode.role === 'MANAGER', endpoint.Id),
info: SystemService.info(),
endpoint: EndpointService.endpoint(endpointId),
tags: TagService.tags(),
})
.then(function success(data) {
@ -69,11 +65,10 @@ angular.module('portainer.docker').controller('DashboardController', [
$scope.serviceCount = data.services.length;
$scope.stackCount = data.stacks.length;
$scope.info = data.info;
$scope.endpoint = data.endpoint;
$scope.endpointTags = $scope.endpoint.TagIds.length
$scope.endpointTags = endpoint.TagIds.length
? _.join(
_.filter(
_.map($scope.endpoint.TagIds, (id) => {
_.map(endpoint.TagIds, (id) => {
const tag = data.tags.find((tag) => tag.Id === id);
return tag ? tag.Name : '';
}),
@ -82,7 +77,7 @@ angular.module('portainer.docker').controller('DashboardController', [
', '
)
: '-';
$scope.offlineMode = EndpointProvider.offlineMode();
$scope.offlineMode = isOfflineEndpoint(endpoint);
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to load dashboard data');

View file

@ -7,6 +7,6 @@
<div class="row">
<div class="col-sm-12">
<host-browser ng-if="$ctrl.host"></host-browser>
<host-browser ng-if="$ctrl.host" endpoint-id="$ctrl.endpoint.Id"></host-browser>
</div>
</div>

View file

@ -1,4 +1,7 @@
angular.module('portainer.docker').component('hostBrowserView', {
templateUrl: './host-browser-view.html',
controller: 'HostBrowserViewController',
bindings: {
endpoint: '<',
},
});

View file

@ -1,3 +1,5 @@
import { isOfflineEndpoint } from '@/portainer/helpers/endpointHelper';
angular.module('portainer.docker').controller('HostViewController', [
'$q',
'SystemService',
@ -6,8 +8,7 @@ angular.module('portainer.docker').controller('HostViewController', [
'AgentService',
'ContainerService',
'Authentication',
'EndpointProvider',
function HostViewController($q, SystemService, Notifications, StateManager, AgentService, ContainerService, Authentication, EndpointProvider) {
function HostViewController($q, SystemService, Notifications, StateManager, AgentService, ContainerService, Authentication) {
var ctrl = this;
this.$onInit = initView;
@ -39,7 +40,7 @@ angular.module('portainer.docker').controller('HostViewController', [
.then(function success(data) {
ctrl.engineDetails = buildEngineDetails(data);
ctrl.hostDetails = buildHostDetails(data.info);
ctrl.state.offlineMode = EndpointProvider.offlineMode();
ctrl.state.offlineMode = isOfflineEndpoint(ctrl.endpoint);
ctrl.jobs = data.jobs;
if (ctrl.state.isAgent && agentApiVersion > 1) {

View file

@ -1,5 +1,6 @@
import _ from 'lodash-es';
import { PorImageRegistryModel } from 'Docker/models/porImageRegistry';
import { isOfflineEndpoint } from '@/portainer/helpers/endpointHelper';
angular.module('portainer.docker').controller('ImagesController', [
'$scope',
@ -11,9 +12,8 @@ angular.module('portainer.docker').controller('ImagesController', [
'HttpRequestHelper',
'FileSaver',
'Blob',
'EndpointProvider',
'endpoint',
function ($scope, $state, Authentication, ImageService, Notifications, ModalService, HttpRequestHelper, FileSaver, Blob, EndpointProvider, endpoint) {
function ($scope, $state, Authentication, ImageService, Notifications, ModalService, HttpRequestHelper, FileSaver, Blob, endpoint) {
$scope.endpoint = endpoint;
$scope.isAdmin = Authentication.isAdmin();
@ -142,7 +142,7 @@ angular.module('portainer.docker').controller('ImagesController', [
ImageService.images(true)
.then(function success(data) {
$scope.images = data;
$scope.offlineMode = EndpointProvider.offlineMode();
$scope.offlineMode = isOfflineEndpoint(endpoint);
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to retrieve images');

View file

@ -1,5 +1,6 @@
import _ from 'lodash-es';
import DockerNetworkHelper from 'Docker/helpers/networkHelper';
import { isOfflineEndpoint } from '@/portainer/helpers/endpointHelper';
angular.module('portainer.docker').controller('NetworksController', [
'$q',
@ -8,9 +9,9 @@ angular.module('portainer.docker').controller('NetworksController', [
'NetworkService',
'Notifications',
'HttpRequestHelper',
'EndpointProvider',
'endpoint',
'AgentService',
function ($q, $scope, $state, NetworkService, Notifications, HttpRequestHelper, EndpointProvider, AgentService) {
function ($q, $scope, $state, NetworkService, Notifications, HttpRequestHelper, endpoint, AgentService) {
$scope.removeAction = function (selectedItems) {
var actionCount = selectedItems.length;
angular.forEach(selectedItems, function (network) {
@ -65,7 +66,7 @@ angular.module('portainer.docker').controller('NetworksController', [
$q.all(req)
.then((data) => {
$scope.offlineMode = EndpointProvider.offlineMode();
$scope.offlineMode = isOfflineEndpoint(endpoint);
const networks = _.forEach(data.networks, (item) => (item.Subs = []));
if ($scope.applicationState.endpoint.mode.agentProxy && $scope.applicationState.endpoint.mode.provider === 'DOCKER_SWARM_MODE') {
$scope.networks = groupSwarmNetworksManagerNodesFirst(data.networks, data.agents);

View file

@ -7,6 +7,6 @@
<div class="row">
<div class="col-sm-12">
<host-browser ng-if="$ctrl.node"></host-browser>
<host-browser ng-if="$ctrl.node" endpoint-id="$ctrl.endpoint.Id"></host-browser>
</div>
</div>

View file

@ -1,4 +1,7 @@
angular.module('portainer.docker').component('nodeBrowserView', {
templateUrl: './node-browser.html',
controller: 'NodeBrowserController',
bindings: {
endpoint: '<',
},
});

View file

@ -22,6 +22,8 @@
show-add-action="true"
show-stack-column="true"
refresh-callback="getServices"
endpoint-public-url="endpoint.PublicURL"
endpoint-id="endpoint.Id"
></services-datatable>
</div>
</div>

View file

@ -8,8 +8,11 @@ angular.module('portainer.docker').controller('ServicesController', [
'TaskHelper',
'NodeService',
'ContainerService',
function ($q, $scope, ServiceService, ServiceHelper, Notifications, TaskService, TaskHelper, NodeService, ContainerService) {
'endpoint',
function ($q, $scope, ServiceService, ServiceHelper, Notifications, TaskService, TaskHelper, NodeService, ContainerService, endpoint) {
$scope.getServices = getServices;
$scope.endpoint = endpoint;
function getServices() {
var agentProxy = $scope.applicationState.endpoint.mode.agentProxy;

View file

@ -1,14 +1,13 @@
angular.module('portainer.docker').controller('BrowseVolumeController', [
'$scope',
'$transition$',
'StateManager',
function ($scope, $transition$, StateManager) {
function initView() {
$scope.volumeId = $transition$.params().id;
$scope.nodeName = $transition$.params().nodeName;
$scope.agentApiVersion = StateManager.getAgentApiVersion();
}
angular.module('portainer.docker').controller('BrowseVolumeController', BrowseVolumeController);
initView();
},
]);
/* @ngInject */
function BrowseVolumeController($scope, $transition$, StateManager, endpoint) {
function initView() {
$scope.volumeId = $transition$.params().id;
$scope.nodeName = $transition$.params().nodeName;
$scope.agentApiVersion = StateManager.getAgentApiVersion();
$scope.endpointId = endpoint.Id;
}
initView();
}

View file

@ -7,6 +7,6 @@
<div class="row">
<div class="col-sm-12">
<volume-browser volume-id="volumeId" node-name="nodeName" is-upload-enabled="agentApiVersion > 1"></volume-browser>
<volume-browser volume-id="volumeId" node-name="nodeName" is-upload-enabled="agentApiVersion > 1" endpoint-id="endpointId"></volume-browser>
</div>
</div>

View file

@ -1,3 +1,5 @@
import { isOfflineEndpoint } from '@/portainer/helpers/endpointHelper';
angular.module('portainer.docker').controller('VolumesController', [
'$q',
'$scope',
@ -7,11 +9,10 @@ angular.module('portainer.docker').controller('VolumesController', [
'VolumeHelper',
'Notifications',
'HttpRequestHelper',
'EndpointProvider',
'Authentication',
'ModalService',
'endpoint',
function ($q, $scope, $state, VolumeService, ServiceService, VolumeHelper, Notifications, HttpRequestHelper, EndpointProvider, Authentication, ModalService, endpoint) {
function ($q, $scope, $state, VolumeService, ServiceService, VolumeHelper, Notifications, HttpRequestHelper, Authentication, ModalService, endpoint) {
$scope.removeAction = function (selectedItems) {
ModalService.confirmDeletion('Do you want to remove the selected volume(s)?', (confirmed) => {
if (confirmed) {
@ -52,7 +53,7 @@ angular.module('portainer.docker').controller('VolumesController', [
})
.then(function success(data) {
var services = data.services;
$scope.offlineMode = EndpointProvider.offlineMode();
$scope.offlineMode = isOfflineEndpoint(endpoint);
$scope.volumes = data.attached
.map(function (volume) {
volume.dangling = false;