aboutsummaryrefslogtreecommitdiff
path: root/src/client/documents/Documents.ts
diff options
context:
space:
mode:
authorBob Zeleznik <zzzman@gmail.com>2019-09-13 00:55:39 -0400
committerBob Zeleznik <zzzman@gmail.com>2019-09-13 00:55:39 -0400
commite241e61d6521ff5d63de1292f2b4269493f5d7cc (patch)
treec39dc8619e637654cc8937be6b3f0ee0d7f8df96 /src/client/documents/Documents.ts
parent26eed39d2fe140e6bfc3d572bd1aa4717ab52926 (diff)
added "publish" option to convert a document to a recognizable id
Diffstat (limited to 'src/client/documents/Documents.ts')
-rw-r--r--src/client/documents/Documents.ts28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index 602a7f9ad..28e5e5f40 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -20,7 +20,7 @@ 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 { Field, Doc, Opt, DocListCastAsync } from "../../new_fields/Doc";
import { OmitKeys, JSONUtils } from "../../Utils";
import { ImageField, VideoField, AudioField, PdfField, WebField, YoutubeField } from "../../new_fields/URLField";
import { HtmlField } from "../../new_fields/HtmlField";
@@ -607,6 +607,32 @@ export namespace Docs {
export namespace DocUtils {
+ export function Publish(promoteDoc: Doc, targetID: string, addDoc: any, remDoc: any) {
+ if (targetID.startsWith("-")) {
+ targetID = targetID.substr(1, targetID.length - 1);
+ Doc.GetProto(promoteDoc).title = targetID;
+ }
+ DocServer.GetRefField(targetID).then(doc => {
+ let copy = doc instanceof Doc ? doc : Doc.MakeCopy(promoteDoc, true, targetID);
+ !doc && (Doc.GetProto(copy).title = targetID);
+ addDoc && addDoc(copy);
+ !doc && 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) {
if (LinkManager.Instance.doesLinkExist(source, target)) return undefined;
let sv = DocumentManager.Instance.getDocumentView(source);