forked from cory/tildefriends
Added item hiding to the TODO app. Also exposed making lists public and private.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3231 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
e7feab4a4a
commit
4fe5e9e39e
@ -5,6 +5,7 @@ var kChecked = "☑";
|
|||||||
|
|
||||||
let activeList = null;
|
let activeList = null;
|
||||||
let confirmRemove;
|
let confirmRemove;
|
||||||
|
let showHidden = false;
|
||||||
|
|
||||||
terminal.setPrompt("Add Item>");
|
terminal.setPrompt("Add Item>");
|
||||||
|
|
||||||
@ -16,6 +17,22 @@ core.register("onInput", function(command) {
|
|||||||
}
|
}
|
||||||
if (command.action == "set") {
|
if (command.action == "set") {
|
||||||
setItem(command.key, command.item, command.value).then(notifyChanged).then(redisplay);
|
setItem(command.key, command.item, command.value).then(notifyChanged).then(redisplay);
|
||||||
|
} else if (command.action == "setHidden") {
|
||||||
|
setItemHidden(command.key, command.item, command.hidden).then(notifyChanged).then(redisplay);
|
||||||
|
} else if (command.action == "setShowHidden") {
|
||||||
|
showHidden = !showHidden;
|
||||||
|
redisplay();
|
||||||
|
} else if (command.action == "makePublic") {
|
||||||
|
let key = JSON.parse(command.key);
|
||||||
|
delete key.user;
|
||||||
|
key.public = true;
|
||||||
|
let newKey = JSON.stringify(key);
|
||||||
|
readList(command.key).then(function(data) {
|
||||||
|
return writeList(newKey, data);
|
||||||
|
}).then(function() {
|
||||||
|
activeList = newKey;
|
||||||
|
return database.remove(command.key);
|
||||||
|
}).then(redisplay);
|
||||||
} else if (command.action == "remove") {
|
} else if (command.action == "remove") {
|
||||||
confirmRemove = command;
|
confirmRemove = command;
|
||||||
redisplay();
|
redisplay();
|
||||||
@ -99,6 +116,17 @@ function setItem(key, name, value) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setItemHidden(key, name, hidden) {
|
||||||
|
return readList(key).then(function(todo) {
|
||||||
|
for (var i = 0; i < todo.items.length; i++) {
|
||||||
|
if (todo.items[i].name == name) {
|
||||||
|
todo.items[i].hidden = hidden;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return writeList(key, todo);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function removeItem(key, name) {
|
function removeItem(key, name) {
|
||||||
return readList(key).then(function(todo) {
|
return readList(key).then(function(todo) {
|
||||||
todo.items = todo.items.filter(function(item) {
|
todo.items = todo.items.filter(function(item) {
|
||||||
@ -110,12 +138,17 @@ function removeItem(key, name) {
|
|||||||
|
|
||||||
function printList(name, key, items) {
|
function printList(name, key, items) {
|
||||||
terminal.print(name,
|
terminal.print(name,
|
||||||
|
" - ",
|
||||||
|
{command: "action:" + JSON.stringify({action: "setShowHidden", value: !showHidden}), value: showHidden ? "stop showing hidden" : "show hidden"},
|
||||||
" - ",
|
" - ",
|
||||||
{command: "action:" + JSON.stringify({action: "lists"}), value: "back"},
|
{command: "action:" + JSON.stringify({action: "lists"}), value: "back"},
|
||||||
" - ",
|
" - ",
|
||||||
{command: "action:" + JSON.stringify({action: (confirmRemove === true ? "reallyRemoveList" : "removeList"), key: key}), value: (confirmRemove === true ? "confirm remove" : "remove")});
|
{command: "action:" + JSON.stringify({action: (confirmRemove === true ? "reallyRemoveList" : "removeList"), key: key}), value: (confirmRemove === true ? "confirm remove" : "remove list")},
|
||||||
|
JSON.parse(key).public ? "" : [" - ", {command: "action:" + JSON.stringify({action: "makePublic", key: key}), value: "make public"}]);
|
||||||
terminal.print("=".repeat(name.length));
|
terminal.print("=".repeat(name.length));
|
||||||
for (var i = 0; i < items.length; i++) {
|
for (var i = 0; i < items.length; i++) {
|
||||||
|
var visible = !items[i].hidden;
|
||||||
|
if (showHidden || visible) {
|
||||||
var isChecked = items[i].value;
|
var isChecked = items[i].value;
|
||||||
var style = ["", "text-decoration: line-through"];
|
var style = ["", "text-decoration: line-through"];
|
||||||
terminal.print(
|
terminal.print(
|
||||||
@ -123,6 +156,13 @@ function printList(name, key, items) {
|
|||||||
" ",
|
" ",
|
||||||
{style: style[isChecked ? 1 : 0], value: items[i].name},
|
{style: style[isChecked ? 1 : 0], value: items[i].name},
|
||||||
" (",
|
" (",
|
||||||
|
{command: "action:" + JSON.stringify({
|
||||||
|
action: "setHidden",
|
||||||
|
key: key,
|
||||||
|
item: items[i].name,
|
||||||
|
hidden: visible,
|
||||||
|
}), value: visible ? "hide" : "unhide"},
|
||||||
|
" ",
|
||||||
{command: "action:" + JSON.stringify({
|
{command: "action:" + JSON.stringify({
|
||||||
action: (confirmRemove && confirmRemove.item == items[i].name ? "reallyRemove" : "remove"),
|
action: (confirmRemove && confirmRemove.item == items[i].name ? "reallyRemove" : "remove"),
|
||||||
key: key,
|
key: key,
|
||||||
@ -130,6 +170,7 @@ function printList(name, key, items) {
|
|||||||
")");
|
")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function redisplay() {
|
function redisplay() {
|
||||||
terminal.clear();
|
terminal.clear();
|
||||||
@ -166,7 +207,7 @@ function hasPermission(key) {
|
|||||||
let result = false;
|
let result = false;
|
||||||
try {
|
try {
|
||||||
let data = JSON.parse(key);
|
let data = JSON.parse(key);
|
||||||
result = data.public || data.user == core.user.name;
|
result = data.public || data.user == core.user.name || !data.user;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
@ -182,6 +223,15 @@ function getName(key) {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isPrivate(key) {
|
||||||
|
let isPrivate = false;
|
||||||
|
try {
|
||||||
|
isPrivate = !JSON.parse(key).public;
|
||||||
|
} catch (error) {
|
||||||
|
}
|
||||||
|
return isPrivate;
|
||||||
|
}
|
||||||
|
|
||||||
function getVisibleLists() {
|
function getVisibleLists() {
|
||||||
return database.getAll().then(function(data) {
|
return database.getAll().then(function(data) {
|
||||||
return data.filter(hasPermission);
|
return data.filter(hasPermission);
|
||||||
@ -196,7 +246,7 @@ function printListOfLists() {
|
|||||||
terminal.print({
|
terminal.print({
|
||||||
command: "action:" + JSON.stringify({action: "editList", key: key}),
|
command: "action:" + JSON.stringify({action: "editList", key: key}),
|
||||||
value: getName(key),
|
value: getName(key),
|
||||||
});
|
}, " ", isPrivate(key) ? "(private)" : "(public)");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user