Repository: incubator-nifi Updated Branches: refs/heads/NIFI-475 31ec55c38 -> 3ac6f30ec
NIFI-475: - Prompting the user to save changes before navigating to the controller service definition. Project: http://git-wip-us.apache.org/repos/asf/incubator-nifi/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-nifi/commit/3ac6f30e Tree: http://git-wip-us.apache.org/repos/asf/incubator-nifi/tree/3ac6f30e Diff: http://git-wip-us.apache.org/repos/asf/incubator-nifi/diff/3ac6f30e Branch: refs/heads/NIFI-475 Commit: 3ac6f30ecc2a8028c8f64c24f41d12a22ee1a932 Parents: 31ec55c Author: Matt Gilman <[email protected]> Authored: Tue Apr 7 09:41:39 2015 -0400 Committer: Matt Gilman <[email protected]> Committed: Tue Apr 7 09:41:39 2015 -0400 ---------------------------------------------------------------------- .../propertytable/jquery.propertytable.js | 74 +++++--- .../js/nf/canvas/nf-controller-service.js | 174 ++++++++++--------- 2 files changed, 141 insertions(+), 107 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/3ac6f30e/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/jquery/propertytable/jquery.propertytable.js ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/jquery/propertytable/jquery.propertytable.js b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/jquery/propertytable/jquery.propertytable.js index dee3e27..c2b947d 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/jquery/propertytable/jquery.propertytable.js +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/jquery/propertytable/jquery.propertytable.js @@ -23,7 +23,17 @@ * * { * readOnly: true, - * dialogContainer: 'body' + * dialogContainer: 'body', + * descriptorDeferred: function () { + * return $.Deferred(function (deferred) { + * deferred.resolve(); + * }).promise; + * }, + * goToServiceDeferred: function () { + * return $.Deferred(function (deferred) { + * deferred.resolve(); + * }).promise; + * } * } */ @@ -1084,6 +1094,39 @@ } } }; + + var goToControllerService = function (property) { + // close the dialog + var dialog = table.closest('.dialog'); + if (dialog.hasClass('modal')) { + dialog.modal('hide'); + } else { + dialog.hide(); + } + + $.Deferred(function (deferred) { + if ($('#settings').is(':visible')) { + deferred.resolve(); + } else { + // reload the settings and show + nf.Settings.loadSettings().done(function () { + nf.Settings.showSettings(); + deferred.resolve(); + }); + } + }).done(function () { + var controllerServiceGrid = $('#controller-services-table').data('gridInstance'); + var controllerServiceData = controllerServiceGrid.getData(); + + // select the desired service + var row = controllerServiceData.getRowById(property.value); + controllerServiceGrid.setSelectedRows([row]); + controllerServiceGrid.scrollRowIntoView(row); + + // select the controller services tab + $('#settings-tabs').find('li:eq(1)').click(); + }); + }; // initialize the grid var propertyGrid = new Slick.Grid(table, propertyData, propertyColumns, propertyConfigurationOptions); @@ -1114,29 +1157,16 @@ // prevents standard edit logic e.stopImmediatePropagation(); } else if (target.hasClass('go-to-service')) { - // close the dialog - var dialog = table.closest('.dialog'); - if (dialog.hasClass('modal')) { - dialog.modal('hide'); + if (options.readOnly === true) { + goToControllerService(property); } else { - dialog.hide(); + // load the property descriptor if possible + if (typeof options.goToServiceDeferred === 'function') { + options.goToServiceDeferred().done(function() { + goToControllerService(property); + }); + } } - - // reload the settings and show - nf.Settings.loadSettings().done(function () { - nf.Settings.showSettings(); - - var controllerServiceGrid = $('#controller-services-table').data('gridInstance'); - var controllerServiceData = controllerServiceGrid.getData(); - - // select the selected row - var row = controllerServiceData.getRowById(property.value); - controllerServiceGrid.setSelectedRows([row]); - controllerServiceGrid.scrollRowIntoView(row); - - // select the controller services tab - $('#settings-tabs').find('li:eq(1)').click(); - }); } } }); http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/3ac6f30e/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-controller-service.js ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-controller-service.js b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-controller-service.js index 29c7710..2584bc2 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-controller-service.js +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-controller-service.js @@ -1072,6 +1072,79 @@ nf.ControllerService = (function () { }; /** + * Goes to a service configuration from the property table. + */ + var goToServiceFromProperty = function () { + return $.Deferred(function (deferred) { + // close all fields currently being edited + $('#controller-service-properties').propertytable('saveRow'); + + // determine if changes have been made + if (isSaveRequired()) { + // see if those changes should be saved + nf.Dialog.showYesNoDialog({ + dialogContent: 'Save changes before going to this Controller Service?', + overlayBackground: false, + noHandler: function () { + deferred.resolve(); + }, + yesHandler: function () { + var controllerService = $('#controller-service-configuration').data('controllerServiceDetails'); + saveControllerService(controllerService).done(function () { + deferred.resolve(); + }).fail(function () { + deferred.reject(); + }); + } + }); + } else { + deferred.resolve(); + } + }).promise(); + }; + + var saveControllerService = function (controllerService) { + // marshal the settings and properties and update the controller service + var updatedControllerService = marshalDetails(); + + // ensure details are valid as far as we can tell + if (validateDetails(updatedControllerService)) { + var previouslyReferencedServiceIds = []; + $.each(identifyReferencedServiceDescriptors(controllerService), function (_, descriptor) { + var modifyingService = !nf.Common.isUndefined(updatedControllerService.controllerService.properties) && !nf.Common.isUndefined(updatedControllerService.controllerService.properties[descriptor.name]); + var isCurrentlyConfigured = nf.Common.isDefinedAndNotNull(controllerService.properties[descriptor.name]); + + // if we are attempting to update a controller service reference + if (modifyingService && isCurrentlyConfigured) { + + // record the current value if set + previouslyReferencedServiceIds.push(controllerService.properties[descriptor.name]); + } + }); + + // update the selected component + return $.ajax({ + type: 'PUT', + data: JSON.stringify(updatedControllerService), + url: controllerService.uri, + dataType: 'json', + processData: false, + contentType: 'application/json' + }).done(function (response) { + if (nf.Common.isDefinedAndNotNull(response.controllerService)) { + // update the revision + nf.Client.setRevision(response.revision); + + // reload all previously referenced controller services + $.each(previouslyReferencedServiceIds, function(_, oldServiceReferenceId) { + reloadControllerService(oldServiceReferenceId); + }); + } + }).fail(handleControllerServiceConfigurationError); + } + }; + + /** * Identifies the descriptors that identify controller services. * * @param {object} component @@ -1183,7 +1256,8 @@ nf.ControllerService = (function () { $('#controller-service-properties').propertytable({ readOnly: false, dialogContainer: '#new-controller-service-property-container', - descriptorDeferred: getControllerServicePropertyDescriptor + descriptorDeferred: getControllerServicePropertyDescriptor, + goToServiceDeferred: goToServiceFromProperty }); // initialize the disable service dialog @@ -1327,7 +1401,8 @@ nf.ControllerService = (function () { $('#controller-service-properties').propertytable('destroy').propertytable({ readOnly: false, dialogContainer: '#new-controller-service-property-container', - descriptorDeferred: getControllerServicePropertyDescriptor + descriptorDeferred: getControllerServicePropertyDescriptor, + goToServiceDeferred: goToServiceFromProperty }); // update the mode @@ -1394,49 +1469,15 @@ nf.ControllerService = (function () { // close all fields currently being edited $('#controller-service-properties').propertytable('saveRow'); - // marshal the settings and properties and update the controller service - var updatedControllerService = marshalDetails(); - - // ensure details are valid as far as we can tell - if (validateDetails(updatedControllerService)) { - var previouslyReferencedServiceIds = []; - $.each(identifyReferencedServiceDescriptors(controllerService), function (_, descriptor) { - var modifyingService = !nf.Common.isUndefined(updatedControllerService.controllerService.properties) && !nf.Common.isUndefined(updatedControllerService.controllerService.properties[descriptor.name]); - var isCurrentlyConfigured = nf.Common.isDefinedAndNotNull(controllerService.properties[descriptor.name]); - - // if we are attempting to update a controller service reference - if (modifyingService && isCurrentlyConfigured) { - // record the current value if set - previouslyReferencedServiceIds.push(controllerService.properties[descriptor.name]); - } - }); + // save the controller service + saveControllerService(controllerService).done(function (response) { + // reload the controller service + renderControllerService(response.controllerService); + reloadControllerServiceReferences(response.controllerService); - // update the selected component - $.ajax({ - type: 'PUT', - data: JSON.stringify(updatedControllerService), - url: controllerService.uri, - dataType: 'json', - processData: false, - contentType: 'application/json' - }).done(function (response) { - if (nf.Common.isDefinedAndNotNull(response.controllerService)) { - nf.Client.setRevision(response.revision); - - // reload the controller service - renderControllerService(response.controllerService); - reloadControllerServiceReferences(response.controllerService); - - // reload all previously referenced controller services - $.each(previouslyReferencedServiceIds, function(_, oldServiceReferenceId) { - reloadControllerService(oldServiceReferenceId); - }); - - // close the details panel - controllerServiceDialog.modal('hide'); - } - }).fail(handleControllerServiceConfigurationError); - } + // close the details panel + controllerServiceDialog.modal('hide'); + }); } } }, { @@ -1482,47 +1523,10 @@ nf.ControllerService = (function () { overlayBackground: false, noHandler: openCustomUi, yesHandler: function () { - // marshal the settings and properties and update the controller service - var updatedControllerService = marshalDetails(); - - // ensure details are valid as far as we can tell - if (validateDetails(updatedControllerService)) { - var previouslyReferencedServiceIds = []; - $.each(identifyReferencedServiceDescriptors(controllerService), function (_, descriptor) { - var modifyingService = !nf.Common.isUndefined(updatedControllerService.controllerService.properties) && !nf.Common.isUndefined(updatedControllerService.controllerService.properties[descriptor.name]); - var isCurrentlyConfigured = nf.Common.isDefinedAndNotNull(controllerService.properties[descriptor.name]); - - // if we are attempting to update a controller service reference - if (modifyingService && isCurrentlyConfigured) { - - // record the current value if set - previouslyReferencedServiceIds.push(controllerService.properties[descriptor.name]); - } - }); - - // update the selected component - $.ajax({ - type: 'PUT', - data: JSON.stringify(updatedControllerService), - url: controllerService.uri, - dataType: 'json', - processData: false, - contentType: 'application/json' - }).done(function (response) { - if (nf.Common.isDefinedAndNotNull(response.controllerService)) { - // update the revision - nf.Client.setRevision(response.revision); - - // reload all previously referenced controller services - $.each(previouslyReferencedServiceIds, function(_, oldServiceReferenceId) { - reloadControllerService(oldServiceReferenceId); - }); - - // open the custom ui - openCustomUi(); - } - }).fail(handleControllerServiceConfigurationError); - } + saveControllerService(controllerService).done(function () { + // open the custom ui + openCustomUi(); + }); } }); } else {
