mirror of https://github.com/portainer/portainer
feat(node-details): move labels table and save button
parent
21fece80da
commit
e09f653155
|
@ -2,26 +2,10 @@ angular
|
||||||
.module('portainer.docker')
|
.module('portainer.docker')
|
||||||
.controller('NodeAvailabilitySelectController', [
|
.controller('NodeAvailabilitySelectController', [
|
||||||
function NodeAvailabilitySelectController() {
|
function NodeAvailabilitySelectController() {
|
||||||
this.state = {
|
|
||||||
hasChanges: false
|
|
||||||
};
|
|
||||||
this.onChange = onChange;
|
this.onChange = onChange;
|
||||||
this.save = save;
|
|
||||||
this.cancelChanges = cancelChanges;
|
|
||||||
|
|
||||||
function onChange() {
|
function onChange() {
|
||||||
this.state.hasChanges = this.originalValue !== this.availability;
|
|
||||||
}
|
|
||||||
|
|
||||||
function save() {
|
|
||||||
this.onSave({ availability: this.availability });
|
this.onSave({ availability: this.availability });
|
||||||
}
|
}
|
||||||
|
|
||||||
function cancelChanges() {
|
|
||||||
this.state.hasChanges = false;
|
|
||||||
this.availability = this.originalValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -5,17 +5,4 @@
|
||||||
<option value="pause">Pause</option>
|
<option value="pause">Pause</option>
|
||||||
<option value="drain">Drain</option>
|
<option value="drain">Drain</option>
|
||||||
</select>
|
</select>
|
||||||
<div class="btn-toolbar" role="toolbar">
|
|
||||||
<div class="btn-group" role="group">
|
|
||||||
<button type="button" class="btn btn-primary btn-sm" ng-disabled="!$ctrl.state.hasChanges"
|
|
||||||
ng-click="$ctrl.save()">Apply changes</button>
|
|
||||||
<button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown"
|
|
||||||
aria-haspopup="true" aria-expanded="false">
|
|
||||||
<span class="caret"></span>
|
|
||||||
</button>
|
|
||||||
<ul class="dropdown-menu">
|
|
||||||
<li><a ng-click="$ctrl.cancelChanges()">Reset changes</a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
|
@ -3,14 +3,11 @@ 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 label = ctrl.labels.splice(index, 1);
|
var label = ctrl.labels.splice(index, 1);
|
||||||
if (label !== null) {
|
if (label !== null) {
|
||||||
ctrl.hasChanges = true;
|
ctrl.onChangedLabels({ labels: ctrl.labels });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,13 +16,11 @@ angular.module('portainer.docker').controller('NodeLabelsTableController', [
|
||||||
label.value !== label.originalValue ||
|
label.value !== label.originalValue ||
|
||||||
label.key !== label.originalKey
|
label.key !== label.originalKey
|
||||||
) {
|
) {
|
||||||
ctrl.hasChanges = true;
|
ctrl.onChangedLabels({ labels: ctrl.labels });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function save() {
|
|
||||||
ctrl.onChangedLabels({ labels: ctrl.labels });
|
|
||||||
}
|
|
||||||
|
|
||||||
function cancelChanges() {
|
function cancelChanges() {
|
||||||
ctrl.labels = ctrl.labels
|
ctrl.labels = ctrl.labels
|
||||||
|
|
|
@ -31,23 +31,5 @@
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
|
||||||
<td></td>
|
|
||||||
<td>
|
|
||||||
<div class="btn-toolbar" role="toolbar">
|
|
||||||
<div class="btn-group" role="group">
|
|
||||||
<button type="button" class="btn btn-primary btn-sm" ng-disabled="!$ctrl.hasChanges"
|
|
||||||
ng-click="$ctrl.save()">Apply changes</button>
|
|
||||||
<button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown"
|
|
||||||
aria-haspopup="true" aria-expanded="false">
|
|
||||||
<span class="caret"></span>
|
|
||||||
</button>
|
|
||||||
<ul class="dropdown-menu">
|
|
||||||
<li><a ng-click="$ctrl.cancelChanges()">Reset changes</a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
|
@ -1,27 +1,33 @@
|
||||||
angular
|
angular
|
||||||
.module('portainer.docker')
|
.module('portainer.docker')
|
||||||
.controller('SwarmNodeDetailsPanelController', [
|
.controller('SwarmNodeDetailsPanelController', [
|
||||||
function SwarmNodeDetailsPanelController() {
|
'NodeService', 'LabelHelper', 'Notifications', '$state',
|
||||||
this.state = {
|
function SwarmNodeDetailsPanelController(NodeService, LabelHelper, Notifications, $state) {
|
||||||
managerAddress: ''
|
var ctrl = this;
|
||||||
|
ctrl.state = {
|
||||||
|
managerAddress: '',
|
||||||
|
hasChanges: false
|
||||||
};
|
};
|
||||||
this.$onChanges = $onChanges;
|
ctrl.$onChanges = $onChanges;
|
||||||
this.addLabel = addLabel;
|
ctrl.addLabel = addLabel;
|
||||||
this.updateNodeLabels = updateNodeLabels;
|
ctrl.updateNodeLabels = updateNodeLabels;
|
||||||
this.updateNodeAvailability = updateNodeAvailability;
|
ctrl.updateNodeAvailability = updateNodeAvailability;
|
||||||
|
ctrl.saveChanges = saveChanges;
|
||||||
|
ctrl.cancelChanges = cancelChanges;
|
||||||
|
|
||||||
var managerRole = 'manager';
|
var managerRole = 'manager';
|
||||||
|
|
||||||
function $onChanges() {
|
function $onChanges() {
|
||||||
if (!this.details) {
|
if (!ctrl.details) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.details.role === managerRole) {
|
if (ctrl.details.role === managerRole) {
|
||||||
this.state.managerAddress = '(' + this.details.managerAddress + ')';
|
ctrl.state.managerAddress = '(' + ctrl.details.managerAddress + ')';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function addLabel() {
|
function addLabel() {
|
||||||
this.details.nodeLabels.push({
|
ctrl.details.nodeLabels.push({
|
||||||
key: '',
|
key: '',
|
||||||
value: '',
|
value: '',
|
||||||
originalValue: '',
|
originalValue: '',
|
||||||
|
@ -30,11 +36,61 @@ angular
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateNodeLabels(labels) {
|
function updateNodeLabels(labels) {
|
||||||
this.onChangedLabels({ labels: labels });
|
ctrl.details.nodeLabels = labels;
|
||||||
|
ctrl.state.hasChanges = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateNodeAvailability(availability) {
|
function updateNodeAvailability(availability) {
|
||||||
this.onChangedAvailability({ availability: availability });
|
ctrl.details.availability = availability;
|
||||||
|
ctrl.state.hasChanges = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveChanges() {
|
||||||
|
var originalNode = ctrl.originalNode;
|
||||||
|
var config = {
|
||||||
|
Name: originalNode.Name,
|
||||||
|
Availability: ctrl.details.availability,
|
||||||
|
Role: originalNode.Role,
|
||||||
|
Labels: LabelHelper.fromKeyValueToLabelHash(ctrl.details.nodeLabels),
|
||||||
|
Id: originalNode.Id,
|
||||||
|
Version: originalNode.Version
|
||||||
|
};
|
||||||
|
|
||||||
|
NodeService.updateNode(config)
|
||||||
|
.then(onUpdateSuccess)
|
||||||
|
.catch(notifyOnError);
|
||||||
|
|
||||||
|
function onUpdateSuccess() {
|
||||||
|
Notifications.success('Node successfully updated', 'Node updated');
|
||||||
|
$state.go(
|
||||||
|
'docker.nodes.node',
|
||||||
|
{ id: originalNode.Id },
|
||||||
|
{ reload: true }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function notifyOnError(error) {
|
||||||
|
Notifications.error('Failure', error, 'Failed to update node');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancelChanges() {
|
||||||
|
cancelLabelChanges();
|
||||||
|
ctrl.details.availability = ctrl.originalNode.Availability;
|
||||||
|
ctrl.state.hasChanges = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancelLabelChanges() {
|
||||||
|
ctrl.details.nodeLabels = ctrl.details.nodeLabels
|
||||||
|
.filter(function(label) {
|
||||||
|
return label.originalValue || label.originalKey;
|
||||||
|
})
|
||||||
|
.map(function(label) {
|
||||||
|
return Object.assign(label, {
|
||||||
|
value: label.originalValue,
|
||||||
|
key: label.originalKey
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -16,15 +16,15 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td>Availability</td>
|
<td>Availability</td>
|
||||||
<td>
|
<td>
|
||||||
<node-availability-select
|
<node-availability-select on-save="$ctrl.updateNodeAvailability(availability)"
|
||||||
on-save="$ctrl.updateNodeAvailability(availability)"
|
availability="$ctrl.details.availability" original-value="$ctrl.details.availability">
|
||||||
availability="$ctrl.details.availability"
|
</node-availability-select>
|
||||||
original-value="$ctrl.details.availability"></node-availability-select>
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Status</td>
|
<td>Status</td>
|
||||||
<td><span class="label label-{{ $ctrl.details.status | nodestatusbadge }}">{{ $ctrl.details.status }}</span></td>
|
<td><span class="label label-{{ $ctrl.details.status | nodestatusbadge }}">{{
|
||||||
|
$ctrl.details.status }}</span></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr ng-if=" $ctrl.details.engineLabels.length">
|
<tr ng-if=" $ctrl.details.engineLabels.length">
|
||||||
<td>Engine Labels</td>
|
<td>Engine Labels</td>
|
||||||
|
@ -39,14 +39,36 @@
|
||||||
</div>
|
</div>
|
||||||
Node Labels
|
Node Labels
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td></td>
|
||||||
<node-labels-table
|
</tr>
|
||||||
labels="$ctrl.details.nodeLabels"
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<node-labels-table labels="$ctrl.details.nodeLabels"
|
||||||
on-changed-labels="$ctrl.updateNodeLabels(labels)"></node-labels-table>
|
on-changed-labels="$ctrl.updateNodeLabels(labels)"></node-labels-table>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<div class="btn-toolbar" role="toolbar">
|
||||||
|
<div class="btn-group" role="group">
|
||||||
|
<button type="button" class="btn btn-primary btn-sm"
|
||||||
|
ng-disabled="!$ctrl.state.hasChanges" ng-click="$ctrl.saveChanges()">
|
||||||
|
Apply changes
|
||||||
|
</button>
|
||||||
|
<button type="button" class="btn btn-default btn-sm dropdown-toggle"
|
||||||
|
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||||
|
<span class="caret"></span>
|
||||||
|
</button>
|
||||||
|
<ul class="dropdown-menu">
|
||||||
|
<li><a ng-click="$ctrl.cancelChanges()">Reset changes</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
</rd-widget-body>
|
</rd-widget-body>
|
||||||
</rd-widget>
|
</rd-widget>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -4,7 +4,6 @@ angular.module('portainer.docker').component('swarmNodeDetailsPanel', {
|
||||||
controller: 'SwarmNodeDetailsPanelController',
|
controller: 'SwarmNodeDetailsPanelController',
|
||||||
bindings: {
|
bindings: {
|
||||||
details: '<',
|
details: '<',
|
||||||
onChangedLabels: '&',
|
originalNode: '<'
|
||||||
onChangedAvailability: '&'
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
angular.module('portainer.docker').controller('NodeDetailsViewController', [
|
angular.module('portainer.docker').controller('NodeDetailsViewController', [
|
||||||
'$stateParams', 'NodeService', 'LabelHelper', 'Notifications', '$state', 'StateManager', 'AgentService',
|
'$stateParams', 'NodeService', 'StateManager', 'AgentService',
|
||||||
function NodeDetailsViewController($stateParams, NodeService, LabelHelper, Notifications, $state, StateManager, AgentService) {
|
function NodeDetailsViewController($stateParams, NodeService, StateManager, AgentService) {
|
||||||
var ctrl = this;
|
var ctrl = this;
|
||||||
var originalNode;
|
|
||||||
|
|
||||||
ctrl.$onInit = initView;
|
ctrl.$onInit = initView;
|
||||||
ctrl.updateLabels = updateLabels;
|
|
||||||
ctrl.updateAvailability = updateAvailability;
|
|
||||||
|
|
||||||
ctrl.state = {
|
ctrl.state = {
|
||||||
isAgent: false
|
isAgent: false
|
||||||
|
@ -18,7 +15,7 @@ angular.module('portainer.docker').controller('NodeDetailsViewController', [
|
||||||
|
|
||||||
var nodeId = $stateParams.id;
|
var nodeId = $stateParams.id;
|
||||||
NodeService.node(nodeId).then(function(node) {
|
NodeService.node(nodeId).then(function(node) {
|
||||||
originalNode = node;
|
ctrl.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);
|
||||||
|
@ -76,39 +73,9 @@ angular.module('portainer.docker').controller('NodeDetailsViewController', [
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateLabels(labels) {
|
|
||||||
originalNode.Labels = labels;
|
|
||||||
updateNode(originalNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateAvailability(availability) {
|
|
||||||
originalNode.Availability = availability;
|
|
||||||
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 transformPlugins(pluginsList, type) {
|
function transformPlugins(pluginsList, type) {
|
||||||
return pluginsList
|
return pluginsList
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
>
|
>
|
||||||
<swarm-node-details-panel
|
<swarm-node-details-panel
|
||||||
details="$ctrl.nodeDetails"
|
details="$ctrl.nodeDetails"
|
||||||
on-changed-labels="$ctrl.updateLabels(labels)"
|
original-node="$ctrl.originalNode"
|
||||||
on-changed-availability="$ctrl.updateAvailability(availability)"
|
|
||||||
></swarm-node-details-panel>
|
></swarm-node-details-panel>
|
||||||
</host-overview>
|
</host-overview>
|
Loading…
Reference in New Issue