aboutsummaryrefslogtreecommitdiff
path: root/src/fields/Doc.ts
diff options
context:
space:
mode:
authorusodhi <61431818+usodhi@users.noreply.github.com>2020-11-17 19:28:30 +0530
committerusodhi <61431818+usodhi@users.noreply.github.com>2020-11-17 19:28:30 +0530
commit86408e6d93fbe6501694371736fe74b81ed39cf3 (patch)
tree17b89a6209c66284f89e2636a8157435ce1045c0 /src/fields/Doc.ts
parenta002e0e5c5910f78c8f3910ad4101386d30ebf70 (diff)
parent28dccafaa4aa446dd88c1b6f4218a0d7f79fa1bb (diff)
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into acls_uv
Diffstat (limited to 'src/fields/Doc.ts')
-rw-r--r--src/fields/Doc.ts22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/fields/Doc.ts b/src/fields/Doc.ts
index 1a062fa3b..4c3c45d92 100644
--- a/src/fields/Doc.ts
+++ b/src/fields/Doc.ts
@@ -25,6 +25,7 @@ import JSZip = require("jszip");
import { saveAs } from "file-saver";
import { CollectionDockingView } from "../client/views/collections/CollectionDockingView";
import { SelectionManager } from "../client/util/SelectionManager";
+import { DocumentView } from "../client/views/nodes/DocumentView";
export namespace Field {
export function toKeyValueString(doc: Doc, key: string): string {
@@ -91,6 +92,7 @@ export const AclAddonly = Symbol("AclAddonly");
export const AclEdit = Symbol("AclEdit");
export const AclAdmin = Symbol("AclAdmin");
export const UpdatingFromServer = Symbol("UpdatingFromServer");
+export const ForceServerWrite = Symbol("ForceServerWrite");
export const CachedUpdates = Symbol("Cached updates");
const AclMap = new Map<string, symbol>([
@@ -184,9 +186,10 @@ export class Doc extends RefField {
@observable public [AclSym]: { [key: string]: symbol };
private [UpdatingFromServer]: boolean = false;
+ private [ForceServerWrite]: boolean = false;
private [Update] = (diff: any) => {
- !this[UpdatingFromServer] && DocServer.UpdateField(this[Id], diff);
+ (!this[UpdatingFromServer] || this[ForceServerWrite]) && DocServer.UpdateField(this[Id], diff);
}
private [Self] = this;
@@ -679,7 +682,7 @@ export namespace Doc {
templateLayoutDoc.resolvedDataDoc && (templateLayoutDoc = Cast(templateLayoutDoc.proto, Doc, null) || templateLayoutDoc); // if the template has already been applied (ie, a nested template), then use the template's prototype
if (!targetDoc[expandedLayoutFieldKey]) {
_pendingMap.set(targetDoc[Id] + expandedLayoutFieldKey + args, true);
- setTimeout(() => {
+ setTimeout(action(() => {
const newLayoutDoc = Doc.MakeDelegate(templateLayoutDoc, undefined, "[" + templateLayoutDoc.title + "]");
// the template's arguments are stored in params which is derefenced to find
// the actual field key where the parameterized template data is stored.
@@ -693,7 +696,7 @@ export namespace Doc {
targetDoc[expandedLayoutFieldKey] = newLayoutDoc;
_pendingMap.delete(targetDoc[Id] + expandedLayoutFieldKey + args);
- });
+ }));
}
}
}
@@ -882,6 +885,15 @@ export namespace Doc {
export function SetLayout(doc: Doc, layout: Doc | string) { doc[StrCast(doc.layoutKey, "layout")] = layout; }
export function LayoutField(doc: Doc) { return doc[StrCast(doc.layoutKey, "layout")]; }
export function LayoutFieldKey(doc: Doc): string { return StrCast(Doc.Layout(doc).layout).split("'")[1]; }
+ export function NativeAspect(doc: Doc, dataDoc?: Doc, useDim?: boolean) {
+ return Doc.NativeWidth(doc, dataDoc, useDim) / (Doc.NativeHeight(doc, dataDoc, useDim) || 1);
+ }
+ export function NativeWidth(doc?: Doc, dataDoc?: Doc, useWidth?: boolean) { return !doc ? 0 : NumCast(doc._nativeWidth, NumCast((dataDoc || doc)[Doc.LayoutFieldKey(doc) + "-nativeWidth"], useWidth ? doc[WidthSym]() : 0)); }
+ export function NativeHeight(doc?: Doc, dataDoc?: Doc, useHeight?: boolean) { return !doc ? 0 : NumCast(doc._nativeHeight, NumCast((dataDoc || doc)[Doc.LayoutFieldKey(doc) + "-nativeHeight"], useHeight ? doc[HeightSym]() : 0)); }
+ export function SetNativeWidth(doc: Doc, width: number | undefined) { doc[Doc.LayoutFieldKey(doc) + "-nativeWidth"] = width; }
+ export function SetNativeHeight(doc: Doc, height: number | undefined) { doc[Doc.LayoutFieldKey(doc) + "-nativeHeight"] = height; }
+
+
const manager = new DocData();
export function SearchQuery(): string { return manager._searchQuery; }
export function SetSearchQuery(query: string) { runInAction(() => manager._searchQuery = query); }
@@ -1086,14 +1098,14 @@ export namespace Doc {
export function toggleNativeDimensions(layoutDoc: Doc, contentScale: number, panelWidth: number, panelHeight: number) {
runInAction(() => {
- if (layoutDoc._nativeWidth || layoutDoc._nativeHeight) {
+ if (Doc.NativeWidth(layoutDoc) || Doc.NativeHeight(layoutDoc)) {
layoutDoc._viewScale = NumCast(layoutDoc._viewScale, 1) * contentScale;
layoutDoc._nativeWidth = undefined;
layoutDoc._nativeHeight = undefined;
}
else {
layoutDoc._autoHeight = false;
- if (!layoutDoc._nativeWidth) {
+ if (!Doc.NativeWidth(layoutDoc)) {
layoutDoc._nativeWidth = NumCast(layoutDoc._width, panelWidth);
layoutDoc._nativeHeight = NumCast(layoutDoc._height, panelHeight);
}