1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-20 13:59:40 +02:00

feat(stack-details): Add the ability to duplicate a stack (#2278)

* feat(stack-details): add duplicate-stack button

* feat(stack-details): add stack-duplication-form component

* feat(stack-details): add duplicate stack method on controller

* feat(stack-details): add duplicate stack method

* feat(stack-details): remove old duplication in progress flag

* feat(stack-details): combine migration and duplication forms

* feat(stack-details): pass new stack name to server

* feat(stack-details): add option to rename migrated stack

* feat(stack-details): disable both migrate/duplicate buttons

* feat(stack-details): disable migration button on same endpoint

* feat(stack-details): change duplicate icon

* style(stack-details): remove whitespaces and fix pattern

* feat(stack-details): add name to migration payload in swagger.yml

* style(stack-details): add semicolon

* bug(stack-details): toggle endpoints before and after duplication
This commit is contained in:
Chaim Lev-Ari 2018-10-01 04:36:49 +03:00 committed by Anthony Lapenna
parent 6e262e6e89
commit 9b4870d57e
8 changed files with 205 additions and 54 deletions

View file

@ -0,0 +1,76 @@
angular.module('portainer.app').controller('StackDuplicationFormController', [
'Notifications',
function StackDuplicationFormController(Notifications) {
var ctrl = this;
ctrl.state = {
duplicationInProgress: false,
migrationInProgress: false
};
ctrl.formValues = {
endpoint: null,
newName: ''
};
ctrl.isFormValidForDuplication = isFormValidForDuplication;
ctrl.isFormValidForMigration = isFormValidForMigration;
ctrl.duplicateStack = duplicateStack;
ctrl.migrateStack = migrateStack;
ctrl.isMigrationButtonDisabled = isMigrationButtonDisabled;
function isFormValidForMigration() {
return ctrl.formValues.endpoint && ctrl.formValues.endpoint.Id;
}
function isFormValidForDuplication() {
return isFormValidForMigration() && ctrl.formValues.newName;
}
function duplicateStack() {
if (!ctrl.formValues.newName) {
Notifications.error(
'Failure',
null,
'Stack name is required for duplication'
);
return;
}
ctrl.state.duplicationInProgress = true;
ctrl.onDuplicate({
endpointId: ctrl.formValues.endpoint.Id,
name: ctrl.formValues.newName ? ctrl.formValues.newName : undefined
})
.finally(function() {
ctrl.state.duplicationInProgress = false;
});
}
function migrateStack() {
ctrl.state.migrationInProgress = true;
ctrl.onMigrate({
endpointId: ctrl.formValues.endpoint.Id,
name: ctrl.formValues.newName ? ctrl.formValues.newName : undefined
})
.finally(function() {
ctrl.state.migrationInProgress = false;
});
}
function isMigrationButtonDisabled() {
return (
!ctrl.isFormValidForMigration() ||
ctrl.state.duplicationInProgress ||
ctrl.state.migrationInProgress ||
isTargetEndpointAndCurrentEquals()
);
}
function isTargetEndpointAndCurrentEquals() {
return (
ctrl.formValues.endpoint &&
ctrl.formValues.endpoint.Id === ctrl.currentEndpointId
);
}
}
]);