@atomist/sdm-pack-aspect
Version:
an Atomist SDM Extension Pack for visualizing drift across an organization
85 lines • 4.09 kB
JavaScript
;
/*
* 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.
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const _ = require("lodash");
function aspectReportDetailsOf(type, workspaceId, details, aspectRegistry) {
return __awaiter(this, void 0, void 0, function* () {
if (!details[type]) {
details[type] = (yield aspectRegistry.reportDetailsOf(type, workspaceId)) || {};
}
return details[type];
});
}
function getAspectReports(fus, aspectRegistry, workspaceId) {
return __awaiter(this, void 0, void 0, function* () {
const aspects = aspectRegistry.aspects;
const reports = [];
const categories = [];
const loadedDetails = {};
for (const fu of fus) {
for (const f of fu.fingerprints) {
const details = yield aspectReportDetailsOf(f.type, workspaceId, loadedDetails, aspectRegistry);
f.details = details;
categories.push(details.category);
}
}
_.uniq(categories.filter(c => !!c)).forEach(k => {
const fu = fus.filter(f => f.fingerprints.map(fp => fp.details.category).includes(k));
if (fu.length > 0) {
const allFps = _.uniqBy(_.flatten(fu.map(f => f.fingerprints))
.filter(fp => fp.details.category === k), "type");
reports.push({
category: k,
count: fu.length,
aspects: _.uniqBy(allFps.map(f => {
const rd = f.details;
return {
name: (aspectRegistry.aspectOf(f.type) || {}).displayName || rd.displayName,
type: (aspectRegistry.aspectOf(f.type) || {}).name || rd.name,
description: rd.description,
shortName: rd.shortName,
unit: rd.unit,
url: `/api/v1/${workspaceId}/${rd.url}`,
manage: rd.manage !== undefined ? rd.manage : true,
};
}), "url")
.sort((r1, r2) => {
const i1 = aspects.findIndex(r => r.name === r1.type);
const i2 = aspects.findIndex(r => r.name === r2.type);
return i1 - i2;
}),
});
}
});
return reports.sort((r1, r2) => {
const i1 = aspects.filter(a => a.details).findIndex(r => r.details.category === r1.category);
const i2 = aspects.filter(a => a.details).findIndex(r => r.details.category === r2.category);
return i1 - i2;
});
});
}
exports.getAspectReports = getAspectReports;
//# sourceMappingURL=categories.js.map