[NIFI-2697] revert transmission switch toggle on failed update request. This closes #1600

This commit is contained in:
Scott Aslan 2017-03-17 12:32:33 -04:00 committed by Matt Gilman
parent b3b65219a0
commit 40acd4a6e1
No known key found for this signature in database
GPG Key ID: DF61EC19432AEE37
1 changed files with 38 additions and 20 deletions

View File

@ -251,27 +251,35 @@
// if can modify, support updating the remote group port // if can modify, support updating the remote group port
if (nfCanvasUtils.canModify(remoteProcessGroup)) { if (nfCanvasUtils.canModify(remoteProcessGroup)) {
// show the enabled transmission switch
var createTransmissionSwitch = function (port) {
var transmissionSwitch; var transmissionSwitch;
if (port.connected === true) { if (port.connected === true) {
if (port.transmitting === true) { if (port.transmitting === true) {
transmissionSwitch = (nfNgBridge.injector.get('$compile')($('<md-switch style="margin:0px" class="md-primary enabled-active-transmission" aria-label="Toggle port transmission"></md-switch>'))(nfNgBridge.rootScope)).appendTo(portContainerEditContainer); transmissionSwitch = (nfNgBridge.injector.get('$compile')($('<md-switch style="margin:0px" class="md-primary enabled-active-transmission" aria-label="Toggle port transmission"></md-switch>'))(nfNgBridge.rootScope));
transmissionSwitch.click(); transmissionSwitch.click();
} else { } else {
if (port.exists === true) { if (port.exists === true) {
transmissionSwitch = (nfNgBridge.injector.get('$compile')($('<md-switch style="margin:0px" class="md-primary enabled-inactive-transmission" aria-label="Toggle port transmission"></md-switch>'))(nfNgBridge.rootScope)).appendTo(portContainerEditContainer); transmissionSwitch = (nfNgBridge.injector.get('$compile')($('<md-switch style="margin:0px" class="md-primary enabled-inactive-transmission" aria-label="Toggle port transmission"></md-switch>'))(nfNgBridge.rootScope));
} else { } else {
(nfNgBridge.injector.get('$compile')($('<md-switch ng-disabled="true" style="margin:0px" class="md-primary disabled-inactive-transmission" aria-label="Toggle port transmission"></md-switch>'))(nfNgBridge.rootScope)).appendTo(portContainerEditContainer); (nfNgBridge.injector.get('$compile')($('<md-switch ng-disabled="true" style="margin:0px" class="md-primary disabled-inactive-transmission" aria-label="Toggle port transmission"></md-switch>'))(nfNgBridge.rootScope));
} }
} }
} else { } else {
if (port.transmitting === true) { if (port.transmitting === true) {
(nfNgBridge.injector.get('$compile')($('<md-switch style="margin:0px" class="md-primary disabled-active-transmission" aria-label="Toggle port transmission"></md-switch>'))(nfNgBridge.rootScope)).appendTo(portContainerEditContainer); (nfNgBridge.injector.get('$compile')($('<md-switch style="margin:0px" class="md-primary disabled-active-transmission" aria-label="Toggle port transmission"></md-switch>'))(nfNgBridge.rootScope));
} else { } else {
(nfNgBridge.injector.get('$compile')($('<md-switch ng-disabled="true" style="margin:0px" class="md-primary disabled-inactive-transmission" aria-label="Toggle port transmission"></md-switch>'))(nfNgBridge.rootScope)).appendTo(portContainerEditContainer); (nfNgBridge.injector.get('$compile')($('<md-switch ng-disabled="true" style="margin:0px" class="md-primary disabled-inactive-transmission" aria-label="Toggle port transmission"></md-switch>'))(nfNgBridge.rootScope));
} }
} }
return transmissionSwitch;
};
// show the enabled transmission switch
var transmissionSwitch = createTransmissionSwitch(port);
transmissionSwitch.appendTo(portContainerEditContainer);
// only support configuration when the remote port exists // only support configuration when the remote port exists
if (port.exists === true && port.connected === true) { if (port.exists === true && port.connected === true) {
// create the button for editing the ports configuration // create the button for editing the ports configuration
@ -300,8 +308,7 @@
// only allow modifications to transmission when the swtich is defined // only allow modifications to transmission when the swtich is defined
if (nfCommon.isDefinedAndNotNull(transmissionSwitch)) { if (nfCommon.isDefinedAndNotNull(transmissionSwitch)) {
// create toggle for changing transmission state var transmissionSwitchClickFunction = function () {
transmissionSwitch.click(function () {
// get the component being edited // get the component being edited
var remoteProcessGroupId = $('#remote-process-group-ports-id').text(); var remoteProcessGroupId = $('#remote-process-group-ports-id').text();
var remoteProcessGroupData = d3.select('#id-' + remoteProcessGroupId).datum(); var remoteProcessGroupData = d3.select('#id-' + remoteProcessGroupId).datum();
@ -373,6 +380,14 @@
} }
} }
}).fail(function (xhr, status, error) { }).fail(function (xhr, status, error) {
// create replacement switch
var newTransmissionSwitch = createTransmissionSwitch(port);
// add click handler
newTransmissionSwitch.click(transmissionSwitchClickFunction);
//replace DOM element
transmissionSwitch.replaceWith(newTransmissionSwitch);
// update transmissionSwitch variable to reference the new switch
transmissionSwitch = newTransmissionSwitch;
if (xhr.status === 400) { if (xhr.status === 400) {
var errors = xhr.responseText.split('\n'); var errors = xhr.responseText.split('\n');
@ -391,7 +406,10 @@
nfErrorHandler.handleAjaxError(xhr, status, error); nfErrorHandler.handleAjaxError(xhr, status, error);
} }
}); });
}); };
// create toggle for changing transmission state
transmissionSwitch.click(transmissionSwitchClickFunction);
} }
} else { } else {
// show the disabled transmission switch // show the disabled transmission switch