mirror of https://github.com/portainer/portainer
feat(engine-details): add update label functionality
parent
79878cfb85
commit
50ef742c63
|
@ -3,12 +3,14 @@ angular.module('portainer.docker').controller('NodeLabelsTableController', [
|
||||||
var ctrl = this;
|
var ctrl = this;
|
||||||
ctrl.removeLabel = removeLabel;
|
ctrl.removeLabel = removeLabel;
|
||||||
ctrl.updateLabel = updateLabel;
|
ctrl.updateLabel = updateLabel;
|
||||||
|
ctrl.save = save;
|
||||||
|
ctrl.hasChanges = false;
|
||||||
|
ctrl.cancelChanges = cancelChanges;
|
||||||
|
|
||||||
function removeLabel(index) {
|
function removeLabel(index) {
|
||||||
var removedElement = ctrl.labels.splice(index, 1);
|
var label = ctrl.labels.splice(index, 1);
|
||||||
if (removedElement !== null) {
|
if (label !== null) {
|
||||||
console.log(ctrl.labels);
|
ctrl.hasChanges = true;
|
||||||
ctrl.onChangedLabels({labels: ctrl.labels});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,8 +19,26 @@ angular.module('portainer.docker').controller('NodeLabelsTableController', [
|
||||||
label.value !== label.originalValue ||
|
label.value !== label.originalValue ||
|
||||||
label.key !== label.originalKey
|
label.key !== label.originalKey
|
||||||
) {
|
) {
|
||||||
ctrl.onChangedLabels({labels: ctrl.labels});
|
ctrl.hasChanges = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function save() {
|
||||||
|
ctrl.onChangedLabels({ labels: ctrl.labels });
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancelChanges() {
|
||||||
|
ctrl.labels = ctrl.labels
|
||||||
|
.filter(function(label) {
|
||||||
|
return label.originalValue || label.originalKey;
|
||||||
|
})
|
||||||
|
.map(function(label) {
|
||||||
|
return Object.assign(label, {
|
||||||
|
value: label.originalValue,
|
||||||
|
key: label.originalKey
|
||||||
|
});
|
||||||
|
});
|
||||||
|
ctrl.hasChanges = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -36,14 +36,14 @@
|
||||||
<td>
|
<td>
|
||||||
<div class="btn-toolbar" role="toolbar">
|
<div class="btn-toolbar" role="toolbar">
|
||||||
<div class="btn-group" role="group">
|
<div class="btn-group" role="group">
|
||||||
<button type="button" class="btn btn-primary btn-sm" ng-disabled="!$ctrl.hasChanges()"
|
<button type="button" class="btn btn-primary btn-sm" ng-disabled="!$ctrl.hasChanges"
|
||||||
ng-click="$ctrl.save()">Apply changes</button>
|
ng-click="$ctrl.save()">Apply changes</button>
|
||||||
<button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown"
|
<button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown"
|
||||||
aria-haspopup="true" aria-expanded="false">
|
aria-haspopup="true" aria-expanded="false">
|
||||||
<span class="caret"></span>
|
<span class="caret"></span>
|
||||||
</button>
|
</button>
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
<li><a ng-click="$ctrl.cancelChanges(node)">Reset changes</a></li>
|
<li><a ng-click="$ctrl.cancelChanges()">Reset changes</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -2,18 +2,40 @@ angular
|
||||||
.module('portainer.docker')
|
.module('portainer.docker')
|
||||||
.controller('SwarmNodeDetailsPanelController', [
|
.controller('SwarmNodeDetailsPanelController', [
|
||||||
function SwarmNodeDetailsPanelController() {
|
function SwarmNodeDetailsPanelController() {
|
||||||
this.$onInit = initView;
|
|
||||||
this.state = {
|
this.state = {
|
||||||
managerAddress: ''
|
managerAddress: ''
|
||||||
};
|
};
|
||||||
|
this.$onInit = initView;
|
||||||
|
this.$onChanges = $onChanges;
|
||||||
|
this.addLabel = addLabel;
|
||||||
|
this.updateNodeLabels = updateNodeLabels;
|
||||||
var managerRole = 'manager';
|
var managerRole = 'manager';
|
||||||
|
|
||||||
function initView() {
|
function initView() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function $onChanges() {
|
||||||
|
if (!this.details) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (this.details.role === managerRole) {
|
if (this.details.role === managerRole) {
|
||||||
this.state.managerAddress =
|
this.state.managerAddress =
|
||||||
'(Manager address: ' + this.details.managerAddress + ')';
|
'(Manager address: ' + this.details.managerAddress + ')';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addLabel() {
|
||||||
|
this.details.nodeLabels.push({
|
||||||
|
key: '',
|
||||||
|
value: '',
|
||||||
|
originalValue: '',
|
||||||
|
originalKey: ''
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateNodeLabels(labels) {
|
||||||
|
this.onChangedLabels({labels: labels});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -26,8 +26,19 @@
|
||||||
<td>{{ $ctrl.details.engineLabels | commaSeperated }}</td>
|
<td>{{ $ctrl.details.engineLabels | commaSeperated }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Node Labels</td>
|
<td>
|
||||||
<td>{{ $ctrl.details.nodeLabels | commaSeperated }} </td>
|
<div class="nopadding">
|
||||||
|
<a class="btn btn-default btn-sm pull-right" ng-click="$ctrl.addLabel(node)">
|
||||||
|
<i class="fa fa-plus-circle" aria-hidden="true"></i> label
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
Node Labels
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<node-labels-table
|
||||||
|
labels="$ctrl.details.nodeLabels"
|
||||||
|
on-changed-labels="$ctrl.onChangedLabels(labels)"></node-labels-table>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -3,6 +3,7 @@ angular.module('portainer.docker').component('swarmNodeDetailsPanel', {
|
||||||
'app/docker/components/host-view-panels/swarm-node-details-panel/swarm-node-details-panel.html',
|
'app/docker/components/host-view-panels/swarm-node-details-panel/swarm-node-details-panel.html',
|
||||||
controller: 'SwarmNodeDetailsPanelController',
|
controller: 'SwarmNodeDetailsPanelController',
|
||||||
bindings: {
|
bindings: {
|
||||||
details: '<'
|
details: '<',
|
||||||
|
onChangedLabels: '&'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,13 +1,26 @@
|
||||||
angular.module('portainer.docker').controller('NodeDetailsViewController', [
|
angular.module('portainer.docker').controller('NodeDetailsViewController', [
|
||||||
'$stateParams',
|
'$stateParams',
|
||||||
'NodeService',
|
'NodeService',
|
||||||
function NodeDetailsViewController($stateParams, NodeService) {
|
'NodeHelper',
|
||||||
|
'LabelHelper',
|
||||||
|
'Notifications',
|
||||||
|
'$state',
|
||||||
|
function NodeDetailsViewController(
|
||||||
|
$stateParams,
|
||||||
|
NodeService,
|
||||||
|
NodeHelper,
|
||||||
|
LabelHelper,
|
||||||
|
Notifications,
|
||||||
|
$state
|
||||||
|
) {
|
||||||
var ctrl = this;
|
var ctrl = this;
|
||||||
|
var originalNode;
|
||||||
ctrl.$onInit = initView;
|
ctrl.$onInit = initView;
|
||||||
|
ctrl.updateLabels = updateLabels;
|
||||||
|
|
||||||
function initView() {
|
function initView() {
|
||||||
NodeService.node($stateParams.id).then(function(node) {
|
NodeService.node($stateParams.id).then(function(node) {
|
||||||
|
originalNode = node;
|
||||||
ctrl.hostDetails = buildHostDetails(node);
|
ctrl.hostDetails = buildHostDetails(node);
|
||||||
ctrl.engineDetails = buildEngineDetails(node);
|
ctrl.engineDetails = buildEngineDetails(node);
|
||||||
ctrl.nodeDetails = buildNodeDetails(node);
|
ctrl.nodeDetails = buildNodeDetails(node);
|
||||||
|
@ -52,6 +65,35 @@ angular.module('portainer.docker').controller('NodeDetailsViewController', [
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateLabels(labels) {
|
||||||
|
originalNode.labels = labels;
|
||||||
|
updateNode(originalNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateNode(node) {
|
||||||
|
var config = {
|
||||||
|
Name: node.Name,
|
||||||
|
Availability: node.Availability,
|
||||||
|
Role: node.Role,
|
||||||
|
Labels: LabelHelper.fromKeyValueToLabelHash(node.Labels),
|
||||||
|
Id: node.Id,
|
||||||
|
Version: node.Version
|
||||||
|
};
|
||||||
|
|
||||||
|
NodeService.updateNode(config)
|
||||||
|
.then(onUpdateSuccess)
|
||||||
|
.catch(notifyOnError);
|
||||||
|
|
||||||
|
function onUpdateSuccess() {
|
||||||
|
Notifications.success('Node successfully updated', 'Node updated');
|
||||||
|
$state.go('docker.nodes.node', { id: node.Id }, { reload: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
function notifyOnError(error) {
|
||||||
|
Notifications.error('Failure', error, 'Failed to update node');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getPlugins(pluginsList, type) {
|
function getPlugins(pluginsList, type) {
|
||||||
return pluginsList
|
return pluginsList
|
||||||
.filter(function(plugin) {
|
.filter(function(plugin) {
|
||||||
|
|
Loading…
Reference in New Issue