aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/js/app.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/js/app.js')
-rw-r--r--app/js/app.js51
1 files changed, 47 insertions, 4 deletions
diff --git a/app/js/app.js b/app/js/app.js
index 55153d4..10a489c 100644
--- a/app/js/app.js
+++ b/app/js/app.js
@@ -20,6 +20,8 @@ function login(username, password) {
20 // clearly not the best option 20 // clearly not the best option
21 localStorage.username = username; 21 localStorage.username = username;
22 localStorage.password = password; 22 localStorage.password = password;
23
24 loadDirectory(app.path);
23 }); 25 });
24} 26}
25 27
@@ -32,20 +34,61 @@ function logout() {
32 delete localStorage.password; 34 delete localStorage.password;
33} 35}
34 36
37function sanitize(filePath) {
38 filePath = '/' + filePath;
39 return filePath.replace(/\/+/g, '/');
40}
41
42function loadDirectory(filePath) {
43 app.busy = true;
44
45 filePath = filePath ? sanitize(filePath) : '/';
46
47 console.log(filePath);
48
49 superagent.get('/api/files/' + filePath).query({ username: app.session.username, password: app.session.password }).end(function (error, result) {
50 app.busy = false;
51
52 if (error) return console.error(error);
53 if (result.statusCode === 401) return logout();
54
55 app.entries = result.body.entries;
56 app.path = filePath;
57 app.pathParts = filePath.split('/').filter(function (e) { return !!e; });
58 console.log(app.pathParts)
59 });
60}
61
62function open(entry) {
63 var path = sanitize(app.path + '/' + entry.filePath);
64
65 if (entry.isDirectory) return loadDirectory(path);
66
67 window.location.href = window.location.origin + path;
68}
69
70function up() {
71 loadDirectory(app.path.split('/').slice(0, -1).filter(function (p) { return !!p; }).join('/'));
72}
73
35var app = new Vue({ 74var app = new Vue({
36 el: '#app', 75 el: '#app',
37 data: { 76 data: {
38 busy: true, 77 busy: true,
78 path: '/',
79 pathParts: [],
39 session: { 80 session: {
40 valid: false 81 valid: false
41 }, 82 },
42 loginData: { 83 loginData: {},
43 84 entries: []
44 }
45 }, 85 },
46 methods: { 86 methods: {
47 login: login, 87 login: login,
48 logout: logout 88 logout: logout,
89 loadDirectory: loadDirectory,
90 open: open,
91 up: up
49 } 92 }
50}); 93});
51 94