Skip to content

Commit

Permalink
add a bunch of workflowy stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
acenturyandabit committed Dec 31, 2021
1 parent ecd0bd1 commit a243a0a
Show file tree
Hide file tree
Showing 9 changed files with 500 additions and 106 deletions.
261 changes: 215 additions & 46 deletions cat.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion filemanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"operators/workflow/workflow.js",
"operators/workflow/focusMode.js",
"operators/workflow/search.js",
"operators/workflow/copypaste.js",
"operators/workflow/workflow_gitfriendly_contextmenu.js",
"operators/workflow/workflow_gitfriendly.js",
"operators/workflow/advancedentry.js",
Expand All @@ -52,7 +53,7 @@
"3pt/svg.min.js",
"3pt/svg.foreignobject.js",
"operators/itemcluster/itemcluster.svg.js",
"operators/itemcluster/contextmenu/orbit.js",
"operators/itemcluster/contextmenu/entropic_hierarchy.js",
"operators/itemcluster/itemcluster.contextmenu.js",
"operators/itemcluster/itemcluster.scalegrid.js",
"operators/itemcluster/itemcluster.rapidentry.js",
Expand Down
2 changes: 1 addition & 1 deletion operators/workflow/advancedentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ function workflowy_advanced_entry() {
this.parse(e.target, plaintextOperatingOnID);
polymorph_core.items[plaintextOperatingOnID][this.settings.titleProperty] = e.target.innerText; // polymorph_core.RTParseElement(e.target, id, this.settings.titleProperty);
this.container.fire("updateItem", { id: plaintextOperatingOnID, sender: this });
this.renderItem(plaintextOperatingOnID);
this.renderItem(plaintextOperatingOnID, "d");
});
}
3 changes: 3 additions & 0 deletions operators/workflow/copypaste.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function workflowy_copy_paste() {
console.log(this.contextmenu.el);
}
4 changes: 2 additions & 2 deletions operators/workflow/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function workflowy_gitfriendly_search() {
// Hide everything
for (let i in this.renderedItemCache) {
if (i) {
if (this.settings.filterHide) this.resolveSpan(i).el.style.display = "none";
if (this.settings.filterHides) this.resolveSpan(i).el.style.display = "none";
this.resolveSpan(i).el.classList.remove("searchFocused");
}
}
Expand All @@ -33,7 +33,7 @@ function workflowy_gitfriendly_search() {
}
if (i != ptree.length - 1 || this.holdExpanded[v]) {
this.holdExpanded[v] = true;
setExpandedState(el, true, true, true);
this.setExpandedState(el, true, true, true);
}
// set it to expanded
// unless it's the last one
Expand Down
41 changes: 36 additions & 5 deletions operators/workflow/workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ polymorph_core.registerOperator("workflow", {
rootItemListItem: "",
rootItemListItemProperty: "",
linkProp: "to",
bracketPropertyPrefix: container.id
bracketPropertyPrefix: container.id,
sortBackwards: false,
unsortableBeforeSorted: false
};
polymorph_core.operatorTemplate.call(this, container, defaultSettings);
//Can probably replace this with direct instantiation instead of a getter, if we're careful.
Expand Down Expand Up @@ -1014,6 +1016,20 @@ polymorph_core.registerOperator("workflow", {
object: this.settings,
property: "bracketPropertyPrefix",
label: "Prefix for bracket properties"
}),
sortBackwards: new polymorph_core._option({
div: this.dialogDiv,
type: "boolean",
object: this.settings,
property: "sortBackwards",
label: "Reverse item sort order"
}),
unsortableBeforeSorted: new polymorph_core._option({
div: this.dialogDiv,
type: "boolean",
object: this.settings,
property: "unsortableBeforeSorted",
label: "Place unsortable items before sortable items in order"
})
}
this.showDialog = function() {
Expand Down Expand Up @@ -1162,24 +1178,39 @@ polymorph_core.registerOperator("workflow", {
return;
}

// map items to item/date pairs
let itemMapper = (a) => {
let result;
if (polymorph_core.items[a][property] && polymorph_core.items[a][property].date && polymorph_core.items[a][property].date.length) {
result = dateParser.getSortingTime(polymorph_core.items[a][property].datestring, new Date(polymorph_core.items[a][property].date[0].refdate))
if (result) result = result.date;
}
if (!result) result = Date.now() * 10000;
if (!result) {
// no date
if (this.settings.unsortableBeforeSorted) {
result = -1;
} else {
result = Date.now() * 10000;
}
}
return [a, result];
}
property = `_${this.settings.bracketPropertyPrefix}_${property}`;
let objs;
if (root && root.dataset.id) {
let objs = polymorph_core.items[root.dataset.id].toOrder.map(itemMapper);
objs = polymorph_core.items[root.dataset.id].toOrder.map(itemMapper);
} else if (!root) {
objs = this.rootItems.map(itemMapper);
}
if (this.settings.sortBackwards) {
objs.sort((a, b) => b[1] - a[1]);
} else {
objs.sort((a, b) => a[1] - b[1]);
}
if (root && root.dataset.id) {
polymorph_core.items[root.dataset.id].toOrder = objs.map(i => i[0]);
polymorph_core.fire("updateItem", { id: root.dataset.id, sender: this });
} else if (!root) {
let objs = this.rootItems.map(itemMapper);
objs.sort((a, b) => a[1] - b[1]);
this.rootItems = objs.map(i => i[0]);
polymorph_core.fire("updateItem", { id: this.rootItemId, sender: this });
}
Expand Down
30 changes: 25 additions & 5 deletions operators/workflow/workflow_gitfriendly.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ polymorph_core.registerOperator("workflow_gf", {
focusExclusionID: "",
collapseProperty: "collapsed",
advancedInputMode: false,
filterHides: false
filterHides: false,
sortBackwards: false,
unsortableBeforeSorted: false
};
polymorph_core.operatorTemplate.call(this, container, defaultSettings);
_workflow_focusMode_extend.apply(this);
Expand Down Expand Up @@ -144,6 +146,7 @@ polymorph_core.registerOperator("workflow_gf", {
i.style.display = "block";
});
}
this.setExpandedState = setExpandedState;

let restoreClickFlag = false;
this.rootdiv.addEventListener("click", (e) => {
Expand Down Expand Up @@ -510,7 +513,7 @@ polymorph_core.registerOperator("workflow_gf", {
setParent(id, polymorph_core.items[spanWithID.parentElement.parentElement.dataset.id][this.settings.parentProperty]);
polymorph_core.fire("updateItem", { id: id, sender: this }); // force rerender in other operators
this.renderItem(id, "d");
wasme.focus();
focusOnElement(wasme);
} else {
// already a root node, do nothing
}
Expand Down Expand Up @@ -725,10 +728,12 @@ polymorph_core.registerOperator("workflow_gf", {
.sort((a, b) => {
let a_date = getDate(a[1]);
let b_date = getDate(b[1]);
if (a_date && !b_date) return -1;
if (b_date && !a_date) return 1;
let inversionFactor = (this.settings.unsortableBeforeSorted) ? -1 : 1;
if (a_date && !b_date) return -1 * inversionFactor;
if (b_date && !a_date) return 1 * inversionFactor;
if (!a_date && !b_date) return 0;
return a_date - b_date;
if (this.settings.sortBackwards) return a_date - b_date;
else return b_date - a_date;
}).forEach((v, i) => {
if (polymorph_core.items[v[0]][this.settings.orderProperty] != i) {
polymorph_core.items[v[0]][this.settings.orderProperty] = i;
Expand Down Expand Up @@ -1089,6 +1094,20 @@ polymorph_core.registerOperator("workflow_gf", {
object: () => this.settings,
property: "filterHides",
label: "Filter should hideitems"
}),
sortBackwards: new polymorph_core._option({
div: this.dialogDiv,
type: "boolean",
object: () => this.settings,
property: "sortBackwards",
label: "Reverse item sort order"
}),
unsortableBeforeSorted: new polymorph_core._option({
div: this.dialogDiv,
type: "boolean",
object: () => this.settings,
property: "unsortableBeforeSorted",
label: "Place unsortable items before sortable items in order"
})
}

Expand Down Expand Up @@ -1151,6 +1170,7 @@ polymorph_core.registerOperator("workflow_gf", {
workflowy_gitfriendly_extend_contextMenu.apply(this);
workflowy_gitfriendly_search.apply(this);
workflowy_advanced_entry.apply(this);
workflowy_copy_paste.apply(this);

oldFocus = 0; // ready to go
});
1 change: 1 addition & 0 deletions operators/workflow/workflow_gitfriendly_contextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ let workflowy_gitfriendly_extend_contextMenu = function() {
contextmenu.addEventListener("input", (e) => {
if (this.contextMenuActions[e.target.dataset.action]) this.contextMenuActions[e.target.dataset.action](e);
});
this.contextmenu = contextmenu;
//<li data-action="sortbydate">Copy subitems recursively as list</li>
this.contextMenuActions = {};
/*let savedStyle = undefined;
Expand Down
Loading

0 comments on commit a243a0a

Please sign in to comment.