aboutsummaryrefslogtreecommitdiff
path: root/src/server/authentication/models/current_user_utils.ts
diff options
context:
space:
mode:
authoreeng5 <eleanor.eng5@gmail.com>2019-11-19 17:47:13 -0500
committereeng5 <eleanor.eng5@gmail.com>2019-11-19 17:47:13 -0500
commit7d89d10a3d43755c267fd48e18701d457ae7aa1c (patch)
tree059312d4d2dfeaa96b5e272abc7608b0d68b96b4 /src/server/authentication/models/current_user_utils.ts
parentab285371f6fb2a4f1e64888bafbc84b602f23416 (diff)
parent667d196a2cbc8e237de5be9a6f7ec4ecca9d2bb5 (diff)
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into server_refactor
Diffstat (limited to 'src/server/authentication/models/current_user_utils.ts')
-rw-r--r--src/server/authentication/models/current_user_utils.ts323
1 files changed, 163 insertions, 160 deletions
diff --git a/src/server/authentication/models/current_user_utils.ts b/src/server/authentication/models/current_user_utils.ts
index 5a8815983..052aa54a6 100644
--- a/src/server/authentication/models/current_user_utils.ts
+++ b/src/server/authentication/models/current_user_utils.ts
@@ -1,19 +1,20 @@
-import { action, computed, observable, runInAction, reaction } from "mobx";
+import { action, computed, observable, reaction, runInAction } from "mobx";
import * as rp from 'request-promise';
import { DocServer } from "../../../client/DocServer";
import { Docs } from "../../../client/documents/Documents";
import { Attribute, AttributeGroup, Catalog, Schema } from "../../../client/northstar/model/idea/idea";
import { ArrayUtil } from "../../../client/northstar/utils/ArrayUtil";
-import { CollectionViewType } from "../../../client/views/collections/CollectionBaseView";
-import { CollectionView } from "../../../client/views/collections/CollectionView";
+import { UndoManager } from "../../../client/util/UndoManager";
import { Doc, DocListCast } from "../../../new_fields/Doc";
import { List } from "../../../new_fields/List";
import { listSpec } from "../../../new_fields/Schema";
-import { Cast, StrCast, PromiseValue } from "../../../new_fields/Types";
+import { ScriptField, ComputedField } from "../../../new_fields/ScriptField";
+import { Cast, PromiseValue } from "../../../new_fields/Types";
import { Utils } from "../../../Utils";
-import { ScriptField } from "../../../new_fields/ScriptField";
import { ButtonBox } from "../../../client/views/nodes/ButtonBox";
-import { UndoManager } from "../../../client/util/UndoManager";
+import { nullAudio } from "../../../new_fields/URLField";
+import { DragManager } from "../../../client/util/DragManager";
+import { InkingControl } from "../../../client/views/InkingControl";
export class CurrentUserUtils {
private static curr_id: string;
@@ -21,178 +22,186 @@ export class CurrentUserUtils {
private static mainDocId: string | undefined;
public static get id() { return this.curr_id; }
- @computed public static get UserDocument() { return Doc.UserDoc(); }
public static get MainDocId() { return this.mainDocId; }
public static set MainDocId(id: string | undefined) { this.mainDocId = id; }
+ @computed public static get UserDocument() { return Doc.UserDoc(); }
+ @computed public static get ActivePen() { return Doc.UserDoc().activePen instanceof Doc && (Doc.UserDoc().activePen as Doc).pen as Doc; }
@observable public static GuestTarget: Doc | undefined;
@observable public static GuestWorkspace: Doc | undefined;
- private static createUserDocument(id: string): Doc {
- let doc = new Doc(id, true);
- doc.viewType = CollectionViewType.Tree;
- doc.layout = CollectionView.LayoutString();
- doc.title = Doc.CurrentUserEmail;
- doc.data = new List<Doc>();
- doc.gridGap = 5;
- doc.xMargin = 5;
- doc.yMargin = 5;
- doc.height = 42;
- doc.boxShadow = "0 0";
- doc.convertToButtons = true; // for CollectionLinearView used as the docButton layout
- doc.optionalRightCollection = Docs.Create.StackingDocument([], { title: "New mobile uploads" });
- return this.updateUserDocument(doc);// this should be the last
+ // a default set of note types .. not being used yet...
+ static setupNoteTypes(doc: Doc) {
+ return [
+ Docs.Create.TextDocument({ title: "Note", backgroundColor: "yellow", isTemplateDoc: true }),
+ Docs.Create.TextDocument({ title: "Idea", backgroundColor: "pink", isTemplateDoc: true }),
+ Docs.Create.TextDocument({ title: "Topic", backgroundColor: "lightBlue", isTemplateDoc: true }),
+ Docs.Create.TextDocument({ title: "Person", backgroundColor: "lightGreen", isTemplateDoc: true }),
+ Docs.Create.TextDocument({ title: "Todo", backgroundColor: "orange", isTemplateDoc: true })
+ ];
}
- static updateUserDocument(doc: Doc) {
+ // setup the "creator" buttons for the sidebar-- eg. the default set of draggable document creation tools
+ static setupCreatorButtons(doc: Doc) {
+ let notes = CurrentUserUtils.setupNoteTypes(doc);
+ doc.noteTypes = Docs.Create.TreeDocument(notes, { title: "Note Types", height: 75 });
+ doc.activePen = doc;
+ let docProtoData: { title: string, icon: string, drag?: string, ignoreClick?: boolean, click?: string, ischecked?: string, activePen?: Doc, backgroundColor?: string, dragFactory?: Doc }[] = [
+ { title: "collection", icon: "folder", ignoreClick: true, drag: 'Docs.Create.FreeformDocument([], { nativeWidth: undefined, nativeHeight: undefined, width: 150, height: 100, title: "freeform" })' },
+ { title: "todo item", icon: "check", ignoreClick: true, drag: 'getCopy(this.dragFactory, true)', dragFactory: notes[notes.length - 1] },
+ { title: "web page", icon: "globe-asia", ignoreClick: true, drag: 'Docs.Create.WebDocument("https://en.wikipedia.org/wiki/Hedgehog", { width: 300, height: 300, title: "New Webpage" })' },
+ { title: "cat image", icon: "cat", ignoreClick: true, drag: 'Docs.Create.ImageDocument("https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg", { width: 200, title: "an image of a cat" })' },
+ { title: "record", icon: "microphone", ignoreClick: true, drag: `Docs.Create.AudioDocument("${nullAudio}", { width: 200, title: "ready to record audio" })` },
+ { title: "clickable button", icon: "bolt", ignoreClick: true, drag: 'Docs.Create.ButtonDocument({ width: 150, height: 50, title: "Button" })' },
+ { title: "presentation", icon: "tv", ignoreClick: true, drag: 'Doc.UserDoc().curPresentation = Docs.Create.PresDocument(new List<Doc>(), { width: 200, height: 500, title: "a presentation trail" })' },
+ { title: "import folder", icon: "cloud-upload-alt", ignoreClick: true, drag: 'Docs.Create.DirectoryImportDocument({ title: "Directory Import", width: 400, height: 400 })' },
+ { title: "use pen", icon: "pen-nib", click: 'activatePen(this.activePen.pen = sameDocs(this.activePen.pen, this) ? undefined : this,2, this.backgroundColor)', backgroundColor: "blue", ischecked: `sameDocs(this.activePen.pen, this)`, activePen: doc },
+ { title: "use highlighter", icon: "highlighter", click: 'activateBrush(this.activePen.pen = sameDocs(this.activePen.pen, this) ? undefined : this,20,this.backgroundColor)', backgroundColor: "yellow", ischecked: `sameDocs(this.activePen.pen, this)`, activePen: doc },
+ { title: "use eraser", icon: "eraser", click: 'activateEraser(this.activePen.pen = sameDocs(this.activePen.pen, this) ? undefined : this);', ischecked: `sameDocs(this.activePen.pen, this)`, backgroundColor: "pink", activePen: doc },
+ { title: "use scrubber", icon: "eraser", click: 'activateScrubber(this.activePen.pen = sameDocs(this.activePen.pen, this) ? undefined : this);', ischecked: `sameDocs(this.activePen.pen, this)`, backgroundColor: "green", activePen: doc },
+ { title: "use drag", icon: "mouse-pointer", click: 'deactivateInk();this.activePen.pen = this;', ischecked: `sameDocs(this.activePen.pen, this)`, backgroundColor: "white", activePen: doc },
+ ];
+ return docProtoData.map(data => Docs.Create.FontIconDocument({
+ nativeWidth: 100, nativeHeight: 100, width: 100, height: 100, dropAction: data.click ? "copy" : undefined, title: data.title, icon: data.icon, ignoreClick: data.ignoreClick,
+ onDragStart: data.drag ? ScriptField.MakeFunction(data.drag) : undefined, onClick: data.click ? ScriptField.MakeScript(data.click) : undefined,
+ ischecked: data.ischecked ? ComputedField.MakeFunction(data.ischecked) : undefined, activePen: data.activePen,
+ backgroundColor: data.backgroundColor, removeDropProperties: new List<string>(["dropAction"]), dragFactory: data.dragFactory,
+ }));
+ }
- if (doc.undoBtn === undefined) {
- doc.undoBtn = Docs.Create.FontIconDocument({ nativeWidth: 100, nativeHeight: 100, width: 100, height: 100, title: "Collection", icon: "undo-alt" });
- (doc.undoBtn as Doc).onClick = ScriptField.MakeScript('undo()');
- Doc.AddDocToList(doc, "docButtons", doc.undoBtn as Doc);
- }
- if (doc.redoBtn === undefined) {
- doc.redoBtn = Docs.Create.FontIconDocument({ nativeWidth: 100, nativeHeight: 100, width: 100, height: 100, title: "Collection", icon: "redo-alt" });
- (doc.redoBtn as Doc).onClick = ScriptField.MakeScript('redo()');
- Doc.AddDocToList(doc, "docButtons", doc.redoBtn as Doc);
- }
+ // setup the Creator button which will display the creator panel. This panel will include the drag creators and the color picker. when clicked, this panel will be displayed in the target container (ie, sidebarContainer)
+ static setupToolsPanel(sidebarContainer: Doc, doc: Doc) {
+ // setup a masonry view of all he creators
+ const dragCreators = Docs.Create.MasonryDocument(CurrentUserUtils.setupCreatorButtons(doc), {
+ width: 500, autoHeight: true, columnWidth: 35, ignoreClick: true, lockedPosition: true, chromeStatus: "disabled", title: "buttons",
+ dropConverter: ScriptField.MakeScript("convertToButtons(dragData)", { dragData: DragManager.DocumentDragData.name }), yMargin: 5
+ });
+ // setup a color picker
+ const color = Docs.Create.ColorDocument({
+ title: "color picker", width: 400, dropAction: "alias", forceActive: true, removeDropProperties: new List<string>(["dropAction", "forceActive"])
+ });
+
+ return Docs.Create.ButtonDocument({
+ width: 35, height: 35, backgroundColor: "#222222", color: "lightgrey", title: "Tools", fontSize: 10, targetContainer: sidebarContainer,
+ sourcePanel: Docs.Create.StackingDocument([dragCreators, color], {
+ width: 500, height: 800, lockedPosition: true, chromeStatus: "disabled", title: "tools stack"
+ }),
+ onClick: ScriptField.MakeScript("this.targetContainer.proto = this.sourcePanel"),
+ });
+ }
+
+ // setup the Library button which will display the library panel. This panel includes a collection of workspaces, documents, and recently closed views
+ static setupLibraryPanel(sidebarContainer: Doc, doc: Doc) {
// setup workspaces library item
- if (doc.workspaces === undefined) {
- const workspaces = Docs.Create.TreeDocument([], { title: "WORKSPACES", height: 100 });
- workspaces.boxShadow = "0 0";
- doc.workspaces = workspaces;
- }
- PromiseValue(Cast(doc.workspaces, Doc)).then(workspaces => {
- if (workspaces) {
- workspaces.backgroundColor = "#eeeeee";
- workspaces.preventTreeViewOpen = true;
- workspaces.forceActive = true;
- workspaces.lockedPosition = true;
- if (StrCast(workspaces.title) === "Workspaces") {
- workspaces.title = "WORKSPACES";
- }
- }
+ doc.workspaces = Docs.Create.TreeDocument([], {
+ title: "WORKSPACES", height: 100, forceActive: true, boxShadow: "0 0", lockedPosition: true, backgroundColor: "#eeeeee"
});
- // setup notes list
- if (doc.noteTypes === undefined) {
- let notes = [Docs.Create.TextDocument({ title: "Note", backgroundColor: "yellow", isTemplate: true }),
- Docs.Create.TextDocument({ title: "Idea", backgroundColor: "pink", isTemplate: true }),
- Docs.Create.TextDocument({ title: "Topic", backgroundColor: "lightBlue", isTemplate: true }),
- Docs.Create.TextDocument({ title: "Person", backgroundColor: "lightGreen", isTemplate: true })];
- const noteTypes = Docs.Create.TreeDocument(notes, { title: "Note Types", height: 75 });
- doc.noteTypes = noteTypes;
- }
- PromiseValue(Cast(doc.noteTypes, Doc)).then(noteTypes => noteTypes && PromiseValue(noteTypes.data).then(DocListCast));
+ doc.documents = Docs.Create.TreeDocument([], {
+ title: "DOCUMENTS", height: 42, forceActive: true, boxShadow: "0 0", preventTreeViewOpen: true, lockedPosition: true, backgroundColor: "#eeeeee"
+ });
// setup Recently Closed library item
- if (doc.recentlyClosed === undefined) {
- const recentlyClosed = Docs.Create.TreeDocument([], { title: "Recently Closed".toUpperCase(), height: 75 });
- recentlyClosed.boxShadow = "0 0";
- doc.recentlyClosed = recentlyClosed;
- }
- PromiseValue(Cast(doc.recentlyClosed, Doc)).then(recent => {
- if (recent) {
- recent.backgroundColor = "#eeeeee";
- recent.preventTreeViewOpen = true;
- recent.forceActive = true;
- recent.lockedPosition = true;
- if (StrCast(recent.title) === "Recently Closed") {
- recent.title = "RECENTLY CLOSED";
- }
- }
+ doc.recentlyClosed = Docs.Create.TreeDocument([], {
+ title: "RECENTLY CLOSED", height: 75, forceActive: true, boxShadow: "0 0", preventTreeViewOpen: true, lockedPosition: true, backgroundColor: "#eeeeee"
});
+ return Docs.Create.ButtonDocument({
+ width: 50, height: 35, backgroundColor: "#222222", color: "lightgrey", title: "Library", fontSize: 10,
+ sourcePanel: Docs.Create.TreeDocument([doc.workspaces as Doc, doc.documents as Doc, doc.recentlyClosed as Doc], {
+ title: "Library", xMargin: 5, yMargin: 5, gridGap: 5, forceActive: true, dropAction: "alias", lockedPosition: true
+ }),
+ targetContainer: sidebarContainer,
+ onClick: ScriptField.MakeScript("this.targetContainer.proto = this.sourcePanel;")
+ });
+ }
- if (doc.curPresentation === undefined) {
- const curPresentation = Docs.Create.PresDocument(new List<Doc>(), { title: "Presentation" });
- curPresentation.boxShadow = "0 0";
- doc.curPresentation = curPresentation;
- }
+ // setup the Search button which will display the search panel.
+ static setupSearchPanel(sidebarContainer: Doc) {
+ return Docs.Create.ButtonDocument({
+ width: 50, height: 35, backgroundColor: "#222222", color: "lightgrey", title: "Search", fontSize: 10,
+ sourcePanel: Docs.Create.QueryDocument({
+ title: "search stack", ignoreClick: true
+ }),
+ targetContainer: sidebarContainer,
+ lockedPosition: true,
+ onClick: ScriptField.MakeScript("this.targetContainer.proto = this.sourcePanel")
+ });
+ }
- if (doc.Library === undefined) {
- let Search = Docs.Create.ButtonDocument({ width: 50, height: 35, borderRounding: "50%", boxShadow: "2px 2px 1px", title: "Search" });
- let Library = Docs.Create.ButtonDocument({ width: 50, height: 35, borderRounding: "50%", boxShadow: "2px 2px 1px", title: "Library" });
- let Create = Docs.Create.ButtonDocument({ width: 35, height: 35, borderRounding: "50%", boxShadow: "2px 2px 1px", title: "Create" });
- if (doc.sidebarContainer === undefined) {
- doc.sidebarContainer = new Doc();
- (doc.sidebarContainer as Doc).chromeStatus = "disabled";
- }
+ // setup the list of sidebar mode buttons which determine what is displayed in the sidebar
+ static setupSidebarButtons(doc: Doc) {
+ doc.sidebarContainer = new Doc();
+ (doc.sidebarContainer as Doc).chromeStatus = "disabled";
+ (doc.sidebarContainer as Doc).onClick = ScriptField.MakeScript("freezeSidebar()");
- const library = Docs.Create.TreeDocument([doc.workspaces as Doc, doc, doc.recentlyClosed as Doc], { title: "Library" });
- library.forceActive = true;
- library.lockedPosition = true;
- library.gridGap = 5;
- library.xMargin = 5;
- library.yMargin = 5;
- library.dropAction = "alias";
- Library.targetContainer = doc.sidebarContainer;
- Library.library = library;
- Library.onClick = ScriptField.MakeScript("this.targetContainer.proto = this.library");
+ doc.ToolsBtn = this.setupToolsPanel(doc.sidebarContainer as Doc, doc);
+ doc.LibraryBtn = this.setupLibraryPanel(doc.sidebarContainer as Doc, doc);
+ doc.SearchBtn = this.setupSearchPanel(doc.sidebarContainer as Doc);
- const searchBox = Docs.Create.QueryDocument({ title: "search stack" });
- searchBox.ignoreClick = true;
- Search.searchBox = searchBox;
- Search.targetContainer = doc.sidebarContainer;
- Search.onClick = ScriptField.MakeScript("this.targetContainer.proto = this.searchBox");
+ // Finally, setup the list of buttons to display in the sidebar
+ doc.sidebarButtons = Docs.Create.StackingDocument([doc.SearchBtn as Doc, doc.LibraryBtn as Doc, doc.ToolsBtn as Doc], {
+ width: 500, height: 80, boxShadow: "0 0", sectionFilter: "title", hideHeadings: true, ignoreClick: true,
+ backgroundColor: "lightgrey", chromeStatus: "disabled", title: "library stack"
+ });
+ }
- let createCollection = Docs.Create.FontIconDocument({ nativeWidth: 100, nativeHeight: 100, width: 100, height: 100, title: "Collection", icon: "folder" });
- createCollection.onDragStart = ScriptField.MakeFunction('Docs.Create.FreeformDocument([], { nativeWidth: undefined, nativeHeight: undefined, width: 150, height: 100, title: "freeform" })');
- let createWebPage = Docs.Create.FontIconDocument({ nativeWidth: 100, nativeHeight: 100, width: 100, height: 100, title: "Web Page", icon: "globe-asia" });
- createWebPage.onDragStart = ScriptField.MakeFunction('Docs.Create.WebDocument("https://en.wikipedia.org/wiki/Hedgehog", { width: 300, height: 300, title: "New Webpage" })');
- let createCatImage = Docs.Create.FontIconDocument({ nativeWidth: 100, nativeHeight: 100, width: 100, height: 100, title: "Image", icon: "cat" });
- createCatImage.onDragStart = ScriptField.MakeFunction('Docs.Create.ImageDocument("https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg", { width: 200, title: "an image of a cat" })');
- let createButton = Docs.Create.FontIconDocument({ nativeWidth: 100, nativeHeight: 100, width: 100, height: 100, title: "Button", icon: "bolt" });
- createButton.onDragStart = ScriptField.MakeFunction('Docs.Create.ButtonDocument({ width: 150, height: 50, title: "Button" })');
- let createPresentation = Docs.Create.FontIconDocument({ nativeWidth: 100, nativeHeight: 100, width: 100, height: 100, title: "Presentation", icon: "tv" });
- createPresentation.onDragStart = ScriptField.MakeFunction('Doc.UserDoc().curPresentation = Docs.Create.PresDocument(new List<Doc>(), { width: 200, height: 500, title: "a presentation trail" })');
- let createFolderImport = Docs.Create.FontIconDocument({ nativeWidth: 100, nativeHeight: 100, width: 100, height: 100, title: "Import Folder", icon: "cloud-upload-alt" });
- createFolderImport.onDragStart = ScriptField.MakeFunction('Docs.Create.DirectoryImportDocument({ title: "Directory Import", width: 400, height: 400 })');
- const dragCreators = Docs.Create.MasonryDocument([createCollection, createWebPage, createCatImage, createButton, createPresentation, createFolderImport], { width: 500, autoHeight: true, columnWidth: 35, ignoreClick: true, lockedPosition: true, chromeStatus: "disabled", title: "buttons" });
- const color = Docs.Create.ColorDocument({ title: "color picker", width: 400 });
- color.dropAction = "alias";
- color.ignoreClick = true;
- color.removeDropProperties = new List<string>(["dropAction", "ignoreClick"]);
- const creators = Docs.Create.StackingDocument([dragCreators, color], { width: 500, height: 800, chromeStatus: "disabled", title: "creator stack" });
- Create.targetContainer = doc.sidebarContainer;
- Create.creators = creators;
- Create.onClick = ScriptField.MakeScript("this.targetContainer.proto = this.creators");
+ /// sets up the default list of buttons to be shown in the expanding button menu at the bottom of the Dash window
+ static setupExpandingButtons(doc: Doc) {
+ doc.undoBtn = Docs.Create.FontIconDocument(
+ { nativeWidth: 100, nativeHeight: 100, width: 100, height: 100, dropAction: "alias", onClick: ScriptField.MakeScript("undo()"), removeDropProperties: new List<string>(["dropAction"]), title: "undo button", icon: "undo-alt" });
+ doc.redoBtn = Docs.Create.FontIconDocument(
+ { nativeWidth: 100, nativeHeight: 100, width: 100, height: 100, dropAction: "alias", onClick: ScriptField.MakeScript("redo()"), removeDropProperties: new List<string>(["dropAction"]), title: "redo button", icon: "redo-alt" });
- const libraryButtons = Docs.Create.StackingDocument([Search, Library, Create], { width: 500, height: 80, chromeStatus: "disabled", title: "library stack" });
- libraryButtons.sectionFilter = "title";
- libraryButtons.boxShadow = "0 0";
- libraryButtons.ignoreClick = true;
- libraryButtons.hideHeadings = true;
- libraryButtons.backgroundColor = "lightgrey";
+ doc.expandingButtons = Docs.Create.LinearDocument([doc.undoBtn as Doc, doc.redoBtn as Doc], {
+ title: "expanding buttons", gridGap: 5, xMargin: 5, yMargin: 5, height: 42, width: 100, boxShadow: "0 0",
+ backgroundColor: "black", preventTreeViewOpen: true, forceActive: true, lockedPosition: true,
+ dropConverter: ScriptField.MakeScript("convertToButtons(dragData)", { dragData: DragManager.DocumentDragData.name })
+ });
+ }
- doc.libraryButtons = libraryButtons;
- doc.Library = Library;
- doc.Create = Create;
- doc.Search = Search;
- }
- PromiseValue(Cast(doc.libraryButtons, Doc)).then(libraryButtons => { });
- PromiseValue(Cast(doc.Library, Doc)).then(library => library && library.library && library.targetContainer && (library.onClick as ScriptField).script.run({ this: library }));
- PromiseValue(Cast(doc.Create, Doc)).then(async create => create && create.creators && create.targetContainer);
- PromiseValue(Cast(doc.Search, Doc)).then(async search => search && search.searchBox && search.targetContainer);
+ // sets up the default set of documents to be shown in the Overlay layer
+ static setupOverlays(doc: Doc) {
+ doc.overlays = Docs.Create.FreeformDocument([], { title: "Overlays", backgroundColor: "#aca3a6" });
+ doc.linkFollowBox = Docs.Create.LinkFollowBoxDocument({ x: 250, y: 20, width: 500, height: 370, title: "Link Follower" });
+ Doc.AddDocToList(doc.overlays as Doc, "data", doc.linkFollowBox as Doc);
+ }
- if (doc.overlays === undefined) {
- const overlays = Docs.Create.FreeformDocument([], { title: "Overlays" });
- Doc.GetProto(overlays).backgroundColor = "#aca3a6";
- doc.overlays = overlays;
- }
+ // the initial presentation Doc to use
+ static setupDefaultPresentation(doc: Doc) {
+ doc.curPresentation = Docs.Create.PresDocument(new List<Doc>(), { title: "Presentation", boxShadow: "0 0" });
+ }
- if (doc.linkFollowBox === undefined) {
- PromiseValue(Cast(doc.overlays, Doc)).then(overlays => overlays && Doc.AddDocToList(overlays, "data", doc.linkFollowBox = Docs.Create.LinkFollowBoxDocument({ x: 250, y: 20, width: 500, height: 370, title: "Link Follower" })));
- }
+ static setupMobileUploads(doc: Doc) {
+ doc.optionalRightCollection = Docs.Create.StackingDocument([], { title: "New mobile uploads" });
+ }
+
+ static updateUserDocument(doc: Doc) {
+ doc.title = Doc.CurrentUserEmail;
+ new InkingControl();
+ (doc.optionalRightCollection === undefined) && CurrentUserUtils.setupMobileUploads(doc);
+ (doc.overlays === undefined) && CurrentUserUtils.setupOverlays(doc);
+ (doc.expandingButtons === undefined) && CurrentUserUtils.setupExpandingButtons(doc);
+ (doc.curPresentation === undefined) && CurrentUserUtils.setupDefaultPresentation(doc);
+ (doc.sidebarButtons === undefined) && CurrentUserUtils.setupSidebarButtons(doc);
+
+ // this is equivalent to using PrefetchProxies to make sure the recentlyClosed doc is ready
+ PromiseValue(Cast(doc.recentlyClosed, Doc)).then(recent => recent && PromiseValue(recent.data).then(DocListCast));
+ // this is equivalent to using PrefetchProxies to make sure all the sidebarButtons and noteType internal Doc's have been retrieved.
+ PromiseValue(Cast(doc.noteTypes, Doc)).then(noteTypes => noteTypes && PromiseValue(noteTypes.data).then(DocListCast));
+ PromiseValue(Cast(doc.sidebarButtons, Doc)).then(stackingDoc => {
+ stackingDoc && PromiseValue(Cast(stackingDoc.data, listSpec(Doc))).then(sidebarButtons => {
+ sidebarButtons && sidebarButtons.map((sidebarBtn, i) => {
+ sidebarBtn && PromiseValue(Cast(sidebarBtn, Doc)).then(async btn => {
+ btn && btn.sourcePanel && btn.targetContainer && i === 1 && (btn.onClick as ScriptField).script.run({ this: btn });
+ });
+ });
+ });
+ });
- doc.title = "DOCUMENTS";
- doc.backgroundColor = "#eeeeee";
- doc.width = 100;
- doc.preventTreeViewOpen = true;
- doc.forceActive = true;
- doc.lockedPosition = true;
- doc.undoBtn && reaction(() => UndoManager.undoStack.slice(), () => (doc.undoBtn as Doc).opacity = UndoManager.CanUndo() ? 1 : 0.4, { fireImmediately: true });
- doc.redoBtn && reaction(() => UndoManager.redoStack.slice(), () => (doc.redoBtn as Doc).opacity = UndoManager.CanRedo() ? 1 : 0.4, { fireImmediately: true });
+ // setup reactions to change the highlights on the undo/redo buttons -- would be better to encode this in the undo/redo buttons, but the undo/redo stacks are not wired up that way yet
+ doc.undoBtn && reaction(() => UndoManager.undoStack.slice(), () => Doc.GetProto(doc.undoBtn as Doc).opacity = UndoManager.CanUndo() ? 1 : 0.4, { fireImmediately: true });
+ doc.redoBtn && reaction(() => UndoManager.redoStack.slice(), () => Doc.GetProto(doc.redoBtn as Doc).opacity = UndoManager.CanRedo() ? 1 : 0.4, { fireImmediately: true });
return doc;
}
@@ -213,14 +222,8 @@ export class CurrentUserUtils {
Doc.CurrentUserEmail = email;
await rp.get(Utils.prepend("/getUserDocumentId")).then(id => {
if (id && id !== "guest") {
- return DocServer.GetRefField(id).then(async field => {
- if (field instanceof Doc) {
- await this.updateUserDocument(field);
- runInAction(() => Doc.SetUserDoc(field));
- } else {
- runInAction(() => Doc.SetUserDoc(this.createUserDocument(id)));
- }
- });
+ return DocServer.GetRefField(id).then(async field =>
+ Doc.SetUserDoc(await this.updateUserDocument(field instanceof Doc ? field : new Doc(id, true))));
} else {
throw new Error("There should be a user id! Why does Dash think there isn't one?");
}