nifi-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [nifi] rfellows commented on a change in pull request #3606: [WIP] Nifi 6282
Date Fri, 23 Aug 2019 14:56:32 GMT
rfellows commented on a change in pull request #3606: [WIP] Nifi 6282
URL: https://github.com/apache/nifi/pull/3606#discussion_r317170768
 
 

 ##########
 File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-ui/src/main/webapp/js/nf/canvas/nf-parameter-contexts.js
 ##########
 @@ -0,0 +1,2298 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* global define, module, require, exports */
+
+(function (root, factory) {
+    if (typeof define === 'function' && define.amd) {
+        define(['jquery',
+                'Slick',
+                'd3',
+                'nf.Client',
+                'nf.Dialog',
+                'nf.Storage',
+                'nf.Common',
+                'nf.CanvasUtils',
+                'nf.ng.Bridge',
+                'nf.ErrorHandler',
+                'nf.FilteredDialogCommon',
+                'nf.Shell',
+                'nf.ComponentState',
+                'nf.ComponentVersion',
+                'nf.PolicyManagement',
+                'nf.Processor',
+                'nf.ProcessGroup',
+                'nf.ProcessGroupConfiguration'],
+            function ($, Slick, d3, nfClient, nfDialog, nfStorage, nfCommon, nfCanvasUtils, nfNgBridge, nfErrorHandler, nfFilteredDialogCommon, nfShell, nfComponentState, nfComponentVersion, nfPolicyManagement, nfProcessor, nfProcessGroup, nfProcessGroupConfiguration) {
+                return (nf.ParameterContexts = factory($, Slick, d3, nfClient, nfDialog, nfStorage, nfCommon, nfCanvasUtils, nfNgBridge, nfErrorHandler, nfFilteredDialogCommon, nfShell, nfComponentState, nfComponentVersion, nfPolicyManagement, nfProcessor, nfProcessGroup, nfProcessGroupConfiguration));
+            });
+    } else if (typeof exports === 'object' && typeof module === 'object') {
+        module.exports = (nf.ParameterContexts =
+            factory(require('jquery'),
+                require('Slick'),
+                require('d3'),
+                require('nf.Client'),
+                require('nf.Dialog'),
+                require('nf.Storage'),
+                require('nf.Common'),
+                require('nf.CanvasUtils'),
+                require('nf.ng.Bridge'),
+                require('nf.ErrorHandler'),
+                require('nf.FilteredDialogCommon'),
+                require('nf.Shell'),
+                require('nf.ComponentState'),
+                require('nf.ComponentVersion'),
+                require('nf.PolicyManagement'),
+                require('nf.Processor'),
+                require('nf.ProcessGroup'),
+                require('nf.ProcessGroupConfiguration')));
+    } else {
+        nf.ParameterContexts = factory(root.$,
+            root.Slick,
+            root.d3,
+            root.nf.Client,
+            root.nf.Dialog,
+            root.nf.Storage,
+            root.nf.Common,
+            root.nf.CanvasUtils,
+            root.nf.ng.Bridge,
+            root.nf.ErrorHandler,
+            root.nf.FilteredDialogCommon,
+            root.nf.Shell,
+            root.nf.ComponentState,
+            root.nf.ComponentVersion,
+            root.nf.PolicyManagement,
+            root.nf.Processor,
+            root.nf.ProcessGroup,
+            root.nf.ProcessGroupConfiguration);
+    }
+}(this, function ($, Slick, d3, nfClient, nfDialog, nfStorage, nfCommon, nfCanvasUtils, nfNgBridge, nfErrorHandler, nfFilteredDialogCommon, nfShell, nfComponentState, nfComponentVersion, nfPolicyManagement, nfProcessor, nfProcessGroup, nfProcessGroupConfiguration) {
+    'use strict';
+
+    var config = {
+        urls: {
+            parameterContexts: '../nifi-api/parameter-contexts'
+        }
+    };
+
+    var parameterContextsGridOptions = {
+        forceFitColumns: true,
+        enableTextSelectionOnCells: true,
+        enableCellNavigation: true,
+        enableColumnReorder: false,
+        autoEdit: false,
+        multiSelect: false,
+        rowHeight: 24
+    };
+
+    var parametersGridOptions = {
+        forceFitColumns: true,
+        enableTextSelectionOnCells: true,
+        enableCellNavigation: true,
+        enableColumnReorder: false,
+        editable: false,
+        enableAddRow: false,
+        autoEdit: false,
+        multiSelect: false,
+        rowHeight: 24
+    };
+
+    /**
+     * Formatter for the name column.
+     *
+     * @param {type} row
+     * @param {type} cell
+     * @param {type} value
+     * @param {type} columnDef
+     * @param {type} dataContext
+     * @returns {String}
+     */
+    var nameFormatter = function (row, cell, value, columnDef, dataContext) {
+        if (!dataContext.permissions.canRead) {
+            return '<span class="blank">' + nfCommon.escapeHtml(dataContext.id) + '</span>';
+        }
+
+        return nfCommon.escapeHtml(dataContext.component.name);
+    };
+
+    /**
+     * Sorts the specified data using the specified sort details.
+     *
+     * @param {object} sortDetails
+     * @param {object} data
+     */
+    var sort = function (sortDetails, data) {
+        // defines a function for sorting
+        var comparer = function (a, b) {
+            if (a.permissions.canRead && b.permissions.canRead) {
+                var aString = nfCommon.isDefinedAndNotNull(a.component[sortDetails.columnId]) ? a.component[sortDetails.columnId] : '';
+                var bString = nfCommon.isDefinedAndNotNull(b.component[sortDetails.columnId]) ? b.component[sortDetails.columnId] : '';
+                return aString === bString ? 0 : aString > bString ? 1 : -1;
+            } else {
+                if (!a.permissions.canRead && !b.permissions.canRead) {
+                    return 0;
+                }
+                if (a.permissions.canRead) {
+                    return 1;
+                } else {
+                    return -1;
+                }
+            }
+        };
+
+        // perform the sort
+        data.sort(comparer, sortDetails.sortAsc);
+    };
+
+    var lastSelectedId = null;
+
+    /**
+     * Sorts the specified data using the specified sort details.
+     *
+     * @param {object} sortDetails
+     * @param {object} data
+     */
+    var sortParameters = function (sortDetails, data) {
+        // defines a function for sorting
+        var comparer = function (a, b) {
+            if (sortDetails.columnId === 'name') {
+                var aString = nfCommon.isDefinedAndNotNull(a[sortDetails.columnId]) ? a[sortDetails.columnId] : '';
+                var bString = nfCommon.isDefinedAndNotNull(b[sortDetails.columnId]) ? b[sortDetails.columnId] : '';
+                return aString === bString ? 0 : aString > bString ? 1 : -1;
+            }
+        };
+
+        // perform the sort
+        data.sort(comparer, sortDetails.sortAsc);
+    };
+
+    /**
+     * Reset the dialog.
+     */
+    var resetDialog = function () {
+        $('#parameter-context-name').val('');
+        $('#parameter-context-description-field').val('');
+        $('#parameter-table, #add-parameter').show();
+        $('#parameter-context-tabs').show();
+        $('#parameter-context-tabs').find('.tab')[0].click();
+        $('#parameter-context-update-status').hide();
+
+        $('#process-group-parameter').text('');
+        $('#parameter-process-group-id').text('').removeData('revision');
+        $('#parameter-affected-components-context').removeClass('unset').text('');
+
+        var parameterGrid = $('#parameter-table').data('gridInstance');
+        var parameterData = parameterGrid.getData();
+        parameterData.setItems([]);
+
+        var affectedProcessorContainer = $('#parameter-context-affected-processors');
+        nfCommon.cleanUpTooltips(affectedProcessorContainer, 'div.referencing-component-state');
+        nfCommon.cleanUpTooltips(affectedProcessorContainer, 'div.referencing-component-bulletins');
+        affectedProcessorContainer.empty();
+
+        var affectedControllerServicesContainer = $('#parameter-context-affected-controller-services');
+        nfCommon.cleanUpTooltips(affectedControllerServicesContainer, 'div.referencing-component-state');
+        nfCommon.cleanUpTooltips(affectedControllerServicesContainer, 'div.referencing-component-bulletins');
+        affectedControllerServicesContainer.empty();
+
+        $('#parameter-context-affected-unauthorized-components').empty();
+        $('#parameter-referencing-components-container').empty();
+
+        // reset the last selected parameter
+        lastSelectedId = null;
+
+        // reset the current parameter context
+        currentParameterContextEntity = null;
+
+        // clean up any tooltips that may have been generated
+        nfCommon.cleanUpTooltips($('#parameter-table'), 'div.fa-question-circle');
+    };
+
+    /**
+     * Marshals the parameters in the table.
+     */
+    var marshalParameters = function () {
+        var parameters = [];
+        var table = $('#parameter-table');
+        var parameterGrid = table.data('gridInstance');
+        var parameterData = parameterGrid.getData();
+        $.each(parameterData.getItems(), function () {
+            var parameter = {
+                'name': this.name
+            };
+
+            // if the parameter has been deleted
+            if (this.hidden === true && this.previousValue !== null) {
+                // hidden parameters were removed by the user, clear the value
+                parameters.push({
+                    'parameter': parameter
+                });
+            } else if (this.isModified === true) { // the parameter is modified
+                // check if the value has changed
+                if (this.value !== this.previousValue) {
+                    parameter['sensitive'] = this.sensitive;
+
+                    // for non-sensitive values we always include the value
+                    if (!this.sensitive) {
+                        parameter['value'] = this.value;
+                    } else {
+                        // for sensitive parameters we don't know it's value so we only include the
+                        // value if it has changed or if the empty string set checkbox has been checked
+                        if (!nfCommon.isBlank(this.value) || this.isEmptyStringSet === true) {
+                            parameter['value'] = this.value;
+                        } else if (nfCommon.isBlank(this.value) && this.previousValue !== '********') {
+                            // the sensitive parameter has not ever been saved and we still need to send the value as part of the update
+                            parameter['value'] = this.previousValue;
+                        } else if (nfCommon.isNull(this.value) && this.previousValue === '********') {
+                            // the sensitive parameter has not ever been saved and we still need to send the value as part of the update even if that value is '********'
+                            parameter['value'] = '********';
+                        }
+                    }
+
+                    parameter['description'] = this.description;
+                } else if (this.value === this.previousValue && this.sensitive === true) {
+                    // if the user sets the sensitive parameter's value to the mask returned by the server
+                    parameter['value'] = this.value;
+                    parameter['sensitive'] = this.sensitive;
+                    parameter['description'] = this.description;
+                } else if (this.description !== this.previousDescription) {
+                    parameter['value'] = this.value;
+                    parameter['sensitive'] = this.sensitive;
+                    parameter['description'] = this.description;
+                }
+
+                parameters.push({
+                    'parameter': parameter
+                });
+            }
+        });
+
+        return parameters;
+    };
+
+    /**
+     * Handles outstanding changes.
+     *
+     * @returns {deferred}
+     */
+    var handleOutstandingChanges = function () {
+        if (!$('#parameter-dialog').hasClass('hidden')) {
+            // commit the current edit
+            addNewParameter();
+        }
+
+        return $.Deferred(function (deferred) {
+            if ($('#parameter-context-update-status').is(':visible')) {
+                close();
+                deferred.resolve();
+            } else {
+                var parameters = marshalParameters();
+
+                // if there are no parameters there is nothing to save
+                if ($.isEmptyObject(parameters)) {
+                    close();
+                    deferred.resolve();
+                } else {
+                    // see if those changes should be saved
+                    nfDialog.showYesNoDialog({
+                        headerText: 'Parameters',
+                        dialogContent: 'Save changes before leaving parameter context configuration?',
+                        noHandler: function () {
+                            close();
+                            deferred.resolve();
+                        },
+                        yesHandler: function () {
+                            updateParameterContext(currentParameterContextEntity).done(function () {
+                                deferred.resolve();
+                            }).fail(function () {
+                                deferred.reject();
+                            });
+                        }
+                    });
+                }
+            }
+
+        }).promise();
+    };
+
+    /**
+     * Adds a border to the controller service referencing components if necessary.
+     *
+     * @argument {jQuery} referenceContainer
+     */
+    var updateReferencingComponentsBorder = function (referenceContainer) {
+        // determine if it is too big
+        var tooBig = referenceContainer.get(0).scrollHeight > Math.round(referenceContainer.innerHeight()) ||
+            referenceContainer.get(0).scrollWidth > Math.round(referenceContainer.innerWidth());
+
+        // draw the border if necessary
+        if (referenceContainer.is(':visible') && tooBig) {
+            referenceContainer.css('border-width', '1px');
+        } else {
+            referenceContainer.css('border-width', '0px');
+        }
+    };
+
+    /**
+     * Cancels adding a new parameter context.
+     */
+    var close = function () {
+        $('#parameter-context-dialog').modal('hide');
+    };
+
+    /**
+     * Renders the specified affected component.
+     *
+     * @param {object} affectedProcessorEntity
+     * @param {jQuery} container
+     */
+    var renderAffectedProcessor = function (affectedProcessorEntity, container) {
+        var affectedProcessorContainer = $('<li class="affected-component-container"></li>').appendTo(container);
+        var affectedProcessor = affectedProcessorEntity.component;
+
+        // processor state
+        $('<div class="referencing-component-state"></div>').addClass(function () {
+            if (nfCommon.isDefinedAndNotNull(affectedProcessor.state)) {
+                var icon = $(this);
+
+                var state = affectedProcessor.state.toLowerCase();
+                if (state === 'stopped' && !nfCommon.isEmpty(affectedProcessor.validationErrors)) {
+                    state = 'invalid';
+
+                    // build the validation error listing
+                    var list = nfCommon.formatUnorderedList(affectedProcessor.validationErrors);
+
+                    // add tooltip for the warnings
+                    icon.qtip($.extend({},
+                        nfCanvasUtils.config.systemTooltipConfig,
+                        {
+                            content: list
+                        }));
+                }
+
+                return state;
+            } else {
+                return '';
+            }
+        }).appendTo(affectedProcessorContainer);
+
+
+        // processor name
+        $('<span class="referencing-component-name link"></span>').text(affectedProcessor.name).on('click', function () {
+            // check if there are outstanding changes
+            handleOutstandingChanges().done(function () {
+                // close the shell
+                $('#shell-dialog').modal('hide');
+
+                // show the component in question
+                nfCanvasUtils.showComponent(affectedProcessor.processGroupId, affectedProcessor.id);
+            });
+        }).appendTo(affectedProcessorContainer);
+
+        // bulletin
+        $('<div class="referencing-component-bulletins"></div>').addClass(affectedProcessor.id + '-affected-bulletins').appendTo(affectedProcessorContainer);
+
+        // processor active threads
+        $('<span class="referencing-component-active-thread-count"></span>').text(function () {
+            if (nfCommon.isDefinedAndNotNull(affectedProcessor.activeThreadCount) && affectedProcessor.activeThreadCount > 0) {
+                return '(' + affectedProcessor.activeThreadCount + ')';
+            } else {
+                return '';
+            }
+        }).appendTo(affectedProcessorContainer);
+    };
+
+    /**
+     * Renders the specified affect controller service.
+     *
+     * @param {object} affectedControllerServiceEntity
+     * @param {jQuery} container
+     */
+    var renderAffectedControllerService = function (affectedControllerServiceEntity, container) {
+        var affectedControllerServiceContainer = $('<li class="affected-component-container"></li>').appendTo(container);
+        var affectedControllerService = affectedControllerServiceEntity.component;
+
+        // controller service state
+        $('<div class="referencing-component-state"></div>').addClass(function () {
+            if (nfCommon.isDefinedAndNotNull(affectedControllerService.state)) {
+                var icon = $(this);
+
+                var state = affectedControllerService.state === 'ENABLED' ? 'enabled' : 'disabled';
+                if (state === 'disabled' && !nfCommon.isEmpty(affectedControllerService.validationErrors)) {
+                    state = 'invalid';
+
+                    // build the error listing
+                    var list = nfCommon.formatUnorderedList(affectedControllerService.validationErrors);
+
+                    // add tooltip for the warnings
+                    icon.qtip($.extend({},
+                        nfCanvasUtils.config.systemTooltipConfig,
+                        {
+                            content: list
+                        }));
+                }
+                return state;
+            } else {
+                return '';
+            }
+        }).appendTo(affectedControllerServiceContainer);
+
+        // bulletin
+        $('<div class="referencing-component-bulletins"></div>').addClass(affectedControllerService.id + '-affected-bulletins').appendTo(affectedControllerServiceContainer);
+
+        // controller service name
+        $('<span class="referencing-component-name link"></span>').text(affectedControllerService.name).on('click', function () {
+            // check if there are outstanding changes
+            handleOutstandingChanges().done(function () {
+                // close the shell
+                $('#shell-dialog').modal('hide');
+
+                // show the component in question
+                nfProcessGroupConfiguration.showConfiguration(affectedControllerService.processGroupId).done(function () {
+                    nfProcessGroupConfiguration.selectControllerService(affectedControllerService.id);
+                });
+            });
+        }).appendTo(affectedControllerServiceContainer);
+    };
+
+    /**
+     * Populates the affected components for the specified parameter context.
+     *
+     * @param {object} affectedComponents
+     */
+    var populateAffectedComponents = function (affectedComponents) {
+        // toggles the visibility of a container
+        var toggle = function (twist, container) {
+            if (twist.hasClass('expanded')) {
+                twist.removeClass('expanded').addClass('collapsed');
+                container.hide();
+            } else {
+                twist.removeClass('collapsed').addClass('expanded');
+                container.show();
+            }
+        };
+
+        var affectedProcessors = [];
+        var affectedControllerServices = [];
+        var unauthorizedAffectedComponents = [];
+
+        // clear the affected components from the previous selection
+        var affectedProcessorContainer = $('.parameter-context-affected-processors');
+        nfCommon.cleanUpTooltips(affectedProcessorContainer, 'div.referencing-component-state');
+        nfCommon.cleanUpTooltips(affectedProcessorContainer, 'div.referencing-component-bulletins');
+        affectedProcessorContainer.empty();
+
+        var affectedControllerServiceContainer = $('.parameter-context-affected-controller-services');
+        nfCommon.cleanUpTooltips(affectedControllerServiceContainer, 'div.referencing-component-state');
+        nfCommon.cleanUpTooltips(affectedControllerServiceContainer, 'div.referencing-component-bulletins');
+        affectedControllerServiceContainer.empty();
+
+        var unauthorizedComponentsContainer = $('.parameter-context-affected-unauthorized-components');
+        unauthorizedComponentsContainer.empty();
+
+        var parameterReferencingComponentsContainer = $('#parameter-referencing-components-container').empty();
+
+        // affected component will be undefined when a new parameter is added
+        if (nfCommon.isUndefined(affectedComponents)) {
+            // set to pending
+            $('<div class="affected-component-container"><span class="unset">Pending Apply</span></div>').appendTo(parameterReferencingComponentsContainer);
+        } else {
+            var referencingComponentsForBulletinRetrieval = [];
+
+            // bin the affected components according to their type
+            $.each(affectedComponents, function (_, affectedComponentEntity) {
+                if (affectedComponentEntity.permissions.canRead === true && affectedComponentEntity.permissions.canWrite === true) {
+                    referencingComponentsForBulletinRetrieval.push(affectedComponentEntity.id);
+
+                    if (affectedComponentEntity.component.referenceType === 'PROCESSOR') {
+                        affectedProcessors.push(affectedComponentEntity);
+                    } else {
+                        affectedControllerServices.push(affectedComponentEntity);
+                    }
+                } else {
+                    // if we're unauthorized only because the user is lacking write permissions, we can still query for bulletins
+                    if (affectedComponentEntity.permissions.canRead === true) {
+                        referencingComponentsForBulletinRetrieval.push(affectedComponentEntity.id);
+                    }
+
+                    unauthorizedAffectedComponents.push(affectedComponentEntity);
+                }
+            });
+
+            var affectedProcessGroups = {};
+
+            // bin the affected processors according to their PG
+            $.each(affectedProcessors, function (_, affectedProcessorEntity) {
+                var pg = nfProcessGroup.get(affectedProcessorEntity.component.processGroupId);
+                var pgName;
+                if (nfCommon.isDefinedAndNotNull(pg)) {
+                    pgName = pg.component.name;
+                } else {
+                    pgName = nfCanvasUtils.getGroupName();
+                }
+
+                if (affectedProcessGroups[affectedProcessorEntity.component.processGroupId]) {
+                    affectedProcessGroups[affectedProcessorEntity.component.processGroupId].affectedProcessors.push(affectedProcessorEntity);
+                    affectedProcessGroups[affectedProcessorEntity.component.processGroupId].id = affectedProcessorEntity.component.processGroupId;
+                    affectedProcessGroups[affectedProcessorEntity.component.processGroupId].name = pgName;
+                } else {
+                    affectedProcessGroups[affectedProcessorEntity.component.processGroupId] = {
+                        affectedProcessors: [],
+                        affectedControllerServices: [],
+                        unauthorizedAffectedComponents: [],
+                        name: pgName,
+                        id: affectedProcessorEntity.component.processGroupId
+                    };
+
+                    affectedProcessGroups[affectedProcessorEntity.component.processGroupId].affectedProcessors.push(affectedProcessorEntity);
+                }
+            });
+
+            // bin the affected CS according to their PG
+            $.each(affectedControllerServices, function (_, affectedControllerServiceEntity) {
+                var pg = nfProcessGroup.get(affectedControllerServiceEntity.component.processGroupId);
+                var pgName;
+                if (nfCommon.isDefinedAndNotNull(pg)) {
+                    pgName = pg.component.name;
+                } else {
+                    pgName = nfCanvasUtils.getGroupName();
+                }
+
+                if (affectedProcessGroups[affectedControllerServiceEntity.component.processGroupId]) {
+                    affectedProcessGroups[affectedControllerServiceEntity.component.processGroupId].affectedControllerServices.push(affectedControllerServiceEntity);
+                    affectedProcessGroups[affectedControllerServiceEntity.component.processGroupId].id = affectedControllerServiceEntity.component.processGroupId;
+                    affectedProcessGroups[affectedControllerServiceEntity.component.processGroupId].name = pgName;
+                } else {
+                    affectedProcessGroups[affectedControllerServiceEntity.component.processGroupId] = {
+                        affectedProcessors: [],
+                        affectedControllerServices: [],
+                        unauthorizedAffectedComponents: [],
+                        name: pgName,
+                        id: affectedControllerServiceEntity.component.processGroupId
+                    };
+
+                    affectedProcessGroups[affectedControllerServiceEntity.component.processGroupId].affectedControllerServices.push(affectedControllerServiceEntity);
+                }
+            });
+
+            // bin the affected unauthorized components according to their PG
+            $.each(unauthorizedAffectedComponents, function (_, unauthorizedAffectedComponentEntity) {
+                var pg = nfProcessGroup.get(unauthorizedAffectedComponentEntity.component.processGroupId);
+                var pgName;
+                if (nfCommon.isDefinedAndNotNull(pg)) {
+                    pgName = pg.component.name;
+                } else {
+                    pgName = nfCanvasUtils.getGroupName();
+                }
+
+                if (unauthorizedAffectedComponentEntity.permissions.canRead === true) {
+                    if (affectedProcessGroups[unauthorizedAffectedComponentEntity.component.processGroupId]) {
+                        affectedProcessGroups[unauthorizedAffectedComponentEntity.component.processGroupId].unauthorizedAffectedComponents.push(unauthorizedAffectedComponentEntity);
+                        affectedProcessGroups[unauthorizedAffectedComponentEntity.component.processGroupId].id = unauthorizedAffectedComponentEntity.component.processGroupId;
+                        affectedProcessGroups[unauthorizedAffectedComponentEntity.component.processGroupId].name = pgName;
+                    } else {
+                        affectedProcessGroups[unauthorizedAffectedComponentEntity.component.processGroupId] = {
+                            affectedProcessors: [],
+                            affectedControllerServices: [],
+                            unauthorizedAffectedComponents: [],
+                            name: pgName,
+                            id: unauthorizedAffectedComponentEntity.component.processGroupId
+                        };
+
+                        affectedProcessGroups[unauthorizedAffectedComponentEntity.component.processGroupId].unauthorizedAffectedComponents.push(unauthorizedAffectedComponentEntity);
+                    }
+                }
+            });
+
+            var parameterReferencingComponentsContainer = $('#parameter-referencing-components-container');
+            var groups = $('<ul class="referencing-component-listing clear"></ul>');
+
+            var affectedProcessGroupsArray = [];
+            for (var key in affectedProcessGroups) {
+                if (affectedProcessGroups.hasOwnProperty(key)) {
+                    affectedProcessGroupsArray.push(affectedProcessGroups[key]);
+                }
+            }
+
+            //sort alphabetically
+            var sortedAffectedProcessGroups = affectedProcessGroupsArray.sort(function (a, b) {
+                if (a.name < b.name) {
+                    return -1;
+                }
+                if (a.name > b.name) {
+                    return 1;
+                }
+                return 0;
+            });
+
+            sortedAffectedProcessGroups.forEach(function (affectedProcessGroup) {
+                // container for this pg's references
+                var referencingPgReferencesContainer = $('<div class="referencing-component-references"></div>');
+                parameterReferencingComponentsContainer.append(referencingPgReferencesContainer);
+
+                // create the collapsable listing for each PG
+                var createReferenceBlock = function (titleText, list) {
+                    var twist = $('<div class="expansion-button collapsed"></div>');
+                    var title = $('<span class="referencing-component-title"></span>').text(titleText);
+                    var count = $('<span class="referencing-component-count"></span>').text('(' + (affectedProcessGroup.affectedProcessors.length + affectedProcessGroup.affectedControllerServices.length + affectedProcessGroup.unauthorizedAffectedComponents.length) + ')');
+                    var referencingComponents = $('#referencing-components-template').clone();
+                    referencingComponents.removeAttr('id');
+                    referencingComponents.removeClass('hidden');
+
+                    // create the reference block
+                    var groupTwist = $('<div class="referencing-component-block pointer unselectable"></div>').data('processGroupId', key).on('click', function () {
+                        if (twist.hasClass('collapsed')) {
+                            groupTwist.append(referencingComponents);
+
+                            var processorContainer = groupTwist.find('.parameter-context-affected-processors');
+                            nfCommon.cleanUpTooltips(processorContainer, 'div.referencing-component-state');
+                            nfCommon.cleanUpTooltips(processorContainer, 'div.referencing-component-bulletins');
+                            processorContainer.empty();
+
+                            var controllerServiceContainer = groupTwist.find('.parameter-context-affected-controller-services');
+                            nfCommon.cleanUpTooltips(controllerServiceContainer, 'div.referencing-component-state');
+                            nfCommon.cleanUpTooltips(controllerServiceContainer, 'div.referencing-component-bulletins');
+                            controllerServiceContainer.empty();
+
+                            var unauthorizedComponentsContainer = groupTwist.find('.parameter-context-affected-unauthorized-components').empty();
+
+                            if (affectedProcessGroups[$(this).data('processGroupId')].affectedProcessors.length === 0) {
+                                $('<li class="affected-component-container"><span class="unset">None</span></li>').appendTo(processorContainer);
+                            } else {
+                                // sort the affected processors
+                                affectedProcessGroups[$(this).data('processGroupId')].affectedProcessors.sort(nameComparator);
+
+                                // render each and register a click handler
+                                $.each(affectedProcessGroups[$(this).data('processGroupId')].affectedProcessors, function (_, affectedProcessorEntity) {
+                                    renderAffectedProcessor(affectedProcessorEntity, processorContainer);
+                                });
+                            }
+
+                            if (affectedProcessGroups[$(this).data('processGroupId')].affectedControllerServices.length === 0) {
+                                $('<li class="affected-component-container"><span class="unset">None</span></li>').appendTo(controllerServiceContainer);
+                            } else {
+                                // sort the affected controller services
+                                affectedProcessGroups[$(this).data('processGroupId')].affectedControllerServices.sort(nameComparator);
+
+                                // render each and register a click handler
+                                $.each(affectedProcessGroups[$(this).data('processGroupId')].affectedControllerServices, function (_, affectedControllerServiceEntity) {
+                                    renderAffectedControllerService(affectedControllerServiceEntity, controllerServiceContainer);
+                                });
+                            }
+
+                            if (affectedProcessGroups[$(this).data('processGroupId')].unauthorizedAffectedComponents.length === 0) {
+                                $('<li class="affected-component-container"><span class="unset">None</span></li>').appendTo(unauthorizedComponentsContainer);
+                            } else {
+                                // sort the unauthorized affected components
+                                affectedProcessGroups[$(this).data('processGroupId')].unauthorizedAffectedComponents.sort(function (a, b) {
+                                    if (a.permissions.canRead === true && b.permissions.canRead === true) {
+                                        // processors before controller services
+                                        var sortVal = a.component.referenceType === b.component.referenceType ? 0 : a.component.referenceType > b.component.referenceType ? -1 : 1;
+
+                                        // if a and b are the same type, then sort by name
+                                        if (sortVal === 0) {
+                                            sortVal = a.component.name === b.component.name ? 0 : a.component.name > b.component.name ? 1 : -1;
+                                        }
+
+                                        return sortVal;
+                                    } else {
+
+                                        // if lacking read and write perms on both, sort by id
+                                        if (a.permissions.canRead === false && b.permissions.canRead === false) {
+                                            return a.id > b.id ? 1 : -1;
+                                        } else {
+                                            // if only one has read perms, then let it come first
+                                            if (a.permissions.canRead === true) {
+                                                return -1;
+                                            } else {
+                                                return 1;
+                                            }
+                                        }
+                                    }
+                                });
+
+                                $.each(affectedProcessGroups[$(this).data('processGroupId')].unauthorizedAffectedComponents, function (_, unauthorizedAffectedComponentEntity) {
+                                    if (unauthorizedAffectedComponentEntity.permissions.canRead === true) {
+                                        if (unauthorizedAffectedComponentEntity.component.referenceType === 'PROCESSOR') {
+                                            renderAffectedProcessor(unauthorizedAffectedComponentEntity, unauthorizedComponentsContainer);
+                                        } else {
+                                            renderAffectedControllerService(unauthorizedAffectedComponentEntity, unauthorizedComponentsContainer);
+                                        }
+                                    } else {
+                                        var affectedUnauthorizedComponentContainer = $('<li class="affected-component-container"></li>').appendTo(unauthorizedComponentsContainer);
+                                        $('<span class="unset"></span>').text(unauthorizedAffectedComponentEntity.id).appendTo(affectedUnauthorizedComponentContainer);
+                                    }
+                                });
+                            }
+
+                            // query for the bulletins
+                            if (referencingComponentsForBulletinRetrieval.length > 0) {
+                                nfCanvasUtils.queryBulletins(referencingComponentsForBulletinRetrieval).done(function (response) {
+                                    var bulletins = response.bulletinBoard.bulletins;
+
+                                    var bulletinsBySource = d3.nest()
+                                        .key(function (d) {
+                                            return d.sourceId;
+                                        })
+                                        .map(bulletins, d3.map);
+
+                                    bulletinsBySource.each(function (sourceBulletins, sourceId) {
+                                        $('div.' + sourceId + '-affected-bulletins').each(function () {
+                                            var bulletinIcon = $(this);
+
+                                            // if there are bulletins update them
+                                            if (sourceBulletins.length > 0) {
+                                                // format the new bulletins
+                                                var formattedBulletins = nfCommon.getFormattedBulletins(sourceBulletins);
+
+                                                var list = nfCommon.formatUnorderedList(formattedBulletins);
+
+                                                // update existing tooltip or initialize a new one if appropriate
+                                                bulletinIcon.addClass('has-bulletins').show().qtip($.extend({},
+                                                    nfCanvasUtils.config.systemTooltipConfig,
+                                                    {
+                                                        content: list
+                                                    }));
+                                            }
+                                        });
+                                    });
+                                });
+                            }
+                        } else {
+                            groupTwist.find('.referencing-components-template').remove();
+                        }
+
+                        // toggle this block
+                        toggle(twist, list);
+
+                        // update the border if necessary
+                        updateReferencingComponentsBorder($('#parameter-referencing-components-container'));
+                    }).append(twist).append(title).append(count).appendTo(referencingPgReferencesContainer);
+
+                    // add the listing
+                    list.appendTo(referencingPgReferencesContainer);
+
+                    // expand the group twist
+                    groupTwist.click();
+
+                    // update the border if necessary
+                    updateReferencingComponentsBorder($('#parameter-referencing-components-container'));
+                };
+
+                // get process group and show name or UUID based on user permissions
+                var pg = nfProcessGroup.get(affectedProcessGroup.id);
+                if (!nfCommon.isUndefinedOrNull(pg)) {
+                    if (pg.permissions.canRead === true) {
+                        // create block for this process group
+                        createReferenceBlock(pg.component.name, groups);
+                    } else {
+                        // create block for this process group
+                        createReferenceBlock(affectedProcessGroup.id, groups);
+                    }
+                } else {
+                    var processGroupName = affectedProcessGroup.id;
+
+                    // attempt to resolve the group name
+                    var breadcrumbs = nfNgBridge.injector.get('breadcrumbsCtrl').getBreadcrumbs();
+                    $.each(breadcrumbs, function (_, breadcrumbEntity) {
+                        if (breadcrumbEntity.id === affectedProcessGroup.id) {
+                            processGroupName = breadcrumbEntity.label;
+                            return false;
+                        }
+                    });
+                    // create block for this process group
+                    createReferenceBlock(processGroupName, groups);
+                }
+            });
+        }
+    };
+
+    /**
+     * Sorts the specified entities based on the name.
+     *
+     * @param {object} a
+     * @param {object} b
+     * @returns {number}
+     */
+    var nameComparator = function (a, b) {
+        return a.component.name.localeCompare(b.component.name);
+    };
+
+    var parameterKeyRegex = /^[a-zA-Z0-9-_. ]+/;
+
+    /**
+     * Adds a new parameter.
+     */
+    var addNewParameter = function () {
+        var parameterName = $.trim($('#parameter-name').val());
+
+        // ensure the parameter name is specified
+        if (parameterName !== '' && parameterKeyRegex.test(parameterName)) {
+            var parameterGrid = $('#parameter-table').data('gridInstance');
+            var parameterData = parameterGrid.getData();
+
+            // ensure the parameter name is unique
+            var matchingParameter = null;
+            $.each(parameterData.getItems(), function (_, item) {
+                if (parameterName === item.name) {
+                    matchingParameter = item;
+                    return false;
+                }
+            });
+
+            if (matchingParameter === null) {
+                var isChecked = $('#parameter-dialog').find('.nf-checkbox').hasClass('checkbox-checked');
+
+                var parameter = {
+                    id: parameterCount,
+                    hidden: false,
+                    type: 'Parameter',
+                    sensitive: $('#parameter-dialog').find('input[name="sensitive"]:checked').val() === "sensitive" ? true : false,
+                    name: parameterName,
+                    description: $.trim($('#parameter-description-field').val()),
+                    previousValue: null,
+                    previousDescription: null,
+                    isEditable: true,
+                    isEmptyStringSet: isChecked,
+                    isModified: true
+                };
+
+                var value = $.trim($('#parameter-value-field').val());
+                if (!nfCommon.isBlank(value)) {
+                    parameter.value = value;
+                } else {
+                    if (isChecked) {
+                        parameter.value = '';
+                    } else {
+                        parameter.value = null;
+                    }
+                }
+
+                // add a row for the new parameter
+                parameterData.addItem(parameter);
+
+                // sort the data
+                parameterData.reSort();
+
+                // select the new parameter row
+                var row = parameterData.getRowById(parameterCount);
+                parameterGrid.setActiveCell(row, parameterGrid.getColumnIndex('value'));
+                parameterCount++;
+            } else {
+                nfDialog.showOkDialog({
+                    headerText: 'Parameter Exists',
+                    dialogContent: 'A parameter with this name already exists.'
+                });
+
+                // select the existing properties row
+                var matchingRow = parameterData.getRowById(matchingParameter.id);
+                parameterGrid.setSelectedRows([matchingRow]);
+                parameterGrid.scrollRowIntoView(matchingRow);
+            }
+
+            // close the new parameter dialog
+            $('#parameter-dialog').modal('hide');
+
+            // update the buttons to possibly trigger the disabled state
+            $('#parameter-context-dialog').modal('refreshButtons');
+
+        } else if (!parameterKeyRegex.test(parameterName)) {
+            nfDialog.showOkDialog({
+                headerText: 'Configuration Error',
+                dialogContent: 'This parameter appears to have an invalid character or characters. Only alpha-numeric characters (a-z, A-Z, 0-9), hyphens (-), underscores (_), periods (.), and spaces ( ) are accepted.'
+            });
+        } else {
+            nfDialog.showOkDialog({
+                headerText: 'Configuration Error',
+                dialogContent: 'The name of the parameter must be specified.'
+            });
+        }
+    };
+
+    /**
+     * Update a parameter.
+     */
+    var updateParameter = function () {
+        var parameterName = $.trim($('#parameter-name').val());
+
+        // ensure the parameter name is specified
+        if (parameterName !== '') {
+            var parameterGrid = $('#parameter-table').data('gridInstance');
+            var parameterData = parameterGrid.getData();
+
+            // ensure the parameter name is unique
+            var matchingParameter = null;
+            $.each(parameterData.getItems(), function (_, item) {
+                if (parameterName === item.name) {
+                    matchingParameter = item;
+                    return false;
+                }
+            });
+
+            if (matchingParameter !== null) {
+                var isChecked = $('#parameter-dialog').find('.nf-checkbox').hasClass('checkbox-checked');
+
+                var parameter = {
+                    id: matchingParameter.id,
+                    hidden: false,
+                    type: 'Parameter',
+                    sensitive: matchingParameter.sensitive,
+                    name: parameterName,
+                    description: $.trim($('#parameter-description-field').val()),
+                    previousValue: matchingParameter.value,
+                    previousDescription: matchingParameter.description,
+                    isEditable: matchingParameter.isEditable,
+                    isEmptyStringSet: isChecked,
+                    isModified: true
+                };
+
+                var value = $.trim($('#parameter-value-field').val());
+                if (!nfCommon.isBlank(value)) {
+                    parameter.value = value;
+                } else {
+                    if (isChecked) {
+                        parameter.value = '';
+                    } else {
+                        parameter.value = null;
+                    }
+                }
+
+                // update row for the parameter
+                parameterData.updateItem(matchingParameter.id, parameter);
+
+                // sort the data
+                parameterData.reSort();
+
+                // select the parameter row
+                var row = parameterData.getRowById(matchingParameter.id);
+                parameterGrid.setActiveCell(row, parameterGrid.getColumnIndex('value'));
+            } else {
+                nfDialog.showOkDialog({
+                    headerText: 'Parameter Does Not Exists',
+                    dialogContent: 'A parameter with this name does not exist.'
+                });
+            }
+
+            // close the new parameter dialog
+            $('#parameter-dialog').modal('hide');
+
+            // update the buttons to possibly trigger the disabled state
+            $('#parameter-context-dialog').modal('refreshButtons');
+        } else {
+            nfDialog.showOkDialog({
+                headerText: 'Create Parameter Error',
+                dialogContent: 'The name of the parameter must be specified.'
+            });
+        }
+    };
+
+    /**
+     * Updates parameter contexts by issuing an update request and polling until it's completion.
+     *
+     * @param parameterContextEntity
+     * @returns {*}
+     */
+    var updateParameterContext = function (parameterContextEntity) {
+        var parameters = marshalParameters();
+
+        if (parameters.length === 0) {
+            // no
+            parameterContextEntity.component.parameters = [];
+            if ($('#parameter-context-name').val() === parameterContextEntity.component.name &&
+                $('#parameter-context-description-field').val() === parameterContextEntity.component.description) {
+                close();
+
+                return;
+            }
+        } else {
+            parameterContextEntity.component.parameters = parameters;
+        }
+
+        parameterContextEntity.component.name = $('#parameter-context-name').val();
+        parameterContextEntity.component.description = $('#parameter-context-description-field').val();
+
+        // update the parameters context
+        var parameterNames = parameterContextEntity.component.parameters.map(function (parameterEntity) {
+            return parameterEntity.parameter.name;
+        });
+        $('#parameter-affected-components-context').removeClass('unset').text(parameterNames.join(', '));
+
+        return $.Deferred(function (deferred) {
+            // updates the button model to show the close button
+            var updateToCloseButtonModel = function () {
+                $('#parameter-context-dialog').modal('setButtonModel', [{
+                    buttonText: 'Close',
+                    color: {
+                        base: '#728E9B',
+                        hover: '#004849',
+                        text: '#ffffff'
+                    },
+                    handler: {
+                        click: function () {
+                            deferred.resolve();
+                            close();
+                        }
+                    }
+                }]);
+            };
+
+            var updateToApplyOrCancelButtonModel = function () {
+                $('#parameter-context-dialog').modal('setButtonModel', [{
+                    buttonText: 'Apply',
+                    color: {
+                        base: '#728E9B',
+                        hover: '#004849',
+                        text: '#ffffff'
+                    },
+                    disabled: function () {
+                        if ($('#parameter-context-name').val() !== '') {
+                            return false;
+                        }
+                        return true;
+                    },
+                    handler: {
+                        click: function () {
+                            if ($('#parameter-referencing-components-container').is(':visible')) {
+                                updateReferencingComponentsBorder($('#parameter-referencing-components-container'));
+                            }
+
+                            updateParameterContext(parameterContextEntity);
+                        }
+                    }
+                }, {
+                    buttonText: 'Cancel',
+                    color: {
+                        base: '#E3E8EB',
+                        hover: '#C7D2D7',
+                        text: '#004849'
+                    },
+                    handler: {
+                        click: function () {
+                            deferred.resolve();
+
+                            if ($('#parameter-referencing-components-container').is(':visible')) {
+                                updateReferencingComponentsBorder($('#parameter-referencing-components-container'));
+                            }
+
+                            close();
+                        }
+                    }
+                }]);
+            };
+
+            var cancelled = false;
+
+            // update the button model to show the cancel button
+            $('#parameter-context-dialog').modal('setButtonModel', [{
+                buttonText: 'Cancel',
+                color: {
+                    base: '#E3E8EB',
+                    hover: '#C7D2D7',
+                    text: '#004849'
+                },
+                handler: {
+                    click: function () {
+                        cancelled = true;
+
+                        if ($('#parameter-referencing-components-container').is(':visible')) {
+                            updateReferencingComponentsBorder($('#parameter-referencing-components-container'));
+                        }
+
+                        updateToCloseButtonModel();
+                    }
+                }
+            }]);
+
+            var requestId;
+            var handleAjaxFailure = function (xhr, status, error) {
+                // delete the request if possible
+                if (nfCommon.isDefinedAndNotNull(requestId)) {
+                    deleteUpdateRequest(parameterContextEntity.id, requestId);
+                }
+
+                // update the step status
+                $('#parameter-context-update-steps').find('div.parameter-context-step.ajax-loading').removeClass('ajax-loading').addClass('ajax-error');
+
+                if ($('#parameter-referencing-components-container').is(':visible')) {
+                    updateReferencingComponentsBorder($('#parameter-referencing-components-container'));
+                }
+
+                // update the button model
+                updateToApplyOrCancelButtonModel();
+            };
+
+            submitUpdateRequest(parameterContextEntity).done(function (response) {
+                var pollUpdateRequest = function (updateRequestEntity) {
+                    var updateRequest = updateRequestEntity.request;
+                    var errored = nfCommon.isDefinedAndNotNull(updateRequest.failureReason);
+
+                    // get the request id
+                    requestId = updateRequest.requestId;
+
+                    // update the affected components
+                    populateAffectedComponents(updateRequest.affectedComponents);
 
 Review comment:
   Update on this one. This seems to only happen when you are only updating the description of a parameter and not the value. Maybe this is as designed since changing the descriptions probably doesn't require any changes to the flow.
   
   It is just a bit confusing since the label in the app says "Referencing components" and not "Affected Components". Technically there are referencing components, but they are not impacted by the update.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message