diff --git a/core/core.js b/core/core.js index b42db1e0..d42486f7 100644 --- a/core/core.js +++ b/core/core.js @@ -110,7 +110,11 @@ function getPackages() { var packageNames = File.readDirectory("packages/" + packageOwners[i] + "/"); for (var j = 0; j < packageNames.length; j++) { if (packageNames[j].charAt(0) != ".") { - packages.push({owner: packageOwners[i], name: packageNames[j]}); + packages.push({ + owner: packageOwners[i], + name: packageNames[j], + manifest: getManifest("packages/" + packageOwners[i] + "/" + packageNames[j] + "/" + packageNames[j] + ".js"), + }); } } } diff --git a/packages/cory/index/index.js b/packages/cory/index/index.js index 1e54a237..acd11f5b 100644 --- a/packages/cory/index/index.js +++ b/packages/cory/index/index.js @@ -4,16 +4,25 @@ core.register("onSessionBegin", index); core.register("onSessionEnd", index); function index() { - Promise.all([core.getPackages(), core.getUsers()]).then(function(values) { + return Promise.all([core.getPackages(), core.getUsers()]).then(function(values) { let packages = values[0]; let users = values[1]; let usersByApp = {}; + let servicesByApp = {}; for (let i in users) { let user = users[i]; - if (!usersByApp["/~" + user.packageOwner + "/" + user.packageName]) { - usersByApp["/~" + user.packageOwner + "/" + user.packageName] = []; + let key = "/~" + user.packageOwner + "/" + user.packageName; + if (user.key.substring(0, "service_".length) == "service_") { + if (!servicesByApp[key]) { + servicesByApp[key] = []; + } + servicesByApp[key].push(user); + } else { + if (!usersByApp[key]) { + usersByApp[key] = []; + } + usersByApp[key].push(user.name); } - usersByApp["/~" + user.packageOwner + "/" + user.packageName].push(user.name); } terminal.cork(); @@ -23,23 +32,32 @@ function index() { return Math.sign(x.owner.localeCompare(y.owner)) * 10 + Math.sign(x.name.localeCompare(y.name)) * 1; }).forEach(function(app) { let users = usersByApp["/~" + app.owner + "/" + app.name]; + let services = servicesByApp["/~" + app.owner + "/" + app.name]; let message = []; - if (users) { + if (users || services) { message.push(" ["); - let counts = {}; - for (let i = 0; i < users.length; i++) { - counts[users[i]] = (counts[users[i]] || 0) + 1; + if (users) { + let counts = {}; + for (let i = 0; i < users.length; i++) { + counts[users[i]] = (counts[users[i]] || 0) + 1; + } + let names = Object.keys(counts).sort(); + for (let i = 0; i < names.length; i++) { + var name = names[i]; + if (message.length > 1) { + message.push(", "); + } + message.push({class: "orange", value: name}); + if (counts[name] > 1) { + message.push({class: "base01", value: "(x" + counts[name] + ")"}); + } + } } - let names = Object.keys(counts).sort(); - for (let i = 0; i < names.length; i++) { - var name = names[i]; - if (message.length > 1) { + if (services) { + if (users) { message.push(", "); } - message.push({class: "orange", value: name}); - if (counts[name] > 1) { - message.push({class: "base01", value: "(x" + counts[name] + ")"}); - } + message.push("⚒".repeat(services.length)); } message.push("]"); } @@ -52,4 +70,6 @@ function index() { }); } -index(); \ No newline at end of file +index().catch(function(error) { + terminal.print("ERROR:", error); +}); \ No newline at end of file diff --git a/packages/cory/ui/ui.js b/packages/cory/ui/ui.js new file mode 100644 index 00000000..ef8cf19b --- /dev/null +++ b/packages/cory/ui/ui.js @@ -0,0 +1,91 @@ +"use strict"; + +function fileList(title, prefix, editCallback) { + terminal.setEcho(false); + terminal.clear(); + terminal.print(title); + if (core.user.credentials.permissions.authenticated) { + terminal.print({command: "new"}); + } + + let makeSaveCallback = function(oldName, oldValue) { + return function(newName, newValue) { + print(newName, " ", newValue); + return database.set(prefix + newName, newValue); + } + } + let backCallback = function() { + return fileList(title, prefix, editCallback); + } + + return database.getAll().then(function(entries) { + terminal.readLine().then(function(input) { + if (input == "new") { + editCallback("untitled", "", makeSaveCallback("untitled", ""), backCallback); + } else if (input.substring(0, "open:".length) == "open:") { + var title = input.substring("open:".length + prefix.length); + database.get(prefix + title).then(function(contents) { + editCallback(title, contents, makeSaveCallback(title, contents), backCallback); + }); + } else if (input == "home") { + filelist(title, prefix, editCallback); + } else if (input.substring(0, "delete:".length) == "delete:") { + terminal.clear(); + var title = input.substring(7); + terminal.print("Are you sure you want to delete '", title.substring(prefix.length), "'?"); + terminal.print({command: "confirmDelete:" + title, value: "delete it"}); + terminal.print({command: "home", value: "cancel"}); + terminal.readLine().then(function(input) { + if (input == "home") { + backCallback(); + } else if (input.substring(0, "confirmDelete:".length) == "confirmDelete:") { + var title = input.substring("confirmDelete:".length); + return database.remove(title).then(backCallback); + } else { + backCallback(); + } + }); + } + }); + for (var i = 0; i < entries.length; i++) { + if (entries[i].substring(0, prefix.length) == prefix) { + if (core.user.credentials.permissions.authenticated) { + terminal.print( + "* ", + {style: "font-weight: bold", value: {command: "open:" + entries[i], value: entries[i].substring(prefix.length)}}, + " (", + {command: "delete:" + entries[i], value: "x"}, + ")"); + } else { + terminal.print( + "* ", + {style: "font-weight: bold", value: {command: "open:" + entries[i], value: entries[i].substring(prefix.length)}}); + } + } + } + }); +} + +function testEdit(name, value, save, back) { + terminal.clear(); + terminal.print("testEdit ", name, " ", value); + terminal.print({command: "++"}); + terminal.print({command: "--"}); + terminal.print({command: "back"}); + terminal.readLine().then(function(command) { + if (command == "back") { + terminal.print("calling back"); + back(); + } else if (command == "++") { + save(name, (parseInt(value || "0") + 1).toString()).then(back); + } else if (command == "--") { + save(name, (parseInt(value || "0") - 1).toString()).then(back); + } + }); +} + +if (imports.terminal) { + fileList("Test File List", "fileList_", testEdit); +} + +exports.fileList = fileList; \ No newline at end of file