aboutsummaryrefslogtreecommitdiff
path: root/src/client/documents/Documents.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/documents/Documents.ts')
-rw-r--r--src/client/documents/Documents.ts83
1 files changed, 60 insertions, 23 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index 7233fbea5..49d1820f5 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -16,9 +16,7 @@ import { action } from "mobx";
import { ColumnAttributeModel } from "../northstar/core/attribute/AttributeModel";
import { AttributeTransformationModel } from "../northstar/core/attribute/AttributeTransformationModel";
import { AggregateFunction } from "../northstar/model/idea/idea";
-import { MINIMIZED_ICON_SIZE } from "../views/globalCssVariables.scss";
-import { IconBox } from "../views/nodes/IconBox";
-import { OmitKeys, JSONUtils } from "../../Utils";
+import { OmitKeys, JSONUtils, Utils } from "../../Utils";
import { Field, Doc, Opt, DocListCastAsync, FieldResult, DocListCast } from "../../new_fields/Doc";
import { ImageField, VideoField, AudioField, PdfField, WebField, YoutubeField } from "../../new_fields/URLField";
import { HtmlField } from "../../new_fields/HtmlField";
@@ -37,6 +35,7 @@ import { DocumentManager } from "../util/DocumentManager";
import DirectoryImportBox from "../util/Import & Export/DirectoryImportBox";
import { Scripting } from "../util/Scripting";
import { ButtonBox } from "../views/nodes/ButtonBox";
+import { SliderBox } from "../views/nodes/SliderBox";
import { FontIconBox } from "../views/nodes/FontIconBox";
import { SchemaHeaderField } from "../../new_fields/SchemaHeaderField";
import { PresBox } from "../views/nodes/PresBox";
@@ -55,6 +54,7 @@ import { InkField } from "../../new_fields/InkField";
import { InkingControl } from "../views/InkingControl";
import { RichTextField } from "../../new_fields/RichTextField";
import { Networking } from "../Network";
+import { extname } from "path";
const requestImageSize = require('../util/request-image-size');
const path = require('path');
@@ -131,6 +131,7 @@ export interface DocumentOptions {
strokeWidth?: number;
color?: string;
treeViewHideTitle?: boolean; // whether to hide the title of a tree view
+ treeViewHideHeaderFields?: boolean; // whether to hide the drop down options for tree view items.
treeViewOpen?: boolean; // whether this document is expanded in a tree view
treeViewChecked?: ScriptField; // script to call when a tree view checkbox is checked
isFacetFilter?: boolean; // whether document functions as a facet filter in a tree view
@@ -213,10 +214,6 @@ export namespace Docs {
layout: { view: PDFBox, dataField: data },
options: { curPage: 1 }
}],
- [DocumentType.ICON, {
- layout: { view: IconBox, dataField: data },
- options: { _width: Number(MINIMIZED_ICON_SIZE), _height: Number(MINIMIZED_ICON_SIZE) },
- }],
[DocumentType.IMPORT, {
layout: { view: DirectoryImportBox, dataField: data },
options: { _height: 150 }
@@ -231,6 +228,9 @@ export namespace Docs {
[DocumentType.BUTTON, {
layout: { view: ButtonBox, dataField: data },
}],
+ [DocumentType.SLIDER, {
+ layout: { view: SliderBox, dataField: data },
+ }],
[DocumentType.PRES, {
layout: { view: PresBox, dataField: data },
options: {}
@@ -345,8 +345,44 @@ export namespace Docs {
*/
export namespace Create {
- export async function Buxton() {
- console.log(await Networking.FetchFromServer("/newBuxton"));
+ export function Buxton() {
+ const loading = new Doc;
+ loading.title = "Please wait for the import script...";
+ const parent = TreeDocument([loading], {
+ title: "The Buxton Collection",
+ _width: 400,
+ _height: 400,
+ _LODdisable: true
+ });
+ Networking.FetchFromServer("/buxton").then(response => {
+ const devices = JSON.parse(response);
+ if (!Array.isArray(devices)) {
+ if ("error" in devices) {
+ loading.title = devices.error;
+ } else {
+ console.log(devices);
+ alert("The importer returned an unexpected import format. Check the console.");
+ }
+ return;
+ }
+ const parentProto = Doc.GetProto(parent);
+ parentProto.data = new List<Doc>();
+ devices.forEach(device => {
+ const { __images } = device;
+ delete device.__images;
+ const { ImageDocument, StackingDocument } = Docs.Create;
+ if (Array.isArray(__images)) {
+ const constructed = __images.map(relative => Utils.prepend(relative));
+ const deviceImages = constructed.map((url, i) => ImageDocument(url, { title: `image${i}.${extname(url)}` }));
+ const doc = StackingDocument(deviceImages, { title: device.title, _LODdisable: true });
+ const deviceProto = Doc.GetProto(doc);
+ deviceProto.hero = new ImageField(constructed[0]);
+ Docs.Get.DocumentHierarchyFromJson(device, undefined, deviceProto);
+ Doc.AddDocToList(parentProto, "data", doc);
+ }
+ });
+ });
+ return parent;
}
Scripting.addGlobal(Buxton);
@@ -476,10 +512,6 @@ export namespace Docs {
return doc;
}
- export function IconDocument(icon: string, options: DocumentOptions = {}) {
- return InstanceFromProto(Prototypes.get(DocumentType.ICON), new IconField(icon), options);
- }
-
export function PdfDocument(url: string, options: DocumentOptions = {}) {
return InstanceFromProto(Prototypes.get(DocumentType.PDF), new PdfField(new URL(url)), options);
}
@@ -558,6 +590,10 @@ export namespace Docs {
export function MulticolumnDocument(documents: Array<Doc>, options: DocumentOptions) {
return InstanceFromProto(Prototypes.get(DocumentType.COL), new List(documents), { _chromeStatus: "collapsed", schemaColumns: new List([new SchemaHeaderField("title", "#f1efeb")]), ...options, _viewType: CollectionViewType.Multicolumn });
}
+ export function MultirowDocument(documents: Array<Doc>, options: DocumentOptions) {
+ return InstanceFromProto(Prototypes.get(DocumentType.COL), new List(documents), { _chromeStatus: "collapsed", schemaColumns: new List([new SchemaHeaderField("title", "#f1efeb")]), ...options, _viewType: CollectionViewType.Multirow });
+ }
+
export function MasonryDocument(documents: Array<Doc>, options: DocumentOptions) {
return InstanceFromProto(Prototypes.get(DocumentType.COL), new List(documents), { _chromeStatus: "collapsed", schemaColumns: new List([new SchemaHeaderField("title", "#f1efeb")]), ...options, _viewType: CollectionViewType.Masonry });
@@ -567,6 +603,10 @@ export namespace Docs {
return InstanceFromProto(Prototypes.get(DocumentType.BUTTON), undefined, { ...(options || {}) });
}
+ export function SliderDocument(options?: DocumentOptions) {
+ return InstanceFromProto(Prototypes.get(DocumentType.SLIDER), undefined, { ...(options || {}) });
+ }
+
export function FontIconDocument(options?: DocumentOptions) {
return InstanceFromProto(Prototypes.get(DocumentType.FONTICON), undefined, { ...(options || {}) });
@@ -636,7 +676,7 @@ export namespace Docs {
* or the result of any JSON.parse() call.
* @param title an optional title to give to the highest parent document in the hierarchy
*/
- export function DocumentHierarchyFromJson(input: any, title?: string): Opt<Doc> {
+ export function DocumentHierarchyFromJson(input: any, title?: string, appendToTarget?: Doc): Opt<Doc> {
if (input === undefined || input === null || ![...primitives, "object"].includes(typeof input)) {
return undefined;
}
@@ -646,7 +686,7 @@ export namespace Docs {
}
let converted: Doc;
if (typeof parsed === "object" && !(parsed instanceof Array)) {
- converted = convertObject(parsed, title);
+ converted = convertObject(parsed, title, appendToTarget);
} else {
(converted = new Doc).json = toField(parsed);
}
@@ -661,12 +701,12 @@ export namespace Docs {
* @returns the object mapped from JSON to field values, where each mapping
* might involve arbitrary recursion (since toField might itself call convertObject)
*/
- const convertObject = (object: any, title?: string): Doc => {
- const target = new Doc();
+ const convertObject = (object: any, title?: string, target?: Doc): Doc => {
+ const resolved = target ?? new Doc;
let result: Opt<Field>;
- Object.keys(object).map(key => (result = toField(object[key], key)) && (target[key] = result));
- title && !target.title && (target.title = title);
- return target;
+ Object.keys(object).map(key => (result = toField(object[key], key)) && (resolved[key] = result));
+ title && !resolved.title && (resolved.title = title);
+ return resolved;
};
/**
@@ -713,9 +753,6 @@ export namespace Docs {
} else if (field instanceof PdfField) {
created = Docs.Create.PdfDocument((field).url.href, resolved);
layout = PDFBox.LayoutString;
- } else if (field instanceof IconField) {
- created = Docs.Create.IconDocument((field).icon, resolved);
- layout = IconBox.LayoutString;
} else if (field instanceof AudioField) {
created = Docs.Create.AudioDocument((field).url.href, resolved);
layout = AudioBox.LayoutString;