diff options
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/documents/Documents.ts | 2 | ||||
| -rw-r--r-- | src/client/util/CurrentUserUtils.ts | 4 | ||||
| -rw-r--r-- | src/client/views/collections/CollectionDockingView.tsx | 34 |
3 files changed, 20 insertions, 20 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts index 0a3865a13..8aa478cc1 100644 --- a/src/client/documents/Documents.ts +++ b/src/client/documents/Documents.ts @@ -780,8 +780,6 @@ export namespace Docs { LinkManager.Instance.addLink(doc); - source.doc.links === undefined && (Doc.GetProto(source.doc).links = ComputedField.MakeFunction("links(self)")); - target.doc.links === undefined && (Doc.GetProto(target.doc).links = ComputedField.MakeFunction("links(self)")); return doc; } diff --git a/src/client/util/CurrentUserUtils.ts b/src/client/util/CurrentUserUtils.ts index 2a84171cb..e601d33f7 100644 --- a/src/client/util/CurrentUserUtils.ts +++ b/src/client/util/CurrentUserUtils.ts @@ -1156,8 +1156,8 @@ export class CurrentUserUtils { input.click(); } - public static snapshotDashboard = (userDoc: Doc) => { - const copy = CollectionDockingView.Copy(CurrentUserUtils.ActiveDashboard); + public static async snapshotDashboard(userDoc: Doc) { + const copy = await CollectionDockingView.Copy(CurrentUserUtils.ActiveDashboard); Doc.AddDocToList(Cast(userDoc.myDashboards, Doc, null), "data", copy); CurrentUserUtils.openDashboard(userDoc, copy); } diff --git a/src/client/views/collections/CollectionDockingView.tsx b/src/client/views/collections/CollectionDockingView.tsx index b9757dde3..57f4555a1 100644 --- a/src/client/views/collections/CollectionDockingView.tsx +++ b/src/client/views/collections/CollectionDockingView.tsx @@ -342,25 +342,27 @@ export class CollectionDockingView extends CollectionSubView(doc => doc) { } } - public static Copy(doc: Doc) { + public static async Copy(doc: Doc, clone = false) { + clone = !Doc.UserDoc().noviceMode; let json = StrCast(doc.dockingConfig); + if (clone) { + const cloned = (await Doc.MakeClone(doc)); + Array.from(cloned.map.entries()).map(entry => json = json.replace(entry[0], entry[1][Id])); + Doc.SetInPlace(cloned.clone, "dockingConfig", json, true); + return cloned.clone; + } const matches = json.match(/\"documentId\":\"[a-z0-9-]+\"/g); - const docids = matches?.map(m => m.replace("\"documentId\":\"", "").replace("\"", "")) || []; - const docs = docids.map(id => DocServer.GetCachedRefField(id)).filter(f => f).map(f => f as Doc); - const newtabs = docs.map(doc => { - const copy = Doc.MakeAlias(doc); - json = json.replace(doc[Id], copy[Id]); - return copy; + const origtabids = matches?.map(m => m.replace("\"documentId\":\"", "").replace("\"", "")) || []; + const origtabs = origtabids.map(id => DocServer.GetCachedRefField(id)).filter(f => f).map(f => f as Doc); + const newtabs = origtabs.map(origtab => { + const origtabdocs = DocListCast(origtab.data); + const newtab = origtabdocs.length ? Doc.MakeCopy(origtab, true) : Doc.MakeAlias(origtab); + const newtabdocs = origtabdocs.map(origtabdoc => Doc.MakeAlias(origtabdoc)); + newtabdocs.length && Doc.SetInPlace(newtab, "data", new List<Doc>(newtabdocs), true); + json = json.replace(origtab[Id], newtab[Id]); + return newtab; }); - const copy = Docs.Create.DockDocument(newtabs, json, { title: "Snapshot: " + doc.title }); - const docsublists = DocListCast(doc.data); - const copysublists = DocListCast(copy.data); - const docother = Cast(docsublists[1], Doc, null); - const copyother = Cast(copysublists[1], Doc, null); - const newother = DocListCast(docother.data).map(doc => Doc.MakeAlias(doc)); - Doc.GetProto(copyother).data = new List<Doc>(newother); - - return copy; + return Docs.Create.DockDocument(newtabs, json, { title: "Snapshot: " + doc.title }); } @action |
