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.ts57
1 files changed, 48 insertions, 9 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index 654431905..5752bb096 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -33,7 +33,12 @@ import { DocServer } from "../DocServer";
import { StrokeData, InkField } from "../../new_fields/InkField";
import { dropActionType } from "../util/DragManager";
import { DateField } from "../../new_fields/DateField";
+<<<<<<< HEAD
import { PDFBox2 } from "../views/pdf/PDFBox2";
+=======
+import { schema } from "prosemirror-schema-basic";
+import { UndoManager } from "../util/UndoManager";
+>>>>>>> 01a223f2e6685506cc1e5db69e9062d5ff0d3246
export interface DocumentOptions {
x?: number;
@@ -64,6 +69,38 @@ export interface DocumentOptions {
}
const delegateKeys = ["x", "y", "width", "height", "panX", "panY"];
+export namespace DocUtils {
+ export function MakeLink(source: Doc, target: Doc) {
+ let protoSrc = source.proto ? source.proto : source;
+ let protoTarg = target.proto ? target.proto : target;
+ UndoManager.RunInBatch(() => {
+ let linkDoc = Docs.TextDocument({ width: 100, height: 30, borderRounding: -1 });
+ //let linkDoc = new Doc;
+ linkDoc.proto!.title = "-link name-";
+ linkDoc.proto!.linkDescription = "";
+ linkDoc.proto!.linkTags = "Default";
+
+ linkDoc.proto!.linkedTo = target;
+ linkDoc.proto!.linkedFrom = source;
+
+ let linkedFrom = Cast(protoTarg.linkedFromDocs, listSpec(Doc));
+ if (!linkedFrom) {
+ protoTarg.linkedFromDocs = linkedFrom = new List<Doc>();
+ }
+ linkedFrom.push(linkDoc);
+
+ let linkedTo = Cast(protoSrc.linkedToDocs, listSpec(Doc));
+ if (!linkedTo) {
+ protoSrc.linkedToDocs = linkedTo = new List<Doc>();
+ }
+ linkedTo.push(linkDoc);
+ return linkDoc;
+ }, "make link");
+ }
+
+
+}
+
export namespace Docs {
let textProto: Doc;
let histoProto: Doc;
@@ -109,8 +146,8 @@ export namespace Docs {
deleg.data = value;
return Doc.assign(deleg, options);
}
- function SetDelegateOptions<U extends Field>(doc: Doc, options: DocumentOptions) {
- const deleg = Doc.MakeDelegate(doc);
+ function SetDelegateOptions(doc: Doc, options: DocumentOptions, id?: string) {
+ const deleg = Doc.MakeDelegate(doc, id);
return Doc.assign(deleg, options);
}
@@ -167,7 +204,7 @@ export namespace Docs {
return audioProto;
}
- function CreateInstance(proto: Doc, data: Field, options: DocumentOptions) {
+ function CreateInstance(proto: Doc, data: Field, options: DocumentOptions, delegId?: string) {
const { omit: protoProps, extract: delegateProps } = OmitKeys(options, delegateKeys);
if (!("author" in protoProps)) {
protoProps.author = CurrentUserUtils.email;
@@ -177,7 +214,7 @@ export namespace Docs {
}
protoProps.isPrototype = true;
- return SetDelegateOptions(SetInstanceOptions(proto, protoProps, data), delegateProps);
+ return SetDelegateOptions(SetInstanceOptions(proto, protoProps, data), delegateProps, delegId);
}
export function ImageDocument(url: string, options: DocumentOptions = {}) {
@@ -208,16 +245,18 @@ export namespace Docs {
export function PdfDocument(url: string, options: DocumentOptions = {}) {
return CreateInstance(pdfProto, new PdfField(new URL(url)), options);
}
+
export async function DBDocument(url: string, options: DocumentOptions = {}) {
let schemaName = options.title ? options.title : "-no schema-";
let ctlog = await Gateway.Instance.GetSchema(url, schemaName);
if (ctlog && ctlog.schemas) {
let schema = ctlog.schemas[0];
let schemaDoc = Docs.TreeDocument([], { ...options, nativeWidth: undefined, nativeHeight: undefined, width: 150, height: 100, title: schema.displayName! });
- let schemaDocuments = Cast(schemaDoc.data, listSpec(Doc));
+ let schemaDocuments = Cast(schemaDoc.data, listSpec(Doc), []);
if (!schemaDocuments) {
return;
}
+ CurrentUserUtils.AddNorthstarSchema(schema, schemaDoc);
const docs = schemaDocuments;
CurrentUserUtils.GetAllNorthstarColumnAttributes(schema).map(attr => {
DocServer.GetRefField(attr.displayName! + ".alias").then(action((field: Opt<Field>) => {
@@ -252,14 +291,14 @@ export namespace Docs {
}
return CreateInstance(collProto, new List(documents), { schemaColumns: new List(["title"]), ...options, viewType: CollectionViewType.Freeform });
}
- export function SchemaDocument(documents: Array<Doc>, options: DocumentOptions) {
- return CreateInstance(collProto, new List(documents), { schemaColumns: new List(["title"]), ...options, viewType: CollectionViewType.Schema });
+ export function SchemaDocument(schemaColumns: string[], documents: Array<Doc>, options: DocumentOptions) {
+ return CreateInstance(collProto, new List(documents), { schemaColumns: new List(schemaColumns), ...options, viewType: CollectionViewType.Schema });
}
export function TreeDocument(documents: Array<Doc>, options: DocumentOptions) {
return CreateInstance(collProto, new List(documents), { schemaColumns: new List(["title"]), ...options, viewType: CollectionViewType.Tree });
}
- export function DockDocument(documents: Array<Doc>, config: string, options: DocumentOptions) {
- return CreateInstance(collProto, new List(documents), { ...options, viewType: CollectionViewType.Docking, dockingConfig: config });
+ export function DockDocument(documents: Array<Doc>, config: string, options: DocumentOptions, id?: string) {
+ return CreateInstance(collProto, new List(documents), { ...options, viewType: CollectionViewType.Docking, dockingConfig: config }, id);
}
export function CaptionDocument(doc: Doc) {