Add basic fileset-browser navigation

master
Sven Slootweg 8 years ago
parent e79a0b8d77
commit b00998de6b

@ -3,6 +3,16 @@ app
fileset-browser fileset-browser
script. script.
this.tags["fileset-browser"].on("click", () => { const path = require("path");
console.log("Clicked!");
}) this.on("mount", () => {
let browser = this.tags["fileset-browser"];
browser.navigate(path.join(__dirname, "../../../"));
browser.on("clickEntry", function(entry) {
if (entry.type === "folder") {
browser.navigate(entry.path);
}
})
});

@ -1,6 +1,6 @@
fileset-browser fileset-browser
.browser .browser
.entry(each="{entry in entries}" class="{folder: entry.type === 'folder'}") .entry(each="{entry in entries}", class="{folder: entry.type === 'folder'}", onclick="{handleClickEntry}")
span.filename {entry.name} span.filename {entry.name}
span.size(hide="{entry.type === 'folder'}") {entry.size} span.size(hide="{entry.type === 'folder'}") {entry.size}
@ -13,9 +13,18 @@ fileset-browser
font-size: 14px; font-size: 14px;
background: linear-gradient(to bottom, #efefef 0%,#e5e5e5 100%); background: linear-gradient(to bottom, #efefef 0%,#e5e5e5 100%);
padding: 4px 6px; padding: 4px 6px;
cursor: default;
&:hover {
background: linear-gradient(to bottom, #efefef 0%,#d6d6d6 100%);
}
&.folder { &.folder {
background: linear-gradient(to bottom, #e2e2e2 0%,#d4d4d4 100%); background: linear-gradient(to bottom, #e2e2e2 0%,#d4d4d4 100%);
&:hover {
background: linear-gradient(to bottom, #e2e2e2 0%,#c4c4c4 100%);
}
} }
.filename { .filename {
@ -31,28 +40,31 @@ fileset-browser
script. script.
const $ = require("jquery"); const $ = require("jquery");
const path = require("path");
const byteSize = require("byte-size"); const byteSize = require("byte-size");
const xtend = require("xtend"); const xtend = require("xtend");
const rfr = require("rfr"); const rfr = require("rfr");
const listDirectory = rfr("lib/filesystem/list-directory"); const listDirectory = rfr("lib/filesystem/list-directory");
console.log(this);
Promise.try(() => { Object.assign(this, {
return listDirectory(path.join(__dirname, "../../../")); entries: [],
}).map((entry) => {
return xtend(entry, { handleClickEntry: (event) => {
size: byteSize(entry.size, {units: "iec"}) this.trigger("clickEntry", event.item.entry);
}); },
}).then((entries) => {
this.entries = entries; navigate: function(path) {
this.update(); return Promise.try(() => {
}); return listDirectory(path, {
includeParent: true
/* });
this.on("mount", () => { }).map((entry) => {
$("strong", this.root).on("click", () => { return xtend(entry, {
this.trigger("click"); size: byteSize(entry.size, {units: "iec"})
}); });
}); }).tap((entries) => {
*/ this.entries = entries;
this.update();
});
}
});

@ -40,9 +40,15 @@ function getType(stats) {
} }
} }
module.exports = function(basePath) { module.exports = function(basePath, options = {}) {
return Promise.try(() => { return Promise.try(() => {
return fs.readdirAsync(basePath); return fs.readdirAsync(basePath);
}).then((entries) => {
if (options.includeParent) {
entries.unshift("..");
}
return entries;
}).map((entry) => { }).map((entry) => {
let fullPath = path.join(basePath, entry); let fullPath = path.join(basePath, entry);

Loading…
Cancel
Save