/* * 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. * * Modifications to the original nifi code for the ONAP project are made * available under the Apache License, Version 2.0 */ /* 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.ControllerServices', 'nf.ErrorHandler', 'nf.FilteredDialogCommon', 'nf.ReportingTask', 'nf.Shell', 'nf.ComponentState', 'nf.ComponentVersion', 'nf.PolicyManagement'], function ($, Slick, d3, nfClient, nfDialog, nfStorage, nfCommon, nfCanvasUtils, nfControllerServices, nfErrorHandler, nfFilteredDialogCommon, nfReportingTask, nfShell, nfComponentState, nfComponentVersion, nfPolicyManagement) { return (nf.Settings = factory($, Slick, d3, nfClient, nfDialog, nfStorage, nfCommon, nfCanvasUtils, nfControllerServices, nfErrorHandler, nfFilteredDialogCommon, nfReportingTask, nfShell, nfComponentState, nfComponentVersion, nfPolicyManagement)); }); } else if (typeof exports === 'object' && typeof module === 'object') { module.exports = (nf.Settings = factory(require('jquery'), require('Slick'), require('d3'), require('nf.Client'), require('nf.Dialog'), require('nf.Storage'), require('nf.Common'), require('nf.CanvasUtils'), require('nf.ControllerServices'), require('nf.ErrorHandler'), require('nf.FilteredDialogCommon'), require('nf.ReportingTask'), require('nf.Shell'), require('nf.ComponentState'), require('nf.ComponentVersion'), require('nf.PolicyManagement'))); } else { nf.Settings = factory(root.$, root.Slick, root.d3, root.nf.Client, root.nf.Dialog, root.nf.Storage, root.nf.Common, root.nf.CanvasUtils, root.nf.ControllerServices, root.nf.ErrorHandler, root.nf.FilteredDialogCommon, root.nf.ReportingTask, root.nf.Shell, root.nf.ComponentState, root.nf.ComponentVersion, root.nf.PolicyManagement); } }(this, function ($, Slick, d3, nfClient, nfDialog, nfStorage, nfCommon, nfCanvasUtils, nfControllerServices, nfErrorHandler, nfFilteredDialogCommon, nfReportingTask, nfShell, nfComponentState, nfComponentVersion, nfPolicyManagement) { 'use strict'; var config = { urls: { api: '../nifi-api', controllerConfig: '../nifi-api/controller/config', reportingTaskTypes: '../nifi-api/flow/reporting-task-types', createReportingTask: '../nifi-api/controller/reporting-tasks', reportingTasks: '../nifi-api/flow/reporting-tasks', registries: '../nifi-api/controller/registry-clients' } }; var gridOptions = { forceFitColumns: true, enableTextSelectionOnCells: true, enableCellNavigation: true, enableColumnReorder: false, autoEdit: false, multiSelect: false, rowHeight: 24 }; var dcaeDistributorApiHostname; //get hostname $.ajax({ type: 'GET', url: '../nifi-api/flow/config', dataType: 'json', contentType: 'application/json', success: function(data){ dcaeDistributorApiHostname= data.flowConfiguration.dcaeDistributorApiHostname; console.log(dcaeDistributorApiHostname); } }); /** * Gets the controller services table. * * @returns {*|jQuery|HTMLElement} */ var getDistributionEnvironmentsTable = function () { return $('#distribution-environments-table'); }; /** * Gets the controller services table. * * @returns {*|jQuery|HTMLElement} */ var getControllerServicesTable = function () { return $('#controller-services-table'); }; /** * Saves the settings for the controller. * * @param version */ var saveSettings = function (version) { // marshal the configuration details var configuration = marshalConfiguration(); var entity = { 'revision': nfClient.getRevision({ 'revision': { 'version': version } }), 'disconnectedNodeAcknowledged': nfStorage.isDisconnectionAcknowledged(), 'component': configuration }; // save the new configuration details $.ajax({ type: 'PUT', url: config.urls.controllerConfig, data: JSON.stringify(entity), dataType: 'json', contentType: 'application/json' }).done(function (response) { // close the settings dialog nfDialog.showOkDialog({ headerText: 'Settings', dialogContent: 'Settings successfully applied.' }); // register the click listener for the save button $('#settings-save').off('click').on('click', function () { saveSettings(response.revision.version); }); }).fail(nfErrorHandler.handleAjaxError); } /** * Initializes the general tab. */ var initGeneral = function () { }; /** * Marshals the details to include in the configuration request. */ var marshalConfiguration = function () { // create the configuration var configuration = {}; configuration['maxTimerDrivenThreadCount'] = $('#maximum-timer-driven-thread-count-field').val(); configuration['maxEventDrivenThreadCount'] = $('#maximum-event-driven-thread-count-field').val(); return configuration; }; /** * Determines if the item matches the filter. * * @param {object} item The item to filter * @param {object} args The filter criteria * @returns {boolean} Whether the item matches the filter */ var matchesRegex = function (item, args) { if (args.searchString === '') { return true; } try { // perform the row filtering var filterExp = new RegExp(args.searchString, 'i'); } catch (e) { // invalid regex return false; } // determine if the item matches the filter var matchesLabel = item['label'].search(filterExp) >= 0; var matchesTags = item['tags'].search(filterExp) >= 0; return matchesLabel || matchesTags; }; /** * Determines if the specified tags match all the tags selected by the user. * * @argument {string[]} tagFilters The tag filters * @argument {string} tags The tags to test */ var matchesSelectedTags = function (tagFilters, tags) { var selectedTags = []; $.each(tagFilters, function (_, filter) { selectedTags.push(filter); }); // normalize the tags var normalizedTags = tags.toLowerCase(); var matches = true; $.each(selectedTags, function (i, selectedTag) { if (normalizedTags.indexOf(selectedTag) === -1) { matches = false; return false; } }); return matches; }; /** * Whether the specified item is selectable. * * @param item reporting task type */ var isSelectable = function (item) { return item.restricted === false || nfCommon.canAccessComponentRestrictions(item.explicitRestrictions); }; /** * 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 '' + nfCommon.escapeHtml(dataContext.id) + ''; } 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) { if (sortDetails.columnId === 'moreDetails') { var aBulletins = 0; if (!nfCommon.isEmpty(a.bulletins)) { aBulletins = a.bulletins.length; } var bBulletins = 0; if (!nfCommon.isEmpty(b.bulletins)) { bBulletins = b.bulletins.length; } return aBulletins - bBulletins; } else if (sortDetails.columnId === 'type') { var aType = nfCommon.isDefinedAndNotNull(a.component[sortDetails.columnId]) ? nfCommon.substringAfterLast(a.component[sortDetails.columnId], '.') : ''; var bType = nfCommon.isDefinedAndNotNull(b.component[sortDetails.columnId]) ? nfCommon.substringAfterLast(b.component[sortDetails.columnId], '.') : ''; return aType === bType ? 0 : aType > bType ? 1 : -1; } else if (sortDetails.columnId === 'state') { var aState; if (a.component.validationStatus === 'VALIDATING') { aState = 'Validating'; } else if (a.component.validationStatus === 'INVALID') { aState = 'Invalid'; } else { aState = nfCommon.isDefinedAndNotNull(a.component[sortDetails.columnId]) ? a.component[sortDetails.columnId] : ''; } var bState; if (b.component.validationStatus === 'VALIDATING') { bState = 'Validating'; } else if (b.component.validationStatus === 'INVALID') { bState = 'Invalid'; } else { bState = nfCommon.isDefinedAndNotNull(b.component[sortDetails.columnId]) ? b.component[sortDetails.columnId] : ''; } return aState === bState ? 0 : aState > bState ? 1 : -1; } else { 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); }; /** * Get the text out of the filter field. If the filter field doesn't * have any text it will contain the text 'filter list' so this method * accounts for that. */ var getReportingTaskTypeFilterText = function () { return $('#reporting-task-type-filter').val(); }; /** * Filters the reporting task type table. */ var applyReportingTaskTypeFilter = function () { // get the dataview var reportingTaskTypesGrid = $('#reporting-task-types-table').data('gridInstance'); // ensure the grid has been initialized if (nfCommon.isDefinedAndNotNull(reportingTaskTypesGrid)) { var reportingTaskTypesData = reportingTaskTypesGrid.getData(); // update the search criteria reportingTaskTypesData.setFilterArgs({ searchString: getReportingTaskTypeFilterText() }); reportingTaskTypesData.refresh(); // update the buttons to possibly trigger the disabled state $('#new-reporting-task-dialog').modal('refreshButtons'); // update the selection if possible if (reportingTaskTypesData.getLength() > 0) { nfFilteredDialogCommon.choseFirstRow(reportingTaskTypesGrid); } } }; /** * Hides the selected reporting task. */ var clearSelectedReportingTask = function () { $('#reporting-task-type-description').attr('title', '').text(''); $('#reporting-task-type-name').attr('title', '').text(''); $('#reporting-task-type-bundle').attr('title', '').text(''); $('#selected-reporting-task-name').text(''); $('#selected-reporting-task-type').text('').removeData('bundle'); $('#reporting-task-description-container').hide(); }; /** * Clears the selected reporting task type. */ var clearReportingTaskSelection = function () { // clear the selected row clearSelectedReportingTask(); // clear the active cell the it can be reselected when its included var reportingTaskTypesGrid = $('#reporting-task-types-table').data('gridInstance'); reportingTaskTypesGrid.resetActiveCell(); }; /** * Performs the filtering. * * @param {object} item The item subject to filtering * @param {object} args Filter arguments * @returns {Boolean} Whether or not to include the item */ var filterReportingTaskTypes = function (item, args) { // determine if the item matches the filter var matchesFilter = matchesRegex(item, args); // determine if the row matches the selected tags var matchesTags = true; if (matchesFilter) { var tagFilters = $('#reporting-task-tag-cloud').tagcloud('getSelectedTags'); var hasSelectedTags = tagFilters.length > 0; if (hasSelectedTags) { matchesTags = matchesSelectedTags(tagFilters, item['tags']); } } // determine if the row matches the selected source group var matchesGroup = true; if (matchesFilter && matchesTags) { var bundleGroup = $('#reporting-task-bundle-group-combo').combo('getSelectedOption'); if (nfCommon.isDefinedAndNotNull(bundleGroup) && bundleGroup.value !== '') { matchesGroup = (item.bundle.group === bundleGroup.value); } } // determine if this row should be visible var matches = matchesFilter && matchesTags && matchesGroup; // if this row is currently selected and its being filtered if (matches === false && $('#selected-reporting-task-type').text() === item['type']) { clearReportingTaskSelection(); } return matches; }; /** * Adds the currently selected reporting task. */ var addSelectedReportingTask = function () { var selectedTaskType = $('#selected-reporting-task-type').text(); var selectedTaskBundle = $('#selected-reporting-task-type').data('bundle'); // ensure something was selected if (selectedTaskType === '') { nfDialog.showOkDialog({ headerText: 'Settings', dialogContent: 'The type of reporting task to create must be selected.' }); } else { addReportingTask(selectedTaskType, selectedTaskBundle); } }; /** * Adds a new reporting task of the specified type. * * @param {string} reportingTaskType * @param {object} reportingTaskBundle */ var addReportingTask = function (reportingTaskType, reportingTaskBundle) { // build the reporting task entity var reportingTaskEntity = { 'revision': nfClient.getRevision({ 'revision': { 'version': 0 } }), 'disconnectedNodeAcknowledged': nfStorage.isDisconnectionAcknowledged(), 'component': { 'type': reportingTaskType, 'bundle': reportingTaskBundle } }; // add the new reporting task var addTask = $.ajax({ type: 'POST', url: config.urls.createReportingTask, data: JSON.stringify(reportingTaskEntity), dataType: 'json', contentType: 'application/json' }).done(function (reportingTaskEntity) { // add the item var reportingTaskGrid = $('#reporting-tasks-table').data('gridInstance'); var reportingTaskData = reportingTaskGrid.getData(); reportingTaskData.addItem($.extend({ type: 'ReportingTask', bulletins: [] }, reportingTaskEntity)); // resort reportingTaskData.reSort(); reportingTaskGrid.invalidate(); // select the new reporting task var row = reportingTaskData.getRowById(reportingTaskEntity.id); nfFilteredDialogCommon.choseRow(reportingTaskGrid, row); reportingTaskGrid.scrollRowIntoView(row); }).fail(nfErrorHandler.handleAjaxError); // hide the dialog $('#new-reporting-task-dialog').modal('hide'); return addTask; }; /** * Adds the specified entity. */ var addRegistry = function () { var registryEntity = { 'revision': nfClient.getRevision({ 'revision': { 'version': 0 } }), 'disconnectedNodeAcknowledged': nfStorage.isDisconnectionAcknowledged(), 'component': { 'name': $('#registry-name').val(), 'uri': $('#registry-location').val(), 'description': $('#registry-description').val() } }; // add the new registry var addRegistry = $.ajax({ type: 'POST', url: config.urls.registries, data: JSON.stringify(registryEntity), dataType: 'json', contentType: 'application/json' }).done(function (registryEntity) { // add the item var registriesGrid = $('#registries-table').data('gridInstance'); var registriesData = registriesGrid.getData(); registriesData.addItem($.extend({ type: 'Registry' }, registryEntity)); // resort registriesData.reSort(); registriesGrid.invalidate(); // select the new reporting task var row = registriesData.getRowById(registryEntity.id); nfFilteredDialogCommon.choseRow(registriesGrid, row); registriesGrid.scrollRowIntoView(row); }).fail(nfErrorHandler.handleAjaxError); // hide the dialog $('#registry-configuration-dialog').modal('hide'); return addRegistry; }; /** * Adds the specific environment. */ var addDistributionEnvironment= function () { var environmentEntity = { 'name': $('#distribution-environment-name').val(), 'runtimeApiUrl': $('#distribution-environment-location').val(), 'description': $('#distribution-environment-description').val() // 'nextDistributionTargetId': $('#distribution-environment-nextDistributionTargetId').val() }; console.log("before POST call "); console.log(environmentEntity); // add the new distribution environment var addDistributionEnvironment= $.ajax({ type: 'POST', url: dcaeDistributorApiHostname+'/distribution-targets', data: JSON.stringify(environmentEntity), dataType: 'json', contentType: 'application/json' }).done(function (environmentEntity) { // add the item console.log("after POST call in response "); console.log(environmentEntity); var environmentsGrid = $('#distribution-environments-table').data('gridInstance'); console.log(environmentsGrid); var environmentsData = environmentsGrid.getData(); environmentsData.addItem($.extend({ type: 'Environment' }, environmentEntity)); // resort environmentsData.reSort(); environmentsGrid.invalidate(); // select the new distribution env. var row = environmentsData.getRowById(environmentEntity.id); nfFilteredDialogCommon.choseRow(environmentsGrid, row); registriesGrid.scrollRowIntoView(row); }).fail(nfErrorHandler.handleAjaxError); // hide the dialog $('#distribution-environment-dialog').modal('hide'); return addDistributionEnvironment; }; /** * Updates the registry with the specified id. * * @param registryId */ var updateRegistry = function (registryId) { var registriesGrid = $('#registries-table').data('gridInstance'); var registriesData = registriesGrid.getData(); var registryEntity = registriesData.getItemById(registryId); var requestRegistryEntity = { 'revision': nfClient.getRevision(registryEntity), 'disconnectedNodeAcknowledged': nfStorage.isDisconnectionAcknowledged(), 'component': { 'id': registryId, 'name': $('#registry-name').val(), 'uri': $('#registry-location').val(), 'description': $('#registry-description').val() } }; // add the new reporting task var updateRegistry = $.ajax({ type: 'PUT', url: registryEntity.uri, data: JSON.stringify(requestRegistryEntity), dataType: 'json', contentType: 'application/json' }).done(function (registryEntity) { // add the item registriesData.updateItem(registryId, $.extend({ type: 'Registry' }, registryEntity)); }).fail(nfErrorHandler.handleAjaxError); // hide the dialog $('#registry-configuration-dialog').modal('hide'); return updateRegistry; }; /** * Updates the distribution environment with the specified id. * * @param environmentId */ var updateDistributionEnvironment = function (environmentId) { var environmentsGrid = $('#distribution-environments-table').data('gridInstance'); var environmentsData = environmentsGrid.getData(); var environmentEntity = environmentsData.getItemById(environmentId); var requestEnvironmentEntity = { 'id': environmentId, 'name': $('#distribution-environment-name').val(), 'runtimeApiUrl': $('#distribution-environment-location').val(), 'description': $('#distribution-environment-description').val(), // 'nextDistributionTargetId': $('#distribution-environment-nextDistributionTargetId').val() }; console.log(requestEnvironmentEntity); // updating distribution environment var updateDistributionEnvironment = $.ajax({ type: 'PUT', url: dcaeDistributorApiHostname+'/distribution-targets/'+environmentEntity.id, data: JSON.stringify(requestEnvironmentEntity), dataType: 'json', contentType: 'application/json' }).done(function (environmentEntity) { // update the item console.log(environmentsGrid); environmentsData.updateItem(environmentId, $.extend({ type: 'Environment' }, environmentEntity)); }).fail(nfErrorHandler.handleAjaxError); // hide the dialog $('#distribution-environment-dialog').modal('hide'); return updateDistributionEnvironment; }; /** * Initializes the new reporting task dialog. */ var initNewReportingTaskDialog = function () { // initialize the reporting task type table var reportingTaskTypesColumns = [ { id: 'type', name: 'Type', field: 'label', formatter: nfCommon.typeFormatter, sortable: true, resizable: true }, { id: 'version', name: 'Version', field: 'version', formatter: nfCommon.typeVersionFormatter, sortable: true, resizable: true }, { id: 'tags', name: 'Tags', field: 'tags', sortable: true, resizable: true, formatter: nfCommon.genericValueFormatter } ]; // initialize the dataview var reportingTaskTypesData = new Slick.Data.DataView({ inlineFilters: false }); reportingTaskTypesData.setItems([]); reportingTaskTypesData.setFilterArgs({ searchString: getReportingTaskTypeFilterText() }); reportingTaskTypesData.setFilter(filterReportingTaskTypes); // initialize the sort nfCommon.sortType({ columnId: 'type', sortAsc: true }, reportingTaskTypesData); // initialize the grid var reportingTaskTypesGrid = new Slick.Grid('#reporting-task-types-table', reportingTaskTypesData, reportingTaskTypesColumns, gridOptions); reportingTaskTypesGrid.setSelectionModel(new Slick.RowSelectionModel()); reportingTaskTypesGrid.registerPlugin(new Slick.AutoTooltips()); reportingTaskTypesGrid.setSortColumn('type', true); reportingTaskTypesGrid.onSort.subscribe(function (e, args) { nfCommon.sortType({ columnId: args.sortCol.field, sortAsc: args.sortAsc }, reportingTaskTypesData); }); reportingTaskTypesGrid.onSelectedRowsChanged.subscribe(function (e, args) { if ($.isArray(args.rows) && args.rows.length === 1) { var reportingTaskTypeIndex = args.rows[0]; var reportingTaskType = reportingTaskTypesGrid.getDataItem(reportingTaskTypeIndex); // set the reporting task type description if (nfCommon.isDefinedAndNotNull(reportingTaskType)) { // show the selected reporting task $('#reporting-task-description-container').show(); if (nfCommon.isBlank(reportingTaskType.description)) { $('#reporting-task-type-description') .attr('title', '') .html('No description specified'); } else { $('#reporting-task-type-description') .width($('#reporting-task-description-container').innerWidth() - 1) .html(reportingTaskType.description) .ellipsis(); } var bundle = nfCommon.formatBundle(reportingTaskType.bundle); var type = nfCommon.formatType(reportingTaskType); // populate the dom $('#reporting-task-type-name').text(type).attr('title', type); $('#reporting-task-type-bundle').text(bundle).attr('title', bundle); $('#selected-reporting-task-name').text(reportingTaskType.label); $('#selected-reporting-task-type').text(reportingTaskType.type).data('bundle', reportingTaskType.bundle); // refresh the buttons based on the current selection $('#new-reporting-task-dialog').modal('refreshButtons'); } } }); reportingTaskTypesGrid.onDblClick.subscribe(function (e, args) { var reportingTaskType = reportingTaskTypesGrid.getDataItem(args.row); if (isSelectable(reportingTaskType)) { addReportingTask(reportingTaskType.type, reportingTaskType.bundle); } }); reportingTaskTypesGrid.onViewportChanged.subscribe(function (e, args) { nfCommon.cleanUpTooltips($('#reporting-task-types-table'), 'div.view-usage-restriction'); }); // wire up the dataview to the grid reportingTaskTypesData.onRowCountChanged.subscribe(function (e, args) { reportingTaskTypesGrid.updateRowCount(); reportingTaskTypesGrid.render(); // update the total number of displayed processors $('#displayed-reporting-task-types').text(args.current); }); reportingTaskTypesData.onRowsChanged.subscribe(function (e, args) { reportingTaskTypesGrid.invalidateRows(args.rows); reportingTaskTypesGrid.render(); }); reportingTaskTypesData.syncGridSelection(reportingTaskTypesGrid, true); // hold onto an instance of the grid $('#reporting-task-types-table').data('gridInstance', reportingTaskTypesGrid).on('mouseenter', 'div.slick-cell', function (e) { var usageRestriction = $(this).find('div.view-usage-restriction'); if (usageRestriction.length && !usageRestriction.data('qtip')) { var rowId = $(this).find('span.row-id').text(); // get the status item var item = reportingTaskTypesData.getItemById(rowId); // show the tooltip if (item.restricted === true) { var restrictionTip = $('
'); if (nfCommon.isBlank(item.usageRestriction)) { restrictionTip.append($('').text('Requires the following permissions:')); } else { restrictionTip.append($('').text(item.usageRestriction + ' Requires the following permissions:')); } var restrictions = []; if (nfCommon.isDefinedAndNotNull(item.explicitRestrictions)) { $.each(item.explicitRestrictions, function (_, explicitRestriction) { var requiredPermission = explicitRestriction.requiredPermission; restrictions.push("'" + requiredPermission.label + "' - " + nfCommon.escapeHtml(explicitRestriction.explanation)); }); } else { restrictions.push('Access to restricted components regardless of restrictions.'); } restrictionTip.append(nfCommon.formatUnorderedList(restrictions)); usageRestriction.qtip($.extend({}, nfCommon.config.tooltipConfig, { content: restrictionTip, position: { container: $('#summary'), at: 'bottom right', my: 'top left', adjust: { x: 4, y: 4 } } })); } } }); var generalRestriction = nfCommon.getPolicyTypeListing('restricted-components'); // load the available reporting tasks $.ajax({ type: 'GET', url: config.urls.reportingTaskTypes, dataType: 'json' }).done(function (response) { var id = 0; var tags = []; var groups = d3.set(); var restrictedUsage = d3.map(); var requiredPermissions = d3.map(); // begin the update reportingTaskTypesData.beginUpdate(); // go through each reporting task type $.each(response.reportingTaskTypes, function (i, documentedType) { if (documentedType.restricted === true) { if (nfCommon.isDefinedAndNotNull(documentedType.explicitRestrictions)) { $.each(documentedType.explicitRestrictions, function (_, explicitRestriction) { var requiredPermission = explicitRestriction.requiredPermission; // update required permissions if (!requiredPermissions.has(requiredPermission.id)) { requiredPermissions.set(requiredPermission.id, requiredPermission.label); } // update component restrictions if (!restrictedUsage.has(requiredPermission.id)) { restrictedUsage.set(requiredPermission.id, []); } restrictedUsage.get(requiredPermission.id).push({ type: nfCommon.formatType(documentedType), bundle: nfCommon.formatBundle(documentedType.bundle), explanation: nfCommon.escapeHtml(explicitRestriction.explanation) }) }); } else { // update required permissions if (!requiredPermissions.has(generalRestriction.value)) { requiredPermissions.set(generalRestriction.value, generalRestriction.text); } // update component restrictions if (!restrictedUsage.has(generalRestriction.value)) { restrictedUsage.set(generalRestriction.value, []); } restrictedUsage.get(generalRestriction.value).push({ type: nfCommon.formatType(documentedType), bundle: nfCommon.formatBundle(documentedType.bundle), explanation: nfCommon.escapeHtml(documentedType.usageRestriction) }); } } // record the group groups.add(documentedType.bundle.group); // add the documented type reportingTaskTypesData.addItem({ id: id++, label: nfCommon.substringAfterLast(documentedType.type, '.'), type: documentedType.type, bundle: documentedType.bundle, description: nfCommon.escapeHtml(documentedType.description), restricted: documentedType.restricted, usageRestriction: nfCommon.escapeHtml(documentedType.usageRestriction), explicitRestrictions: documentedType.explicitRestrictions, tags: documentedType.tags.join(', ') }); // count the frequency of each tag for this type $.each(documentedType.tags, function (i, tag) { tags.push(tag.toLowerCase()); }); }); // end the update reportingTaskTypesData.endUpdate(); // resort reportingTaskTypesData.reSort(); reportingTaskTypesGrid.invalidate(); // set the component restrictions and the corresponding required permissions nfCanvasUtils.addComponentRestrictions(restrictedUsage, requiredPermissions); // set the total number of processors $('#total-reporting-task-types, #displayed-reporting-task-types').text(response.reportingTaskTypes.length); // create the tag cloud $('#reporting-task-tag-cloud').tagcloud({ tags: tags, select: applyReportingTaskTypeFilter, remove: applyReportingTaskTypeFilter }); // build the combo options var options = [{ text: 'all groups', value: '' }]; groups.each(function (group) { options.push({ text: group, value: group }); }); // initialize the bundle group combo $('#reporting-task-bundle-group-combo').combo({ options: options, select: applyReportingTaskTypeFilter }); }).fail(nfErrorHandler.handleAjaxError); var navigationKeys = [$.ui.keyCode.UP, $.ui.keyCode.PAGE_UP, $.ui.keyCode.DOWN, $.ui.keyCode.PAGE_DOWN]; // define the function for filtering the list $('#reporting-task-type-filter').off('keyup').on('keyup', function (e) { var code = e.keyCode ? e.keyCode : e.which; // ignore navigation keys if ($.inArray(code, navigationKeys) !== -1) { return; } if (code === $.ui.keyCode.ENTER) { var selected = reportingTaskTypesGrid.getSelectedRows(); if (selected.length > 0) { // grid configured with multi-select = false var item = reportingTaskTypesGrid.getDataItem(selected[0]); if (isSelectable(item)) { addSelectedReportingTask(); } } } else { applyReportingTaskTypeFilter(); } }); // setup row navigation nfFilteredDialogCommon.addKeydownListener('#reporting-task-type-filter', reportingTaskTypesGrid, reportingTaskTypesGrid.getData()); // initialize the reporting task dialog $('#new-reporting-task-dialog').modal({ scrollableContentStyle: 'scrollable', headerText: 'Add Reporting Task', buttons: [{ buttonText: 'Add', color: { base: '#728E9B', hover: '#004849', text: '#ffffff' }, disabled: function () { var selected = reportingTaskTypesGrid.getSelectedRows(); if (selected.length > 0) { // grid configured with multi-select = false var item = reportingTaskTypesGrid.getDataItem(selected[0]); return isSelectable(item) === false; } else { return reportingTaskTypesGrid.getData().getLength() === 0; } }, handler: { click: function () { addSelectedReportingTask(); } } }, { buttonText: 'Cancel', color: { base: '#E3E8EB', hover: '#C7D2D7', text: '#004849' }, handler: { click: function () { $(this).modal('hide'); } } }], handler: { close: function () { // clear the selected row clearSelectedReportingTask(); // clear any filter strings $('#reporting-task-type-filter').val(''); // clear the tagcloud $('#reporting-task-tag-cloud').tagcloud('clearSelectedTags'); // reset the group combo $('#reporting-task-bundle-group-combo').combo('setSelectedOption', { value: '' }); // reset the filter applyReportingTaskTypeFilter(); // unselect any current selection var reportingTaskTypesGrid = $('#reporting-task-types-table').data('gridInstance'); reportingTaskTypesGrid.setSelectedRows([]); reportingTaskTypesGrid.resetActiveCell(); }, resize: function () { $('#reporting-task-type-description') .width($('#reporting-task-description-container').innerWidth() - 1) .text($('#reporting-task-type-description').attr('title')) .ellipsis(); } } }); // initialize the registry configuration dialog $('#registry-configuration-dialog').modal({ scrollableContentStyle: 'scrollable', handler: { close: function () { $('#registry-id').text(''); $('#registry-name').val(''); $('#registry-location').val(''); $('#registry-description').val(''); } } }); // initialize the distribution environment dialog $('#distribution-environment-dialog').modal({ scrollableContentStyle: 'scrollable', handler: { close: function () { $('#distribution-environment-id').text(''); $('#distribution-environment-name').val(''); $('#distribution-environment-location').val(''); $('#distribution-environment-description').val(''); // $('#distribution-environment-nextDistributionTargetId').val(''); } } }); }; /** * Initializes the reporting tasks tab. */ var initReportingTasks = function () { // initialize the new reporting task dialog initNewReportingTaskDialog(); var moreReportingTaskDetails = function (row, cell, value, columnDef, dataContext) { if (!dataContext.permissions.canRead) { return ''; } var markup = ''; // always include a button to view the usage markup += ''; var hasErrors = !nfCommon.isEmpty(dataContext.component.validationErrors); var hasBulletins = !nfCommon.isEmpty(dataContext.bulletins); if (hasErrors) { markup += ''; } if (hasBulletins) { markup += ''; } if (hasErrors || hasBulletins) { markup += '' + nfCommon.escapeHtml(dataContext.component.id) + ''; } return markup; }; var reportingTaskRunStatusFormatter = function (row, cell, value, columnDef, dataContext) { // determine the appropriate label var icon = '', label = ''; if (dataContext.status.validationStatus === 'VALIDATING') { icon = 'validating fa fa-spin fa-circle-notch'; label = 'Validating'; } else if (dataContext.status.validationStatus === 'INVALID') { icon = 'invalid fa fa-warning'; label = 'Invalid'; } else { if (dataContext.status.runStatus === 'STOPPED') { label = 'Stopped'; icon = 'fa fa-stop stopped'; } else if (dataContext.status.runStatus === 'RUNNING') { label = 'Running'; icon = 'fa fa-play running'; } else { label = 'Disabled'; icon = 'icon icon-enable-false disabled'; } } // include the active thread count if appropriate var activeThreadCount = ''; if (nfCommon.isDefinedAndNotNull(dataContext.status.activeThreadCount) && dataContext.status.activeThreadCount > 0) { activeThreadCount = '(' + dataContext.status.activeThreadCount + ')'; } // format the markup var formattedValue = '