[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,26 +251,34 @@
// 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 transmissionSwitch; var createTransmissionSwitch = function (port) {
if (port.connected === true) { var transmissionSwitch;
if (port.transmitting === true) { if (port.connected === 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); if (port.transmitting === true) {
transmissionSwitch.click(); 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));
} else { transmissionSwitch.click();
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);
} 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); 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));
} 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));
}
}
} else {
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));
} 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));
} }
} }
} else {
if (port.transmitting === true) { return transmissionSwitch;
(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); };
} 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); // 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) {
@ -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