diff --git a/app/ayanova/src/api/apiutil.js b/app/ayanova/src/api/apiutil.js index 123eea22..e079acad 100644 --- a/app/ayanova/src/api/apiutil.js +++ b/app/ayanova/src/api/apiutil.js @@ -1,6 +1,22 @@ /* Xeslint-disable */ import store from "../store"; +var stringifyPrimitive = function(v) { + switch (typeof v) { + case "string": + return v; + + case "boolean": + return v ? "true" : "false"; + + case "number": + return isFinite(v) ? v : ""; + + default: + return ""; + } +}; + export default { status(response) { if (response.status >= 200 && response.status < 300) { @@ -34,7 +50,7 @@ export default { "Content-Type": "application/json" }; }, - fetchPostNoAuth(data) { + fetchPostNoAuthOptions(data) { return { method: "post", mode: "cors", @@ -42,7 +58,7 @@ export default { body: JSON.stringify(data) }; }, - fetchPost(data) { + fetchPostOptions(data) { return { method: "post", mode: "cors", @@ -50,7 +66,7 @@ export default { body: JSON.stringify(data) }; }, - fetch() { + fetchGetOptions() { /* GET WITH AUTH */ return { method: "get", @@ -84,5 +100,37 @@ export default { } } return store.state.apiUrl + apiPath; + }, + buildQuery(obj, sep, eq, name) { + sep = sep || "&"; + eq = eq || "="; + if (obj === null) { + obj = undefined; + } + + if (typeof obj === "object") { + return Object.keys(obj) + .map(function(k) { + var ks = encodeURIComponent(stringifyPrimitive(k)) + eq; + if (Array.isArray(obj[k])) { + return obj[k] + .map(function(v) { + return ks + encodeURIComponent(stringifyPrimitive(v)); + }) + .join(sep); + } else { + return ks + encodeURIComponent(stringifyPrimitive(obj[k])); + } + }) + .filter(Boolean) + .join(sep); + } + + if (!name) return ""; + return ( + encodeURIComponent(stringifyPrimitive(name)) + + eq + + encodeURIComponent(stringifyPrimitive(obj)) + ); } }; diff --git a/app/ayanova/src/api/auth.js b/app/ayanova/src/api/auth.js index d3718a61..1be8526b 100644 --- a/app/ayanova/src/api/auth.js +++ b/app/ayanova/src/api/auth.js @@ -6,7 +6,7 @@ export default { async authenticate(login, password) { return fetch( apiUtil.APIUrl("auth"), - apiUtil.fetchPostNoAuth({ + apiUtil.fetchPostNoAuthOptions({ login: login, password: password }) diff --git a/app/ayanova/src/api/locale.js b/app/ayanova/src/api/locale.js index 6abf90d7..540924a7 100644 --- a/app/ayanova/src/api/locale.js +++ b/app/ayanova/src/api/locale.js @@ -25,7 +25,7 @@ export default { return; } //step 2: get it - fetch(apiUtil.APIUrl("locale/subset"), apiUtil.fetchPost(needIt)) + fetch(apiUtil.APIUrl("locale/subset"), apiUtil.fetchPostOptions(needIt)) .then(apiUtil.status) .then(apiUtil.json) .then(response => { diff --git a/app/ayanova/src/api/pagedlist.js b/app/ayanova/src/api/pagedlist.js new file mode 100644 index 00000000..1bb177fc --- /dev/null +++ b/app/ayanova/src/api/pagedlist.js @@ -0,0 +1,29 @@ +/* xeslint-disable */ +import apiUtil from "./apiutil"; +export default { + fetch(route, listOptions) { + // listOptions; + + // var futureWithSortExampleListOptions = { + // offset: 5, + // limit: 5, + // sortBy: "name", + // descending: false + // }; + // exampleListOptions; + + var listUrl = route + apiUtil.buildQuery(listOptions); + + return new Promise(function(resolve, reject) { + fetch(apiUtil.APIUrl(listUrl), apiUtil.fetchGetOptions()) + .then(apiUtil.status) + .then(apiUtil.json) + .then(response => { + resolve(response); + }) + .catch(function(error) { + reject(error); + }); + }); + } +}; diff --git a/app/ayanova/src/components/widgetlist.vue b/app/ayanova/src/components/widgetlist.vue index a380866c..711ab2e7 100644 --- a/app/ayanova/src/components/widgetlist.vue +++ b/app/ayanova/src/components/widgetlist.vue @@ -2,9 +2,9 @@ @@ -22,25 +22,26 @@ diff --git a/devdocs/todo.txt b/devdocs/todo.txt index bb8ac3c9..d1a3ae42 100644 --- a/devdocs/todo.txt +++ b/devdocs/todo.txt @@ -32,7 +32,7 @@ Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOiIxNTQyNjY5Njc3IiwiZXhwIjoi UI TODO ITEMS - Make the copyright banner at bottom left aligned, right now it seems weird in small iPhone size when it breaks to two lines (make text smaller?) - + - Change favicon to be AyaNova not VUE - Stage 2 AFTER POSTED TEST ROUND COMPLETED