portainer/app/integrations/storidge/views/profiles/edit/profileController.js

146 lines
4.3 KiB
JavaScript
Raw Normal View History

angular.module('portainer.integrations.storidge').controller('StoridgeProfileController', [
'$scope',
'$state',
'$transition$',
'Notifications',
'StoridgeProfileService',
'ModalService',
function ($scope, $state, $transition$, Notifications, StoridgeProfileService, ModalService) {
$scope.formValues = {
Labels: [],
};
$scope.state = {
NoLimit: false,
LimitIOPS: false,
LimitBandwidth: false,
updateInProgress: false,
deleteInProgress: false,
RecurringSnapshotEnabled: false,
};
$scope.addLabel = function () {
$scope.formValues.Labels.push({ name: '', value: '' });
};
$scope.removeLabel = function (index) {
$scope.formValues.Labels.splice(index, 1);
};
function prepareLabels(profile) {
var labels = {};
$scope.formValues.Labels.forEach(function (label) {
if (label.name && label.value) {
labels[label.name] = label.value;
}
});
profile.Labels = labels;
}
function initLabels(labels) {
$scope.formValues.Labels = Object.keys(labels).map(function (key) {
return { name: key, value: labels[key] };
});
}
$scope.RedundancyOptions = [
{ value: 2, label: '2-copy' },
{ value: 3, label: '3-copy' },
];
$scope.update = function () {
var profile = $scope.profile;
if (!$scope.state.LimitIOPS) {
delete profile.MinIOPS;
delete profile.MaxIOPS;
feat(integrations): storidge evolution (#2711) * feat(storidge): update storidge routes * feat(storidge): add new fields on profile create/edit * feat(storidge): add drives list and details view * feat(storidge): add node details / cordon / uncordon / remove * feat(storidge): add volume and snapshot details * feat(storidge): add snapshot creation on volume details * feat(storidge): add rescan drives button * refactor(storidge): move add / remove / put in / put ouf maintenance buttons for cluster nodes * style(storidge): change cluster / node icon color based on status * feat(storidge): profiles can enable snapshots without interval + interval in minutes * refactor(storidge): split cluster and node status badge filter * fix(storidge): error on volume IOPS update * fix(storidge): snapshot can now be created without comments * feat(storidge): remove snapshots panels when volume snapshots are disabled * fix(app): paginatedItemLimit now retrieved for datables extending GenericDatatableController * fix(storidge): addDrive is called with the good parameters * fix(storidge): update model and views for Storidge v2695 * refactor(storidge): webpack migration * fix(storidge): display modifications + fix js errors * feat(storidge): snapshots, profile and nodes evolution * fix(storidge): values for InterfaceDriver on profile create/edit * feat(storidge): v5 update without style (profile / statuses / volume) * fix(storidge): description tables on the same view have now the same fixed offset * fix(app): override rdash-ui select style * Revert "fix(app): override rdash-ui select style" This reverts commit e7248332611345dc803be83560282517c44c0646. * feat(storidge): wip on update 6 * feat(storidge): update 6 * feat(storidge): update 6 * feat(storidge): update 6 * feat(storidge): update 7 - node details + cluster views * fix(storidge): update 7 - profiles creation + volume details * fix(storidge): update 7 - profile create/edit interface type * feat(storidge): update 8 - add drive * feat(storidge): update 8 - UI refactors + cluster availability * fix(storidge): update 8 - revert cluster availability * feat(storidge): update 8 - node availability on swarm overview * feat(storidge): cluster condition badge * fix(storidge): update 9 - move add storage button + api profile filesystem kv to obj * feat(storidge): update 9 - disable add drive button when action is in progress * fix(storidge): update 9 - add drive button will now change only for the concerned drive * fix(storidge): update 10 - disable remove drive button when removal in progress * fix(api): update Storidge proxy creation process * refactor(api): update version number * feat(extensions): fix an issue with Storidge API URL * feat(storidge): force the use of a manager node
2019-05-24 21:53:10 +00:00
}
if (!$scope.state.LimitBandwidth) {
delete profile.MinBandwidth;
delete profile.MaxBandwidth;
}
if (profile.SnapshotEnabled) {
if (!profile.SnapshotMax || profile.SnapshotMax <= 0) {
profile.SnapshotMax = 1;
}
if (!$scope.state.RecurringSnapshotEnabled) {
delete profile.SnapshotInterval;
}
if ($scope.state.RecurringSnapshotEnabled && (!profile.SnapshotInterval || profile.SnapshotInterval <= 0)) {
profile.SnapshotInterval = 1440;
}
} else {
delete profile.SnapshotMax;
delete profile.SnapshotInterval;
feat(integrations): storidge evolution (#2711) * feat(storidge): update storidge routes * feat(storidge): add new fields on profile create/edit * feat(storidge): add drives list and details view * feat(storidge): add node details / cordon / uncordon / remove * feat(storidge): add volume and snapshot details * feat(storidge): add snapshot creation on volume details * feat(storidge): add rescan drives button * refactor(storidge): move add / remove / put in / put ouf maintenance buttons for cluster nodes * style(storidge): change cluster / node icon color based on status * feat(storidge): profiles can enable snapshots without interval + interval in minutes * refactor(storidge): split cluster and node status badge filter * fix(storidge): error on volume IOPS update * fix(storidge): snapshot can now be created without comments * feat(storidge): remove snapshots panels when volume snapshots are disabled * fix(app): paginatedItemLimit now retrieved for datables extending GenericDatatableController * fix(storidge): addDrive is called with the good parameters * fix(storidge): update model and views for Storidge v2695 * refactor(storidge): webpack migration * fix(storidge): display modifications + fix js errors * feat(storidge): snapshots, profile and nodes evolution * fix(storidge): values for InterfaceDriver on profile create/edit * feat(storidge): v5 update without style (profile / statuses / volume) * fix(storidge): description tables on the same view have now the same fixed offset * fix(app): override rdash-ui select style * Revert "fix(app): override rdash-ui select style" This reverts commit e7248332611345dc803be83560282517c44c0646. * feat(storidge): wip on update 6 * feat(storidge): update 6 * feat(storidge): update 6 * feat(storidge): update 6 * feat(storidge): update 7 - node details + cluster views * fix(storidge): update 7 - profiles creation + volume details * fix(storidge): update 7 - profile create/edit interface type * feat(storidge): update 8 - add drive * feat(storidge): update 8 - UI refactors + cluster availability * fix(storidge): update 8 - revert cluster availability * feat(storidge): update 8 - node availability on swarm overview * feat(storidge): cluster condition badge * fix(storidge): update 9 - move add storage button + api profile filesystem kv to obj * feat(storidge): update 9 - disable add drive button when action is in progress * fix(storidge): update 9 - add drive button will now change only for the concerned drive * fix(storidge): update 10 - disable remove drive button when removal in progress * fix(api): update Storidge proxy creation process * refactor(api): update version number * feat(extensions): fix an issue with Storidge API URL * feat(storidge): force the use of a manager node
2019-05-24 21:53:10 +00:00
}
prepareLabels(profile);
$scope.state.updateInProgress = true;
StoridgeProfileService.update(profile)
.then(function success() {
Notifications.success('Profile successfully updated');
$state.go('storidge.profiles');
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to update profile');
})
.finally(function final() {
$scope.state.updateInProgress = false;
});
};
$scope.delete = function () {
ModalService.confirmDeletion('Do you want to remove this profile?', function onConfirm(confirmed) {
if (!confirmed) {
return;
}
deleteProfile();
});
};
function deleteProfile() {
var profile = $scope.profile;
$scope.state.deleteInProgress = true;
StoridgeProfileService.delete(profile.Name)
.then(function success() {
Notifications.success('Profile successfully deleted');
$state.go('storidge.profiles');
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to delete profile');
})
.finally(function final() {
$scope.state.deleteInProgress = false;
});
}
function initView() {
StoridgeProfileService.profile($transition$.params().id)
.then(function success(data) {
var profile = data;
if ((profile.MinIOPS && profile.MinIOPS !== 0) || (profile.MaxIOPS && profile.MaxIOPS !== 0)) {
$scope.state.LimitIOPS = true;
} else if ((profile.MinBandwidth && profile.MinBandwidth !== 0) || (profile.MaxBandwidth && profile.MaxBandwidth !== 0)) {
$scope.state.LimitBandwidth = true;
} else {
$scope.state.NoLimit = true;
}
if (profile.SnapshotEnabled && profile.SnapshotInterval !== 0) {
$scope.state.RecurringSnapshotEnabled = true;
}
initLabels(profile.Labels);
$scope.profile = profile;
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to retrieve profile details');
});
}
initView();
},
]);