UNPKG

@atomist/sdm-pack-aspect

Version:

an Atomist SDM Extension Pack for visualizing drift across an organization

65 lines 2.6 kB
"use strict"; /* * Copyright © 2019 Atomist, Inc. * * Licensed 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. */ Object.defineProperty(exports, "__esModule", { value: true }); const _ = require("lodash"); const AspectCategories = {}; const AspectReportDetails = []; /** * Store a categories for a given Aspects */ function registerCategories(aspect, ...categories) { AspectCategories[aspect.name] = categories; } exports.registerCategories = registerCategories; /** * Store a details for a given Aspects */ function registerReportDetails(aspect, details = {}) { AspectReportDetails.push(Object.assign({ name: aspect.displayName, type: aspect.name, description: `Details about the ${aspect.displayName} aspect`, url: `filter/aspectReport?type=${aspect.name}`, manage: true }, details)); } exports.registerReportDetails = registerReportDetails; /** * Retrieve categories or undefined for a given Aspect */ function getCategories(aspect) { return AspectCategories[aspect.name]; } exports.getCategories = getCategories; function getAspectReports(fus, workspaceId) { const reports = []; const categories = _.uniq(_.flatten(_.values(AspectCategories))); categories.forEach(k => { const fu = fus.filter(f => (f.categories || []).includes(k)); if (fu.length > 0) { reports.push({ category: k, count: fu.length, aspects: _.uniqBy(fu.filter(f => !!AspectReportDetails.some(a => a.type === f.type)).map(f => { const rd = AspectReportDetails.find(a => a.type === f.type); return Object.assign({}, rd, { url: `/api/v1/${workspaceId}/${rd.url}` }); }), "url").sort((r1, r2) => { const i1 = AspectReportDetails.findIndex(r => r.type === r1.type); const i2 = AspectReportDetails.findIndex(r => r.type === r2.type); return i1 - i2; }), }); } }); return reports; } exports.getAspectReports = getAspectReports; //# sourceMappingURL=categories.js.map