UNPKG

@netgrif/components

Version:

Netgrif Application Engine frontend Angular components

95 lines 4.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.schematicEntryPoint = void 0; const schematics_1 = require("@angular-devkit/schematics"); const utility_functions_1 = require("../../_utility/utility-functions"); const view_utility_functions_1 = require("../_utility/view-utility-functions"); const view_class_info_1 = require("../../_commons/view-class-info"); const view_service_functions_1 = require("../_utility/view-service-functions"); function schematicEntryPoint() { return (tree) => { const naeConfig = (0, utility_functions_1.getNaeConfiguration)(tree); let arrayCreateSchematic = []; getSchematicArguments(tree, naeConfig.views).forEach(it => { arrayCreateSchematic.push((0, schematics_1.schematic)('create-view-prompt', it)); }); return (0, schematics_1.chain)(arrayCreateSchematic); }; } exports.schematicEntryPoint = schematicEntryPoint; function getSchematicArguments(tree, naeViews) { if (Object.keys(naeViews).length === 0) { return [emptyArguments()]; } const generatedViews = (0, view_service_functions_1.getGeneratedViewClassNames)(tree); const arrayMissingView = findMissingView(naeViews, generatedViews).filter(filterUndefined); return arrayMissingView.length === 0 ? [emptyArguments()] : arrayMissingView; } function filterUndefined(item) { return item.path !== undefined; } /** * Finds the first view that is declared in `nae.json` but was not yet generated in the app. * @param naeViews configuration holding all the views from one level and their children * @param generatedViews class names of views that have already been generated * @param pathPrefix web path prefix common to all views of the given level * @returns [CreateViewArguments]{@link CreateViewArguments} of the missing view. * Arguments will be empty (and thus a prompt will be displayed) if no missing views exist */ function findMissingView(naeViews, generatedViews, pathPrefix = '') { let arrayMissingView = []; for (const pathSegment of Object.keys(naeViews)) { const view = naeViews[pathSegment]; const viewPath = (0, view_utility_functions_1.constructRoutePath)(pathPrefix, pathSegment); if (viewPath === undefined) { throw new schematics_1.SchematicsException(`Please set viewPath! (PathSegment: ${pathSegment} )`); } if (view.layout === undefined && view.component === undefined) { throw new schematics_1.SchematicsException(`View must have either the 'layout' or the 'component' attribute defined! (Path: ${viewPath} )`); } if (!!view.layout) { if (view.layout.name === 'groupNavigation') { continue; } const viewClassInfo = new view_class_info_1.ViewClassInfo(viewPath, view.layout.name, view.layout.componentName); if (!generatedViews.has(viewClassInfo.className)) { arrayMissingView.push({ path: viewPath, viewType: view.layout.name, componentName: view.layout.componentName, layoutParams: view.layout.params, access: view.access, enableCaseTitle: view.layout.enableCaseTitle, isCaseTitleRequired: view.layout.isCaseTitleRequired, showDeleteMenu: view.layout.showDeleteMenu, confirmWorkflowDeletion: view.layout.confirmWorkflowDeletion }); } } else { if (view.component !== undefined && !generatedViews.has(view.component.class)) { arrayMissingView.push({ path: viewPath, viewType: 'customView', componentName: view.component.class, customImportPath: view.component.from, access: view.access }); } } if (!!view.children) { const result = findMissingView(view.children, generatedViews, viewPath); arrayMissingView.push(...result); } } return arrayMissingView; } function emptyArguments() { return { path: undefined, viewType: undefined, componentName: undefined, access: undefined }; } //# sourceMappingURL=schematic-create-view.js.map