From be18e46a171d269e4db2428887ecfdae6a0241b1 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Thu, 2 Jun 2016 23:33:01 +0000 Subject: [PATCH] Organized the index slightly. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3235 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- packages/cory/blog/blog.js | 2 + packages/cory/index/index.js | 80 +++++++++++++++++++++--------------- packages/cory/smtp/smtp.js | 2 +- packages/cory/ui/ui.js | 2 + 4 files changed, 51 insertions(+), 35 deletions(-) diff --git a/packages/cory/blog/blog.js b/packages/cory/blog/blog.js index 33515b57..63766109 100644 --- a/packages/cory/blog/blog.js +++ b/packages/cory/blog/blog.js @@ -1,5 +1,7 @@ "use strict"; +//! {"category": "work in progress"} + class Log { constructor(name, capacity) { this._name = name; diff --git a/packages/cory/index/index.js b/packages/cory/index/index.js index 8fa464c6..b502bea3 100644 --- a/packages/cory/index/index.js +++ b/packages/cory/index/index.js @@ -27,48 +27,60 @@ function index() { } } + let packagesByCategory = {}; + packages.forEach(function(app) { + let category = (app.manifest ? app.manifest.category : null) || "other"; + if (!packagesByCategory[category]) { + packagesByCategory[category] = []; + } + packagesByCategory[category].push(app); + }); + terminal.cork(); terminal.clear(); terminal.print("Available applications [active users]:"); - packages.sort(function(x, y) { - 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 || services) { - message.push(" ["); - if (users) { - let counts = {}; - for (let i = 0; i < users.length; i++) { - counts[users[i]] = (counts[users[i]] || 0) + 1; + for (let category in packagesByCategory) { + terminal.print({style: "font-weight: bold", value: category}); + packagesByCategory[category].sort(function(x, y) { + 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 || services) { + message.push(" ["); + 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("]"); } - if (services) { - if (users) { - message.push(", "); - } - message.push("⚒".repeat(services.length)); - } - message.push("]"); - } - terminal.print( - "* ", - {href: "/~" + app.owner + "/" + app.name, target: "_self"}, - message, - app.manifest && app.manifest.description ? " - " + app.manifest.description.toString() : ""); - }); + terminal.print( + "• ", + {href: "/~" + app.owner + "/" + app.name, target: "_self"}, + message, + app.manifest && app.manifest.description ? " - " + app.manifest.description.toString() : ""); + }); + } terminal.uncork(); }); } diff --git a/packages/cory/smtp/smtp.js b/packages/cory/smtp/smtp.js index 69e5805b..5cf446c2 100644 --- a/packages/cory/smtp/smtp.js +++ b/packages/cory/smtp/smtp.js @@ -1,6 +1,6 @@ "use strict"; -//! {"permissions": ["network"]} +//! {"category": "libraries", "permissions": ["network"]} terminal.print("Hello, world!"); diff --git a/packages/cory/ui/ui.js b/packages/cory/ui/ui.js index b88429e1..ab5a5a0d 100644 --- a/packages/cory/ui/ui.js +++ b/packages/cory/ui/ui.js @@ -1,5 +1,7 @@ "use strict"; +//! {"category": "libraries"} + function fileList(settings) { let prefix = settings.prefix || "";