diff options
author | Johannes Zellner <johannes@nebulon.de> | 2016-03-01 15:10:25 +0100 |
---|---|---|
committer | Johannes Zellner <johannes@nebulon.de> | 2016-03-01 15:10:25 +0100 |
commit | d3312ed1aace3c72570f60be56d846fb9ecbc584 (patch) | |
tree | 7c55ab933fae9c5577bd8f098da98da3cd5ad577 /app/js | |
parent | 6eb72d64efc4a22aeb6cd5f52d1e4508ffed137f (diff) | |
download | Surfer-d3312ed1aace3c72570f60be56d846fb9ecbc584.tar.gz Surfer-d3312ed1aace3c72570f60be56d846fb9ecbc584.tar.zst Surfer-d3312ed1aace3c72570f60be56d846fb9ecbc584.zip |
Make directory listing navigatable
Diffstat (limited to 'app/js')
-rw-r--r-- | app/js/app.js | 51 |
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 | ||
37 | function sanitize(filePath) { | ||
38 | filePath = '/' + filePath; | ||
39 | return filePath.replace(/\/+/g, '/'); | ||
40 | } | ||
41 | |||
42 | function 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 | |||
62 | function 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 | |||
70 | function up() { | ||
71 | loadDirectory(app.path.split('/').slice(0, -1).filter(function (p) { return !!p; }).join('/')); | ||
72 | } | ||
73 | |||
35 | var app = new Vue({ | 74 | var 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 | ||