From d2ec862ad60f0501a5184f9d424cc5db07b998b0 Mon Sep 17 00:00:00 2001 From: Tyler Schicke Date: Mon, 6 May 2019 17:26:45 -0400 Subject: Added author and creation date --- src/client/documents/Documents.ts | 8 ++++++++ src/client/views/nodes/FieldView.tsx | 3 +++ src/new_fields/DateField.ts | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 src/new_fields/DateField.ts (limited to 'src') diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts index 8706359e4..37d263e75 100644 --- a/src/client/documents/Documents.ts +++ b/src/client/documents/Documents.ts @@ -33,6 +33,7 @@ import { listSpec } from "../../new_fields/Schema"; import { DocServer } from "../DocServer"; import { StrokeData, InkField } from "../../new_fields/InkField"; import { dropActionType } from "../util/DragManager"; +import { DateField } from "../../new_fields/DateField"; export interface DocumentOptions { x?: number; @@ -168,6 +169,13 @@ export namespace Docs { function CreateInstance(proto: Doc, data: Field, options: DocumentOptions) { const { omit: protoProps, extract: delegateProps } = OmitKeys(options, delegateKeys); + if (!("author" in protoProps)) { + protoProps.author = CurrentUserUtils.email; + } + if (!("creationDate" in protoProps)) { + protoProps.creationDate = new DateField; + } + return SetDelegateOptions(SetInstanceOptions(proto, protoProps, data), delegateProps); } diff --git a/src/client/views/nodes/FieldView.tsx b/src/client/views/nodes/FieldView.tsx index a1e083b36..613c24fa4 100644 --- a/src/client/views/nodes/FieldView.tsx +++ b/src/client/views/nodes/FieldView.tsx @@ -17,6 +17,7 @@ import { List } from "../../../new_fields/List"; import { ImageField, VideoField, AudioField } from "../../../new_fields/URLField"; import { IconField } from "../../../new_fields/IconField"; import { RichTextField } from "../../../new_fields/RichTextField"; +import { DateField } from "../../../new_fields/DateField"; // @@ -77,6 +78,8 @@ export class FieldView extends React.Component { } else if (field instanceof AudioField) { return ; + } else if (field instanceof DateField) { + return

{field.date.toLocaleString()}

; } else if (field instanceof Doc) { return ( diff --git a/src/new_fields/DateField.ts b/src/new_fields/DateField.ts new file mode 100644 index 000000000..c0a79f267 --- /dev/null +++ b/src/new_fields/DateField.ts @@ -0,0 +1,18 @@ +import { Deserializable } from "../client/util/SerializationHelper"; +import { serializable, date } from "serializr"; +import { ObjectField, Copy } from "./ObjectField"; + +@Deserializable("date") +export class DateField extends ObjectField { + @serializable(date()) + readonly date: Date; + + constructor(date: Date = new Date()) { + super(); + this.date = date; + } + + [Copy]() { + return new DateField(this.date); + } +} -- cgit v1.2.3-70-g09d2