aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTyler Schicke <tyler_schicke@brown.edu>2019-07-05 16:32:59 -0400
committerTyler Schicke <tyler_schicke@brown.edu>2019-07-05 16:32:59 -0400
commitc42d288a6ea658542f398ee48492ff35e14d400d (patch)
tree35ba3cd22edbb14ad85aca39c2845011b92329a0
parent806a53f8754b4e6c49dad0c622d7c7ef84334348 (diff)
user document stuff
-rw-r--r--src/server/authentication/models/current_user_utils.ts46
1 files changed, 33 insertions, 13 deletions
diff --git a/src/server/authentication/models/current_user_utils.ts b/src/server/authentication/models/current_user_utils.ts
index 3134ecaff..30a6f108a 100644
--- a/src/server/authentication/models/current_user_utils.ts
+++ b/src/server/authentication/models/current_user_utils.ts
@@ -10,7 +10,7 @@ import { CollectionView } from "../../../client/views/collections/CollectionView
import { Doc } from "../../../new_fields/Doc";
import { List } from "../../../new_fields/List";
import { listSpec } from "../../../new_fields/Schema";
-import { Cast } from "../../../new_fields/Types";
+import { Cast, FieldValue } from "../../../new_fields/Types";
import { RouteStore } from "../../RouteStore";
export class CurrentUserUtils {
@@ -31,17 +31,8 @@ export class CurrentUserUtils {
doc.viewType = CollectionViewType.Tree;
doc.dropAction = "alias";
doc.layout = CollectionView.LayoutString();
- doc.workspaces = Docs.TreeDocument([], { title: "Workspaces", height: 100 });
- (doc.workspaces as Doc).excludeFromLibrary = true;
- (doc.workspaces as Doc).workspaceLibrary = true;
- doc.recentlyClosed = Docs.TreeDocument([], { title: "Recently Closed", height: 75 });
- (doc.workspaces as Doc).excludeFromLibrary = true;
- doc.sidebar = Docs.StackingDocument([doc.workspaces as Doc, doc, doc.recentlyClosed as Doc], { title: "Sidebar" });
- (doc.sidebar as Doc).excludeFromLibrary = true;
- (doc.sidebar as Doc).gridGap = 5;
- (doc.sidebar as Doc).xMargin = 5;
- (doc.sidebar as Doc).yMargin = 5;
doc.title = this.email;
+ this.updateUserDocument(doc);
doc.data = new List<Doc>();
doc.excludeFromLibrary = true;
doc.optionalRightCollection = Docs.StackingDocument([], { title: "New mobile uploads" });
@@ -50,6 +41,29 @@ export class CurrentUserUtils {
return doc;
}
+ static updateUserDocument(doc: Doc) {
+ if (doc.workspaces === undefined) {
+ const workspaces = Docs.TreeDocument([], { title: "Workspaces", height: 100 });
+ workspaces.excludeFromLibrary = true;
+ workspaces.workspaceLibrary = true;
+ doc.workspaces = workspaces;
+ }
+ if (doc.recentlyClosed === undefined) {
+ const recentlyClosed = Docs.TreeDocument([], { title: "Recently Closed", height: 75 });
+ recentlyClosed.excludeFromLibrary = true;
+ doc.recentlyClosed = recentlyClosed;
+ }
+ if (doc.sidebar === undefined) {
+ const sidebar = Docs.StackingDocument([doc.workspaces as Doc, doc, doc.recentlyClosed as Doc], { title: "Sidebar" });
+ sidebar.excludeFromLibrary = true;
+ sidebar.gridGap = 5;
+ sidebar.xMargin = 5;
+ sidebar.yMargin = 5;
+ doc.sidebar = sidebar;
+ }
+
+ }
+
public static async loadCurrentUser(): Promise<any> {
let userPromise = rp.get(DocServer.prepend(RouteStore.getCurrUser)).then(response => {
if (response) {
@@ -62,8 +76,14 @@ export class CurrentUserUtils {
});
let userDocPromise = await rp.get(DocServer.prepend(RouteStore.getUserDocumentId)).then(id => {
if (id) {
- return DocServer.GetRefField(id).then(field =>
- runInAction(() => this.user_document = field instanceof Doc ? field : this.createUserDocument(id)));
+ return DocServer.GetRefField(id).then(async field => {
+ if (field instanceof Doc) {
+ await this.updateUserDocument(field);
+ runInAction(() => this.user_document = field);
+ } else {
+ runInAction(() => this.user_document = this.createUserDocument(id));
+ }
+ });
} else {
throw new Error("There should be a user id! Why does Dash think there isn't one?");
}