diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2017-07-04 02:11:44 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2017-07-04 02:11:44 +0200 |
| commit | 2263f412817d6d2d36372e7617feb0d97fa57af8 (patch) | |
| tree | c5bc7fd177636a295a508c12e1cc2d703c252056 /client/client.js | |
| parent | 0075896decfe2ebf81c2610f4367929c0d51b1d8 (diff) | |
break out browser and tasks
Diffstat (limited to 'client/client.js')
| -rw-r--r-- | client/client.js | 100 |
1 files changed, 51 insertions, 49 deletions
diff --git a/client/client.js b/client/client.js index 9ee689c..d727a66 100644 --- a/client/client.js +++ b/client/client.js @@ -1,6 +1,56 @@ +export default { + folder: crud('folder'), + file: crud('file'), + task: crud('task'), + job: crud('job'), + upload: (folder_id, files) => { + var data = new FormData() + for (var i = 0; i < files.length; i++) { + data.append('file', files[i]) + } + return fetch('/folders/' + folder_id, postBody(data)) + .then(req => req.json()) + .catch(error) + }, +} + +function crud(type_s) { + const type = '/' + type_s + 's/' + return { + index: (data) => { + return fetch(_get_url(type, data), _get_headers()) + .then(req => req.json()) + .catch(error) + }, + + show: (id) => { + return fetch(type + id) + .then(req => req.json()) + .catch(error) + }, + + create: (data) => { + return fetch(type, post(data)) + .then(req => req.json()) + .catch(error) + }, + + update: (data) => { + return fetch(type + data.id, put(data)) + .then(req => req.json()) + .catch(error) + }, + + destroy: (data) => { + return fetch(type + data.id, destroy(data)) + .then(req => req.json()) + .catch(error) + }, + } +} + function _get_url(_url, data) { const url = new URL(window.location.origin + _url) - console.log(_url, data, window.location.origin) if (data) { Object.keys(data).forEach(key => url.searchParams.append(key, data[key])) } @@ -56,51 +106,3 @@ function destroy(data) { function error(err) { console.warn(err) } -function crud(type_s) { - const type = '/' + type_s + 's/' - return { - index: (data) => { - return fetch(_get_url(type, data), _get_headers()) - .then(req => req.json()) - .catch(error) - }, - - show: (id) => { - return fetch(type + id) - .then(req => req.json()) - .catch(error) - }, - - create: (data) => { - return fetch(type, post(data)) - .then(req => req.json()) - .catch(error) - }, - - update: (data) => { - return fetch(type + data.id, put(data)) - .then(req => req.json()) - .catch(error) - }, - - destroy: (data) => { - return fetch(type + data.id, destroy(data)) - .then(req => req.json()) - .catch(error) - }, - } -} - -export default { - folder: crud('folder'), - file: crud('file'), - upload: (folder_id, files) => { - var data = new FormData() - for (var i = 0; i < files.length; i++) { - data.append('file', files[i]) - } - return fetch('/folders/' + folder_id, postBody(data)) - .then(req => req.json()) - .catch(error) - }, -}
\ No newline at end of file |
