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,24 +138,37 @@ 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 isChecked = items[i].value;
|
var visible = !items[i].hidden;
|
||||||
var style = ["", "text-decoration: line-through"];
|
if (showHidden || visible) {
|
||||||
terminal.print(
|
var isChecked = items[i].value;
|
||||||
{command: "action:" + JSON.stringify({action: "set", key: key, item: items[i].name, value: !isChecked}), value: isChecked ? kChecked : kUnchecked},
|
var style = ["", "text-decoration: line-through"];
|
||||||
" ",
|
terminal.print(
|
||||||
{style: style[isChecked ? 1 : 0], value: items[i].name},
|
{command: "action:" + JSON.stringify({action: "set", key: key, item: items[i].name, value: !isChecked}), value: isChecked ? kChecked : kUnchecked},
|
||||||
" (",
|
" ",
|
||||||
{command: "action:" + JSON.stringify({
|
{style: style[isChecked ? 1 : 0], value: items[i].name},
|
||||||
action: (confirmRemove && confirmRemove.item == items[i].name ? "reallyRemove" : "remove"),
|
" (",
|
||||||
key: key,
|
{command: "action:" + JSON.stringify({
|
||||||
item: items[i].name}), value: (confirmRemove && confirmRemove.item == items[i].name ? "confirm remove" : "remove")},
|
action: "setHidden",
|
||||||
")");
|
key: key,
|
||||||
|
item: items[i].name,
|
||||||
|
hidden: visible,
|
||||||
|
}), value: visible ? "hide" : "unhide"},
|
||||||
|
" ",
|
||||||
|
{command: "action:" + JSON.stringify({
|
||||||
|
action: (confirmRemove && confirmRemove.item == items[i].name ? "reallyRemove" : "remove"),
|
||||||
|
key: key,
|
||||||
|
item: items[i].name}), value: (confirmRemove && confirmRemove.item == items[i].name ? "confirm remove" : "remove")},
|
||||||
|
")");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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