aboutsummaryrefslogtreecommitdiff
path: root/src/client/documents/Documents.ts
diff options
context:
space:
mode:
authorandrewdkim <adkim414@gmail.com>2019-10-01 18:55:50 -0400
committerandrewdkim <adkim414@gmail.com>2019-10-01 18:55:50 -0400
commit23619154f8688ffcb25a988158d75934c0cacbf7 (patch)
treed7462da0f0e8b9de091263af166959872e8af0f6 /src/client/documents/Documents.ts
parent45b9f489033cd323614463ca9c36f41900bf1965 (diff)
parent69e4a936c4eb0cc2e35e4e7f3258aed1f72b8da7 (diff)
still unfinished
Diffstat (limited to 'src/client/documents/Documents.ts')
-rw-r--r--src/client/documents/Documents.ts94
1 files changed, 74 insertions, 20 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index 1f9b575a4..3482033d5 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -1,7 +1,6 @@
import { HistogramField } from "../northstar/dash-fields/HistogramField";
import { HistogramBox } from "../northstar/dash-nodes/HistogramBox";
import { HistogramOperation } from "../northstar/operations/HistogramOperation";
-import { CollectionPDFView } from "../views/collections/CollectionPDFView";
import { CollectionVideoView } from "../views/collections/CollectionVideoView";
import { CollectionView } from "../views/collections/CollectionView";
import { CollectionViewType } from "../views/collections/CollectionBaseView";
@@ -20,9 +19,13 @@ import { AttributeTransformationModel } from "../northstar/core/attribute/Attrib
import { AggregateFunction } from "../northstar/model/idea/idea";
import { MINIMIZED_ICON_SIZE } from "../views/globalCssVariables.scss";
import { IconBox } from "../views/nodes/IconBox";
-import { Field, Doc, Opt } from "../../new_fields/Doc";
import { OmitKeys, JSONUtils } from "../../Utils";
+<<<<<<< HEAD
import { ImageField, VideoField, AudioField, PdfField, WebField, YoutubeField, WebCamField } from "../../new_fields/URLField";
+=======
+import { Field, Doc, Opt, DocListCastAsync } from "../../new_fields/Doc";
+import { ImageField, VideoField, AudioField, PdfField, WebField, YoutubeField } from "../../new_fields/URLField";
+>>>>>>> 69e4a936c4eb0cc2e35e4e7f3258aed1f72b8da7
import { HtmlField } from "../../new_fields/HtmlField";
import { List } from "../../new_fields/List";
import { Cast, NumCast } from "../../new_fields/Types";
@@ -46,10 +49,14 @@ import { ComputedField } from "../../new_fields/ScriptField";
import { ProxyField } from "../../new_fields/Proxy";
import { DocumentType } from "./DocumentTypes";
import { LinkFollowBox } from "../views/linking/LinkFollowBox";
+<<<<<<< HEAD
import { DashWebCam } from "../views/webcam/DashWebCam";
import { DashWebRTC } from "../views/webcam/DashWebRTC";
//import { PresBox } from "../views/nodes/PresBox";
//import { PresField } from "../../new_fields/PresField";
+=======
+import { PresElementBox } from "../views/presentationview/PresElementBox";
+>>>>>>> 69e4a936c4eb0cc2e35e4e7f3258aed1f72b8da7
var requestImageSize = require('../util/request-image-size');
var path = require('path');
@@ -67,7 +74,7 @@ export interface DocumentOptions {
panY?: number;
page?: number;
scale?: number;
- layout?: string;
+ layout?: string | Doc;
isTemplate?: boolean;
templates?: List<string>;
viewType?: number;
@@ -97,12 +104,13 @@ export namespace Docs {
export namespace Prototypes {
- type LayoutSource = { LayoutString: () => string };
+ type LayoutSource = { LayoutString: (ext?: string) => string };
type CollectionLayoutSource = { LayoutString: (fieldStr: string, fieldExt?: string) => string };
type CollectionViewType = [CollectionLayoutSource, string, string?];
type PrototypeTemplate = {
layout: {
view: LayoutSource,
+ ext?: string, // optional extension field for layout source
collectionView?: CollectionViewType
},
options?: Partial<DocumentOptions>
@@ -123,7 +131,7 @@ export namespace Docs {
}],
[DocumentType.IMG, {
layout: { view: ImageBox, collectionView: [CollectionView, data, anno] as CollectionViewType },
- options: { nativeWidth: 600, curPage: 0 }
+ options: { curPage: 0 }
}],
[DocumentType.WEB, {
layout: { view: WebBox, collectionView: [CollectionView, data, anno] as CollectionViewType },
@@ -139,14 +147,14 @@ export namespace Docs {
}],
[DocumentType.VID, {
layout: { view: VideoBox, collectionView: [CollectionVideoView, data, anno] as CollectionViewType },
- options: { nativeWidth: 600, curPage: 0 },
+ options: { curPage: 0 },
}],
[DocumentType.AUDIO, {
layout: { view: AudioBox },
options: { height: 32 }
}],
[DocumentType.PDF, {
- layout: { view: PDFBox, collectionView: [CollectionPDFView, data, anno] as CollectionViewType },
+ layout: { view: PDFBox, ext: anno },
options: { nativeWidth: 1200, curPage: 1 }
}],
[DocumentType.ICON, {
@@ -160,7 +168,6 @@ export namespace Docs {
[DocumentType.LINKDOC, {
data: new List<Doc>(),
layout: { view: EmptyBox },
- options: {}
}],
[DocumentType.YOUTUBE, {
layout: { view: YoutubeBox }
@@ -179,9 +186,15 @@ export namespace Docs {
[DocumentType.LINKFOLLOW, {
layout: { view: LinkFollowBox }
}],
+<<<<<<< HEAD
[DocumentType.WEBCAM, {
layout: { view: DashWebRTC }
}]
+=======
+ [DocumentType.PRESELEMENT, {
+ layout: { view: PresElementBox }
+ }],
+>>>>>>> 69e4a936c4eb0cc2e35e4e7f3258aed1f72b8da7
]);
// All document prototypes are initialized with at least these values
@@ -259,7 +272,7 @@ export namespace Docs {
// synthesize the default options, the type and title from computed values and
// whatever options pertain to this specific prototype
let options = { title: title, type: type, baseProto: true, ...defaultOptions, ...(template.options || {}) };
- let primary = layout.view.LayoutString();
+ let primary = layout.view.LayoutString(layout.ext);
let collectionView = layout.collectionView;
if (collectionView) {
options.layout = collectionView[0].LayoutString(collectionView[1], collectionView[2]);
@@ -338,7 +351,13 @@ export namespace Docs {
export function ImageDocument(url: string, options: DocumentOptions = {}) {
let imgField = new ImageField(new URL(url));
let inst = InstanceFromProto(Prototypes.get(DocumentType.IMG), imgField, { title: path.basename(url), ...options });
- requestImageSize(imgField.url.href)
+ let target = imgField.url.href;
+ if (new RegExp(window.location.origin).test(target)) {
+ let extension = path.extname(target);
+ target = `${target.substring(0, target.length - extension.length)}_o${extension}`;
+ }
+ // if (target !== "http://www.cs.brown.edu/") {
+ requestImageSize(target)
.then((size: any) => {
let aspect = size.height / size.width;
if (!inst.proto!.nativeWidth) {
@@ -348,6 +367,7 @@ export namespace Docs {
inst.proto!.height = NumCast(inst.proto!.width) * aspect;
})
.catch((err: any) => console.log(err));
+ // }
return inst;
}
export function PresDocument(initial: List<Doc> = new List(), options: DocumentOptions = {}) {
@@ -462,6 +482,10 @@ export namespace Docs {
return InstanceFromProto(Prototypes.get(DocumentType.LINKFOLLOW), undefined, { ...(options || {}) });
}
+ export function PresElementBoxDocument(options?: DocumentOptions) {
+ return InstanceFromProto(Prototypes.get(DocumentType.PRESELEMENT), undefined, { ...(options || {}) });
+ }
+
export function DockDocument(documents: Array<Doc>, config: string, options: DocumentOptions, id?: string) {
return InstanceFromProto(Prototypes.get(DocumentType.COL), new List(documents), { ...options, viewType: CollectionViewType.Docking, dockingConfig: config }, id);
}
@@ -516,10 +540,13 @@ export namespace Docs {
* @param title an optional title to give to the highest parent document in the hierarchy
*/
export function DocumentHierarchyFromJson(input: any, title?: string): Opt<Doc> {
- if (input === null || ![...primitives, "object"].includes(typeof input)) {
+ if (input === undefined || input === null || ![...primitives, "object"].includes(typeof input)) {
return undefined;
}
- let parsed: any = typeof input === "string" ? JSONUtils.tryParse(input) : input;
+ let parsed = input;
+ if (typeof input === "string") {
+ parsed = JSONUtils.tryParse(input);
+ }
let converted: Doc;
if (typeof parsed === "object" && !(parsed instanceof Array)) {
converted = convertObject(parsed, title);
@@ -616,10 +643,39 @@ export namespace Docs {
export namespace DocUtils {
- export function MakeLink(source: Doc, target: Doc, targetContext?: Doc, title: string = "", description: string = "", sourceContext?: Doc, id?: string) {
- if (LinkManager.Instance.doesLinkExist(source, target)) return undefined;
+ export function Publish(promoteDoc: Doc, targetID: string, addDoc: any, remDoc: any) {
+ targetID = targetID.replace(/^-/, "").replace(/\([0-9]*\)$/, "");
+ DocServer.GetRefField(targetID).then(doc => {
+ if (promoteDoc !== doc) {
+ let copy = doc as Doc;
+ if (copy) {
+ Doc.Overwrite(promoteDoc, copy, true);
+ } else {
+ copy = Doc.MakeCopy(promoteDoc, true, targetID);
+ }
+ !doc && (copy.title = undefined) && (Doc.GetProto(copy).title = targetID);
+ addDoc && addDoc(copy);
+ remDoc && remDoc(promoteDoc);
+ if (!doc) {
+ DocListCastAsync(promoteDoc.links).then(links => {
+ links && links.map(async link => {
+ if (link) {
+ let a1 = await Cast(link.anchor1, Doc);
+ if (a1 && Doc.AreProtosEqual(a1, promoteDoc)) link.anchor1 = copy;
+ let a2 = await Cast(link.anchor2, Doc);
+ if (a2 && Doc.AreProtosEqual(a2, promoteDoc)) link.anchor2 = copy;
+ LinkManager.Instance.deleteLink(link);
+ LinkManager.Instance.addLink(link);
+ }
+ });
+ });
+ }
+ }
+ });
+ }
+ export function MakeLink(source: Doc, target: Doc, targetContext?: Doc, title: string = "", description: string = "", sourceContext?: Doc, id?: string, anchored1?: boolean) {
let sv = DocumentManager.Instance.getDocumentView(source);
- if (sv && sv.props.ContainingCollectionView && sv.props.ContainingCollectionView.props.Document === target) return;
+ if (sv && sv.props.ContainingCollectionDoc === target) return;
if (target === CurrentUserUtils.UserDocument) return undefined;
let linkDocProto = new Doc(id, true);
@@ -630,21 +686,19 @@ export namespace DocUtils {
linkDocProto.sourceContext = sourceContext;
linkDocProto.title = title === "" ? source.title + " to " + target.title : title;
linkDocProto.linkDescription = description;
- linkDocProto.type = DocumentType.LINK;
linkDocProto.anchor1 = source;
linkDocProto.anchor1Page = source.curPage;
linkDocProto.anchor1Groups = new List<Doc>([]);
+ linkDocProto.anchor1anchored = anchored1;
linkDocProto.anchor2 = target;
linkDocProto.anchor2Page = target.curPage;
linkDocProto.anchor2Groups = new List<Doc>([]);
LinkManager.Instance.addLink(linkDocProto);
- let script = `return links(this);`;
- let computed = CompileScript(script, { params: { this: "Doc" }, typecheck: false });
- computed.compiled && (Doc.GetProto(source).links = new ComputedField(computed));
- computed.compiled && (Doc.GetProto(target).links = new ComputedField(computed));
+ Doc.GetProto(source).links = ComputedField.MakeFunction("links(this)");
+ Doc.GetProto(target).links = ComputedField.MakeFunction("links(this)");
}, "make link");
return linkDocProto;
}