Commit d3312ed1 by Johannes Zellner

Make directory listing navigatable

1 parent 6eb72d64
......@@ -29,3 +29,7 @@ pre {
[v-cloak] {
display: none;
}
.hand {
cursor: hand;
}
\ No newline at end of file
......@@ -2,6 +2,7 @@
<head>
<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/style.css">
......@@ -63,27 +64,39 @@
<div class="row">
<div class="col-lg-12">
<ol class="breadcrumb">
<li><a href="#">Home</a></li>
<li><a href="#">Library</a></li>
<li class="active">Data</li>
<li><i class="fa fa-home"></i>&nbsp;</li>
<li v-for="part in pathParts">
{{ part }}
</li>
</ol>
</div>
<div class="col-lg-12">
<table class="table table-hover">
<table class="table table-hover table-condensed">
<thead>
<tr>
<th>Type</th>
<th>Name</th>
<th>Size</th>
<th>Modified</th>
<th style="text-align: right;">Action</th>
</tr>
</thead>
<tbody>
<tr>
<th>Type</th>
<th>Name</th>
<th>Size</th>
<th>Modified</th>
<tr v-show="path !== '/'" v-on:click="up()" class="hand">
<th><i class="fa fa-chevron-up"></i></th>
<th>..</th>
<th></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>
</tbody>
</table>
......
......@@ -20,6 +20,8 @@ function login(username, password) {
// clearly not the best option
localStorage.username = username;
localStorage.password = password;
loadDirectory(app.path);
});
}
......@@ -32,20 +34,61 @@ function logout() {
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({
el: '#app',
data: {
busy: true,
path: '/',
pathParts: [],
session: {
valid: false
},
loginData: {
}
loginData: {},
entries: []
},
methods: {
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!