aboutsummaryrefslogtreecommitdiff
path: root/src/client/util/CurrentUserUtils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/util/CurrentUserUtils.ts')
-rw-r--r--src/client/util/CurrentUserUtils.ts118
1 files changed, 63 insertions, 55 deletions
diff --git a/src/client/util/CurrentUserUtils.ts b/src/client/util/CurrentUserUtils.ts
index afb1442bf..7a38886fe 100644
--- a/src/client/util/CurrentUserUtils.ts
+++ b/src/client/util/CurrentUserUtils.ts
@@ -74,16 +74,16 @@ export class CurrentUserUtils {
@observable public static headerBarHeight: number = 0;
@observable public static searchPanelWidth: number = 0;
- static AssignScripts(doc:Doc, scripts?:{ [key: string]: string;}, functions?:{[key:string]: string}) {
+ static AssignScripts(doc:Doc, scripts?:{ [key: string]: string;}, funcs?:{[key:string]: string}) {
scripts && Object.keys(scripts).map(key => {
if (ScriptCast(doc[key])?.script.originalScript !== scripts[key] && scripts[key]) {
doc[key] = ScriptField.MakeScript(scripts[key], { dragData: DragManager.DocumentDragData.name, value:"any", scriptContext: "any" }, {"_readOnly_": true});
}
});
- functions && Object.keys(functions).map(key => {
+ funcs && Object.keys(funcs).map(key => {
const cfield = ComputedField.WithoutComputed(() => FieldValue(doc[key]));
- if (ScriptCast(cfield)?.script.originalScript !== functions[key] && functions[key]) {
- doc[key] = ComputedField.MakeFunction(functions[key], { dragData: DragManager.DocumentDragData.name }, {"_readOnly_": true});
+ if (ScriptCast(cfield)?.script.originalScript !== funcs[key] && funcs[key]) {
+ doc[key] = ComputedField.MakeFunction(funcs[key], { dragData: DragManager.DocumentDragData.name }, {"_readOnly_": true});
}
});
return doc;
@@ -180,14 +180,14 @@ export class CurrentUserUtils {
}
/// Initializes collection of templates for notes and click functions
- static setupDocTemplates(doc: Doc) {
+ static setupDocTemplates(doc: Doc, field="myTemplates") {
const templates = [
CurrentUserUtils.setupNoteTemplates(doc),
CurrentUserUtils.setupClickEditorTemplates(doc)
];
const reqdOpts = { title: "template layouts", _xMargin: 0, system: true, };
const reqdScripts = { dropConverter: "convertToButtons(dragData)" };
- return this.AssignScripts(this.AssignOpts(DocCast(doc.templateDocs), reqdOpts, templates) ?? (doc.templateDocs = Docs.Create.TreeDocument(templates, reqdOpts)), reqdScripts);
+ return this.AssignScripts(this.AssignOpts(DocCast(doc[field]), reqdOpts, templates) ?? (doc[field] = Docs.Create.TreeDocument(templates, reqdOpts)), reqdScripts);
}
// setup templates for different document types when they are iconified from Document Decorations
@@ -329,7 +329,7 @@ export class CurrentUserUtils {
static setupCreatorButtons(doc: Doc, dragCreatorDoc?:Doc):Doc {
const creatorBtns = CurrentUserUtils.creatorBtnDescriptors(doc).map((reqdOpts) => {
const btn = dragCreatorDoc ? DocListCast(dragCreatorDoc.data).find(doc => doc.title === reqdOpts.title): undefined;
- const opts:DocumentOptions = {...OmitKeys(reqdOpts, ["backgroundColor"]).omit,
+ const opts:DocumentOptions = {...OmitKeys(reqdOpts, ["funcs", "scripts", "backgroundColor"]).omit,
_nativeWidth: 50, _nativeHeight: 50, _width: 35, _height: 35, _hideContextMenu: true, _stayInCollection: true, _dropAction: "alias",
btnType: ButtonType.ToolButton, backgroundColor: reqdOpts.backgroundColor ?? Colors.DARK_GRAY, color: Colors.WHITE, system: true,
_removeDropProperties: new List<string>(["_stayInCollection"]),
@@ -562,6 +562,7 @@ export class CurrentUserUtils {
if (Cast(myDashboards.childContextMenuFilters, listSpec(ScriptField), null)?.length !== childContextMenuFilters.length) {
myDashboards.childContextMenuFilters = new List<ScriptField>(childContextMenuFilters.map(script => !script ? script: ScriptField.MakeFunction(script)!));
}
+ return myDashboards;
}
/// initializes the left sidebar Trails pane
@@ -728,13 +729,13 @@ export class CurrentUserUtils {
static inkTools():Button[] {
return [
- { title: "Pen", toolTip: "Pen (Ctrl+P)", btnType: ButtonType.ToggleButton, icon: "pen-nib", scripts:{onClick:'{ return setActiveInkTool("pen", _readOnly_);}' }},
- { title: "Write", toolTip: "Write (Ctrl+Shift+P)", btnType: ButtonType.ToggleButton, icon: "pen", scripts:{onClick:'{ return setActiveInkTool("write", _readOnly_);}'} },
- { title: "Eraser", toolTip: "Eraser (Ctrl+E)", btnType: ButtonType.ToggleButton, icon: "eraser", scripts:{onClick:'{ return setActiveInkTool("eraser", _readOnly_);}' }},
- // { title: "Highlighter", toolTip: "Highlighter (Ctrl+H)", btnType: ButtonType.ToggleButton, icon: "highlighter", scripts:{onClick: 'setActiveInkTool("highlighter")'} },
- { title: "Circle", toolTip: "Circle (Ctrl+Shift+C)", btnType: ButtonType.ToggleButton, icon: "circle", scripts:{onClick:'{ return setActiveInkTool("circle", _readOnly_);}'} },
- // { title: "Square", toolTip: "Square (Ctrl+Shift+S)", btnType: ButtonType.ToggleButton, icon: "square", click: 'setActiveInkTool("square")' },
- { title: "Line", toolTip: "Line (Ctrl+Shift+L)", btnType: ButtonType.ToggleButton, icon: "minus", scripts:{onClick: '{ return setActiveInkTool("line", _readOnly_);}' }},
+ { title: "Pen", toolTip: "Pen (Ctrl+P)", btnType: ButtonType.ToggleButton, icon: "pen-nib", scripts:{onClick:'{ return setActiveTool("pen", _readOnly_);}' }},
+ { title: "Write", toolTip: "Write (Ctrl+Shift+P)", btnType: ButtonType.ToggleButton, icon: "pen", scripts:{onClick:'{ return setActiveTool("write", _readOnly_);}'} },
+ { title: "Eraser", toolTip: "Eraser (Ctrl+E)", btnType: ButtonType.ToggleButton, icon: "eraser", scripts:{onClick:'{ return setActiveTool("eraser", _readOnly_);}' }},
+ // { title: "Highlighter", toolTip: "Highlighter (Ctrl+H)", btnType: ButtonType.ToggleButton, icon: "highlighter", scripts:{onClick: 'setActiveTool("highlighter")'} },
+ { title: "Circle", toolTip: "Circle (Ctrl+Shift+C)", btnType: ButtonType.ToggleButton, icon: "circle", scripts:{onClick:'{ return setActiveTool("circle", _readOnly_);}'} },
+ // { title: "Square", toolTip: "Square (Ctrl+Shift+S)", btnType: ButtonType.ToggleButton, icon: "square", click: 'setActiveTool("square")' },
+ { title: "Line", toolTip: "Line (Ctrl+Shift+L)", btnType: ButtonType.ToggleButton, icon: "minus", scripts:{onClick: '{ return setActiveTool("line", _readOnly_);}' }},
{ title: "Fill", toolTip: "Fill color", btnType: ButtonType.ColorButton, ignoreClick: true, icon: "fill-drip", scripts: {script: "{ return setFillColor(value, _readOnly_);}"} },
{ title: "Width", toolTip: "Stroke width", btnType: ButtonType.NumberButton, numBtnType: NumButtonType.Slider, numBtnMin: 1, ignoreClick: true, scripts: {script: '{ return setStrokeWidth(value, _readOnly_);}'} },
{ title: "Color", toolTip: "Stroke color", btnType: ButtonType.ColorButton, icon: "pen", ignoreClick: true, scripts: {script: '{ return setStrokeColor(value, _readOnly_);}'} },
@@ -941,41 +942,39 @@ export class CurrentUserUtils {
}
static async updateUserDocument(doc: Doc, sharingDocumentId: string, linkDatabaseId: string) {
- if (!doc.globalGroupDatabase) doc.globalGroupDatabase = Docs.Prototypes.MainGroupDocument();
- await DocListCastAsync((doc.globalGroupDatabase as Doc).data);
- reaction(() => DateCast((doc.globalGroupDatabase as Doc)["data-lastModified"]),
+ doc.globalGroupDatabase ?? (doc.globalGroupDatabase = Docs.Prototypes.MainGroupDocument());
+ await DocListCastAsync(DocCast(doc.globalGroupDatabase).data);
+ reaction(() => DateCast(DocCast(doc.globalGroupDatabase)["data-lastModified"]),
async () => {
- const groups = await DocListCastAsync((doc.globalGroupDatabase as Doc).data);
+ const groups = await DocListCastAsync(DocCast(doc.globalGroupDatabase).data);
const mygroups = groups?.filter(group => JSON.parse(StrCast(group.members)).includes(Doc.CurrentUserEmail)) || [];
SnappingManager.SetCachedGroups(["Public", ...mygroups?.map(g => StrCast(g.title))]);
}, { fireImmediately: true });
// Document properties on load
- doc.system = true;
- doc.title = Doc.CurrentUserEmail;
- doc.noviceMode = doc.noviceMode === undefined ? "true" : doc.noviceMode;
- doc._raiseWhenDragged = true;
- doc._showLabel = true;
- doc._showMenuLabel = true;
- doc.textAlign = StrCast(doc.textAlign, "left");
- doc.activeInkColor = StrCast(doc.activeInkColor, "rgb(0, 0, 0)");
- doc.activeInkWidth = Number(StrCast(doc.activeInkWidth, "1"));
- doc.activeInkBezier = StrCast(doc.activeInkBezier, "0");
- doc.activeFillColor = StrCast(doc.activeFillColor, "");
- doc.activeArrowStart = StrCast(doc.activeArrowStart, "");
- doc.activeArrowEnd = StrCast(doc.activeArrowEnd, "");
- doc.activeDash = StrCast(doc.activeDash, "0");
- doc.fontSize = StrCast(doc.fontSize, "12px");
- doc.fontFamily = StrCast(doc.fontFamily, "Arial");
- doc.fontColor = StrCast(doc.fontColor, "black");
- doc.fontHighlight = StrCast(doc.fontHighlight, "");
- doc.defaultAclPrivate = BoolCast(doc.defaultAclPrivate, false);
- doc.activeCollectionNestedBackground = Cast(doc.activeCollectionNestedBackground, "string", null);
- doc.noviceMode = BoolCast(doc.noviceMode, true);
- !doc.savedFilters && (doc.savedFilters = new List<Doc>());
+ doc.system ?? (doc.system = true);
+ doc.title ?? (doc.title = Doc.CurrentUserEmail);
+ Doc.noviceMode ?? (Doc.noviceMode = true);
+ doc._raiseWhenDragged ?? (doc._raiseWhenDragged = true);
+ doc._showLabel ?? (doc._showLabel = true);
+ doc._showMenuLabel ?? (doc._showMenuLabel = true);
+ doc.textAlign ?? (doc.textAlign = "left");
+ doc.activeInkColor ?? (doc.activeInkColor = "rgb(0, 0, 0)");;
+ doc.activeInkWidth ?? (doc.activeInkWidth = 1);
+ doc.activeInkBezier ?? (doc.activeInkBezier = "0");
+ doc.activeFillColor ?? (doc.activeFillColor = "");
+ doc.activeArrowStart ?? (doc.activeArrowStart = "");
+ doc.activeArrowEnd ?? (doc.activeArrowEnd = "");
+ doc.activeDash ?? (doc.activeDash == "0");
+ doc.fontSize ?? (doc.fontSize = "12px");
+ doc.fontFamily ?? (doc.fontFamily = "Arial");
+ doc.fontColor ?? (doc.fontColor = "black");
+ doc.fontHighlight ?? (doc.fontHighlight = "");
+ doc.defaultAclPrivate ?? (doc.defaultAclPrivate = false);
+ doc.savedFilters ?? (doc.savedFilters = new List<Doc>());
doc.filterDocCount = 0;
doc.freezeChildren = "remove|add";
- doc.myPublishedDocs = doc.myPublishedDocs ?? new List<Doc>();
- doc.myHeaderBar = doc.myHeaderBar?? Docs.Create.MulticolumnDocument([], { title: "header bar", system: true }); // drop down panel at top of dashboard for stashing documents
+ doc.myPublishedDocs ?? (doc.myPublishedDocs = new List<Doc>());
+ doc.myHeaderBar ?? (doc.myHeaderBar = Docs.Create.MulticolumnDocument([], { title: "header bar", system: true })); // drop down panel at top of dashboard for stashing documents
await this.setupLinkDocs(doc, linkDatabaseId);
await this.setupSharedDocs(doc, sharingDocumentId); // sets up the right sidebar collection for mobile upload documents and sharing
this.setupDefaultIconTemplates(doc); // creates a set of icon templates triggered by the document deoration icon
@@ -985,7 +984,7 @@ export class CurrentUserUtils {
this.setupContextMenuButtons(doc); // set up the row of buttons at the top of the dashboard that change depending on what is selected
this.setupDockedButtons(doc); // the bottom bar of font icons
this.setupLeftSidebarMenu(doc); // the left-side column of buttons that open their contents in a flyout panel on the left
- if (!doc.globalScriptDatabase) doc.globalScriptDatabase = Docs.Prototypes.MainScriptDocument();
+ doc.globalScriptDatabase ?? ( doc.globalScriptDatabase = Docs.Prototypes.MainScriptDocument());
setTimeout(() => DocServer.UPDATE_SERVER_CACHE(), 2500);
doc.fieldInfos = await Docs.setupFieldInfos();
@@ -1022,7 +1021,7 @@ export class CurrentUserUtils {
const userDoc = Docs.newAccount ? new Doc(userDocumentId, true) : field as Doc;
Docs.newAccount &&(userDoc.activePage = "home");
const updated = this.updateUserDocument(Doc.SetUserDoc(userDoc), sharingDocumentId, linkDatabaseId);
- (await DocListCastAsync(Cast(Doc.UserDoc().myLinkDatabase, Doc, null)?.data))?.forEach(async link => { // make sure anchors are loaded to avoid incremental updates to computedFn's in LinkManager
+ (await DocListCastAsync(Doc.LinkDBDoc()?.data))?.forEach(async link => { // make sure anchors are loaded to avoid incremental updates to computedFn's in LinkManager
const a1 = await Cast(link?.anchor1, Doc, null);
const a2 = await Cast(link?.anchor2, Doc, null);
});
@@ -1097,7 +1096,7 @@ export class CurrentUserUtils {
}
}
} else if (input.files && input.files.length !== 0) {
- const importDocs = Cast(Doc.UserDoc().myImportDocs, Doc, null);
+ const importDocs = CurrentUserUtils.MyImports;
const disposer = OverlayView.ShowSpinner();
DocListCastAsync(importDocs.data).then(async list => {
const results = await DocUtils.uploadFilesToDocs(Array.from(input.files || []), {});
@@ -1115,9 +1114,10 @@ export class CurrentUserUtils {
}
public static CaptureDashboardThumbnail() {
+ const activeDashboard = CurrentUserUtils.ActiveDashboard;
const docView = CollectionDockingView.Instance.props.DocumentView?.();
const content = docView?.ContentDiv;
- if (docView && content) {
+ if (docView && content && activeDashboard) {
const _width = Number(getComputedStyle(content).width.replace("px",""));
const _height = Number(getComputedStyle(content).height.replace("px",""));
return CollectionFreeFormView.UpdateIcon(
@@ -1130,20 +1130,22 @@ export class CurrentUserUtils {
const proto = Cast(img.proto, Doc, null)!;
proto["data-nativeWidth"] = _width;
proto["data-nativeHeight"] = _height;
- Doc.GetProto(CurrentUserUtils.ActiveDashboard).thumb = img;
+ Doc.GetProto(activeDashboard).thumb = img;
});
}
}
public static async snapshotDashboard(userDoc: Doc) {
- const copy = await CollectionDockingView.Copy(CurrentUserUtils.ActiveDashboard);
- Doc.AddDocToList(CurrentUserUtils.MyDashboards, "data", copy);
- CurrentUserUtils.openDashboard(userDoc, copy);
+ if (CurrentUserUtils.ActiveDashboard) {
+ const copy = await CollectionDockingView.Copy(CurrentUserUtils.ActiveDashboard);
+ Doc.AddDocToList(CurrentUserUtils.MyDashboards, "data", copy);
+ CurrentUserUtils.openDashboard(userDoc, copy);
+ }
}
public static closeActiveDashboard = () => {
- Doc.UserDoc().activeDashboard = undefined;
+ CurrentUserUtils.ActiveDashboard = undefined;
}
public static createNewDashboard = async (userDoc: Doc, id?: string) => {
@@ -1195,6 +1197,8 @@ export class CurrentUserUtils {
public static get MyHeaderBar() { return DocCast(Doc.UserDoc().myHeaderBar); }
public static get MyTools() { return DocCast(Doc.UserDoc().myTools); }
public static get MyDashboards() { return DocCast(Doc.UserDoc().myDashboards); }
+ public static get MyFileOrphans() { return DocCast(Doc.UserDoc().myFileOrphans); }
+ public static get MyTemplates() { return DocCast(Doc.UserDoc().myTemplates); }
public static get MyLeftSidebarMenu() { return DocCast(Doc.UserDoc().myLeftSidebarMenu); }
public static get MyLeftSidebarPanel() { return DocCast(Doc.UserDoc().myLeftSidebarPanel); }
public static get MySharedDocs() { return DocCast(Doc.UserDoc().mySharedDocs); }
@@ -1202,12 +1206,16 @@ export class CurrentUserUtils {
public static get MyImports() { return DocCast(Doc.UserDoc().myImports); }
public static get MyContextMenuBtns() { return DocCast(Doc.UserDoc().myContextMenuBtns); }
public static get MyRecentlyClosed() { return DocCast(Doc.UserDoc().myRecentlyClosed); }
- public static get MyOverlayDocs() { return DocListCast(DocCast(Doc.UserDoc().myOverlayDocs)?.data); }
+ public static get MyOverlayDocs() { return DocCast(Doc.UserDoc().myOverlayDocs); }
public static get ActiveDashboard() { return DocCast(Doc.UserDoc().activeDashboard); }
+ public static set ActiveDashboard(val:Doc|undefined) { Doc.UserDoc().activeDashboard = val; }
public static get ActivePresentation() { return DocCast(Doc.UserDoc().activePresentation); }
+ public static set ActivePresentation(val) { Doc.UserDoc().activePresentation = val; }
+ public static get ActivePage() { return StrCast(Doc.UserDoc().activePage); }
+ public static set ActivePage(val) { Doc.UserDoc().activePage = val; }
public static get EmptyPane() { return DocCast(Doc.UserDoc().emptyPane); }
- public static set SelectedTool(tool: InkTool) { Doc.UserDoc().activeInkTool = tool; }
- @computed public static get SelectedTool(): InkTool { return StrCast(Doc.UserDoc().activeInkTool, InkTool.None) as InkTool; }
+ public static set ActiveTool(tool: InkTool) { Doc.UserDoc().activeTool = tool; }
+ public static get ActiveTool(): InkTool { return StrCast(Doc.UserDoc().activeTool, InkTool.None) as InkTool; }
}
ScriptingGlobals.add(function openDragFactory(dragFactory: Doc) {
@@ -1219,7 +1227,7 @@ ScriptingGlobals.add(function openDragFactory(dragFactory: Doc) {
}
});
ScriptingGlobals.add(function MySharedDocs() { return CurrentUserUtils.MySharedDocs; }, "document containing all shared Docs");
-ScriptingGlobals.add(function IsNoviceMode() { return Doc.UserDoc().noviceMode; }, "is Dash in novice mode");
+ScriptingGlobals.add(function IsNoviceMode() { return Doc.noviceMode; }, "is Dash in novice mode");
ScriptingGlobals.add(function toggleComicMode() { Doc.UserDoc().renderStyle = Doc.UserDoc().renderStyle === "comic" ? undefined : "comic"; }, "switches between comic and normal document rendering");
ScriptingGlobals.add(function snapshotDashboard() { CurrentUserUtils.snapshotDashboard(Doc.UserDoc()); }, "creates a snapshot copy of a dashboard");
ScriptingGlobals.add(function createNewDashboard() { return CurrentUserUtils.createNewDashboard(Doc.UserDoc()); }, "creates a new dashboard when called");