From f194845e5abafed0e6cc82f3fa512a146c491074 Mon Sep 17 00:00:00 2001 From: rskabali Date: Fri, 26 Aug 2022 11:20:58 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BD=D0=B5=D0=BE=D0=B1=D1=8F=D0=B7=D0=B0=D1=82=D0=B5?= =?UTF-8?q?=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC?= =?UTF-8?q?=D0=B5=D1=82=D1=80=20default-context?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/documentation/arch/aspects.yaml | 99 +++++++++---------- public/documentation/docs/manual/aspects.md | 1 + src/components/Architecture/Aspect.vue | 11 ++- .../Architecture/tabs/TabContext.vue | 18 ++-- src/manifest/query.js | 25 +++-- tests/default-context-query.test.js | 30 ++++++ tests/default/schema.yaml | 5 + 7 files changed, 119 insertions(+), 70 deletions(-) create mode 100644 tests/default-context-query.test.js diff --git a/public/documentation/arch/aspects.yaml b/public/documentation/arch/aspects.yaml index 34896469..c96d50c7 100755 --- a/public/documentation/arch/aspects.yaml +++ b/public/documentation/arch/aspects.yaml @@ -1,50 +1,49 @@ -aspects: # Архитектурные аспекты - dochub: - title: DocHub - location: DocHub - dochub.git: - title: Git - location: DocHub/Git - dochub.git.client: - title: Развитие репы - location: DocHub/GitLab/Git-клиент - dochub.gitlab: - title: GitLab - location: DocHub/GitLab - dochub.gitlab.auth: - title: Авторизация GitLab - location: DocHub/GitLab/Авторизация - dochub.umlrender: - title: Рендеринг PlantUML - location: DocHub/Рендеринг/PlantUML - dochub.contexts: - title: Рендеринг контекстов - location: DocHub/Рендеринг/Контексты - dochub.aspects: - title: Рендеринг аспектов - location: DocHub/Рендеринг/Аспекты - dochub.docs: - title: Рендеринг документов - location: DocHub/Рендеринг/Документы - dochub.navigation: - title: Навигация по архитектуре - location: DocHub/Навигация по архитектуре - dochub.radar: - title: Технологический радар - location: DocHub/Технологический радар - dochub.cache: - title: Кэш данных - location: DocHub/Кэш - dochub.manifest: - title: Манифесты - location: DocHub/Манифесты - dochub.manifest.storage: - title: Хранилище манифестов - location: DocHub/Манифесты/Хранилище манифестов - dochub.manifest.parsing: - title: Парсинг манифестов - location: DocHub/Манифесты/Парсинг манифестов - dochub.dataset: - title: Источники данных - location: DocHub/Источники данных - +aspects: # Архитектурные аспекты + dochub: + title: DocHub + location: DocHub + dochub.git: + title: Git + location: DocHub/Git + dochub.git.client: + title: Развитие репы + location: DocHub/GitLab/Git-клиент + dochub.gitlab: + title: GitLab + location: DocHub/GitLab + dochub.gitlab.auth: + title: Авторизация GitLab + location: DocHub/GitLab/Авторизация + dochub.umlrender: + title: Рендеринг PlantUML + location: DocHub/Рендеринг/PlantUML + dochub.contexts: + title: Рендеринг контекстов + location: DocHub/Рендеринг/Контексты + dochub.aspects: + title: Рендеринг аспектов + location: DocHub/Рендеринг/Аспекты + dochub.docs: + title: Рендеринг документов + location: DocHub/Рендеринг/Документы + dochub.navigation: + title: Навигация по архитектуре + location: DocHub/Навигация по архитектуре + dochub.radar: + title: Технологический радар + location: DocHub/Технологический радар + dochub.cache: + title: Кэш данных + location: DocHub/Кэш + dochub.manifest: + title: Манифесты + location: DocHub/Манифесты + dochub.manifest.storage: + title: Хранилище манифестов + location: DocHub/Манифесты/Хранилище манифестов + dochub.manifest.parsing: + title: Парсинг манифестов + location: DocHub/Манифесты/Парсинг манифестов + dochub.dataset: + title: Источники данных + location: DocHub/Источники данных diff --git a/public/documentation/docs/manual/aspects.md b/public/documentation/docs/manual/aspects.md index 67552561..3a0d7b7a 100644 --- a/public/documentation/docs/manual/aspects.md +++ b/public/documentation/docs/manual/aspects.md @@ -10,6 +10,7 @@ aspects: # Архитектурные аспек dochub.gitlab.auth: title: Авторизация GitLab # Название аспекта location: DocHub/Авторизация # Размещение аспекта в навигационном дереве + default-context: dochub.context # Значения контекста по-умолчанию (Необязательный) ... ``` diff --git a/src/components/Architecture/Aspect.vue b/src/components/Architecture/Aspect.vue index 9293b59b..4fc97a1c 100644 --- a/src/components/Architecture/Aspect.vue +++ b/src/components/Architecture/Aspect.vue @@ -54,6 +54,7 @@ @@ -118,6 +119,11 @@ components() { return query.expression(query.componentsForAspects(this.aspect)).evaluate(this.manifest) || []; }, + defaultContext() { + const contextId = query.expression(query.defaultContextForAspect(this.aspect)).evaluate(this.manifest); + + return contextId ? this.contexts.find(i => i.id === contextId) : null; + }, contexts() { return query.expression(query.contextsForAspects(this.aspect)).evaluate(this.manifest) || []; }, @@ -125,11 +131,6 @@ return (query.expression(query.summaryForAspect(this.aspect)) .evaluate(this.manifest) || []); } - }, - methods: { - goToLink() { - - } } }; diff --git a/src/components/Architecture/tabs/TabContext.vue b/src/components/Architecture/tabs/TabContext.vue index 14f5d025..8300df44 100644 --- a/src/components/Architecture/tabs/TabContext.vue +++ b/src/components/Architecture/tabs/TabContext.vue @@ -35,7 +35,7 @@ diff --git a/src/manifest/query.js b/src/manifest/query.js index 0151d5aa..6ebfdb41 100644 --- a/src/manifest/query.js +++ b/src/manifest/query.js @@ -432,6 +432,16 @@ const SUMMARY_ASPECT_QUERY = ` ) `; +const ASPECT_DEFAULT_CONTEXT = ` +( + $ASPECT_ID := '{%ASPECT%}'; + $MANIFEST := $; + $lookup(aspects, $ASPECT_ID).( + $.'default-context' + ) +) +`; + const ASPECT_LOCATIONS_QUERY = ` ( $ASPECT_ID := '{%ASPECT%}'; @@ -609,7 +619,7 @@ function mergeDeep(sources) { function isObject(item) { return (item && typeof item === 'object' && !Array.isArray(item)); } - + if (!sources.length) return target; const source = sources.shift(); @@ -629,7 +639,7 @@ function mergeDeep(sources) { } function jsonSchema(schema) { - const rules = new ajv({allErrors: true}); + const rules = new ajv({ allErrors: true }); const validator = rules.compile(schema); return (data) => { const isOk = validator(data); @@ -646,7 +656,7 @@ export default { expression(expression, self_) { const obj = { expression, - core : null, + core: null, onError: null, // Событие ошибки выполнения запроса // Исполняет запрос // context - контекст исполнения запроса @@ -659,13 +669,13 @@ export default { this.core.registerFunction('wcard', wcard); this.core.registerFunction('mergedeep', mergeDeep); this.core.registerFunction('jsonschema', jsonSchema); - } + } return Object.freeze(this.core.evaluate(context)); - } catch(e) { + } catch (e) { // eslint-disable-next-line no-console console.error('JSONata error:'); // eslint-disable-next-line no-console - console.log(this.expression.slice(0, e.position) + '%c' + this.expression.slice(e.position), 'color:red' ); + console.log(this.expression.slice(0, e.position) + '%c' + this.expression.slice(e.position), 'color:red'); // eslint-disable-next-line no-console console.error(e); this.onError && this.onError(e); @@ -709,6 +719,9 @@ export default { summaryForAspect(aspect) { return SUMMARY_ASPECT_QUERY.replace(/{%ASPECT%}/g, aspect); }, + defaultContextForAspect(aspect) { + return ASPECT_DEFAULT_CONTEXT.replace(/{%ASPECT%}/g, aspect); + }, // Определение размещения манифестов описывающих аспект locationsForAspect(aspect) { return ASPECT_LOCATIONS_QUERY.replace(/{%ASPECT%}/g, aspect); diff --git a/tests/default-context-query.test.js b/tests/default-context-query.test.js new file mode 100644 index 00000000..f758c132 --- /dev/null +++ b/tests/default-context-query.test.js @@ -0,0 +1,30 @@ +import DefaultSchema from './default/schema.json'; +import Query from '../src/manifest/query'; +import YAML from 'yaml'; + +test('Forms object to schema', () => { + const query = YAML.parse(` + test-aspect: + title: test-aspect + location: test-aspect + default-context: default-context + `); + + DefaultSchema.aspects = query; + const evaluated = Query.expression(Query.defaultContextForAspect('test-aspect')).evaluate(DefaultSchema); + + expect(evaluated).toEqual('default-context'); +}); + +test('Forms object to schema', () => { + const query = YAML.parse(` + test-aspect: + title: test-aspect + location: test-aspect + `); + + DefaultSchema.aspects = query; + const evaluated = Query.expression(Query.defaultContextForAspect('test-aspect')).evaluate(DefaultSchema); + + expect(evaluated).toEqual(undefined); +}); diff --git a/tests/default/schema.yaml b/tests/default/schema.yaml index 03454cc9..9c7e83f1 100644 --- a/tests/default/schema.yaml +++ b/tests/default/schema.yaml @@ -8,3 +8,8 @@ components: test: title: test entity: component +aspects: + test-aspect: + title: test-aspect + location: test-aspect + default-context: default-context \ No newline at end of file