Show service processes differently on the index. Expose manifests to package list. Add a work in process library of shared user interface code.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3193 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
4d0fdfa484
commit
41a12fd1a7
@ -110,7 +110,11 @@ function getPackages() {
|
|||||||
var packageNames = File.readDirectory("packages/" + packageOwners[i] + "/");
|
var packageNames = File.readDirectory("packages/" + packageOwners[i] + "/");
|
||||||
for (var j = 0; j < packageNames.length; j++) {
|
for (var j = 0; j < packageNames.length; j++) {
|
||||||
if (packageNames[j].charAt(0) != ".") {
|
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"),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,16 +4,25 @@ core.register("onSessionBegin", index);
|
|||||||
core.register("onSessionEnd", index);
|
core.register("onSessionEnd", index);
|
||||||
|
|
||||||
function 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 packages = values[0];
|
||||||
let users = values[1];
|
let users = values[1];
|
||||||
let usersByApp = {};
|
let usersByApp = {};
|
||||||
|
let servicesByApp = {};
|
||||||
for (let i in users) {
|
for (let i in users) {
|
||||||
let user = users[i];
|
let user = users[i];
|
||||||
if (!usersByApp["/~" + user.packageOwner + "/" + user.packageName]) {
|
let key = "/~" + user.packageOwner + "/" + user.packageName;
|
||||||
usersByApp["/~" + 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();
|
terminal.cork();
|
||||||
@ -23,9 +32,11 @@ function index() {
|
|||||||
return Math.sign(x.owner.localeCompare(y.owner)) * 10 + Math.sign(x.name.localeCompare(y.name)) * 1;
|
return Math.sign(x.owner.localeCompare(y.owner)) * 10 + Math.sign(x.name.localeCompare(y.name)) * 1;
|
||||||
}).forEach(function(app) {
|
}).forEach(function(app) {
|
||||||
let users = usersByApp["/~" + app.owner + "/" + app.name];
|
let users = usersByApp["/~" + app.owner + "/" + app.name];
|
||||||
|
let services = servicesByApp["/~" + app.owner + "/" + app.name];
|
||||||
let message = [];
|
let message = [];
|
||||||
if (users) {
|
if (users || services) {
|
||||||
message.push(" [");
|
message.push(" [");
|
||||||
|
if (users) {
|
||||||
let counts = {};
|
let counts = {};
|
||||||
for (let i = 0; i < users.length; i++) {
|
for (let i = 0; i < users.length; i++) {
|
||||||
counts[users[i]] = (counts[users[i]] || 0) + 1;
|
counts[users[i]] = (counts[users[i]] || 0) + 1;
|
||||||
@ -41,6 +52,13 @@ function index() {
|
|||||||
message.push({class: "base01", value: "(x" + counts[name] + ")"});
|
message.push({class: "base01", value: "(x" + counts[name] + ")"});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (services) {
|
||||||
|
if (users) {
|
||||||
|
message.push(", ");
|
||||||
|
}
|
||||||
|
message.push("⚒".repeat(services.length));
|
||||||
|
}
|
||||||
message.push("]");
|
message.push("]");
|
||||||
}
|
}
|
||||||
terminal.print(
|
terminal.print(
|
||||||
@ -52,4 +70,6 @@ function index() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
index();
|
index().catch(function(error) {
|
||||||
|
terminal.print("ERROR:", error);
|
||||||
|
});
|
91
packages/cory/ui/ui.js
Normal file
91
packages/cory/ui/ui.js
Normal file
@ -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;
|
Loading…
Reference in New Issue
Block a user