Skip to content

Commit

Permalink
Merge pull request #85 from rosticos/issue-61
Browse files Browse the repository at this point in the history
Добавлен необязательный параметр default-context
  • Loading branch information
rpiontik authored Aug 26, 2022
2 parents d3b558d + f194845 commit 5a9df36
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 70 deletions.
99 changes: 49 additions & 50 deletions public/documentation/arch/aspects.yaml
Original file line number Diff line number Diff line change
@@ -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/Источники данных
1 change: 1 addition & 0 deletions public/documentation/docs/manual/aspects.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ aspects: # Архитектурные аспек
dochub.gitlab.auth:
title: Авторизация GitLab # Название аспекта
location: DocHub/Авторизация # Размещение аспекта в навигационном дереве
default-context: dochub.context # Значения контекста по-умолчанию (Необязательный)
...
```

Expand Down
11 changes: 6 additions & 5 deletions src/components/Architecture/Aspect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<tab-contexts
v-if="contexts.length"
style="width: 100%"
v-bind:default-context="defaultContext"
v-bind:contexts="contexts"
d-flex />
</v-flex>
Expand Down Expand Up @@ -118,18 +119,18 @@
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) || [];
},
summary() {
return (query.expression(query.summaryForAspect(this.aspect))
.evaluate(this.manifest) || []);
}
},
methods: {
goToLink() {
}
}
};
</script>
Expand Down
18 changes: 9 additions & 9 deletions src/components/Architecture/tabs/TabContext.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

<script>
import Schema from '../../Schema/Schema';
import Schema from '@/components/Schema/Schema.vue';
import query from '../../../manifest/query';
export default {
Expand All @@ -44,11 +44,12 @@
Schema
},
props: {
defaultContext: { type: Object, default: null },
contexts: { type: Array, default: () => ([]) }
},
data() {
return {
seleted : null,
selected : null,
currentContext: 0
};
},
Expand All @@ -66,22 +67,21 @@
},
context: {
get() {
return this.seleted ? this.seleted : (this.contexts[0]);
if (!this.selected) {
return this.defaultContext || this.contexts[0];
}
return this.selected;
},
set(value) {
this.seleted = value;
this.selected = value;
}
}
},
watch: {
contexts() {
this.seleted = null;
}
},
methods: {
goToLink() {
}
}
};
</script>
25 changes: 19 additions & 6 deletions src/manifest/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -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%}';
Expand Down Expand Up @@ -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();

Expand All @@ -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);
Expand All @@ -646,7 +656,7 @@ export default {
expression(expression, self_) {
const obj = {
expression,
core : null,
core: null,
onError: null, // Событие ошибки выполнения запроса
// Исполняет запрос
// context - контекст исполнения запроса
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
30 changes: 30 additions & 0 deletions tests/default-context-query.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
5 changes: 5 additions & 0 deletions tests/default/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ components:
test:
title: test
entity: component
aspects:
test-aspect:
title: test-aspect
location: test-aspect
default-context: default-context

0 comments on commit 5a9df36

Please sign in to comment.