2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * Modifications to the original nifi code for the ONAP project are made
18 * available under the Apache License, Version 2.0
21 /* global define, module, require, exports */
23 (function (root, factory) {
24 if (typeof define === 'function' && define.amd) {
33 'nf.ControllerServices',
35 'nf.FilteredDialogCommon',
39 'nf.ComponentVersion',
40 'nf.PolicyManagement'],
41 function ($, Slick, d3, nfClient, nfDialog, nfStorage, nfCommon, nfCanvasUtils, nfControllerServices, nfErrorHandler, nfFilteredDialogCommon, nfReportingTask, nfShell, nfComponentState, nfComponentVersion, nfPolicyManagement) {
42 return (nf.Settings = factory($, Slick, d3, nfClient, nfDialog, nfStorage, nfCommon, nfCanvasUtils, nfControllerServices, nfErrorHandler, nfFilteredDialogCommon, nfReportingTask, nfShell, nfComponentState, nfComponentVersion, nfPolicyManagement));
44 } else if (typeof exports === 'object' && typeof module === 'object') {
45 module.exports = (nf.Settings =
46 factory(require('jquery'),
51 require('nf.Storage'),
53 require('nf.CanvasUtils'),
54 require('nf.ControllerServices'),
55 require('nf.ErrorHandler'),
56 require('nf.FilteredDialogCommon'),
57 require('nf.ReportingTask'),
59 require('nf.ComponentState'),
60 require('nf.ComponentVersion'),
61 require('nf.PolicyManagement')));
63 nf.Settings = factory(root.$,
71 root.nf.ControllerServices,
73 root.nf.FilteredDialogCommon,
74 root.nf.ReportingTask,
76 root.nf.ComponentState,
77 root.nf.ComponentVersion,
78 root.nf.PolicyManagement);
80 }(this, function ($, Slick, d3, nfClient, nfDialog, nfStorage, nfCommon, nfCanvasUtils, nfControllerServices, nfErrorHandler, nfFilteredDialogCommon, nfReportingTask, nfShell, nfComponentState, nfComponentVersion, nfPolicyManagement) {
87 controllerConfig: '../nifi-api/controller/config',
88 reportingTaskTypes: '../nifi-api/flow/reporting-task-types',
89 createReportingTask: '../nifi-api/controller/reporting-tasks',
90 reportingTasks: '../nifi-api/flow/reporting-tasks',
91 registries: '../nifi-api/controller/registry-clients'
96 forceFitColumns: true,
97 enableTextSelectionOnCells: true,
98 enableCellNavigation: true,
99 enableColumnReorder: false,
107 * Gets the controller services table.
109 * @returns {*|jQuery|HTMLElement}
111 var getDistributionEnvironmentsTable = function () {
112 return $('#distribution-environments-table');
116 * Gets the controller services table.
118 * @returns {*|jQuery|HTMLElement}
120 var getControllerServicesTable = function () {
121 return $('#controller-services-table');
125 * Saves the settings for the controller.
129 var saveSettings = function (version) {
130 // marshal the configuration details
131 var configuration = marshalConfiguration();
133 'revision': nfClient.getRevision({
138 'disconnectedNodeAcknowledged': nfStorage.isDisconnectionAcknowledged(),
139 'component': configuration
142 // save the new configuration details
145 url: config.urls.controllerConfig,
146 data: JSON.stringify(entity),
148 contentType: 'application/json'
149 }).done(function (response) {
150 // close the settings dialog
151 nfDialog.showOkDialog({
152 headerText: 'Settings',
153 dialogContent: 'Settings successfully applied.'
156 // register the click listener for the save button
157 $('#settings-save').off('click').on('click', function () {
158 saveSettings(response.revision.version);
160 }).fail(nfErrorHandler.handleAjaxError);
164 * Initializes the general tab.
166 var initGeneral = function () {
170 * Marshals the details to include in the configuration request.
172 var marshalConfiguration = function () {
173 // create the configuration
174 var configuration = {};
175 configuration['maxTimerDrivenThreadCount'] = $('#maximum-timer-driven-thread-count-field').val();
176 configuration['maxEventDrivenThreadCount'] = $('#maximum-event-driven-thread-count-field').val();
177 return configuration;
181 * Determines if the item matches the filter.
183 * @param {object} item The item to filter
184 * @param {object} args The filter criteria
185 * @returns {boolean} Whether the item matches the filter
187 var matchesRegex = function (item, args) {
188 if (args.searchString === '') {
193 // perform the row filtering
194 var filterExp = new RegExp(args.searchString, 'i');
200 // determine if the item matches the filter
201 var matchesLabel = item['label'].search(filterExp) >= 0;
202 var matchesTags = item['tags'].search(filterExp) >= 0;
203 return matchesLabel || matchesTags;
207 * Determines if the specified tags match all the tags selected by the user.
209 * @argument {string[]} tagFilters The tag filters
210 * @argument {string} tags The tags to test
212 var matchesSelectedTags = function (tagFilters, tags) {
213 var selectedTags = [];
214 $.each(tagFilters, function (_, filter) {
215 selectedTags.push(filter);
218 // normalize the tags
219 var normalizedTags = tags.toLowerCase();
222 $.each(selectedTags, function (i, selectedTag) {
223 if (normalizedTags.indexOf(selectedTag) === -1) {
233 * Whether the specified item is selectable.
235 * @param item reporting task type
237 var isSelectable = function (item) {
238 return item.restricted === false || nfCommon.canAccessComponentRestrictions(item.explicitRestrictions);
242 * Formatter for the name column.
246 * @param {type} value
247 * @param {type} columnDef
248 * @param {type} dataContext
251 var nameFormatter = function (row, cell, value, columnDef, dataContext) {
252 if (!dataContext.permissions.canRead) {
253 return '<span class="blank">' + nfCommon.escapeHtml(dataContext.id) + '</span>';
256 return nfCommon.escapeHtml(dataContext.component.name);
260 * Sorts the specified data using the specified sort details.
262 * @param {object} sortDetails
263 * @param {object} data
265 var sort = function (sortDetails, data) {
266 // defines a function for sorting
267 var comparer = function (a, b) {
268 if (a.permissions.canRead && b.permissions.canRead) {
269 if (sortDetails.columnId === 'moreDetails') {
271 if (!nfCommon.isEmpty(a.bulletins)) {
272 aBulletins = a.bulletins.length;
275 if (!nfCommon.isEmpty(b.bulletins)) {
276 bBulletins = b.bulletins.length;
278 return aBulletins - bBulletins;
279 } else if (sortDetails.columnId === 'type') {
280 var aType = nfCommon.isDefinedAndNotNull(a.component[sortDetails.columnId]) ? nfCommon.substringAfterLast(a.component[sortDetails.columnId], '.') : '';
281 var bType = nfCommon.isDefinedAndNotNull(b.component[sortDetails.columnId]) ? nfCommon.substringAfterLast(b.component[sortDetails.columnId], '.') : '';
282 return aType === bType ? 0 : aType > bType ? 1 : -1;
283 } else if (sortDetails.columnId === 'state') {
285 if (a.component.validationStatus === 'VALIDATING') {
286 aState = 'Validating';
287 } else if (a.component.validationStatus === 'INVALID') {
290 aState = nfCommon.isDefinedAndNotNull(a.component[sortDetails.columnId]) ? a.component[sortDetails.columnId] : '';
293 if (b.component.validationStatus === 'VALIDATING') {
294 bState = 'Validating';
295 } else if (b.component.validationStatus === 'INVALID') {
298 bState = nfCommon.isDefinedAndNotNull(b.component[sortDetails.columnId]) ? b.component[sortDetails.columnId] : '';
300 return aState === bState ? 0 : aState > bState ? 1 : -1;
302 var aString = nfCommon.isDefinedAndNotNull(a.component[sortDetails.columnId]) ? a.component[sortDetails.columnId] : '';
303 var bString = nfCommon.isDefinedAndNotNull(b.component[sortDetails.columnId]) ? b.component[sortDetails.columnId] : '';
304 return aString === bString ? 0 : aString > bString ? 1 : -1;
307 if (!a.permissions.canRead && !b.permissions.canRead) {
310 if (a.permissions.canRead) {
319 data.sort(comparer, sortDetails.sortAsc);
323 * Get the text out of the filter field. If the filter field doesn't
324 * have any text it will contain the text 'filter list' so this method
327 var getReportingTaskTypeFilterText = function () {
328 return $('#reporting-task-type-filter').val();
332 * Filters the reporting task type table.
334 var applyReportingTaskTypeFilter = function () {
336 var reportingTaskTypesGrid = $('#reporting-task-types-table').data('gridInstance');
338 // ensure the grid has been initialized
339 if (nfCommon.isDefinedAndNotNull(reportingTaskTypesGrid)) {
340 var reportingTaskTypesData = reportingTaskTypesGrid.getData();
342 // update the search criteria
343 reportingTaskTypesData.setFilterArgs({
344 searchString: getReportingTaskTypeFilterText()
346 reportingTaskTypesData.refresh();
348 // update the buttons to possibly trigger the disabled state
349 $('#new-reporting-task-dialog').modal('refreshButtons');
351 // update the selection if possible
352 if (reportingTaskTypesData.getLength() > 0) {
353 nfFilteredDialogCommon.choseFirstRow(reportingTaskTypesGrid);
359 * Hides the selected reporting task.
361 var clearSelectedReportingTask = function () {
362 $('#reporting-task-type-description').attr('title', '').text('');
363 $('#reporting-task-type-name').attr('title', '').text('');
364 $('#reporting-task-type-bundle').attr('title', '').text('');
365 $('#selected-reporting-task-name').text('');
366 $('#selected-reporting-task-type').text('').removeData('bundle');
367 $('#reporting-task-description-container').hide();
371 * Clears the selected reporting task type.
373 var clearReportingTaskSelection = function () {
374 // clear the selected row
375 clearSelectedReportingTask();
377 // clear the active cell the it can be reselected when its included
378 var reportingTaskTypesGrid = $('#reporting-task-types-table').data('gridInstance');
379 reportingTaskTypesGrid.resetActiveCell();
383 * Performs the filtering.
385 * @param {object} item The item subject to filtering
386 * @param {object} args Filter arguments
387 * @returns {Boolean} Whether or not to include the item
389 var filterReportingTaskTypes = function (item, args) {
390 // determine if the item matches the filter
391 var matchesFilter = matchesRegex(item, args);
393 // determine if the row matches the selected tags
394 var matchesTags = true;
396 var tagFilters = $('#reporting-task-tag-cloud').tagcloud('getSelectedTags');
397 var hasSelectedTags = tagFilters.length > 0;
398 if (hasSelectedTags) {
399 matchesTags = matchesSelectedTags(tagFilters, item['tags']);
403 // determine if the row matches the selected source group
404 var matchesGroup = true;
405 if (matchesFilter && matchesTags) {
406 var bundleGroup = $('#reporting-task-bundle-group-combo').combo('getSelectedOption');
407 if (nfCommon.isDefinedAndNotNull(bundleGroup) && bundleGroup.value !== '') {
408 matchesGroup = (item.bundle.group === bundleGroup.value);
412 // determine if this row should be visible
413 var matches = matchesFilter && matchesTags && matchesGroup;
415 // if this row is currently selected and its being filtered
416 if (matches === false && $('#selected-reporting-task-type').text() === item['type']) {
417 clearReportingTaskSelection();
424 * Adds the currently selected reporting task.
426 var addSelectedReportingTask = function () {
427 var selectedTaskType = $('#selected-reporting-task-type').text();
428 var selectedTaskBundle = $('#selected-reporting-task-type').data('bundle');
430 // ensure something was selected
431 if (selectedTaskType === '') {
432 nfDialog.showOkDialog({
433 headerText: 'Settings',
434 dialogContent: 'The type of reporting task to create must be selected.'
437 addReportingTask(selectedTaskType, selectedTaskBundle);
442 * Adds a new reporting task of the specified type.
444 * @param {string} reportingTaskType
445 * @param {object} reportingTaskBundle
447 var addReportingTask = function (reportingTaskType, reportingTaskBundle) {
448 // build the reporting task entity
449 var reportingTaskEntity = {
450 'revision': nfClient.getRevision({
455 'disconnectedNodeAcknowledged': nfStorage.isDisconnectionAcknowledged(),
457 'type': reportingTaskType,
458 'bundle': reportingTaskBundle
462 // add the new reporting task
463 var addTask = $.ajax({
465 url: config.urls.createReportingTask,
466 data: JSON.stringify(reportingTaskEntity),
468 contentType: 'application/json'
469 }).done(function (reportingTaskEntity) {
471 var reportingTaskGrid = $('#reporting-tasks-table').data('gridInstance');
472 var reportingTaskData = reportingTaskGrid.getData();
473 reportingTaskData.addItem($.extend({
474 type: 'ReportingTask',
476 }, reportingTaskEntity));
479 reportingTaskData.reSort();
480 reportingTaskGrid.invalidate();
482 // select the new reporting task
483 var row = reportingTaskData.getRowById(reportingTaskEntity.id);
484 nfFilteredDialogCommon.choseRow(reportingTaskGrid, row);
485 reportingTaskGrid.scrollRowIntoView(row);
486 }).fail(nfErrorHandler.handleAjaxError);
489 $('#new-reporting-task-dialog').modal('hide');
495 * Adds the specified entity.
497 var addRegistry = function () {
498 var registryEntity = {
499 'revision': nfClient.getRevision({
504 'disconnectedNodeAcknowledged': nfStorage.isDisconnectionAcknowledged(),
506 'name': $('#registry-name').val(),
507 'uri': $('#registry-location').val(),
508 'description': $('#registry-description').val()
512 // add the new registry
513 var addRegistry = $.ajax({
515 url: config.urls.registries,
516 data: JSON.stringify(registryEntity),
518 contentType: 'application/json'
519 }).done(function (registryEntity) {
521 var registriesGrid = $('#registries-table').data('gridInstance');
522 var registriesData = registriesGrid.getData();
523 registriesData.addItem($.extend({
528 registriesData.reSort();
529 registriesGrid.invalidate();
531 // select the new reporting task
532 var row = registriesData.getRowById(registryEntity.id);
533 nfFilteredDialogCommon.choseRow(registriesGrid, row);
534 registriesGrid.scrollRowIntoView(row);
535 }).fail(nfErrorHandler.handleAjaxError);
538 $('#registry-configuration-dialog').modal('hide');
545 * Adds the specific environment.
547 var addDistributionEnvironment= function () {
548 var environmentEntity = {
549 'name': $('#distribution-environment-name').val(),
550 'runtimeApiUrl': $('#distribution-environment-location').val(),
551 'description': $('#distribution-environment-description').val()
552 // 'nextDistributionTargetId': $('#distribution-environment-nextDistributionTargetId').val()
555 console.log("before POST call ");
556 console.log(environmentEntity);
558 // add the new distribution environment
559 var addDistributionEnvironment= $.ajax({
561 url: '/distributor/distribution-targets',
562 data: JSON.stringify(environmentEntity),
564 contentType: 'application/json'
565 }).done(function (environmentEntity) {
567 console.log("after POST call in response ");
568 console.log(environmentEntity);
569 var environmentsGrid = $('#distribution-environments-table').data('gridInstance');
570 console.log(environmentsGrid);
571 var environmentsData = environmentsGrid.getData();
572 environmentsData.addItem($.extend({
574 }, environmentEntity));
578 environmentsData.reSort();
579 environmentsGrid.invalidate();
581 // select the new distribution env.
582 var row = environmentsData.getRowById(environmentEntity.id);
583 nfFilteredDialogCommon.choseRow(environmentsGrid, row);
584 registriesGrid.scrollRowIntoView(row);
585 }).fail(nfErrorHandler.handleAjaxError);
588 $('#distribution-environment-dialog').modal('hide');
590 return addDistributionEnvironment;
595 * Updates the registry with the specified id.
599 var updateRegistry = function (registryId) {
600 var registriesGrid = $('#registries-table').data('gridInstance');
601 var registriesData = registriesGrid.getData();
603 var registryEntity = registriesData.getItemById(registryId);
604 var requestRegistryEntity = {
605 'revision': nfClient.getRevision(registryEntity),
606 'disconnectedNodeAcknowledged': nfStorage.isDisconnectionAcknowledged(),
609 'name': $('#registry-name').val(),
610 'uri': $('#registry-location').val(),
611 'description': $('#registry-description').val()
615 // add the new reporting task
616 var updateRegistry = $.ajax({
618 url: registryEntity.uri,
619 data: JSON.stringify(requestRegistryEntity),
621 contentType: 'application/json'
622 }).done(function (registryEntity) {
624 registriesData.updateItem(registryId, $.extend({
627 }).fail(nfErrorHandler.handleAjaxError);
630 $('#registry-configuration-dialog').modal('hide');
632 return updateRegistry;
637 * Updates the distribution environment with the specified id.
639 * @param environmentId
641 var updateDistributionEnvironment = function (environmentId) {
642 var environmentsGrid = $('#distribution-environments-table').data('gridInstance');
643 var environmentsData = environmentsGrid.getData();
645 var environmentEntity = environmentsData.getItemById(environmentId);
646 var requestEnvironmentEntity = {
648 'name': $('#distribution-environment-name').val(),
649 'runtimeApiUrl': $('#distribution-environment-location').val(),
650 'description': $('#distribution-environment-description').val(),
651 // 'nextDistributionTargetId': $('#distribution-environment-nextDistributionTargetId').val()
654 console.log(requestEnvironmentEntity);
655 // updating distribution environment
656 var updateDistributionEnvironment = $.ajax({
658 url: '/distributor/distribution-targets/'+environmentEntity.id,
659 data: JSON.stringify(requestEnvironmentEntity),
661 contentType: 'application/json'
662 }).done(function (environmentEntity) {
664 console.log(environmentsGrid);
665 environmentsData.updateItem(environmentId, $.extend({
667 }, environmentEntity));
668 }).fail(nfErrorHandler.handleAjaxError);
671 $('#distribution-environment-dialog').modal('hide');
673 return updateDistributionEnvironment;
681 * Initializes the new reporting task dialog.
683 var initNewReportingTaskDialog = function () {
684 // initialize the reporting task type table
685 var reportingTaskTypesColumns = [
690 formatter: nfCommon.typeFormatter,
698 formatter: nfCommon.typeVersionFormatter,
708 formatter: nfCommon.genericValueFormatter
712 // initialize the dataview
713 var reportingTaskTypesData = new Slick.Data.DataView({
716 reportingTaskTypesData.setItems([]);
717 reportingTaskTypesData.setFilterArgs({
718 searchString: getReportingTaskTypeFilterText()
720 reportingTaskTypesData.setFilter(filterReportingTaskTypes);
722 // initialize the sort
726 }, reportingTaskTypesData);
728 // initialize the grid
729 var reportingTaskTypesGrid = new Slick.Grid('#reporting-task-types-table', reportingTaskTypesData, reportingTaskTypesColumns, gridOptions);
730 reportingTaskTypesGrid.setSelectionModel(new Slick.RowSelectionModel());
731 reportingTaskTypesGrid.registerPlugin(new Slick.AutoTooltips());
732 reportingTaskTypesGrid.setSortColumn('type', true);
733 reportingTaskTypesGrid.onSort.subscribe(function (e, args) {
735 columnId: args.sortCol.field,
736 sortAsc: args.sortAsc
737 }, reportingTaskTypesData);
739 reportingTaskTypesGrid.onSelectedRowsChanged.subscribe(function (e, args) {
740 if ($.isArray(args.rows) && args.rows.length === 1) {
741 var reportingTaskTypeIndex = args.rows[0];
742 var reportingTaskType = reportingTaskTypesGrid.getDataItem(reportingTaskTypeIndex);
744 // set the reporting task type description
745 if (nfCommon.isDefinedAndNotNull(reportingTaskType)) {
746 // show the selected reporting task
747 $('#reporting-task-description-container').show();
749 if (nfCommon.isBlank(reportingTaskType.description)) {
750 $('#reporting-task-type-description')
752 .html('<span class="unset">No description specified</span>');
754 $('#reporting-task-type-description')
755 .width($('#reporting-task-description-container').innerWidth() - 1)
756 .html(reportingTaskType.description)
760 var bundle = nfCommon.formatBundle(reportingTaskType.bundle);
761 var type = nfCommon.formatType(reportingTaskType);
764 $('#reporting-task-type-name').text(type).attr('title', type);
765 $('#reporting-task-type-bundle').text(bundle).attr('title', bundle);
766 $('#selected-reporting-task-name').text(reportingTaskType.label);
767 $('#selected-reporting-task-type').text(reportingTaskType.type).data('bundle', reportingTaskType.bundle);
769 // refresh the buttons based on the current selection
770 $('#new-reporting-task-dialog').modal('refreshButtons');
774 reportingTaskTypesGrid.onDblClick.subscribe(function (e, args) {
775 var reportingTaskType = reportingTaskTypesGrid.getDataItem(args.row);
777 if (isSelectable(reportingTaskType)) {
778 addReportingTask(reportingTaskType.type, reportingTaskType.bundle);
781 reportingTaskTypesGrid.onViewportChanged.subscribe(function (e, args) {
782 nfCommon.cleanUpTooltips($('#reporting-task-types-table'), 'div.view-usage-restriction');
785 // wire up the dataview to the grid
786 reportingTaskTypesData.onRowCountChanged.subscribe(function (e, args) {
787 reportingTaskTypesGrid.updateRowCount();
788 reportingTaskTypesGrid.render();
790 // update the total number of displayed processors
791 $('#displayed-reporting-task-types').text(args.current);
793 reportingTaskTypesData.onRowsChanged.subscribe(function (e, args) {
794 reportingTaskTypesGrid.invalidateRows(args.rows);
795 reportingTaskTypesGrid.render();
797 reportingTaskTypesData.syncGridSelection(reportingTaskTypesGrid, true);
799 // hold onto an instance of the grid
800 $('#reporting-task-types-table').data('gridInstance', reportingTaskTypesGrid).on('mouseenter', 'div.slick-cell', function (e) {
801 var usageRestriction = $(this).find('div.view-usage-restriction');
802 if (usageRestriction.length && !usageRestriction.data('qtip')) {
803 var rowId = $(this).find('span.row-id').text();
805 // get the status item
806 var item = reportingTaskTypesData.getItemById(rowId);
809 if (item.restricted === true) {
810 var restrictionTip = $('<div></div>');
812 if (nfCommon.isBlank(item.usageRestriction)) {
813 restrictionTip.append($('<p style="margin-bottom: 3px;"></p>').text('Requires the following permissions:'));
815 restrictionTip.append($('<p style="margin-bottom: 3px;"></p>').text(item.usageRestriction + ' Requires the following permissions:'));
818 var restrictions = [];
819 if (nfCommon.isDefinedAndNotNull(item.explicitRestrictions)) {
820 $.each(item.explicitRestrictions, function (_, explicitRestriction) {
821 var requiredPermission = explicitRestriction.requiredPermission;
822 restrictions.push("'" + requiredPermission.label + "' - " + nfCommon.escapeHtml(explicitRestriction.explanation));
825 restrictions.push('Access to restricted components regardless of restrictions.');
827 restrictionTip.append(nfCommon.formatUnorderedList(restrictions));
829 usageRestriction.qtip($.extend({}, nfCommon.config.tooltipConfig, {
830 content: restrictionTip,
832 container: $('#summary'),
845 var generalRestriction = nfCommon.getPolicyTypeListing('restricted-components');
847 // load the available reporting tasks
850 url: config.urls.reportingTaskTypes,
852 }).done(function (response) {
855 var groups = d3.set();
856 var restrictedUsage = d3.map();
857 var requiredPermissions = d3.map();
860 reportingTaskTypesData.beginUpdate();
862 // go through each reporting task type
863 $.each(response.reportingTaskTypes, function (i, documentedType) {
864 if (documentedType.restricted === true) {
865 if (nfCommon.isDefinedAndNotNull(documentedType.explicitRestrictions)) {
866 $.each(documentedType.explicitRestrictions, function (_, explicitRestriction) {
867 var requiredPermission = explicitRestriction.requiredPermission;
869 // update required permissions
870 if (!requiredPermissions.has(requiredPermission.id)) {
871 requiredPermissions.set(requiredPermission.id, requiredPermission.label);
874 // update component restrictions
875 if (!restrictedUsage.has(requiredPermission.id)) {
876 restrictedUsage.set(requiredPermission.id, []);
879 restrictedUsage.get(requiredPermission.id).push({
880 type: nfCommon.formatType(documentedType),
881 bundle: nfCommon.formatBundle(documentedType.bundle),
882 explanation: nfCommon.escapeHtml(explicitRestriction.explanation)
886 // update required permissions
887 if (!requiredPermissions.has(generalRestriction.value)) {
888 requiredPermissions.set(generalRestriction.value, generalRestriction.text);
891 // update component restrictions
892 if (!restrictedUsage.has(generalRestriction.value)) {
893 restrictedUsage.set(generalRestriction.value, []);
896 restrictedUsage.get(generalRestriction.value).push({
897 type: nfCommon.formatType(documentedType),
898 bundle: nfCommon.formatBundle(documentedType.bundle),
899 explanation: nfCommon.escapeHtml(documentedType.usageRestriction)
905 groups.add(documentedType.bundle.group);
907 // add the documented type
908 reportingTaskTypesData.addItem({
910 label: nfCommon.substringAfterLast(documentedType.type, '.'),
911 type: documentedType.type,
912 bundle: documentedType.bundle,
913 description: nfCommon.escapeHtml(documentedType.description),
914 restricted: documentedType.restricted,
915 usageRestriction: nfCommon.escapeHtml(documentedType.usageRestriction),
916 explicitRestrictions: documentedType.explicitRestrictions,
917 tags: documentedType.tags.join(', ')
920 // count the frequency of each tag for this type
921 $.each(documentedType.tags, function (i, tag) {
922 tags.push(tag.toLowerCase());
927 reportingTaskTypesData.endUpdate();
930 reportingTaskTypesData.reSort();
931 reportingTaskTypesGrid.invalidate();
933 // set the component restrictions and the corresponding required permissions
934 nfCanvasUtils.addComponentRestrictions(restrictedUsage, requiredPermissions);
936 // set the total number of processors
937 $('#total-reporting-task-types, #displayed-reporting-task-types').text(response.reportingTaskTypes.length);
939 // create the tag cloud
940 $('#reporting-task-tag-cloud').tagcloud({
942 select: applyReportingTaskTypeFilter,
943 remove: applyReportingTaskTypeFilter
946 // build the combo options
951 groups.each(function (group) {
958 // initialize the bundle group combo
959 $('#reporting-task-bundle-group-combo').combo({
961 select: applyReportingTaskTypeFilter
963 }).fail(nfErrorHandler.handleAjaxError);
965 var navigationKeys = [$.ui.keyCode.UP, $.ui.keyCode.PAGE_UP, $.ui.keyCode.DOWN, $.ui.keyCode.PAGE_DOWN];
967 // define the function for filtering the list
968 $('#reporting-task-type-filter').off('keyup').on('keyup', function (e) {
969 var code = e.keyCode ? e.keyCode : e.which;
971 // ignore navigation keys
972 if ($.inArray(code, navigationKeys) !== -1) {
976 if (code === $.ui.keyCode.ENTER) {
977 var selected = reportingTaskTypesGrid.getSelectedRows();
979 if (selected.length > 0) {
980 // grid configured with multi-select = false
981 var item = reportingTaskTypesGrid.getDataItem(selected[0]);
982 if (isSelectable(item)) {
983 addSelectedReportingTask();
987 applyReportingTaskTypeFilter();
991 // setup row navigation
992 nfFilteredDialogCommon.addKeydownListener('#reporting-task-type-filter', reportingTaskTypesGrid, reportingTaskTypesGrid.getData());
994 // initialize the reporting task dialog
995 $('#new-reporting-task-dialog').modal({
996 scrollableContentStyle: 'scrollable',
997 headerText: 'Add Reporting Task',
1005 disabled: function () {
1006 var selected = reportingTaskTypesGrid.getSelectedRows();
1008 if (selected.length > 0) {
1009 // grid configured with multi-select = false
1010 var item = reportingTaskTypesGrid.getDataItem(selected[0]);
1011 return isSelectable(item) === false;
1013 return reportingTaskTypesGrid.getData().getLength() === 0;
1017 click: function () {
1018 addSelectedReportingTask();
1023 buttonText: 'Cancel',
1030 click: function () {
1031 $(this).modal('hide');
1036 close: function () {
1037 // clear the selected row
1038 clearSelectedReportingTask();
1040 // clear any filter strings
1041 $('#reporting-task-type-filter').val('');
1043 // clear the tagcloud
1044 $('#reporting-task-tag-cloud').tagcloud('clearSelectedTags');
1046 // reset the group combo
1047 $('#reporting-task-bundle-group-combo').combo('setSelectedOption', {
1052 applyReportingTaskTypeFilter();
1054 // unselect any current selection
1055 var reportingTaskTypesGrid = $('#reporting-task-types-table').data('gridInstance');
1056 reportingTaskTypesGrid.setSelectedRows([]);
1057 reportingTaskTypesGrid.resetActiveCell();
1059 resize: function () {
1060 $('#reporting-task-type-description')
1061 .width($('#reporting-task-description-container').innerWidth() - 1)
1062 .text($('#reporting-task-type-description').attr('title'))
1068 // initialize the registry configuration dialog
1069 $('#registry-configuration-dialog').modal({
1070 scrollableContentStyle: 'scrollable',
1072 close: function () {
1073 $('#registry-id').text('');
1074 $('#registry-name').val('');
1075 $('#registry-location').val('');
1076 $('#registry-description').val('');
1082 // initialize the distribution environment dialog
1083 $('#distribution-environment-dialog').modal({
1084 scrollableContentStyle: 'scrollable',
1086 close: function () {
1087 $('#distribution-environment-id').text('');
1088 $('#distribution-environment-name').val('');
1089 $('#distribution-environment-location').val('');
1090 $('#distribution-environment-description').val('');
1091 // $('#distribution-environment-nextDistributionTargetId').val('');
1098 * Initializes the reporting tasks tab.
1100 var initReportingTasks = function () {
1101 // initialize the new reporting task dialog
1102 initNewReportingTaskDialog();
1104 var moreReportingTaskDetails = function (row, cell, value, columnDef, dataContext) {
1105 if (!dataContext.permissions.canRead) {
1109 var markup = '<div title="View Details" class="pointer view-reporting-task fa fa-info-circle"></div>';
1111 // always include a button to view the usage
1112 markup += '<div title="Usage" class="pointer reporting-task-usage fa fa-book"></div>';
1114 var hasErrors = !nfCommon.isEmpty(dataContext.component.validationErrors);
1115 var hasBulletins = !nfCommon.isEmpty(dataContext.bulletins);
1118 markup += '<div class="pointer has-errors fa fa-warning" ></div>';
1122 markup += '<div class="has-bulletins fa fa-sticky-note-o"></div>';
1125 if (hasErrors || hasBulletins) {
1126 markup += '<span class="hidden row-id">' + nfCommon.escapeHtml(dataContext.component.id) + '</span>';
1132 var reportingTaskRunStatusFormatter = function (row, cell, value, columnDef, dataContext) {
1133 // determine the appropriate label
1134 var icon = '', label = '';
1135 if (dataContext.status.validationStatus === 'VALIDATING') {
1136 icon = 'validating fa fa-spin fa-circle-notch';
1137 label = 'Validating';
1138 } else if (dataContext.status.validationStatus === 'INVALID') {
1139 icon = 'invalid fa fa-warning';
1142 if (dataContext.status.runStatus === 'STOPPED') {
1144 icon = 'fa fa-stop stopped';
1145 } else if (dataContext.status.runStatus === 'RUNNING') {
1147 icon = 'fa fa-play running';
1150 icon = 'icon icon-enable-false disabled';
1154 // include the active thread count if appropriate
1155 var activeThreadCount = '';
1156 if (nfCommon.isDefinedAndNotNull(dataContext.status.activeThreadCount) && dataContext.status.activeThreadCount > 0) {
1157 activeThreadCount = '(' + dataContext.status.activeThreadCount + ')';
1160 // format the markup
1161 var formattedValue = '<div layout="row"><div class="' + icon + '"></div>';
1162 return formattedValue + '<div class="status-text">' + nfCommon.escapeHtml(label) + '</div><div style="float: left; margin-left: 4px;">' + nfCommon.escapeHtml(activeThreadCount) + '</div></div>';
1165 var reportingTaskActionFormatter = function (row, cell, value, columnDef, dataContext) {
1168 var canWrite = dataContext.permissions.canWrite;
1169 var canRead = dataContext.permissions.canRead;
1170 var canOperate = dataContext.operatePermissions.canWrite || canWrite;
1171 var isStopped = dataContext.status.runStatus === 'STOPPED';
1173 if (dataContext.status.runStatus === 'RUNNING') {
1175 markup += '<div title="Stop" class="pointer stop-reporting-task fa fa-stop"></div>';
1178 } else if (isStopped || dataContext.status.runStatus === 'DISABLED') {
1180 if (canRead && canWrite) {
1181 markup += '<div title="Edit" class="pointer edit-reporting-task fa fa-pencil"></div>';
1184 // support starting when stopped and no validation errors
1185 if (canOperate && dataContext.status.runStatus === 'STOPPED' && dataContext.status.validationStatus === 'VALID') {
1186 markup += '<div title="Start" class="pointer start-reporting-task fa fa-play"></div>';
1189 if (canRead && canWrite && dataContext.component.multipleVersionsAvailable === true) {
1190 markup += '<div title="Change Version" class="pointer change-version-reporting-task fa fa-exchange"></div>';
1193 if (canRead && canWrite && nfCommon.canModifyController()) {
1194 markup += '<div title="Remove" class="pointer delete-reporting-task fa fa-trash"></div>';
1198 if (canRead && canWrite && dataContext.component.persistsState === true) {
1199 markup += '<div title="View State" class="pointer view-state-reporting-task fa fa-tasks"></div>';
1202 // allow policy configuration conditionally
1203 if (nfCanvasUtils.isManagedAuthorizer() && nfCommon.canAccessTenants()) {
1204 markup += '<div title="Access Policies" class="pointer edit-access-policies fa fa-key"></div>';
1210 // define the column model for the reporting tasks table
1211 var reportingTasksColumnModel = [
1216 formatter: moreReportingTaskDetails,
1220 toolTip: 'Sorts based on presence of bulletins'
1227 formatter: nameFormatter
1232 formatter: nfCommon.instanceTypeFormatter,
1239 formatter: nfCommon.instanceBundleFormatter,
1248 formatter: reportingTaskRunStatusFormatter
1252 // action column should always be last
1253 reportingTasksColumnModel.push({
1257 formatter: reportingTaskActionFormatter,
1263 // initialize the dataview
1264 var reportingTasksData = new Slick.Data.DataView({
1265 inlineFilters: false
1267 reportingTasksData.setItems([]);
1269 // initialize the sort
1273 }, reportingTasksData);
1275 // initialize the grid
1276 var reportingTasksGrid = new Slick.Grid('#reporting-tasks-table', reportingTasksData, reportingTasksColumnModel, gridOptions);
1277 reportingTasksGrid.setSelectionModel(new Slick.RowSelectionModel());
1278 reportingTasksGrid.registerPlugin(new Slick.AutoTooltips());
1279 reportingTasksGrid.setSortColumn('name', true);
1280 reportingTasksGrid.onSort.subscribe(function (e, args) {
1282 columnId: args.sortCol.id,
1283 sortAsc: args.sortAsc
1284 }, reportingTasksData);
1287 // configure a click listener
1288 reportingTasksGrid.onClick.subscribe(function (e, args) {
1289 var target = $(e.target);
1291 // get the service at this row
1292 var reportingTaskEntity = reportingTasksData.getItem(args.row);
1294 // determine the desired action
1295 if (reportingTasksGrid.getColumns()[args.cell].id === 'actions') {
1296 if (target.hasClass('edit-reporting-task')) {
1297 nfReportingTask.showConfiguration(reportingTaskEntity);
1298 } else if (target.hasClass('start-reporting-task')) {
1299 nfReportingTask.start(reportingTaskEntity);
1300 } else if (target.hasClass('stop-reporting-task')) {
1301 nfReportingTask.stop(reportingTaskEntity);
1302 } else if (target.hasClass('delete-reporting-task')) {
1303 nfReportingTask.promptToDeleteReportingTask(reportingTaskEntity);
1304 } else if (target.hasClass('view-state-reporting-task')) {
1305 var canClear = reportingTaskEntity.status.runStatus === 'STOPPED' && reportingTaskEntity.status.activeThreadCount === 0;
1306 nfComponentState.showState(reportingTaskEntity, canClear);
1307 } else if (target.hasClass('change-version-reporting-task')) {
1308 nfComponentVersion.promptForVersionChange(reportingTaskEntity);
1309 } else if (target.hasClass('edit-access-policies')) {
1310 // show the policies for this service
1311 nfPolicyManagement.showReportingTaskPolicy(reportingTaskEntity);
1313 // close the settings dialog
1314 $('#shell-close-button').click();
1316 } else if (reportingTasksGrid.getColumns()[args.cell].id === 'moreDetails') {
1317 if (target.hasClass('view-reporting-task')) {
1318 nfReportingTask.showDetails(reportingTaskEntity);
1319 } else if (target.hasClass('reporting-task-usage')) {
1320 // close the settings dialog
1321 $('#shell-close-button').click();
1323 // open the documentation for this reporting task
1324 nfShell.showPage('../nifi-docs/documentation?' + $.param({
1325 select: reportingTaskEntity.component.type,
1326 group: reportingTaskEntity.component.bundle.group,
1327 artifact: reportingTaskEntity.component.bundle.artifact,
1328 version: reportingTaskEntity.component.bundle.version
1329 })).done(function () {
1330 nfSettings.showSettings();
1336 // wire up the dataview to the grid
1337 reportingTasksData.onRowCountChanged.subscribe(function (e, args) {
1338 reportingTasksGrid.updateRowCount();
1339 reportingTasksGrid.render();
1341 reportingTasksData.onRowsChanged.subscribe(function (e, args) {
1342 reportingTasksGrid.invalidateRows(args.rows);
1343 reportingTasksGrid.render();
1345 reportingTasksData.syncGridSelection(reportingTasksGrid, true);
1347 // hold onto an instance of the grid
1348 $('#reporting-tasks-table').data('gridInstance', reportingTasksGrid).on('mouseenter', 'div.slick-cell', function (e) {
1349 var errorIcon = $(this).find('div.has-errors');
1350 if (errorIcon.length && !errorIcon.data('qtip')) {
1351 var taskId = $(this).find('span.row-id').text();
1353 // get the task item
1354 var reportingTaskEntity = reportingTasksData.getItemById(taskId);
1356 // format the errors
1357 var tooltip = nfCommon.formatUnorderedList(reportingTaskEntity.component.validationErrors);
1360 if (nfCommon.isDefinedAndNotNull(tooltip)) {
1361 errorIcon.qtip($.extend({},
1362 nfCommon.config.tooltipConfig,
1367 viewport: $('#shell-container'),
1371 method: 'flipinvert flipinvert'
1378 var bulletinIcon = $(this).find('div.has-bulletins');
1379 if (bulletinIcon.length && !bulletinIcon.data('qtip')) {
1380 var taskId = $(this).find('span.row-id').text();
1382 // get the task item
1383 var reportingTaskEntity = reportingTasksData.getItemById(taskId);
1385 // format the tooltip
1386 var bulletins = nfCommon.getFormattedBulletins(reportingTaskEntity.bulletins);
1387 var tooltip = nfCommon.formatUnorderedList(bulletins);
1390 if (nfCommon.isDefinedAndNotNull(tooltip)) {
1391 bulletinIcon.qtip($.extend({},
1392 nfCommon.config.tooltipConfig,
1397 viewport: $('#shell-container'),
1401 method: 'flipinvert flipinvert'
1413 * Initializing Registry table
1415 var initRegistriesTable = function () {
1417 var locationFormatter = function (row, cell, value, columnDef, dataContext) {
1418 if (!dataContext.permissions.canRead) {
1419 return '<span class="blank">' + nfCommon.escapeHtml(dataContext.id) + '</span>';
1422 return nfCommon.escapeHtml(dataContext.component.uri);
1425 var descriptionFormatter = function (row, cell, value, columnDef, dataContext) {
1426 if (!dataContext.permissions.canRead) {
1427 return '<span class="blank">' + nfCommon.escapeHtml(dataContext.id) + '</span>';
1430 return nfCommon.escapeHtml(dataContext.component.description);
1433 var registriesActionFormatter = function (row, cell, value, columnDef, dataContext) {
1436 if (nfCommon.canModifyController()) {
1438 markup += '<div title="Edit" class="pointer edit-registry fa fa-pencil"></div>';
1441 markup += '<div title="Remove" class="pointer remove-registry fa fa-trash"></div>';
1447 // define the column model for the reporting tasks table
1448 var registriesColumnModel = [
1453 formatter: nameFormatter,
1461 formatter: locationFormatter,
1467 name: 'Description',
1468 field: 'description',
1469 formatter: descriptionFormatter,
1475 // action column should always be last
1476 registriesColumnModel.push({
1480 formatter: registriesActionFormatter,
1486 // initialize the dataview
1487 var registriesData = new Slick.Data.DataView({
1488 inlineFilters: false
1490 registriesData.setItems([]);
1492 // initialize the sort
1498 // initialize the grid
1499 var registriesGrid = new Slick.Grid('#registries-table', registriesData, registriesColumnModel, gridOptions);
1500 registriesGrid.setSelectionModel(new Slick.RowSelectionModel());
1501 registriesGrid.registerPlugin(new Slick.AutoTooltips());
1502 registriesGrid.setSortColumn('name', true);
1503 registriesGrid.onSort.subscribe(function (e, args) {
1505 columnId: args.sortCol.id,
1506 sortAsc: args.sortAsc
1510 // configure a click listener
1511 registriesGrid.onClick.subscribe(function (e, args) {
1512 var target = $(e.target);
1514 // get the service at this row
1515 var registryEntity = registriesData.getItem(args.row);
1517 // determine the desired action
1518 if (registriesGrid.getColumns()[args.cell].id === 'actions') {
1519 if (target.hasClass('edit-registry')) {
1520 editRegistry(registryEntity);
1521 } else if (target.hasClass('remove-registry')) {
1522 promptToRemoveRegistry(registryEntity);
1524 } else if (registriesGrid.getColumns()[args.cell].id === 'moreDetails') {
1525 // if (target.hasClass('view-reporting-task')) {
1526 // nfReportingTask.showDetails(reportingTaskEntity);
1527 // } else if (target.hasClass('reporting-task-usage')) {
1528 // // close the settings dialog
1529 // $('#shell-close-button').click();
1531 // // open the documentation for this reporting task
1532 // nfShell.showPage('../nifi-docs/documentation?' + $.param({
1533 // select: reportingTaskEntity.component.type,
1534 // group: reportingTaskEntity.component.bundle.group,
1535 // artifact: reportingTaskEntity.component.bundle.artifact,
1536 // version: reportingTaskEntity.component.bundle.version
1537 // })).done(function () {
1538 // nfSettings.showSettings();
1544 // wire up the dataview to the grid
1545 registriesData.onRowCountChanged.subscribe(function (e, args) {
1546 registriesGrid.updateRowCount();
1547 registriesGrid.render();
1549 registriesData.onRowsChanged.subscribe(function (e, args) {
1550 registriesGrid.invalidateRows(args.rows);
1551 registriesGrid.render();
1553 registriesData.syncGridSelection(registriesGrid, true);
1555 // hold onto an instance of the grid
1556 $('#registries-table').data('gridInstance', registriesGrid);
1563 * Initializing Distribution Environments table
1565 var initDistributionEnvironmentsTable = function () {
1567 var locationFormatter = function (row, cell, value, columnDef, dataContext) {
1568 // if (!dataContext.permissions.canRead) {
1569 return '<span class="blank">' + nfCommon.escapeHtml(dataContext.id) + '</span>';
1572 return nfCommon.escapeHtml(dataContext.component.uri);
1575 var descriptionFormatter = function (row, cell, value, columnDef, dataContext) {
1576 // if (!dataContext.permissions.canRead) {
1577 return '<span class="blank">' + nfCommon.escapeHtml(dataContext.id) + '</span>';
1580 return nfCommon.escapeHtml(dataContext.component.description);
1583 var envActionFormatter = function (row, cell, value, columnDef, dataContext) {
1586 if (nfCommon.canModifyController()) {
1588 markup += '<div title="Edit" class="pointer edit-registry fa fa-pencil"></div>';
1590 // remove environment
1591 markup += '<div title="Remove" class="pointer remove-registry fa fa-trash"></div>';
1597 // define the column model for the Distribution environments table
1598 var environmentsColumnModel = [
1603 // formatter: nameFormatter,
1608 id: 'runtimeApiUrl',
1610 field: 'runtimeApiUrl',
1611 // formatter: locationFormatter,
1617 name: 'Description',
1618 field: 'description',
1619 // formatter: descriptionFormatter,
1625 // id: 'nextDistributionTargetId',
1626 // name: 'Next Distribution TargetId',
1627 // field: 'nextDistributionTargetId',
1628 // formatter: descriptionFormatter,
1634 // action column should always be last
1635 environmentsColumnModel.push({
1639 formatter: envActionFormatter,
1645 // initialize the dataview
1646 var environmentsData = new Slick.Data.DataView({
1647 inlineFilters: false
1649 environmentsData.setItems([]);
1651 // initialize the sort
1655 }, environmentsData);
1657 // initialize the grid
1658 var environmentsGrid = new Slick.Grid('#distribution-environments-table', environmentsData, environmentsColumnModel, gridOptions);
1659 environmentsGrid.setSelectionModel(new Slick.RowSelectionModel());
1660 environmentsGrid.registerPlugin(new Slick.AutoTooltips());
1661 environmentsGrid.setSortColumn('name', true);
1662 environmentsGrid.onSort.subscribe(function (e, args) {
1664 columnId: args.sortCol.id,
1665 sortAsc: args.sortAsc
1666 }, environmentsData);
1669 // configure a click listener
1670 environmentsGrid.onClick.subscribe(function (e, args) {
1671 var target = $(e.target);
1673 // get the service at this row
1674 var environmentEntity = environmentsData.getItem(args.row);
1676 // determine the desired action
1677 if (environmentsGrid.getColumns()[args.cell].id === 'actions') {
1678 if (target.hasClass('edit-registry')) { //left it as edit-registry intentionally to inherit styles
1679 editDistributionEnvironment(environmentEntity);
1680 } else if (target.hasClass('remove-registry')) { //left it as remove-registry intentionally to inherit styles
1681 promptToRemoveDistributionEnvironment(environmentEntity);
1683 } else if (environmentsGrid.getColumns()[args.cell].id === 'moreDetails') { }
1686 // wire up the dataview to the grid
1687 environmentsData.onRowCountChanged.subscribe(function (e, args) {
1688 environmentsGrid.updateRowCount();
1689 environmentsGrid.render();
1691 environmentsData.onRowsChanged.subscribe(function (e, args) {
1692 environmentsGrid.invalidateRows(args.rows);
1693 environmentsGrid.render();
1695 environmentsData.syncGridSelection(environmentsGrid, true);
1697 // hold onto an instance of the grid
1698 $('#distribution-environments-table').data('gridInstance', environmentsGrid);
1704 * Edits the specified registry entity.
1706 * @param registryEntity
1708 var editRegistry = function (registryEntity) {
1709 // populate the dialog
1710 $('#registry-id').text(registryEntity.id);
1711 $('#registry-name').val(registryEntity.component.name);
1712 $('#registry-location').val(registryEntity.component.uri);
1713 $('#registry-description').val(registryEntity.component.description);
1716 $('#registry-configuration-dialog').modal('setHeaderText', 'Edit Registry Client').modal('setButtonModel', [{
1717 buttonText: 'Update',
1724 click: function () {
1725 updateRegistry(registryEntity.id);
1729 buttonText: 'Cancel',
1736 click: function () {
1737 $(this).modal('hide');
1745 * Edits the specified distribution environment entity.
1747 * @param distributionEnvironmentEntity
1749 var editDistributionEnvironment = function (distributionEnvironmentEntity) {
1750 // populate the dialog
1751 $('#distribution-environment-id').text(distributionEnvironmentEntity.id);
1752 $('#distribution-environment-name').val(distributionEnvironmentEntity.name);
1753 $('#distribution-environment-location').val(distributionEnvironmentEntity.runtimeApiUrl);
1754 $('#distribution-environment-description').val(distributionEnvironmentEntity.description);
1755 // $('#distribution-environment-nextDistributionTargetId ').val(distributionEnvironmentEntity.component.description);
1758 $('#distribution-environment-dialog').modal('setHeaderText', 'Edit Environment').modal('setButtonModel', [{
1759 buttonText: 'Update',
1766 click: function () {
1767 updateDistributionEnvironment(distributionEnvironmentEntity.id);
1771 buttonText: 'Cancel',
1778 click: function () {
1779 $(this).modal('hide');
1787 * Prompts the user before attempting to delete the specified environment.
1789 * @param {object} environmentEntity
1791 var promptToRemoveDistributionEnvironment = function (environmentEntity) {
1792 // prompt for deletion
1793 nfDialog.showYesNoDialog({
1794 headerText: 'Delete Environment',
1795 dialogContent: 'Delete Environment \'' + nfCommon.escapeHtml(environmentEntity.name) + '\'?',
1796 yesHandler: function () {
1797 removeDistributionEnvironment(environmentEntity);
1804 * Deletes the specified environment.
1806 * @param {object} environmentEntity
1808 var removeDistributionEnvironment = function (environmentEntity) {
1809 console.log(environmentEntity);
1812 url: '/distributor/distribution-targets/'+environmentEntity.id,
1814 }).done(function (response) {
1815 console.log(response);
1817 var environmentsGrid = $('#distribution-environments-table').data('gridInstance');
1818 console.log(environmentsGrid);
1819 var environmentsData = environmentsGrid.getData();
1820 environmentsData.deleteItem(environmentEntity.id);
1821 }).fail(nfErrorHandler.handleAjaxError);
1826 * Prompts the user before attempting to delete the specified registry.
1828 * @param {object} registryEntity
1830 var promptToRemoveRegistry = function (registryEntity) {
1831 // prompt for deletion
1832 nfDialog.showYesNoDialog({
1833 headerText: 'Delete Registry',
1834 dialogContent: 'Delete registry \'' + nfCommon.escapeHtml(registryEntity.component.name) + '\'?',
1835 yesHandler: function () {
1836 removeRegistry(registryEntity);
1842 * Deletes the specified registry.
1844 * @param {object} registryEntity
1846 var removeRegistry = function (registryEntity) {
1847 var revision = nfClient.getRevision(registryEntity);
1850 url: registryEntity.uri + '?' + $.param({
1851 'version': revision.version,
1852 'clientId': revision.clientId,
1853 'disconnectedNodeAcknowledged': nfStorage.isDisconnectionAcknowledged()
1856 }).done(function (response) {
1858 var registryGrid = $('#registries-table').data('gridInstance');
1859 var registryData = registryGrid.getData();
1860 registryData.deleteItem(registryEntity.id);
1861 }).fail(nfErrorHandler.handleAjaxError);
1865 * Loads the settings.
1867 var loadSettings = function () {
1868 var setUnauthorizedText = function () {
1869 $('#read-only-maximum-timer-driven-thread-count-field').addClass('unset').text('Unauthorized');
1870 $('#read-only-maximum-event-driven-thread-count-field').addClass('unset').text('Unauthorized');
1873 var setEditable = function (editable) {
1875 $('#general-settings div.editable').show();
1876 $('#general-settings div.read-only').hide();
1877 $('#settings-save').show();
1879 $('#general-settings div.editable').hide();
1880 $('#general-settings div.read-only').show();
1881 $('#settings-save').hide();
1885 var settings = $.Deferred(function (deferred) {
1888 url: config.urls.controllerConfig,
1890 }).done(function (response) {
1891 if (response.permissions.canWrite) {
1892 // populate the settings
1893 $('#maximum-timer-driven-thread-count-field').removeClass('unset').val(response.component.maxTimerDrivenThreadCount);
1894 $('#maximum-event-driven-thread-count-field').removeClass('unset').val(response.component.maxEventDrivenThreadCount);
1898 // register the click listener for the save button
1899 $('#settings-save').off('click').on('click', function () {
1900 saveSettings(response.revision.version);
1903 if (response.permissions.canRead) {
1904 // populate the settings
1905 $('#read-only-maximum-timer-driven-thread-count-field').removeClass('unset').text(response.component.maxTimerDrivenThreadCount);
1906 $('#read-only-maximum-event-driven-thread-count-field').removeClass('unset').text(response.component.maxEventDrivenThreadCount);
1908 setUnauthorizedText();
1914 }).fail(function (xhr, status, error) {
1915 if (xhr.status === 403) {
1916 setUnauthorizedText();
1920 deferred.reject(xhr, status, error);
1925 // load the controller services
1926 var controllerServicesUri = config.urls.api + '/flow/controller/controller-services';
1927 var controllerServicesXhr = nfControllerServices.loadControllerServices(controllerServicesUri, getControllerServicesTable());
1929 // load the reporting tasks
1930 var reportingTasks = loadReportingTasks();
1932 // load the registries
1933 var registries = loadRegistries();
1935 // load the distribution environments
1936 var distributionEnvironments = loadDistributionEnvironments();
1938 // return a deferred for all parts of the settings
1939 return $.when(settings, controllerServicesXhr, reportingTasks).done(function (settingsResult, controllerServicesResult) {
1940 var controllerServicesResponse = controllerServicesResult[0];
1942 // update the current time
1943 $('#settings-last-refreshed').text(controllerServicesResponse.currentTime);
1944 }).fail(nfErrorHandler.handleAjaxError);
1948 * Loads the reporting tasks.
1950 var loadReportingTasks = function () {
1953 url: config.urls.reportingTasks,
1955 }).done(function (response) {
1957 $.each(response.reportingTasks, function (_, task) {
1958 tasks.push($.extend({
1959 type: 'ReportingTask',
1964 var reportingTasksElement = $('#reporting-tasks-table');
1965 nfCommon.cleanUpTooltips(reportingTasksElement, 'div.has-errors');
1966 nfCommon.cleanUpTooltips(reportingTasksElement, 'div.has-bulletins');
1968 var reportingTasksGrid = reportingTasksElement.data('gridInstance');
1969 var reportingTasksData = reportingTasksGrid.getData();
1971 // update the reporting tasks
1972 reportingTasksData.setItems(tasks);
1973 reportingTasksData.reSort();
1974 reportingTasksGrid.invalidate();
1979 * Loads the registries.
1981 var loadRegistries = function () {
1984 url: config.urls.registries,
1986 }).done(function (response) {
1987 var registries = [];
1988 $.each(response.registries, function (_, registryEntity) {
1989 registries.push($.extend({
1991 }, registryEntity));
1994 var registriesGrid = $('#registries-table').data('gridInstance');
1995 var registriesData = registriesGrid.getData();
1997 // update the registries
1998 registriesData.setItems(registries);
1999 registriesData.reSort();
2000 registriesGrid.invalidate();
2005 * Loads the distribution environments.
2007 var loadDistributionEnvironments = function(){
2008 console.log("in loadDistributionEnvironments.. ");
2011 url: '/distributor/distribution-targets',
2013 }).done(function (response) {
2014 console.log(response);
2015 var environments = [];
2016 $.each(response.distributionTargets, function (_, environmentEntity) {
2017 console.log(environmentEntity);
2018 environments.push($.extend({
2020 }, environmentEntity));
2023 console.log(environments);
2024 var environmentsGrid = $('#distribution-environments-table').data('gridInstance');
2025 console.log(environmentsGrid);
2026 var environmentsData = environmentsGrid.getData();
2028 // update the distribution environments
2029 environmentsData.setItems(environments);
2030 environmentsData.reSort();
2031 environmentsGrid.invalidate();
2036 * Shows the process group configuration.
2038 var showSettings = function () {
2039 // show the settings dialog
2040 nfShell.showContent('#settings').done(function () {
2044 //reset content to account for possible policy changes
2045 $('#settings-tabs').find('.selected-tab').click();
2047 // adjust the table size
2048 nfSettings.resetTableSize();
2052 * Reset state of this dialog.
2054 var reset = function () {
2055 // reset button state
2056 $('#settings-save').mouseout();
2061 * Initializes the settings page.
2064 // initialize the settings tabs
2065 $('#settings-tabs').tabbs({
2067 selectedTabStyle: 'selected-tab',
2068 scrollableTabContentStyle: 'scrollable',
2071 tabContentId: 'general-settings-tab-content'
2073 name: 'Reporting Task Controller Services',
2074 tabContentId: 'controller-services-tab-content'
2076 name: 'Reporting Tasks',
2077 tabContentId: 'reporting-tasks-tab-content'
2079 name: 'Registry Clients',
2080 tabContentId: 'registries-tab-content'
2082 name: 'Distribution Target Environments',
2083 tabContentId: 'distribution-environment-content'
2086 select: function () {
2087 var tab = $(this).text();
2088 if (tab === 'General') {
2089 $('#controller-cs-availability').hide();
2090 $('#new-service-or-task').hide();
2091 $('#settings-save').show();
2093 var canModifyController = false;
2094 if (nfCommon.isDefinedAndNotNull(nfCommon.currentUser)) {
2095 // only consider write permissions for creating new controller services/reporting tasks
2096 canModifyController = nfCommon.currentUser.controllerPermissions.canWrite === true;
2099 if (canModifyController) {
2100 $('#new-service-or-task').show();
2101 $('div.controller-settings-table').css('top', '32px');
2103 // update the tooltip on the button
2104 $('#new-service-or-task').attr('title', function () {
2105 if (tab === 'Reporting Task Controller Services') {
2106 $('#settings-save').hide();
2107 return 'Create a new reporting task controller service';
2108 } else if (tab === 'Reporting Tasks') {
2109 $('#settings-save').hide();
2110 return 'Create a new reporting task';
2111 } else if (tab === 'Registry Clients') {
2112 $('#settings-save').hide();
2113 return 'Register a new registry client';
2114 }else if (tab === 'Distribution Target Environments') {
2115 console.log("in env tab...");
2116 $('#settings-save').hide();
2117 return 'Add a new distribution environment';
2121 $('#new-service-or-task').hide();
2122 $('div.controller-settings-table').css('top', '0');
2125 if (tab === 'Reporting Task Controller Services') {
2126 $('#controller-cs-availability').show();
2127 } else if (tab === 'Reporting Tasks' || tab === 'Registry Clients'|| tab === 'Distribution Target Environments') {
2128 $('#controller-cs-availability').hide();
2132 nfSettings.resetTableSize();
2137 // settings refresh button
2138 $('#settings-refresh-button').click(function () {
2142 // create a new controller service or reporting task
2143 $('#new-service-or-task').on('click', function () {
2144 console.log("on Add Buttton clicked");
2145 var selectedTab = $('#settings-tabs li.selected-tab').text();
2146 if (selectedTab === 'Reporting Task Controller Services') {
2147 var controllerServicesUri = config.urls.api + '/controller/controller-services';
2148 nfControllerServices.promptNewControllerService(controllerServicesUri, getControllerServicesTable());
2149 } else if (selectedTab === 'Reporting Tasks') {
2150 $('#new-reporting-task-dialog').modal('show');
2152 var reportingTaskTypesGrid = $('#reporting-task-types-table').data('gridInstance');
2153 if (nfCommon.isDefinedAndNotNull(reportingTaskTypesGrid)) {
2154 var reportingTaskTypesData = reportingTaskTypesGrid.getData();
2156 // reset the canvas size after the dialog is shown
2157 reportingTaskTypesGrid.resizeCanvas();
2159 // select the first row if possible
2160 if (reportingTaskTypesData.getLength() > 0) {
2161 nfFilteredDialogCommon.choseFirstRow(reportingTaskTypesGrid);
2165 // set the initial focus
2166 $('#reporting-task-type-filter').focus();
2167 } else if (selectedTab === 'Registry Clients') {
2168 $('#registry-configuration-dialog').modal('setHeaderText', 'Add Registry Client').modal('setButtonModel', [{
2176 click: function () {
2181 buttonText: 'Cancel',
2188 click: function () {
2189 $(this).modal('hide');
2194 // set the initial focus
2195 $('#registry-name').focus();
2196 } else if (selectedTab === 'Distribution Target Environments') {
2197 $('#distribution-environment-dialog').modal('setHeaderText', 'Add New Environment').modal('setButtonModel', [{
2205 click: function () {
2206 addDistributionEnvironment();
2210 buttonText: 'Cancel',
2217 click: function () {
2218 $(this).modal('hide');
2223 $(window).resize(function() {
2226 $("#distribution-environment-content").text(x= x + 1);
2229 $(window).resize(function() {
2232 $("#distribution-environments-table").text(x= x + 1);
2234 console.log("resizing...table...");
2236 // set the initial focus
2237 $('#distribution-environment-name').focus();
2241 // initialize each tab
2243 nfControllerServices.init(getControllerServicesTable(), nfSettings.showSettings);
2244 initReportingTasks();
2245 initRegistriesTable();
2246 initDistributionEnvironmentsTable();
2250 * Update the size of the grid based on its container's current size.
2252 resetTableSize: function () {
2253 nfControllerServices.resetTableSize(getControllerServicesTable());
2254 nfControllerServices.resetTableSize(getDistributionEnvironmentsTable());
2256 var reportingTasksGrid = $('#reporting-tasks-table').data('gridInstance');
2257 if (nfCommon.isDefinedAndNotNull(reportingTasksGrid)) {
2258 reportingTasksGrid.resizeCanvas();
2263 * Shows the settings dialog.
2265 showSettings: function () {
2266 return loadSettings().done(showSettings);
2270 * Loads the settings dialogs.
2272 loadSettings: function () {
2273 return loadSettings();
2277 * Selects the specified controller service.
2279 * @param {string} controllerServiceId
2281 selectControllerService: function (controllerServiceId) {
2282 var controllerServiceGrid = getControllerServicesTable().data('gridInstance');
2283 var controllerServiceData = controllerServiceGrid.getData();
2285 // select the desired service
2286 var row = controllerServiceData.getRowById(controllerServiceId);
2287 nfFilteredDialogCommon.choseRow(controllerServiceGrid, row);
2288 controllerServiceGrid.scrollRowIntoView(row);
2290 // select the controller services tab
2291 $('#settings-tabs').find('li:eq(1)').click();
2295 * Selects the specified reporting task.
2297 * @param {string} reportingTaskId
2299 selectReportingTask: function (reportingTaskId) {
2300 var reportingTaskGrid = $('#reporting-tasks-table').data('gridInstance');
2301 var reportingTaskData = reportingTaskGrid.getData();
2303 // select the desired service
2304 var row = reportingTaskData.getRowById(reportingTaskId);
2305 nfFilteredDialogCommon.choseRow(reportingTaskGrid, row);
2306 reportingTaskGrid.scrollRowIntoView(row);
2308 // select the controller services tab
2309 $('#settings-tabs').find('li:eq(2)').click();
2313 * Sets the controller service and reporting task bulletins in their respective tables.
2315 * @param {object} controllerServiceBulletins
2316 * @param {object} reportingTaskBulletins
2318 setBulletins: function (controllerServiceBulletins, reportingTaskBulletins) {
2319 if ($('#controller-services-table').data('gridInstance')) {
2320 nfControllerServices.setBulletins(getControllerServicesTable(), controllerServiceBulletins);
2324 var reportingTasksGrid = $('#reporting-tasks-table').data('gridInstance');
2325 var reportingTasksData = reportingTasksGrid.getData();
2326 reportingTasksData.beginUpdate();
2328 // if there are some bulletins process them
2329 if (!nfCommon.isEmpty(reportingTaskBulletins)) {
2330 var reportingTaskBulletinsBySource = d3.nest()
2334 .map(reportingTaskBulletins, d3.map);
2336 reportingTaskBulletinsBySource.each(function (sourceBulletins, sourceId) {
2337 var reportingTask = reportingTasksData.getItemById(sourceId);
2338 if (nfCommon.isDefinedAndNotNull(reportingTask)) {
2339 reportingTasksData.updateItem(sourceId, $.extend(reportingTask, {
2340 bulletins: sourceBulletins
2345 // if there are no bulletins clear all
2346 var reportingTasks = reportingTasksData.getItems();
2347 $.each(reportingTasks, function (_, reportingTask) {
2348 reportingTasksData.updateItem(reportingTask.id, $.extend(reportingTask, {
2353 reportingTasksData.endUpdate();