Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulBredl committed Nov 28, 2023
1 parent 66b4ceb commit 8acc2d7
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 16 deletions.
3 changes: 1 addition & 2 deletions meta_configurator/src/components/code-editor/AceEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import 'brace/theme/clouds';
import 'brace/theme/ambiance';
import 'brace/theme/monokai';
import {watchImmediate} from '@vueuse/core';
import {useSettingsStore} from '@/store/settingsStore';
import {setupAnnotationsFromValidationErrors} from '@/components/code-editor/setupAnnotations';
import {setupLinkToCurrentSelection} from '@/components/code-editor/setupLinkToSelection';
import {useSettings} from '@/settings/useSettings';
Expand Down Expand Up @@ -58,7 +57,7 @@ function setupAceProperties(editor: Editor) {
// ace editor starts flashing and becomes unusable
window.setTimeout(() => {
watchImmediate(
() => useSettingsStore().settingsData.codeEditor.fontSize,
() => useSettings().codeEditor.fontSize,
fontSize => {
if (editor && fontSize && fontSize > 6 && fontSize < 65) {
editor.setFontSize(fontSize.toString() + 'px');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import type {ConfigDataTreeNodeType, GuiEditorTreeNode} from '@/model/configDataTreeNode';
import {TreeNodeType} from '@/model/configDataTreeNode';
import type {Path, PathElement} from '@/model/path';
import {useSettingsStore} from '@/store/settingsStore';
import {NUMBER_OF_PROPERTY_TYPES} from '@/model/jsonSchemaType';
import {useSessionStore} from '@/store/sessionStore';
import {ref} from 'vue';
Expand All @@ -13,6 +12,7 @@ import {pathToString} from '@/utility/pathUtils';
import {FontAwesomeIcon} from '@fortawesome/vue-fontawesome';
import 'primeicons/primeicons.css';
import {focus, makeEditableAndSelectContents} from '@/utility/focusUtils';
import {useSettings} from '@/settings/useSettings';

const props = defineProps<{
node: GuiEditorTreeNode;
Expand Down Expand Up @@ -66,8 +66,7 @@ function isDeprecated(): boolean {
* depending on if the maximum depth has been reached or not.
*/
function onPressEnter() {
const settingsStore = useSettingsStore();
if (props.node.data.depth === settingsStore.settingsData.guiEditor.maximumDepth) {
if (props.node.data.depth === useSettings().guiEditor.maximumDepth) {
zoomIntoPath();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import type {
} from '@/model/configDataTreeNode';
import {TreeNodeType} from '@/model/configDataTreeNode';
import type {Path} from '@/model/path';
import {useSettingsStore} from '@/store/settingsStore';
import {pathToString} from '@/utility/pathUtils';
import {PropertySorting} from '@/model/settingsTypes';
import {useSessionStore} from '@/store/sessionStore';
Expand All @@ -15,6 +14,7 @@ import type {EffectiveSchema} from '@/schema/effectiveSchemaCalculator';
import {calculateEffectiveSchema} from '@/schema/effectiveSchemaCalculator';
import {safeMergeSchemas} from '@/schema/mergeAllOfs';
import {useCurrentDataLink} from '@/data/useDataLink';
import {useSettings} from '@/settings/useSettings';

interface TreeNodeResolvingParameters {
absolutePath: Path;
Expand Down Expand Up @@ -86,7 +86,7 @@ export class ConfigTreeNodeResolver {
return (
(!dependsOnUserSelection && data && typeof data !== 'object') || // primitive type in data
(!schema.hasType('object') && !schema.hasType('array')) || // primitive type in schema
depth >= useSettingsStore().settingsData.guiEditor.maximumDepth // maximum depth reached
depth >= useSettings().guiEditor.maximumDepth // maximum depth reached
);
}

Expand Down Expand Up @@ -126,7 +126,7 @@ export class ConfigTreeNodeResolver {
effectiveSchema: EffectiveSchema,
depth = 0
): GuiEditorTreeNode[] {
const depthLimit = useSettingsStore().settingsData.guiEditor.maximumDepth;
const depthLimit = useSettings().guiEditor.maximumDepth;
const schema = effectiveSchema.schema;

let children: GuiEditorTreeNode[] = [];
Expand Down Expand Up @@ -163,7 +163,7 @@ export class ConfigTreeNodeResolver {
* in the settings.
*/
private createObjectChildrenTreeNodes(parameters: TreeNodeResolvingParameters) {
const propertySorting = useSettingsStore().settingsData.guiEditor.propertySorting;
const propertySorting = useSettings().guiEditor.propertySorting;
let result: GuiEditorTreeNode[] = [];

if (propertySorting === PropertySorting.SCHEMA_ORDER) {
Expand Down
4 changes: 2 additions & 2 deletions meta_configurator/src/components/toolbar/downloadFile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {useSettingsStore} from '@/store/settingsStore';
import {useCurrentDataLink} from '@/data/useDataLink';
import {useSettings} from '@/settings/useSettings';

/**
* Downloads the current config file as a JSON or YAML file.
Expand All @@ -22,7 +22,7 @@ export function downloadFile(fileNamePrefix: string): void {
second: '2-digit',
});
const formattedDate = formatter.format(now);
const fileEnding = useSettingsStore().settingsData.dataFormat === 'yaml' ? 'yml' : 'json';
const fileEnding = useSettings().dataFormat === 'yaml' ? 'yml' : 'json';
const fileName: string = `${fileNamePrefix}-${formattedDate}.${fileEnding}`;

// Create a temporary link element
Expand Down
5 changes: 2 additions & 3 deletions meta_configurator/src/components/toolbar/menuItems.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {openUploadSchemaDialog} from '@/components/toolbar/uploadSchema';
import {openUploadFileDialog} from '@/components/toolbar/uploadFile';
import {downloadFile} from '@/components/toolbar/downloadFile';
import {useDataStore} from '@/store/dataStore';
import {openClearFileDialog} from '@/components/toolbar/clearFile';
import {openClearSchemaDialog} from '@/components/toolbar/clearSchema';
import {SessionMode, useSessionStore} from '@/store/sessionStore';
Expand Down Expand Up @@ -58,7 +57,7 @@ export class MenuItems {
{
label: 'Download File',
icon: 'fa-solid fa-download',
command: () => downloadFile(useDataStore().schema.title ?? 'file'),
command: () => downloadFile(useCurrentDataLink().schema.title ?? 'file'),
},
{
separator: true,
Expand Down Expand Up @@ -135,7 +134,7 @@ export class MenuItems {
{
label: 'Download Schema',
icon: 'fa-solid fa-download',
command: () => downloadFile('schema_' + useDataStore().schema.title ?? 'untitled'),
command: () => downloadFile('schema_' + useCurrentDataLink().schema.title ?? 'untitled'),
},
{
separator: true,
Expand Down
4 changes: 2 additions & 2 deletions meta_configurator/src/store/sessionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const useSessionStore = defineStore('sessionStore', () => {
});

/**
* Update the validation service when the page changes.
* Reset the current selected element and expanded elements when the mode changes.
*/
watch(
currentMode,
Expand Down Expand Up @@ -159,14 +159,14 @@ export const useSessionStore = defineStore('sessionStore', () => {
const schema = currentEffectiveSchema.schema.subSchema(key);

if (schema?.oneOf) {
// TODO not working yet
const oneOfSelection = currentSelectedOneOfOptions.value.get(pathToString(currentPath));
if (oneOfSelection !== undefined) {
currentEffectiveSchema = calculateEffectiveSchema(
schema.oneOf[oneOfSelection.index],
useCurrentDataLink().dataAt(currentPath),
currentPath
);
continue;
}
}

Expand Down

0 comments on commit 8acc2d7

Please sign in to comment.