aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Wilkins <samwilkins333@gmail.com>2019-09-12 16:49:47 -0400
committerSam Wilkins <samwilkins333@gmail.com>2019-09-12 16:49:47 -0400
commitce85076e3cc4b14d7e9ff75a4562d479a0374d2f (patch)
tree9ab9a75f9a4ec731e2bba65b3481e74b391c148f
parentcb04cae3e5b7d4ae3fb2e59afe866d95320aab14 (diff)
auto custom
-rw-r--r--src/client/apis/google_docs/GooglePhotosClientUtils.ts11
-rw-r--r--src/client/views/TemplateMenu.tsx4
-rw-r--r--src/client/views/nodes/DocumentView.tsx91
-rw-r--r--src/server/credentials/google_docs_token.json2
4 files changed, 55 insertions, 53 deletions
diff --git a/src/client/apis/google_docs/GooglePhotosClientUtils.ts b/src/client/apis/google_docs/GooglePhotosClientUtils.ts
index 3dac1d65c..f3f652ce1 100644
--- a/src/client/apis/google_docs/GooglePhotosClientUtils.ts
+++ b/src/client/apis/google_docs/GooglePhotosClientUtils.ts
@@ -14,6 +14,7 @@ import { NewMediaItemResult, MediaItem } from "../../../server/apis/google/Share
import { AssertionError } from "assert";
import { List } from "../../../new_fields/List";
import { listSpec } from "../../../new_fields/Schema";
+import { DocumentView } from "../../views/nodes/DocumentView";
export namespace GooglePhotos {
@@ -97,10 +98,10 @@ export namespace GooglePhotos {
}
const idMapping = new Doc;
for (let i = 0; i < images.length; i++) {
- const image = images[i];
+ const image = Doc.GetProto(images[i]);
const mediaItem = mediaItems[i];
image.googlePhotosId = mediaItem.id;
- image.googlePhotosUrl = mediaItem.baseUrl || mediaItem.productUrl;
+ image.googlePhotosUrl = mediaItem.productUrl || mediaItem.baseUrl;
idMapping[mediaItem.id] = image;
}
collection.googlePhotosIdMapping = idMapping;
@@ -143,7 +144,7 @@ export namespace GooglePhotos {
throw new Error("Appending image metadata requires that the targeted collection have already been mapped to an album!");
}
const tagMapping = new Map<string, string>();
- const images = await DocListCastAsync(collection.data);
+ const images = (await DocListCastAsync(collection.data))!.map(Doc.GetProto);
images && images.forEach(image => tagMapping.set(image[Id], ContentCategories.NONE));
const values = Object.values(ContentCategories);
for (let value of values) {
@@ -306,7 +307,9 @@ export namespace GooglePhotos {
return;
}
const url = data.url.href;
- const description = parseDescription(Doc.MakeAlias(source), descriptionKey);
+ const target = Doc.MakeAlias(source);
+ const description = parseDescription(target, descriptionKey);
+ DocumentView.makeCustomViewClicked(target);
media.push({ url, description });
});
if (media.length) {
diff --git a/src/client/views/TemplateMenu.tsx b/src/client/views/TemplateMenu.tsx
index 0586b31e4..4e371ffd1 100644
--- a/src/client/views/TemplateMenu.tsx
+++ b/src/client/views/TemplateMenu.tsx
@@ -57,9 +57,9 @@ export class TemplateMenu extends React.Component<TemplateMenuProps> {
toggleCustom = (e: React.MouseEvent): void => {
this.props.docs.map(dv => {
if (dv.Document.type !== DocumentType.COL && dv.Document.type !== DocumentType.TEMPLATE) {
- dv.makeCustomViewClicked();
+ DocumentView.makeCustomViewClicked(dv.props.Document);
} else if (dv.Document.nativeLayout) {
- dv.makeNativeViewClicked();
+ DocumentView.makeNativeViewClicked(dv.props.Document);
}
});
}
diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx
index 6b305d179..81805af64 100644
--- a/src/client/views/nodes/DocumentView.tsx
+++ b/src/client/views/nodes/DocumentView.tsx
@@ -441,47 +441,6 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu
}
@undoBatch
- makeNativeViewClicked = (): void => {
- this.props.Document.customLayout = this.props.Document.layout;
- this.props.Document.layout = this.props.Document.nativeLayout;
- this.props.Document.type = this.props.Document.nativeType;
- this.props.Document.nativeWidth = this.props.Document.nativeNativeWidth;
- this.props.Document.nativeHeight = this.props.Document.nativeNativeHeight;
- this.props.Document.ignoreAspect = this.props.Document.nativeIgnoreAspect;
- this.props.Document.nativeLayout = undefined;
- this.props.Document.nativeNativeWidth = undefined;
- this.props.Document.nativeNativeHeight = undefined;
- this.props.Document.nativeIgnoreAspect = undefined;
- }
- @undoBatch
- makeCustomViewClicked = (): void => {
- this.props.Document.nativeLayout = this.props.Document.layout;
- this.props.Document.nativeType = this.props.Document.type;
- this.props.Document.nativeNativeWidth = this.props.Document.nativeWidth;
- this.props.Document.nativeNativeHeight = this.props.Document.nativeHeight;
- this.props.Document.nativeIgnoreAspect = this.props.Document.ignoreAspect;
- PromiseValue(Cast(this.props.Document.customLayout, Doc)).then(custom => {
- if (custom) {
- this.props.Document.type = DocumentType.TEMPLATE;
- this.props.Document.layout = custom;
- !custom.nativeWidth && (this.props.Document.nativeWidth = 0);
- !custom.nativeHeight && (this.props.Document.nativeHeight = 0);
- !custom.nativeWidth && (this.props.Document.ignoreAspect = true);
- } else {
- let options = { title: "data", width: NumCast(this.props.Document.width), height: NumCast(this.props.Document.height) + 25, x: -NumCast(this.props.Document.width) / 2, y: -NumCast(this.props.Document.height) / 2, };
- let fieldTemplate = this.props.Document.type === DocumentType.TEXT ? Docs.Create.TextDocument(options) : Docs.Create.ImageDocument("http://www.cs.brown.edu", options);
-
- let docTemplate = Docs.Create.FreeformDocument([fieldTemplate], { title: StrCast(this.Document.title) + "layout", width: NumCast(this.props.Document.width) + 20, height: Math.max(100, NumCast(this.props.Document.height) + 45) });
- let metaKey = "data";
- let proto = Doc.GetProto(docTemplate);
- Doc.MakeTemplate(fieldTemplate, metaKey, proto);
-
- Doc.ApplyTemplateTo(docTemplate, this.props.Document, undefined, false);
- }
- });
- }
-
- @undoBatch
makeBtnClicked = (): void => {
let doc = Doc.GetProto(this.props.Document);
if (doc.isButton || doc.onClick) {
@@ -577,7 +536,7 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu
@action
makeIntoPortal = (): void => {
if (!DocListCast(this.props.Document.links).find(doc => {
- if (Cast(doc.anchor2, Doc) instanceof Doc && (Cast(doc.anchor2, Doc) as Doc)!.title === this.props.Document.title + ".portal") return true;
+ if (Cast(doc.anchor2, Doc) instanceof Doc && (Cast(doc.anchor2, Doc) as Doc).title === this.props.Document.title + ".portal") return true;
return false;
})) {
let portal = Docs.Create.FreeformDocument([], { width: this.props.Document[WidthSym]() + 10, height: this.props.Document[HeightSym](), title: this.props.Document.title + ".portal" });
@@ -611,6 +570,46 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu
});
}
+ public static makeNativeViewClicked = undoBatch((document: Doc): void => {
+ document.customLayout = document.layout;
+ document.layout = document.nativeLayout;
+ document.type = document.nativeType;
+ document.nativeWidth = document.nativeNativeWidth;
+ document.nativeHeight = document.nativeNativeHeight;
+ document.ignoreAspect = document.nativeIgnoreAspect;
+ document.nativeLayout = undefined;
+ document.nativeNativeWidth = undefined;
+ document.nativeNativeHeight = undefined;
+ document.nativeIgnoreAspect = undefined;
+ });
+
+ public static makeCustomViewClicked = undoBatch((document: Doc): void => {
+ document.nativeLayout = document.layout;
+ document.nativeType = document.type;
+ document.nativeNativeWidth = document.nativeWidth;
+ document.nativeNativeHeight = document.nativeHeight;
+ document.nativeIgnoreAspect = document.ignoreAspect;
+ PromiseValue(Cast(document.customLayout, Doc)).then(custom => {
+ if (custom) {
+ document.type = DocumentType.TEMPLATE;
+ document.layout = custom;
+ !custom.nativeWidth && (document.nativeWidth = 0);
+ !custom.nativeHeight && (document.nativeHeight = 0);
+ !custom.nativeWidth && (document.ignoreAspect = true);
+ } else {
+ let options = { title: "data", width: NumCast(document.width), height: NumCast(document.height) + 25, x: -NumCast(document.width) / 2, y: -NumCast(document.height) / 2, };
+ let fieldTemplate = document.type === DocumentType.TEXT ? Docs.Create.TextDocument(options) : Docs.Create.ImageDocument("http://www.cs.brown.edu", options);
+
+ let docTemplate = Docs.Create.FreeformDocument([fieldTemplate], { title: StrCast(document.title) + "layout", width: NumCast(document.width) + 20, height: Math.max(100, NumCast(document.height) + 45) });
+ let metaKey = "data";
+ let proto = Doc.GetProto(docTemplate);
+ Doc.MakeTemplate(fieldTemplate, metaKey, proto);
+
+ Doc.ApplyTemplateTo(docTemplate, document, undefined, false);
+ }
+ });
+ });
+
@action
onContextMenu = async (e: React.MouseEvent): Promise<void> => {
e.persist();
@@ -642,7 +641,7 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu
let existingMake = ContextMenu.Instance.findByDescription("Make...");
let makes: ContextMenuProps[] = existingMake && "subitems" in existingMake ? existingMake.subitems : [];
makes.push({ description: this.props.Document.isBackground ? "Remove Background" : "Into Background", event: this.makeBackground, icon: this.props.Document.lockedPosition ? "unlock" : "lock" });
- makes.push({ description: "Custom Document View", event: this.makeCustomViewClicked, icon: "concierge-bell" });
+ makes.push({ description: "Custom Document View", event: () => DocumentView.makeCustomViewClicked(this.props.Document), icon: "concierge-bell" });
makes.push({ description: "Metadata Field View", event: () => this.props.ContainingCollectionView && Doc.MakeTemplate(this.props.Document, StrCast(this.props.Document.title), this.props.ContainingCollectionView.props.Document), icon: "concierge-bell" });
makes.push({ description: "Into Portal", event: this.makeIntoPortal, icon: "window-restore" });
makes.push({ description: this.layoutDoc.ignoreClick ? "Selectable" : "Unselectable", event: () => this.layoutDoc.ignoreClick = !this.layoutDoc.ignoreClick, icon: this.layoutDoc.ignoreClick ? "unlock" : "lock" });
@@ -667,7 +666,7 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu
let layoutItems: ContextMenuProps[] = existing && "subitems" in existing ? existing.subitems : [];
layoutItems.push({ description: this.props.Document.isBackground ? "As Foreground" : "As Background", event: this.makeBackground, icon: this.props.Document.lockedPosition ? "unlock" : "lock" });
if (this.props.ContainingCollectionView && this.props.ContainingCollectionView.props.Document.layout instanceof Doc) {
- layoutItems.push({ description: "Make View of Metadata Field", event: () => this.props.ContainingCollectionView && Doc.MakeTemplate(this.props.Document, StrCast(this.props.Document.title), this.props.ContainingCollectionView.props.Document), icon: "concierge-bell" })
+ layoutItems.push({ description: "Make View of Metadata Field", event: () => this.props.ContainingCollectionView && Doc.MakeTemplate(this.props.Document, StrCast(this.props.Document.title), this.props.ContainingCollectionView.props.Document), icon: "concierge-bell" });
}
layoutItems.push({ description: `${this.layoutDoc.chromeStatus !== "disabled" ? "Hide" : "Show"} Chrome`, event: () => this.layoutDoc.chromeStatus = (this.layoutDoc.chromeStatus !== "disabled" ? "disabled" : "enabled"), icon: "project-diagram" });
layoutItems.push({ description: `${this.layoutDoc.autoHeight ? "Variable Height" : "Auto Height"}`, event: () => this.layoutDoc.autoHeight = !this.layoutDoc.autoHeight, icon: "plus" });
@@ -679,9 +678,9 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu
layoutItems.push({ description: "Toggle detail", event: () => Doc.ToggleDetailLayout(this.props.Document), icon: "image" });
}
if (this.props.Document.type !== DocumentType.COL && this.props.Document.type !== DocumentType.TEMPLATE) {
- layoutItems.push({ description: "Use Custom Layout", event: this.makeCustomViewClicked, icon: "concierge-bell" });
+ layoutItems.push({ description: "Use Custom Layout", event: () => DocumentView.makeCustomViewClicked(this.props.Document), icon: "concierge-bell" });
} else if (this.props.Document.nativeLayout) {
- layoutItems.push({ description: "Use Native Layout", event: this.makeNativeViewClicked, icon: "concierge-bell" });
+ layoutItems.push({ description: "Use Native Layout", event: () => DocumentView.makeNativeViewClicked(this.props.Document), icon: "concierge-bell" });
}
!existing && cm.addItem({ description: "Layout...", subitems: layoutItems, icon: "compass" });
if (!ClientUtils.RELEASE) {
diff --git a/src/server/credentials/google_docs_token.json b/src/server/credentials/google_docs_token.json
index 5b0b5ab5d..1f097346a 100644
--- a/src/server/credentials/google_docs_token.json
+++ b/src/server/credentials/google_docs_token.json
@@ -1 +1 @@
-{"access_token":"ya29.GlyBB-8WTaj3RgOZt5lYaTgidUCgFXHwwtO1ZOYfo9gYq_YuAGQfVC-uRDJ36fIIEgi9F_TWgp8rda2MEXK4KCtTyeeG6Q8-03pdxEdCMdcgf01cmZbheErDY3iLEQ","refresh_token":"1/HTv_xFHszu2Nf3iiFrUTaeKzC_Vp2-6bpIB06xW_WHI","scope":"https://www.googleapis.com/auth/presentations.readonly https://www.googleapis.com/auth/documents.readonly https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/documents https://www.googleapis.com/auth/photoslibrary https://www.googleapis.com/auth/photoslibrary.appendonly https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/presentations https://www.googleapis.com/auth/photoslibrary.sharing","token_type":"Bearer","expiry_date":1568316273289} \ No newline at end of file
+{"access_token":"ya29.GlyBB937-mpLmukf1RrP8tQNfoWZvuHUjt0IxFuYfqNg1dHv1bBe04Tnc2CD_3p3qrtjjY5i2jUq--zaTf9_-CZi2TU2KnygPgDg4oyP5SgiHXv1pR0vlKRyNjhJqA","refresh_token":"1/HTv_xFHszu2Nf3iiFrUTaeKzC_Vp2-6bpIB06xW_WHI","scope":"https://www.googleapis.com/auth/presentations.readonly https://www.googleapis.com/auth/documents.readonly https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/documents https://www.googleapis.com/auth/photoslibrary https://www.googleapis.com/auth/photoslibrary.appendonly https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/presentations https://www.googleapis.com/auth/photoslibrary.sharing","token_type":"Bearer","expiry_date":1568322341079} \ No newline at end of file