mirror of
https://github.com/portainer/portainer.git
synced 2025-07-19 13:29:41 +02:00
* fix(edge): filtering of edge devices [EE-3210] fixes [EE-3210] changes: - replaces `edgeDeviceFilter` with two filters: - `edgeDevice` - `edgeDeviceUntrusted` these filters will only apply to the edge endpoints in the query (so it's possible to get both regular endpoints and edge devices). if `edgeDevice` is true, will filter out edge agents which are not an edge device. false, will filter out edge devices `edgeDeviceUntrusted` applies only when `edgeDevice` is true. then false (default) will hide the untrusted edge devices, true will show only untrusted edge devices. fix(edge/job-create): retrieve only trusted endpoints + fix endpoint selector pagination limits onChange fix(endpoint-groups): remove listing of untrusted edge envs (aka in waiting room) refactor(endpoints): move filter to another function feat(endpoints): separate edge filters refactor(environments): change getEnv api refactor(endpoints): use single getEnv feat(groups): show error when failed loading envs style(endpoints): remove unused endpointsByGroup * chore(deps): update go to 1.18 * fix(endpoint): filter out untrusted by default * fix(edge): show correct endpoints * style(endpoints): fix typo * fix(endpoints): fix swagger * fix(admin): use new getEnv function Co-authored-by: LP B <xAt0mZ@users.noreply.github.com>
114 lines
3.7 KiB
JavaScript
114 lines
3.7 KiB
JavaScript
import _ from 'lodash-es';
|
|
import { getEnvironments } from '@/portainer/environments/environment.service';
|
|
|
|
export class EditEdgeStackViewController {
|
|
/* @ngInject */
|
|
constructor($async, $state, $window, ModalService, EdgeGroupService, EdgeStackService, Notifications) {
|
|
this.$async = $async;
|
|
this.$state = $state;
|
|
this.$window = $window;
|
|
this.ModalService = ModalService;
|
|
this.EdgeGroupService = EdgeGroupService;
|
|
this.EdgeStackService = EdgeStackService;
|
|
this.Notifications = Notifications;
|
|
|
|
this.stack = null;
|
|
this.edgeGroups = null;
|
|
|
|
this.state = {
|
|
actionInProgress: false,
|
|
activeTab: 0,
|
|
isEditorDirty: false,
|
|
};
|
|
|
|
this.deployStack = this.deployStack.bind(this);
|
|
this.deployStackAsync = this.deployStackAsync.bind(this);
|
|
this.getPaginatedEndpoints = this.getPaginatedEndpoints.bind(this);
|
|
this.getPaginatedEndpointsAsync = this.getPaginatedEndpointsAsync.bind(this);
|
|
}
|
|
|
|
async $onInit() {
|
|
const { stackId, tab } = this.$state.params;
|
|
this.state.activeTab = tab;
|
|
try {
|
|
const [edgeGroups, model, file] = await Promise.all([this.EdgeGroupService.groups(), this.EdgeStackService.stack(stackId), this.EdgeStackService.stackFile(stackId)]);
|
|
this.edgeGroups = edgeGroups;
|
|
this.stack = model;
|
|
this.stackEndpointIds = this.filterStackEndpoints(model.EdgeGroups, edgeGroups);
|
|
this.originalFileContent = file;
|
|
this.formValues = {
|
|
StackFileContent: file,
|
|
EdgeGroups: this.stack.EdgeGroups,
|
|
DeploymentType: this.stack.DeploymentType,
|
|
};
|
|
this.oldFileContent = this.formValues.StackFileContent;
|
|
} catch (err) {
|
|
this.Notifications.error('Failure', err, 'Unable to retrieve stack data');
|
|
}
|
|
|
|
this.$window.onbeforeunload = () => {
|
|
if (this.formValues.StackFileContent !== this.oldFileContent && this.state.isEditorDirty) {
|
|
return '';
|
|
}
|
|
};
|
|
}
|
|
|
|
$onDestroy() {
|
|
this.state.isEditorDirty = false;
|
|
}
|
|
|
|
async uiCanExit() {
|
|
if (this.formValues.StackFileContent.replace(/(\r\n|\n|\r)/gm, '') !== this.oldFileContent.replace(/(\r\n|\n|\r)/gm, '') && this.state.isEditorDirty) {
|
|
return this.ModalService.confirmWebEditorDiscard();
|
|
}
|
|
}
|
|
|
|
filterStackEndpoints(groupIds, groups) {
|
|
return _.flatten(
|
|
_.map(groupIds, (Id) => {
|
|
const group = _.find(groups, { Id });
|
|
return group.Endpoints;
|
|
})
|
|
);
|
|
}
|
|
|
|
deployStack() {
|
|
return this.$async(this.deployStackAsync);
|
|
}
|
|
|
|
async deployStackAsync() {
|
|
this.state.actionInProgress = true;
|
|
try {
|
|
if (this.originalFileContent != this.formValues.StackFileContent) {
|
|
this.formValues.Version = this.stack.Version + 1;
|
|
}
|
|
await this.EdgeStackService.updateStack(this.stack.Id, this.formValues);
|
|
this.Notifications.success('Stack successfully deployed');
|
|
this.state.isEditorDirty = false;
|
|
this.$state.go('edge.stacks');
|
|
} catch (err) {
|
|
this.Notifications.error('Deployment error', err, 'Unable to deploy stack');
|
|
} finally {
|
|
this.state.actionInProgress = false;
|
|
}
|
|
}
|
|
|
|
getPaginatedEndpoints(...args) {
|
|
return this.$async(this.getPaginatedEndpointsAsync, ...args);
|
|
}
|
|
|
|
async getPaginatedEndpointsAsync(lastId, limit, search) {
|
|
try {
|
|
const query = { search, endpointIds: this.stackEndpointIds };
|
|
const { value, totalCount } = await getEnvironments({ start: lastId, limit, query });
|
|
const endpoints = _.map(value, (endpoint) => {
|
|
const status = this.stack.Status[endpoint.Id];
|
|
endpoint.Status = status;
|
|
return endpoint;
|
|
});
|
|
return { endpoints, totalCount };
|
|
} catch (err) {
|
|
this.Notifications.error('Failure', err, 'Unable to retrieve environment information');
|
|
}
|
|
}
|
|
}
|