aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
Diffstat (limited to 'src/client')
-rw-r--r--src/client/util/LinkManager.ts57
-rw-r--r--src/client/views/nodes/LinkEditor.scss2
-rw-r--r--src/client/views/nodes/LinkEditor.tsx34
3 files changed, 46 insertions, 47 deletions
diff --git a/src/client/util/LinkManager.ts b/src/client/util/LinkManager.ts
index c0c607b01..2f40c77e7 100644
--- a/src/client/util/LinkManager.ts
+++ b/src/client/util/LinkManager.ts
@@ -20,49 +20,48 @@ export namespace LinkUtils {
}
}
- // export function getAnchorGroups(link: Doc, anchor: Doc): Doc[] {
- // let groups;
- // if (Doc.AreProtosEqual(anchor, Cast(link.anchor1, Doc, new Doc))) {
- // groups = Cast(link.anchor1Groups, listSpec(Doc), []);
- // } else {
- // groups = Cast(link.anchor2Groups, listSpec(Doc), []);
- // }
-
- // if (groups instanceof Doc[]) {
- // return groups;
- // } else {
- // return [];
- // }
- // // if (Doc.AreProtosEqual(anchor, Cast(link.anchor1, Doc, new Doc))) {
- // // returnCast(link.anchor1Groups, listSpec(Doc), []);
- // // } else {
- // // return Cast(link.anchor2Groups, listSpec(Doc), []);
- // // }
- // }
-
export function setAnchorGroups(link: Doc, anchor: Doc, groups: Doc[]) {
// console.log("setting groups for anchor", anchor["title"]);
if (Doc.AreProtosEqual(anchor, Cast(link.anchor1, Doc, new Doc))) {
link.anchor1Groups = new List<Doc>(groups);
+
+ let print: string[] = [];
+ Cast(link.anchor1Groups, listSpec(Doc), []).forEach(doc => {
+ if (doc instanceof Doc) {
+ print.push(StrCast(doc.type));
+ }
+ });
+ console.log("set anchor's groups as", print);
} else {
link.anchor2Groups = new List<Doc>(groups);
+
+ let print: string[] = [];
+ Cast(link.anchor2Groups, listSpec(Doc), []).forEach(doc => {
+ if (doc instanceof Doc) {
+ print.push(StrCast(doc.type));
+ }
+ });
+ console.log("set anchor's groups as", print);
}
}
export function removeGroupFromAnchor(link: Doc, anchor: Doc, groupType: string) {
- let groups = [];
- if (Doc.AreProtosEqual(anchor, Cast(link.anchor1, Doc, new Doc))) {
- groups = Cast(link.proto!.anchor1Groups, listSpec(Doc), []);
- } else {
- groups = Cast(link.proto!.anchor2Groups, listSpec(Doc), []);
- }
+ let groups = Doc.AreProtosEqual(anchor, Cast(link.anchor1, Doc, new Doc)) ?
+ Cast(link.proto!.anchor1Groups, listSpec(Doc), []) : Cast(link.proto!.anchor2Groups, listSpec(Doc), []);
let newGroups: Doc[] = [];
groups.forEach(groupDoc => {
if (groupDoc instanceof Doc && StrCast(groupDoc.type) !== groupType) {
newGroups.push(groupDoc);
- }
+ } // TODO: promise
});
+
+ // let grouptypes: string[] = [];
+ // newGroups.forEach(groupDoc => {
+ // grouptypes.push(StrCast(groupDoc.type));
+ // });
+ // console.log("remove anchor's groups as", grouptypes);
+
LinkUtils.setAnchorGroups(link, anchor, newGroups);
}
}
@@ -92,7 +91,7 @@ export class LinkManager {
}
@observable public allLinks: Array<Doc> = []; // list of link docs
- @observable public allGroups: Map<string, Array<string>> = new Map(); // map of group type to list of its metadata keys
+ @observable public groupMetadataKeys: Map<string, Array<string>> = new Map(); // map of group type to list of its metadata keys
public findAllRelatedLinks(anchor: Doc): Array<Doc> {
return LinkManager.Instance.allLinks.filter(
@@ -171,7 +170,7 @@ export class LinkManager {
}
public deleteGroup(groupType: string) {
- let deleted = LinkManager.Instance.allGroups.delete(groupType);
+ let deleted = LinkManager.Instance.groupMetadataKeys.delete(groupType);
if (deleted) {
LinkManager.Instance.allLinks.forEach(linkDoc => {
LinkUtils.removeGroupFromAnchor(linkDoc, Cast(linkDoc.anchor1, Doc, new Doc), groupType);
diff --git a/src/client/views/nodes/LinkEditor.scss b/src/client/views/nodes/LinkEditor.scss
index df7bd6086..01f0cb82a 100644
--- a/src/client/views/nodes/LinkEditor.scss
+++ b/src/client/views/nodes/LinkEditor.scss
@@ -127,7 +127,7 @@
display: flex;
justify-content: space-between;
.linkEditor-groupOpts {
- width: calc(33% - 3px);
+ width: calc(20% - 3px);
height: 20px;
// margin-left: 6px;
padding: 0;
diff --git a/src/client/views/nodes/LinkEditor.tsx b/src/client/views/nodes/LinkEditor.tsx
index 386d0cc3e..5097d625e 100644
--- a/src/client/views/nodes/LinkEditor.tsx
+++ b/src/client/views/nodes/LinkEditor.tsx
@@ -37,14 +37,14 @@ class LinkGroupsDropdown extends React.Component<{ groupId: string, groupType: s
@action
createGroup(value: string) {
- LinkManager.Instance.allGroups.set(value, []);
+ LinkManager.Instance.groupMetadataKeys.set(value, []);
this.props.setGroup(this.props.groupId, value);
}
renderOptions = (): JSX.Element[] => {
let allGroups: string[], searchTerm: string, results: string[], exactFound: boolean;
if (this._searchTerm !== "") {
- allGroups = Array.from(LinkManager.Instance.allGroups.keys());
+ allGroups = Array.from(LinkManager.Instance.groupMetadataKeys.keys());
searchTerm = this._searchTerm.toUpperCase();
results = allGroups.filter(group => group.toUpperCase().indexOf(searchTerm) > -1);
exactFound = results.findIndex(group => group.toUpperCase() === searchTerm) > -1;
@@ -90,7 +90,7 @@ class LinkMetadataEditor extends React.Component<{ groupType: string, mdDoc: Doc
@action
editMetadataKey = (value: string): void => {
// TODO: check that metadata doesnt already exist in group
- let groupMdKeys = new Array(...LinkManager.Instance.allGroups.get(this.props.groupType)!);
+ let groupMdKeys = new Array(...LinkManager.Instance.groupMetadataKeys.get(this.props.groupType)!);
if (groupMdKeys) {
let index = groupMdKeys.indexOf(this._key);
if (index > -1) {
@@ -102,7 +102,7 @@ class LinkMetadataEditor extends React.Component<{ groupType: string, mdDoc: Doc
}
this._key = value;
- LinkManager.Instance.allGroups.set(this.props.groupType, groupMdKeys);
+ LinkManager.Instance.groupMetadataKeys.set(this.props.groupType, groupMdKeys);
}
@action
@@ -113,7 +113,7 @@ class LinkMetadataEditor extends React.Component<{ groupType: string, mdDoc: Doc
@action
removeMetadata = (): void => {
- let groupMdKeys = new Array(...LinkManager.Instance.allGroups.get(this.props.groupType)!);
+ let groupMdKeys = new Array(...LinkManager.Instance.groupMetadataKeys.get(this.props.groupType)!);
if (groupMdKeys) {
let index = groupMdKeys.indexOf(this._key);
if (index > -1) {
@@ -124,7 +124,7 @@ class LinkMetadataEditor extends React.Component<{ groupType: string, mdDoc: Doc
}
}
this._key = "";
- LinkManager.Instance.allGroups.set(this.props.groupType, groupMdKeys);
+ LinkManager.Instance.groupMetadataKeys.set(this.props.groupType, groupMdKeys);
}
render() {
@@ -132,7 +132,7 @@ class LinkMetadataEditor extends React.Component<{ groupType: string, mdDoc: Doc
<div className="linkEditor-metadata-row">
<input type="text" value={this._key} placeholder="key" onChange={e => this.editMetadataKey(e.target.value)}></input>:
<input type="text" value={this._value} placeholder="value" onChange={e => this.editMetadataValue(e.target.value)}></input>
- <button onClick={() => this.removeMetadata()}>X</button>
+ <button onClick={() => this.removeMetadata()}>x</button>
</div>
);
}
@@ -199,7 +199,7 @@ export class LinkEditor extends React.Component<LinkEditorProps> {
@action
setGroupType = (groupId: string, groupType: string): void => {
console.log("setting for ", groupId);
- let linkDoc = this.props.linkDoc.proto ? this.props.linkDoc.proto : this.props.linkDoc;
+ // let linkDoc = this.props.linkDoc.proto ? this.props.linkDoc.proto : this.props.linkDoc;
let groupDoc = this._groups.get(groupId);
if (groupDoc) {
console.log("found group doc");
@@ -208,7 +208,7 @@ export class LinkEditor extends React.Component<LinkEditorProps> {
this._groups.set(groupId, groupDoc);
- LinkUtils.setAnchorGroups(linkDoc, this.props.sourceDoc, Array.from(this._groups.values()));
+ LinkUtils.setAnchorGroups(this.props.linkDoc, this.props.sourceDoc, Array.from(this._groups.values()));
console.log("set", Array.from(this._groups.values()).length);
}
@@ -285,7 +285,7 @@ export class LinkEditor extends React.Component<LinkEditorProps> {
let newMdDoc = Docs.TextDocument();
newMdDoc.proto!.anchor1 = StrCast(thisMdDoc.anchor2);
newMdDoc.proto!.anchor2 = StrCast(thisMdDoc.anchor1);
- let keys = LinkManager.Instance.allGroups.get(groupType);
+ let keys = LinkManager.Instance.groupMetadataKeys.get(groupType);
if (keys) {
keys.forEach(key => {
if (thisGroupDoc) { // TODO: clean
@@ -307,7 +307,7 @@ export class LinkEditor extends React.Component<LinkEditorProps> {
renderGroup(groupId: string, groupDoc: Doc) {
let type = StrCast(groupDoc.type);
- if ((type && LinkManager.Instance.allGroups.get(type)) || type === "New Group") {
+ if ((type && LinkManager.Instance.groupMetadataKeys.get(type)) || type === "New Group") {
return (
<div key={groupId} className="linkEditor-group">
<div className="linkEditor-group-row">
@@ -319,8 +319,8 @@ export class LinkEditor extends React.Component<LinkEditorProps> {
{groupDoc.type === "New Group" ? <button className="linkEditor-groupOpts" disabled={true} title="Add KVP">+</button> :
<button className="linkEditor-groupOpts" onClick={() => this.addMetadata(StrCast(groupDoc.proto!.type))} title="Add KVP">+</button>}
<button className="linkEditor-groupOpts" onClick={() => this.copyGroup(groupId, type)} title="Copy group to opposite anchor">↔</button>
- {/* <button className="linkEditor-groupOpts" onClick={() => this.removeGroupFromLink(groupId, type)} title="Remove group from link">x</button>
- <button className="linkEditor-groupOpts" onClick={() => this.deleteGroup(groupId, type)} title="Delete group">xx</button> */}
+ <button className="linkEditor-groupOpts" onClick={() => this.removeGroupFromLink(groupId, type)} title="Remove group from link">x</button>
+ <button className="linkEditor-groupOpts" onClick={() => this.deleteGroup(groupId, type)} title="Delete group">xx</button>
{this.viewGroupAsTable(groupId, type)}
</div>
</div>
@@ -331,7 +331,7 @@ export class LinkEditor extends React.Component<LinkEditorProps> {
}
viewGroupAsTable(groupId: string, groupType: string) {
- let keys = LinkManager.Instance.allGroups.get(groupType);
+ let keys = LinkManager.Instance.groupMetadataKeys.get(groupType);
let groupDoc = this._groups.get(groupId);
if (keys && groupDoc) {
console.log("keys:", ...keys);
@@ -347,7 +347,7 @@ export class LinkEditor extends React.Component<LinkEditorProps> {
@action
addMetadata = (groupType: string): void => {
- let mdKeys = LinkManager.Instance.allGroups.get(groupType);
+ let mdKeys = LinkManager.Instance.groupMetadataKeys.get(groupType);
if (mdKeys) {
if (mdKeys.indexOf("new key") === -1) {
mdKeys.push("new key");
@@ -355,7 +355,7 @@ export class LinkEditor extends React.Component<LinkEditorProps> {
} else {
mdKeys = ["new key"];
}
- LinkManager.Instance.allGroups.set(groupType, mdKeys);
+ LinkManager.Instance.groupMetadataKeys.set(groupType, mdKeys);
}
renderMetadata(groupId: string) {
@@ -364,7 +364,7 @@ export class LinkEditor extends React.Component<LinkEditorProps> {
if (groupDoc) {
let mdDoc = Cast(groupDoc.proto!.metadata, Doc, new Doc);
let groupType = StrCast(groupDoc.proto!.type);
- let groupMdKeys = LinkManager.Instance.allGroups.get(groupType);
+ let groupMdKeys = LinkManager.Instance.groupMetadataKeys.get(groupType);
if (groupMdKeys) {
groupMdKeys.forEach((key, index) => {
metadata.push(