From 191b31e9774be6e9a2a12a8336db40fe14eb94b5 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Mon, 3 Jul 2017 11:04:14 +0100 Subject: [PATCH] Working better :) --- _assets/src/components/DeletePrompt.vue | 2 +- _assets/src/components/DownloadPrompt.vue | 2 +- _assets/src/components/Editor.vue | 4 +-- _assets/src/components/InfoPrompt.vue | 22 ++++++++--------- _assets/src/components/Listing.vue | 24 +++++++++--------- _assets/src/components/ListingItem.vue | 4 +-- _assets/src/components/Login.vue | 4 +-- _assets/src/components/Main.vue | 19 +++++++++++++-- _assets/src/components/MovePrompt.vue | 8 +++--- _assets/src/components/Preview.vue | 14 +++++------ _assets/src/components/RenamePrompt.vue | 8 +++--- _assets/src/components/SwitchViewButton.vue | 4 +-- _assets/src/router/index.js | 3 ++- _assets/src/store/mutations.js | 6 ++--- _assets/src/store/store.js | 1 + _assets/src/utils/api.js | 27 +++++++++++++++++++++ _assets/src/utils/auth.js | 1 + 17 files changed, 99 insertions(+), 54 deletions(-) create mode 100644 _assets/src/utils/api.js diff --git a/_assets/src/components/DeletePrompt.vue b/_assets/src/components/DeletePrompt.vue index 97e581ea..55453d35 100644 --- a/_assets/src/components/DeletePrompt.vue +++ b/_assets/src/components/DeletePrompt.vue @@ -49,7 +49,7 @@ export default { let promises = [] for (let index of this.selected) { - promises.push(webdav.trash(this.req.data.items[index].url)) + promises.push(webdav.trash(this.req.items[index].url)) } Promise.all(promises) diff --git a/_assets/src/components/DownloadPrompt.vue b/_assets/src/components/DownloadPrompt.vue index d7db7eb5..5da0fb86 100644 --- a/_assets/src/components/DownloadPrompt.vue +++ b/_assets/src/components/DownloadPrompt.vue @@ -27,7 +27,7 @@ export default { let files = '' for (let i of this.selected) { - files += this.req.data.items[i].url.replace(window.location.pathname, '') + ',' + files += this.req.items[i].url.replace(window.location.pathname, '') + ',' } files = files.substring(0, files.length - 1) diff --git a/_assets/src/components/Editor.vue b/_assets/src/components/Editor.vue index 5f893880..09009859 100644 --- a/_assets/src/components/Editor.vue +++ b/_assets/src/components/Editor.vue @@ -6,7 +6,7 @@
- +
@@ -19,7 +19,7 @@ export default { computed: { ...mapState(['req']), hasMetadata: function () { - return (this.req.data.metadata !== undefined && this.req.data.metadata !== null) + return (this.req.metadata !== undefined && this.req.metadata !== null) } }, data: function () { diff --git a/_assets/src/components/InfoPrompt.vue b/_assets/src/components/InfoPrompt.vue index 79884301..c8ce2b1c 100644 --- a/_assets/src/components/InfoPrompt.vue +++ b/_assets/src/components/InfoPrompt.vue @@ -9,8 +9,8 @@

Last Modified: {{ humanTime() }}

-

Number of files: {{ req.data.numFiles }}

-

Number of directories: {{ req.data.numDirs }}

+

Number of files: {{ req.numFiles }}

+

Number of directories: {{ req.numDirs }}

@@ -40,30 +40,30 @@ export default { methods: { humanSize: function () { if (this.selectedCount === 0 || this.req.kind !== 'listing') { - return filesize(this.req.data.size) + return filesize(this.req.size) } var sum = 0 for (let i = 0; i < this.selectedCount; i++) { - sum += this.req.data.items[this.selected[i]].size + sum += this.req.items[this.selected[i]].size } return filesize(sum) }, humanTime: function () { if (this.selectedCount === 0) { - return moment(this.req.data.modified).fromNow() + return moment(this.req.modified).fromNow() } - return moment(this.req.data.items[this.selected[0]]).fromNow() + return moment(this.req.items[this.selected[0]]).fromNow() }, name: function () { if (this.selectedCount === 0) { - return this.req.data.name + return this.req.name } - return this.req.data.items[this.selected[0]].name + return this.req.items[this.selected[0]].name }, dir: function () { if (this.selectedCount > 1) { @@ -72,10 +72,10 @@ export default { } if (this.selectedCount === 0) { - return this.req.data.isDir + return this.req.isDir } - return this.req.data.items[this.selected[0]].isDir + return this.req.items[this.selected[0]].isDir }, checksum: function (event, hash) { event.preventDefault() @@ -84,7 +84,7 @@ export default { let link if (this.selectedCount) { - link = this.req.data.items[this.selected[0]].url + link = this.req.items[this.selected[0]].url } else { link = window.location.pathname } diff --git a/_assets/src/components/Listing.vue b/_assets/src/components/Listing.vue index 8b08a6cb..ce37f556 100644 --- a/_assets/src/components/Listing.vue +++ b/_assets/src/components/Listing.vue @@ -1,6 +1,6 @@ @@ -47,7 +47,7 @@ export default { computed: mapState(['req']), methods: { raw: function () { - return this.req.data.url + '?raw=true' + return this.req.url + '?raw=true' }, back: function (event) { let url = page.removeLastDir(window.location.pathname) + '/' diff --git a/_assets/src/components/RenamePrompt.vue b/_assets/src/components/RenamePrompt.vue index 6999d669..c4190d9d 100644 --- a/_assets/src/components/RenamePrompt.vue +++ b/_assets/src/components/RenamePrompt.vue @@ -29,7 +29,7 @@ export default { }, oldName: function () { if (this.req.kind !== 'listing') { - return this.req.data.name + return this.req.name } if (this.selectedCount === 0 || this.selectedCount > 1) { @@ -37,16 +37,16 @@ export default { return } - return this.req.data.items[this.selected[0]].name + return this.req.items[this.selected[0]].name }, submit: function (event) { let oldLink = '' let newLink = '' if (this.req.kind !== 'listing') { - oldLink = this.req.data.url + oldLink = this.req.url } else { - oldLink = this.req.data.items[this.selected[0]].url + oldLink = this.req.items[this.selected[0]].url } this.name = encodeURIComponent(this.name) diff --git a/_assets/src/components/SwitchViewButton.vue b/_assets/src/components/SwitchViewButton.vue index f9f98aee..3342a910 100644 --- a/_assets/src/components/SwitchViewButton.vue +++ b/_assets/src/components/SwitchViewButton.vue @@ -12,7 +12,7 @@ export default { change: function (event) { let display = 'mosaic' - if (this.$store.state.req.data.display === 'mosaic') { + if (this.$store.state.req.display === 'mosaic') { display = 'list' } @@ -20,7 +20,7 @@ export default { document.cookie = `display=${display}; max-age=31536000; path=${this.$store.state.baseURL}` }, icon: function () { - if (this.$store.state.req.data.display === 'mosaic') return 'view_list' + if (this.$store.state.req.display === 'mosaic') return 'view_list' return 'view_module' } } diff --git a/_assets/src/router/index.js b/_assets/src/router/index.js index c17eb508..25f0fd78 100644 --- a/_assets/src/router/index.js +++ b/_assets/src/router/index.js @@ -21,6 +21,7 @@ const router = new Router({ next({ path: '/files' }) }) .catch(() => { + document.title = 'Login' next() }) } @@ -33,7 +34,7 @@ const router = new Router({ }, children: [ { - path: '/files/*', + path: '/files*', name: 'Files', component: Files }, diff --git a/_assets/src/store/mutations.js b/_assets/src/store/mutations.js index 7fea1859..ce786409 100644 --- a/_assets/src/store/mutations.js +++ b/_assets/src/store/mutations.js @@ -18,6 +18,7 @@ const mutations = { state.showDownload = false }, setUser: (state, value) => (state.user = value), + setJWT: (state, value) => (state.jwt = value), multiple: (state, value) => (state.multiple = value), addSelected: (state, value) => (state.selected.push(value)), removeSelected: (state, value) => { @@ -29,11 +30,10 @@ const mutations = { state.selected = [] }, listingDisplay: (state, value) => { - state.req.data.display = value + state.req.display = value }, updateRequest: (state, value) => { - state.req.kind = value.kind - state.req.data = value.data + state.req = value } } diff --git a/_assets/src/store/store.js b/_assets/src/store/store.js index 330b9d5b..2f6c24cc 100644 --- a/_assets/src/store/store.js +++ b/_assets/src/store/store.js @@ -10,6 +10,7 @@ const state = { req: {}, baseURL: document.querySelector('meta[name="base"]').getAttribute('content'), ssl: (window.location.protocol === 'https:'), + jwt: '', selected: [], multiple: false, showInfo: false, diff --git a/_assets/src/utils/api.js b/_assets/src/utils/api.js new file mode 100644 index 00000000..0074aecd --- /dev/null +++ b/_assets/src/utils/api.js @@ -0,0 +1,27 @@ +import store from '../store/store' + +function fetch (url) { + return new Promise((resolve, reject) => { + let request = new window.XMLHttpRequest() + request.open('GET', `${store.state.baseURL}/api/resource${url}`, true) + request.setRequestHeader('Authorization', `Bearer ${store.state.jwt}`) + + request.onload = () => { + if (request.status === 200) { + let req = JSON.parse(request.responseText) + store.commit('updateRequest', req) + console.log(req) + document.title = req.name + resolve() + } else { + reject() + } + } + request.onerror = () => reject() + request.send() + }) +} + +export default { + fetch +} diff --git a/_assets/src/utils/auth.js b/_assets/src/utils/auth.js index df2a2eaf..5de3cb75 100644 --- a/_assets/src/utils/auth.js +++ b/_assets/src/utils/auth.js @@ -6,6 +6,7 @@ function parseToken (token) { document.cookie = `auth=${token}; max-age=86400; path=${store.state.baseURL}` let res = token.split('.') let user = JSON.parse(window.atob(res[1])) + store.commit('setJWT', token) store.commit('setUser', user) }