From 35cb61f0d93983464b29152f159d09ea6bd4edf9 Mon Sep 17 00:00:00 2001 From: Tyler Schicke Date: Wed, 7 Aug 2019 21:37:14 -0400 Subject: Mostly have field level read only working --- src/client/DocServer.ts | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'src/client/DocServer.ts') diff --git a/src/client/DocServer.ts b/src/client/DocServer.ts index 87a87be92..5af89cf49 100644 --- a/src/client/DocServer.ts +++ b/src/client/DocServer.ts @@ -1,6 +1,6 @@ import * as OpenSocket from 'socket.io-client'; import { MessageStore, Diff, YoutubeQueryTypes } from "./../server/Message"; -import { Opt } from '../new_fields/Doc'; +import { Opt, Doc } from '../new_fields/Doc'; import { Utils, emptyFunction } from '../Utils'; import { SerializationHelper } from './util/SerializationHelper'; import { RefField } from '../new_fields/RefField'; @@ -26,6 +26,38 @@ export namespace DocServer { let GUID: string; // indicates whether or not a document is currently being udpated, and, if so, its id + export enum WriteMode { + Always = 0, + None = 1, + SameUser = 2, + } + + const fieldWriteModes: { [field: string]: WriteMode } = {}; + const docsWithUpdates: { [field: string]: Doc[] } = {}; + + export function setFieldWriteMode(field: string, writeMode: WriteMode) { + fieldWriteModes[field] = writeMode; + if (writeMode === WriteMode.Always) { + const docs = docsWithUpdates[field]; + if (docs) { + docs.forEach(doc => Doc.RunCachedUpdate(doc, field)); + delete docsWithUpdates[field]; + } + } + } + + export function getFieldWriteMode(field: string) { + return fieldWriteModes[field]; + } + + export function registerDocWithCachedUpdate(doc: Doc, field: string) { + let list = docsWithUpdates[field]; + if (!list) { + list = docsWithUpdates[field] = []; + } + list.push(doc); + } + export function init(protocol: string, hostname: string, port: number, identifier: string) { _cache = {}; GUID = identifier; -- cgit v1.2.3-70-g09d2 From 68f613b5e762649b743059e494e9307eb103ff0d Mon Sep 17 00:00:00 2001 From: Tyler Schicke Date: Thu, 8 Aug 2019 16:15:22 -0400 Subject: Fixed per field write modes --- src/client/DocServer.ts | 11 +++++++---- src/client/views/MainView.tsx | 17 ++++++++--------- src/new_fields/Doc.ts | 12 ++++++++++-- src/new_fields/util.ts | 2 +- 4 files changed, 26 insertions(+), 16 deletions(-) (limited to 'src/client/DocServer.ts') diff --git a/src/client/DocServer.ts b/src/client/DocServer.ts index 5af89cf49..977eb7772 100644 --- a/src/client/DocServer.ts +++ b/src/client/DocServer.ts @@ -33,7 +33,7 @@ export namespace DocServer { } const fieldWriteModes: { [field: string]: WriteMode } = {}; - const docsWithUpdates: { [field: string]: Doc[] } = {}; + const docsWithUpdates: { [field: string]: Set } = {}; export function setFieldWriteMode(field: string, writeMode: WriteMode) { fieldWriteModes[field] = writeMode; @@ -50,12 +50,15 @@ export namespace DocServer { return fieldWriteModes[field]; } - export function registerDocWithCachedUpdate(doc: Doc, field: string) { + export function registerDocWithCachedUpdate(doc: Doc, field: string, oldValue: any) { let list = docsWithUpdates[field]; if (!list) { - list = docsWithUpdates[field] = []; + list = docsWithUpdates[field] = new Set; + } + if (!list.has(doc)) { + Doc.AddCachedUpdate(doc, field, oldValue); + list.add(doc); } - list.push(doc); } export function init(protocol: string, hostname: string, port: number, identifier: string) { diff --git a/src/client/views/MainView.tsx b/src/client/views/MainView.tsx index ddb023aca..7629a0906 100644 --- a/src/client/views/MainView.tsx +++ b/src/client/views/MainView.tsx @@ -435,6 +435,7 @@ export class MainView extends React.Component { } + private mode: DocServer.WriteMode = DocServer.WriteMode.Always; @observable private _colorPickerDisplay = false; /* for the expandable add nodes menu. Not included with the miscbuttons because once it expands it expands the whole div with it, making canvas interactions limited. */ nodesMenu() { @@ -479,15 +480,13 @@ export class MainView extends React.Component { )}
  • -
  • +
  • )}
  • -
  • +
  • +
  • +
  • +