aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/DocServer.ts42
-rw-r--r--src/client/views/MainView.tsx7
-rw-r--r--src/server/Message.ts2
3 files changed, 43 insertions, 8 deletions
diff --git a/src/client/DocServer.ts b/src/client/DocServer.ts
index 652a9b701..b7b03f04c 100644
--- a/src/client/DocServer.ts
+++ b/src/client/DocServer.ts
@@ -7,11 +7,14 @@ import { RefField } from '../new_fields/RefField';
import { Id, HandleUpdate } from '../new_fields/FieldSymbols';
export namespace DocServer {
- const _cache: { [id: string]: RefField | Promise<Opt<RefField>> } = {};
+ let _cache: { [id: string]: RefField | Promise<Opt<RefField>> } = {};
const _socket = OpenSocket(`${window.location.protocol}//${window.location.hostname}:4321`);
const GUID: string = Utils.GenerateGuid();
+ let _isReadOnly = false;
export function makeReadOnly() {
+ if (_isReadOnly) return;
+ _isReadOnly = true;
_CreateField = field => {
_cache[field[Id]] = field;
};
@@ -19,6 +22,16 @@ export namespace DocServer {
_respondToUpdate = emptyFunction;
}
+ export function makeEditable() {
+ if (!_isReadOnly) return;
+ location.reload();
+ // _isReadOnly = false;
+ // _CreateField = _CreateFieldImpl;
+ // _UpdateField = _UpdateFieldImpl;
+ // _respondToUpdate = _respondToUpdateImpl;
+ // _cache = {};
+ }
+
export function prepend(extension: string): string {
return window.location.origin + extension;
}
@@ -27,6 +40,14 @@ export namespace DocServer {
Utils.Emit(_socket, MessageStore.DeleteAll, {});
}
+ export function DeleteDocument(id: string) {
+ Utils.Emit(_socket, MessageStore.DeleteField, id);
+ }
+
+ export function DeleteDocuments(ids: string[]) {
+ Utils.Emit(_socket, MessageStore.DeleteFields, ids);
+ }
+
export async function GetRefField(id: string): Promise<Opt<RefField>> {
let cached = _cache[id];
if (cached === undefined) {
@@ -97,29 +118,33 @@ export namespace DocServer {
return map;
}
- let _UpdateField = (id: string, diff: any) => {
+ function _UpdateFieldImpl(id: string, diff: any) {
if (id === updatingId) {
return;
}
Utils.Emit(_socket, MessageStore.UpdateField, { id, diff });
- };
+ }
+
+ let _UpdateField = _UpdateFieldImpl;
export function UpdateField(id: string, diff: any) {
_UpdateField(id, diff);
}
- let _CreateField = (field: RefField) => {
+ function _CreateFieldImpl(field: RefField) {
_cache[field[Id]] = field;
const initialState = SerializationHelper.Serialize(field);
Utils.Emit(_socket, MessageStore.CreateField, initialState);
- };
+ }
+
+ let _CreateField = _CreateFieldImpl;
export function CreateField(field: RefField) {
_CreateField(field);
}
let updatingId: string | undefined;
- let _respondToUpdate = (diff: any) => {
+ function _respondToUpdateImpl(diff: any) {
const id = diff.id;
if (id === undefined) {
return;
@@ -141,7 +166,10 @@ export namespace DocServer {
} else {
update(field);
}
- };
+ }
+
+ let _respondToUpdate = _respondToUpdateImpl;
+
function respondToUpdate(diff: any) {
_respondToUpdate(diff);
}
diff --git a/src/client/views/MainView.tsx b/src/client/views/MainView.tsx
index b37ba1cb0..dd07fdc3a 100644
--- a/src/client/views/MainView.tsx
+++ b/src/client/views/MainView.tsx
@@ -13,7 +13,7 @@ import { Id } from '../../new_fields/FieldSymbols';
import { InkTool } from '../../new_fields/InkField';
import { List } from '../../new_fields/List';
import { listSpec } from '../../new_fields/Schema';
-import { Cast, FieldValue, NumCast } from '../../new_fields/Types';
+import { Cast, FieldValue, NumCast, BoolCast } from '../../new_fields/Types';
import { CurrentUserUtils } from '../../server/authentication/models/current_user_utils';
import { RouteStore } from '../../server/RouteStore';
import { emptyFunction, returnOne, returnTrue } from '../../Utils';
@@ -194,6 +194,11 @@ export class MainView extends React.Component {
openWorkspace = async (doc: Doc, fromHistory = false) => {
CurrentUserUtils.MainDocId = doc[Id];
this.mainContainer = doc;
+ if (BoolCast(doc.readOnly)) {
+ DocServer.makeReadOnly();
+ } else {
+ DocServer.makeEditable();
+ }
fromHistory || HistoryUtil.pushState({ type: "doc", docId: doc[Id], initializers: {} });
const col = await Cast(CurrentUserUtils.UserDocument.optionalRightCollection, Doc);
// if there is a pending doc, and it has new data, show it (syip: we use a timeout to prevent collection docking view from being uninitialized)
diff --git a/src/server/Message.ts b/src/server/Message.ts
index e9a8b0f0c..19e0a48aa 100644
--- a/src/server/Message.ts
+++ b/src/server/Message.ts
@@ -45,4 +45,6 @@ export namespace MessageStore {
export const GetRefFields = new Message<string[]>("Get Ref Fields");
export const UpdateField = new Message<Diff>("Update Ref Field");
export const CreateField = new Message<Reference>("Create Ref Field");
+ export const DeleteField = new Message<string>("Delete field");
+ export const DeleteFields = new Message<string[]>("Delete fields");
}