aboutsummaryrefslogtreecommitdiff
path: root/src/new_fields/SchemaHeaderField.ts
diff options
context:
space:
mode:
authorSam Wilkins <samwilkins333@gmail.com>2019-07-30 03:49:18 -0400
committerSam Wilkins <samwilkins333@gmail.com>2019-07-30 03:49:18 -0400
commit79f47098381fef8e247ddb45ce56993669f218cb (patch)
treec7fb7e88586c2eba65ad0b5e8e2bf11a2c1b29cd /src/new_fields/SchemaHeaderField.ts
parent3152e69dfafe1c393bed38f3aad1e55881e62a33 (diff)
parente041988b84553797699a5a232e26e72252460e01 (diff)
successful implementation of different approach
Diffstat (limited to 'src/new_fields/SchemaHeaderField.ts')
-rw-r--r--src/new_fields/SchemaHeaderField.ts87
1 files changed, 87 insertions, 0 deletions
diff --git a/src/new_fields/SchemaHeaderField.ts b/src/new_fields/SchemaHeaderField.ts
new file mode 100644
index 000000000..d5da56b10
--- /dev/null
+++ b/src/new_fields/SchemaHeaderField.ts
@@ -0,0 +1,87 @@
+import { Deserializable } from "../client/util/SerializationHelper";
+import { serializable, createSimpleSchema, primitive } from "serializr";
+import { ObjectField } from "./ObjectField";
+import { Copy, ToScriptString, OnUpdate } from "./FieldSymbols";
+import { scriptingGlobal, Scripting } from "../client/util/Scripting";
+import { ColumnType } from "../client/views/collections/CollectionSchemaView";
+
+export const PastelSchemaPalette = new Map<string, string>([
+ ["pink1", "#FFB4E8"],
+ ["pink2", "#ff9cee"],
+ ["pink3", "#ffccf9"],
+ ["pink4", "#fcc2ff"],
+ ["pink5", "#f6a6ff"],
+ ["purple1", "#b28dff"],
+ ["purple2", "#c5a3ff"],
+ ["purple3", "#d5aaff"],
+ ["purple4", "#ecd4ff"],
+ ["purple5", "#fb34ff"],
+ ["purple6", "#dcd3ff"],
+ ["purple7", "#a79aff"],
+ ["purple8", "#b5b9ff"],
+ ["purple9", "#97a2ff"],
+ ["bluegreen1", "#afcbff"],
+ ["bluegreen2", "#aff8db"],
+ ["bluegreen3", "#c4faf8"],
+ ["bluegreen4", "#85e3ff"],
+ ["bluegreen5", "#ace7ff"],
+ ["bluegreen6", "#6eb5ff"],
+ ["bluegreen7", "#bffcc6"],
+ ["bluegreen8", "#dbffd6"],
+ ["yellow1", "#f3ffe3"],
+ ["yellow2", "#e7ffac"],
+ ["yellow3", "#ffffd1"],
+ ["yellow4", "#fff5ba"],
+ ["red1", "#ffc9de"],
+ ["red2", "#ffabab"],
+ ["red3", "#ffbebc"],
+ ["red4", "#ffcbc1"],
+]);
+
+export const RandomPastel = () => Array.from(PastelSchemaPalette.values())[Math.floor(Math.random() * PastelSchemaPalette.size)];
+
+@scriptingGlobal
+@Deserializable("schemaheader")
+export class SchemaHeaderField extends ObjectField {
+ @serializable(primitive())
+ heading: string;
+ color: string;
+ type: number;
+
+ constructor(heading: string = "", color?: string, type?: ColumnType) {
+ super();
+
+ this.heading = heading;
+ this.color = color === "" || color === undefined ? RandomPastel() : color;
+ if (type) {
+ this.type = type;
+ }
+ else {
+ this.type = 0;
+ }
+ }
+
+ setHeading(heading: string) {
+ this.heading = heading;
+ this[OnUpdate]();
+ }
+
+ setColor(color: string) {
+ this.color = color;
+ this[OnUpdate]();
+ }
+
+ setType(type: ColumnType) {
+ this.type = type;
+ this[OnUpdate]();
+ }
+
+ [Copy]() {
+ return new SchemaHeaderField(this.heading, this.color, this.type);
+ }
+
+ [ToScriptString]() {
+ return `invalid`;
+ }
+}
+