UNPKG

@netgrif/components

Version:

Netgrif Application Engine frontend Angular components

57 lines 2.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addViewToNaeJson = void 0; const schematics_1 = require("@angular-devkit/schematics"); const utility_functions_1 = require("../../_utility/utility-functions"); function addViewToNaeJson(createViewArguments) { return (tree) => { const naeJsonContent = (0, utility_functions_1.getNaeConfiguration)(tree); const pathSegments = (createViewArguments.path).split('/'); const lastPathSegment = pathSegments[pathSegments.length - 1]; if (pathSegments.length === 1) { if (naeJsonContent.views === undefined) { naeJsonContent.views = {}; } if (naeJsonContent.views[lastPathSegment] === undefined) { naeJsonContent.views[lastPathSegment] = createViewObject(createViewArguments, lastPathSegment); } } else { let parentRoute = naeJsonContent.views[pathSegments[0]]; for (let i = 1; i < pathSegments.length - 1; i++) { if (parentRoute.children !== undefined) { parentRoute = parentRoute.children[pathSegments[i]]; } else { // else cannot happen because that would mean this object doesn't have a parent view // such cases end with error in create-view-prompt schematic // the if is necessary because of the strict typescript compiler throw new schematics_1.SchematicsException('Illegal state. View must have all parent views defined.'); } } if (parentRoute.children === undefined) { parentRoute.children = {}; } if (parentRoute.children[lastPathSegment] === undefined) { parentRoute.children[lastPathSegment] = createViewObject(createViewArguments, lastPathSegment); } } tree.overwrite('nae.json', JSON.stringify(naeJsonContent, null, 4)); return tree; }; } exports.addViewToNaeJson = addViewToNaeJson; function createViewObject(createViewArguments, lastPathSegment) { return { layout: { name: createViewArguments.viewType, params: (createViewArguments.layoutParams === undefined) ? {} : createViewArguments.layoutParams }, access: createViewArguments.access, navigation: true, routing: { path: lastPathSegment } }; } //# sourceMappingURL=add-view-to-nae-json.js.map