From 360cf7046bf017fc0e69cb764a9c03d1f096e764 Mon Sep 17 00:00:00 2001 From: mderler Date: Fri, 22 Sep 2023 22:59:20 +0000 Subject: [PATCH 1/3] Add Command type & Factory --- src/App.vue | 25 ++++++++++++++----------- src/commands/command.factory.ts | 13 +++++++++++++ src/commands/command.ts | 3 +++ src/commands/type-filter.command.ts | 13 +++++++++++++ 4 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 src/commands/command.factory.ts create mode 100644 src/commands/command.ts create mode 100644 src/commands/type-filter.command.ts diff --git a/src/App.vue b/src/App.vue index 79cd976..2df8b84 100644 --- a/src/App.vue +++ b/src/App.vue @@ -3,6 +3,7 @@ import axios from 'axios' import InputBar from './components/InputBar.vue' import ValuesDisplay from './components/ValuesDisplay.vue' import TypesDisplay from './components/TypesDisplay.vue' +import CommandFactory from './commands/command.factory' import { ValueType } from './scripts/value_type' import { Value } from './scripts/value' @@ -14,9 +15,9 @@ export default { return { values: new Array(), value_types: new Array(), - filter_start : '', - filter_end : '', - filter_type : '' + filter_start: '', + filter_end: '', + filter_type: '' } }, mounted() { @@ -38,16 +39,18 @@ export default { }, update_search(args: string[]) { console.log('New search arguemnts', args) - this.filter_end='' - this.filter_start='' - this.filter_type='' + this.filter_end = '' + this.filter_start = '' + this.filter_type = '' + const commandFactory = new CommandFactory() for (var i = 0; i < args.length; i++) { - const command = args[i] - console.log('handling command', command) + console.log('handling command', args[i]) const command_and_args = args[i].split(':') if (command_and_args.length == 2) { const key = command_and_args[0] const value = command_and_args[1] + const command = commandFactory.getCommand(key) + command.execute(value) if (key == 'type') { this.filter_type = this.getTypeId(value) console.log('Update typeid', this.filter_type) @@ -60,7 +63,7 @@ export default { continue } } - console.log('Ignoring command', command) + console.log('Ignoring command', args[i]) } this.get_values().then((result) => { this.values = result @@ -79,7 +82,7 @@ export default { get_values() { const promise = new Promise((accept, reject) => { const url = '/api/value/' - var params : { [key: string]: string } = {} + var params: { [key: string]: string } = {} if (this.filter_type != '') { params['type_id'] = this.filter_type } @@ -87,7 +90,7 @@ export default { params['end'] = this.filter_end } if (this.filter_start != '') { - params['start']=this.filter_start + params['start'] = this.filter_start } console.log('Trying to get url', url) axios diff --git a/src/commands/command.factory.ts b/src/commands/command.factory.ts new file mode 100644 index 0000000..0704cf5 --- /dev/null +++ b/src/commands/command.factory.ts @@ -0,0 +1,13 @@ +import type Command from './command' +import TypeFilterCommand from './type-filter.command' + +class CommandFactory { + private static readonly register: Record Command> = { type: TypeFilterCommand } + + public getCommand(command: string) { + const cmd = CommandFactory.register[command] + return new cmd() + } +} + +export default CommandFactory diff --git a/src/commands/command.ts b/src/commands/command.ts new file mode 100644 index 0000000..b8de1f4 --- /dev/null +++ b/src/commands/command.ts @@ -0,0 +1,3 @@ +export default interface Command { + execute(arg: unknown): void +} diff --git a/src/commands/type-filter.command.ts b/src/commands/type-filter.command.ts new file mode 100644 index 0000000..f822c66 --- /dev/null +++ b/src/commands/type-filter.command.ts @@ -0,0 +1,13 @@ +import type Command from './command' + +class TypeFilterCommand implements Command { + execute(arg: unknown): void { + if (typeof arg != 'string') { + throw new TypeError() + } + + console.log(arg) + } +} + +export default TypeFilterCommand From 2bcd6ce25d1b247d285884b84a11783038132e91 Mon Sep 17 00:00:00 2001 From: mderler Date: Sun, 24 Sep 2023 21:10:10 +0000 Subject: [PATCH 2/3] Add type filter command --- src/App.vue | 106 +++++++--------------------- src/commands/command.factory.ts | 23 +++--- src/commands/command.ts | 7 +- src/commands/type-filter.command.ts | 15 ++-- src/main.ts | 2 +- src/stores/value-type.store.ts | 31 ++++++++ src/stores/value.store.ts | 24 +++++++ src/types/url-paras.type.ts | 1 + 8 files changed, 108 insertions(+), 101 deletions(-) create mode 100644 src/stores/value-type.store.ts create mode 100644 src/stores/value.store.ts create mode 100644 src/types/url-paras.type.ts diff --git a/src/App.vue b/src/App.vue index 2df8b84..7851bc3 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,110 +1,53 @@