From 1a6687f4710296e59249bdce1b6fc7f6c2e7ebb1 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Mon, 15 Feb 2021 09:33:44 +0900 Subject: [PATCH] Add label model --- frontend/models/label.ts | 48 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 frontend/models/label.ts diff --git a/frontend/models/label.ts b/frontend/models/label.ts new file mode 100644 index 00000000..112d41bb --- /dev/null +++ b/frontend/models/label.ts @@ -0,0 +1,48 @@ +export class LabelItemList { + constructor(public labelItems: LabelItem[]) {} + + static valueOf(items: LabelItem[]): LabelItemList { + return new LabelItemList(items) + } + + get nameList(): string[] { + return this.labelItems.map(item => item.name) + } + + toArray(): Object[] { + return this.labelItems.map(item => item.toObject()) + } +} + +export class LabelItem { + constructor( + public id: number, + public text: string, + public prefixKey: string, + public suffixKey: string, + public backgroundColor: string, + public textColor: string + ) {} + + static valueOf( + { id, text, prefix_key, suffix_key, background_color, text_color }: + { id: number, text: string, prefix_key: string, suffix_key: string, background_color: string, text_color: string } + ): LabelItem { + return new LabelItem(id, text, prefix_key, suffix_key, background_color, text_color) + } + + get name(): string { + return this.text + } + + toObject(): Object { + return { + id: this.id, + text: this.text, + prefixKey: this.prefixKey, + suffixKey: this.suffixKey, + backgroundColor: this.backgroundColor, + textColor: this.textColor + } + } +}