Commit d3312ed1 by Johannes Zellner

Make directory listing navigatable

1 parent 6eb72d64
...@@ -29,3 +29,7 @@ pre { ...@@ -29,3 +29,7 @@ pre {
[v-cloak] { [v-cloak] {
display: none; display: none;
} }
.hand {
cursor: hand;
}
\ No newline at end of file
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
<head> <head>
<title> Cloudron Surfer </title> <title> Cloudron Surfer </title>
<link rel="stylesheet" href="/admin/css/font-awesome.min.css">
<link rel="stylesheet" href="/admin/css/bootstrap.min.css"> <link rel="stylesheet" href="/admin/css/bootstrap.min.css">
<link rel="stylesheet" href="/admin/css/style.css"> <link rel="stylesheet" href="/admin/css/style.css">
...@@ -63,27 +64,39 @@ ...@@ -63,27 +64,39 @@
<div class="row"> <div class="row">
<div class="col-lg-12"> <div class="col-lg-12">
<ol class="breadcrumb"> <ol class="breadcrumb">
<li><a href="#">Home</a></li> <li><i class="fa fa-home"></i>&nbsp;</li>
<li><a href="#">Library</a></li> <li v-for="part in pathParts">
<li class="active">Data</li> {{ part }}
</li>
</ol> </ol>
</div> </div>
<div class="col-lg-12"> <div class="col-lg-12">
<table class="table table-hover"> <table class="table table-hover table-condensed">
<thead> <thead>
<tr> <tr>
<th>Type</th> <th>Type</th>
<th>Name</th> <th>Name</th>
<th>Size</th> <th>Size</th>
<th>Modified</th> <th>Modified</th>
<th style="text-align: right;">Action</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr> <tr v-show="path !== '/'" v-on:click="up()" class="hand">
<th>Type</th> <th><i class="fa fa-chevron-up"></i></th>
<th>Name</th> <th>..</th>
<th>Size</th> <th></th>
<th>Modified</th> <th></th>
</tr>
<tr v-for="entry in entries" v-on:click="open(entry)" class="hand">
<th>
<i class="fa fa-folder-o" v-show="entry.isDirectory"></i>
<i class="fa fa-file-o" v-show="entry.isFile"></i>
</th>
<th>{{ entry.filePath }}</th>
<th>{{ entry.size }}</th>
<th>{{ entry.mtime }}</th>
<th style="text-align: right;"><button class="btn btn-sm btn-danger"><i class="fa fa-trash"></i></button></th>
</tr> </tr>
</tbody> </tbody>
</table> </table>
......
...@@ -20,6 +20,8 @@ function login(username, password) { ...@@ -20,6 +20,8 @@ function login(username, password) {
// clearly not the best option // clearly not the best option
localStorage.username = username; localStorage.username = username;
localStorage.password = password; localStorage.password = password;
loadDirectory(app.path);
}); });
} }
...@@ -32,20 +34,61 @@ function logout() { ...@@ -32,20 +34,61 @@ function logout() {
delete localStorage.password; delete localStorage.password;
} }
function sanitize(filePath) {
filePath = '/' + filePath;
return filePath.replace(/\/+/g, '/');
}
function loadDirectory(filePath) {
app.busy = true;
filePath = filePath ? sanitize(filePath) : '/';
console.log(filePath);
superagent.get('/api/files/' + filePath).query({ username: app.session.username, password: app.session.password }).end(function (error, result) {
app.busy = false;
if (error) return console.error(error);
if (result.statusCode === 401) return logout();
app.entries = result.body.entries;
app.path = filePath;
app.pathParts = filePath.split('/').filter(function (e) { return !!e; });
console.log(app.pathParts)
});
}
function open(entry) {
var path = sanitize(app.path + '/' + entry.filePath);
if (entry.isDirectory) return loadDirectory(path);
window.location.href = window.location.origin + path;
}
function up() {
loadDirectory(app.path.split('/').slice(0, -1).filter(function (p) { return !!p; }).join('/'));
}
var app = new Vue({ var app = new Vue({
el: '#app', el: '#app',
data: { data: {
busy: true, busy: true,
path: '/',
pathParts: [],
session: { session: {
valid: false valid: false
}, },
loginData: { loginData: {},
entries: []
}
}, },
methods: { methods: {
login: login, login: login,
logout: logout logout: logout,
loadDirectory: loadDirectory,
open: open,
up: up
} }
}); });
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!