This commit is contained in:
2019-01-03 18:25:41 +00:00
parent 1e6eb7ca1a
commit a890bdeeb6
68 changed files with 35812 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
/* xeslint-disable */
import apiUtil from "./apiutil";
export default {
fetchAPIInfo() {
return new Promise(function(resolve, reject) {
//step 2: get it
fetch(apiUtil.APIUrl("ServerInfo"), apiUtil.fetchGetOptions())
.then(apiUtil.status)
.then(apiUtil.json)
.then(response => {
resolve(response);
})
.catch(function(error) {
reject(error);
});
});
}
};

141
ayanova/src/api/apiutil.js Normal file
View File

@@ -0,0 +1,141 @@
/* 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) {
return Promise.resolve(response);
} else {
store.commit("logItem", "API error: " + response.statusText);
return Promise.reject(new Error(response.statusText));
}
},
json(response) {
return response.json();
},
patchAuthorizedHeaders() {
return {
//Accept: "application/json, text/plain, */*",
Accept: "application/json",
"Content-Type": "application/json-patch+json",
Authorization: "Bearer " + store.state.apiToken
};
},
postAuthorizedHeaders() {
return {
Accept: "application/json",
"Content-Type": "application/json",
Authorization: "Bearer " + store.state.apiToken
};
},
postUnAuthorizedHeaders() {
return {
Accept: "application/json",
"Content-Type": "application/json"
};
},
fetchPostNoAuthOptions(data) {
return {
method: "post",
mode: "cors",
headers: this.postUnAuthorizedHeaders(),
body: JSON.stringify(data)
};
},
fetchPostOptions(data) {
return {
method: "post",
mode: "cors",
headers: this.postAuthorizedHeaders(),
body: JSON.stringify(data)
};
},
fetchGetOptions() {
/* GET WITH AUTH */
return {
method: "get",
mode: "cors",
headers: this.postAuthorizedHeaders()
};
},
APIUrl(apiPath) {
if ("" == store.state.apiUrl) {
//construct the api url and store it
//development location?
if (
window.location.hostname == "localhost" &&
window.location.port == "8080"
) {
store.commit("setAPIURL", "http://localhost:7575/api/v8.0/");
store.commit("setHelpURL", "http://localhost:7575/docs/");
store.commit(
"logItem",
"apiutil::APIUrl -> setting to dev. mode: " + store.state.apiUrl
);
} else {
//production location <protocol>//<hostname>:<port>/
store.commit(
"setHelpURL",
window.location.protocol + "//" + window.location.host + "/docs/"
);
store.commit(
"setAPIURL",
window.location.protocol + "//" + window.location.host + "/api/v8.0/"
);
store.commit(
"logItem",
"apiutil::APIUrl -> setting to: " + store.state.apiUrl
);
}
}
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))
);
}
};

28
ayanova/src/api/auth.js Normal file
View File

@@ -0,0 +1,28 @@
/* Xeslint-disable */
import apiUtil from "./apiutil";
import { processLogin, processLogout } from "../utils/authutil";
export default {
async authenticate(login, password) {
return fetch(
apiUtil.APIUrl("auth"),
apiUtil.fetchPostNoAuthOptions({
login: login,
password: password
})
)
.then(apiUtil.status)
.then(apiUtil.json)
.then(processLogin)
.then(() => {
return Promise.resolve(true);
}) //succeeded, nothing to return
.catch(function(error) {
processLogout();
return Promise.reject(error);
});
},
logout() {
processLogout();
}
};

43
ayanova/src/api/locale.js Normal file
View File

@@ -0,0 +1,43 @@
/* xeslint-disable */
import store from "../store";
import apiUtil from "./apiutil";
import _ from "../utils/libs/lodash.js";
export default {
get(key) {
// debugger;
if (!_.has(store.state.localeText, key)) {
return "?" + key + "?";
}
return store.state.localeText[key];
},
fetch(keys) {
return new Promise(function(resolve, reject) {
//step 1: build an array of keys that we don't have already
//Note: this will ensure only unique keys go into the store so it's safe to call this with dupes as can happen
var needIt = [];
for (var i = 0; i < keys.length; i++) {
if (!_.has(store.state.localeText, keys[i])) {
needIt.push(keys[i]);
}
}
if (needIt.length == 0) {
resolve();
return;
}
//step 2: get it
fetch(apiUtil.APIUrl("locale/subset"), apiUtil.fetchPostOptions(needIt))
.then(apiUtil.status)
.then(apiUtil.json)
.then(response => {
_.forEach(response.data, function(item) {
store.commit("addLocaleText", item);
});
resolve();
})
.catch(function(error) {
reject(error);
});
});
}
};

View File

@@ -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);
});
});
}
};