mock api rewtite + more vuex
This commit is contained in:
parent
bb204e12ab
commit
91f582c289
@ -93,7 +93,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import "bootstrap-icons/icons/exclamation-triangle-fill.svg?sprite";
|
import "bootstrap-icons/icons/exclamation-triangle-fill.svg?sprite";
|
||||||
import { mapGetters } from "vuex";
|
import { mapGetters, mapMutations } from "vuex";
|
||||||
|
|
||||||
import InfobaseURLEditor from "@/components/InfobaseURLEditor.vue";
|
import InfobaseURLEditor from "@/components/InfobaseURLEditor.vue";
|
||||||
|
|
||||||
@ -109,31 +109,25 @@ export default {
|
|||||||
infobases: [],
|
infobases: [],
|
||||||
url_editors: {},
|
url_editors: {},
|
||||||
}),
|
}),
|
||||||
computed: mapGetters(["allInfobases", "isLoading", "isLoadingError"]),
|
computed: mapGetters([
|
||||||
|
"allInfobases",
|
||||||
|
"getInfobaseByName",
|
||||||
|
"isLoading",
|
||||||
|
"isLoadingError",
|
||||||
|
]),
|
||||||
methods: {
|
methods: {
|
||||||
infobase(name) {
|
...mapMutations({
|
||||||
return this.allInfobases.find((infobase) => name === infobase.name);
|
set_url: "setInfobaseURL",
|
||||||
},
|
set_publication: "setInfobasePublication",
|
||||||
|
}),
|
||||||
add_publication(name) {
|
add_publication(name) {
|
||||||
let infobase = this.infobase(name);
|
this.set_publication({ name, publicated: true });
|
||||||
if (infobase === undefined) return;
|
|
||||||
|
|
||||||
infobase.publicated = true;
|
|
||||||
},
|
},
|
||||||
remove_publication(name) {
|
remove_publication(name) {
|
||||||
let infobase = this.infobase(name);
|
this.set_publication({ name, publicated: false });
|
||||||
if (infobase === undefined) return;
|
|
||||||
|
|
||||||
infobase.publicated = false;
|
|
||||||
},
|
|
||||||
set_url(name, url) {
|
|
||||||
let infobase = this.infobase(name);
|
|
||||||
if (infobase === undefined) return;
|
|
||||||
|
|
||||||
infobase.url = url;
|
|
||||||
},
|
},
|
||||||
start_edit_url(name) {
|
start_edit_url(name) {
|
||||||
let infobase = this.infobase(name);
|
let infobase = this.getInfobaseByName(name);
|
||||||
if (infobase === undefined) return;
|
if (infobase === undefined) return;
|
||||||
|
|
||||||
this.url_editors[name] = true;
|
this.url_editors[name] = true;
|
||||||
@ -142,7 +136,7 @@ export default {
|
|||||||
delete this.url_editors[name];
|
delete this.url_editors[name];
|
||||||
},
|
},
|
||||||
apply_edit_url({ name, url }) {
|
apply_edit_url({ name, url }) {
|
||||||
this.set_url(name, url);
|
this.set_url({ name, url });
|
||||||
delete this.url_editors[name];
|
delete this.url_editors[name];
|
||||||
},
|
},
|
||||||
is_edit_url_active(name) {
|
is_edit_url_active(name) {
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
const api_base = "http://localhost:17653/api/v1";
|
//const api_base = "http://localhost:5000/api/v1"; // test1
|
||||||
|
const api_base = "http://localhost:17653/api/v1"; // test2 - mock
|
||||||
|
|
||||||
const LoadingStatus = Object.freeze({
|
const LoadingStatus = Object.freeze({
|
||||||
Loaded: {loading: false, error: false},
|
Loaded: { loading: false, error: false },
|
||||||
Loading: {loading: true, error: false},
|
Loading: { loading: true, error: false },
|
||||||
Error: {loading: false, error: true},
|
Error: { loading: false, error: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@ -16,41 +18,45 @@ export default {
|
|||||||
is_loading: false,
|
is_loading: false,
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
setLoadingStatus(state, {loading, error}) {
|
setLoadingStatus(state, { loading, error }) {
|
||||||
state.is_loading = loading && ! error;
|
state.is_loading = loading && !error;
|
||||||
state.loading_error = error;
|
state.loading_error = error;
|
||||||
},
|
},
|
||||||
updateInfobases(state, infobases) {
|
setInfobases(state, infobases) {
|
||||||
state.infobases = infobases;
|
state.infobases = infobases;
|
||||||
},
|
},
|
||||||
|
setInfobase(state, { name, infobase }) {
|
||||||
|
let idx = state.infobases.findindex((infobase) => name === infobase.name);
|
||||||
|
if (-1 === idx) return;
|
||||||
|
state.infobases[idx] = infobase;
|
||||||
|
},
|
||||||
|
setInfobaseURL(state, { name, url }) {
|
||||||
|
let infobase = state.infobases.find((infobase) => name === infobase.name);
|
||||||
|
if (infobase === undefined) return;
|
||||||
|
infobase.url = url;
|
||||||
|
},
|
||||||
|
setInfobasePublication(state, { name, publicated }) {
|
||||||
|
let infobase = state.infobases.find((infobase) => name === infobase.name);
|
||||||
|
if (infobase === undefined) return;
|
||||||
|
infobase.publicated = publicated;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
async fetchInfobases(ctx) {
|
async fetchInfobases(ctx) {
|
||||||
ctx.commit("setLoadingStatus", LoadingStatus.Loading);
|
ctx.commit("setLoadingStatus", LoadingStatus.Loading);
|
||||||
try {
|
try {
|
||||||
const res = await axios.get(`${api_base}/infobases`);
|
const res = await axios.get(`${api_base}/infobases-all`);
|
||||||
if (!res) {
|
if (!res) {
|
||||||
ctx.commit("setLoadingStatus", LoadingStatus.Error);
|
ctx.commit("setLoadingStatus", LoadingStatus.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const names = res.data;
|
const infobases = res.data;
|
||||||
if (!Array.isArray(names)) {
|
if (!Array.isArray(infobases)) {
|
||||||
ctx.commit("setLoadingStatus", LoadingStatus.Error);
|
ctx.commit("setLoadingStatus", LoadingStatus.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
ctx.commit("setInfobases", infobases);
|
||||||
if (0 < names.length) {
|
|
||||||
if ("string" !== typeof names[0]) {
|
|
||||||
ctx.commit("setLoadingStatus", LoadingStatus.Error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.commit("setLoadingStatus", LoadingStatus.Loaded);
|
ctx.commit("setLoadingStatus", LoadingStatus.Loaded);
|
||||||
let infobases = names.map((name) => {
|
|
||||||
return { name: name, publicated: "bpdemo" === name, url: "/" };
|
|
||||||
});
|
|
||||||
ctx.commit("updateInfobases", infobases);
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
ctx.commit("setLoadingStatus", LoadingStatus.Error);
|
ctx.commit("setLoadingStatus", LoadingStatus.Error);
|
||||||
}
|
}
|
||||||
@ -60,6 +66,8 @@ export default {
|
|||||||
allInfobases(state) {
|
allInfobases(state) {
|
||||||
return state.infobases;
|
return state.infobases;
|
||||||
},
|
},
|
||||||
|
getInfobaseByName: (state) => (name) =>
|
||||||
|
state.infobases.find((infobase) => name === infobase.name),
|
||||||
isLoading(state) {
|
isLoading(state) {
|
||||||
return state.is_loading;
|
return state.is_loading;
|
||||||
},
|
},
|
||||||
|
@ -1,11 +1,27 @@
|
|||||||
{
|
{
|
||||||
"index": ["infobases", "publications", "module", "config"],
|
"index": ["infobases-all", "infobases-available", "publications", "module", "config", "config-test", "apache-restart"],
|
||||||
"infobases":["test1", "accounting", "bpdemo", "hrm31", "Trade-2021"],
|
"infobases-available":["test1", "accounting", "bpdemo", "hrm31", "Trade-2021"],
|
||||||
"publications":["accounting", "hrm31"],
|
"infobases-all":[
|
||||||
"publication":[
|
{"name": "test1", "url": "", "publicated": false},
|
||||||
{"name": "accounting", "url": "/acc"},
|
{"name": "accounting", "url": "/acc", "publicated": true},
|
||||||
{"name": "hrm31", "url": "/hrm"}
|
{"name": "bpdemo", "url": "", "publicated": false},
|
||||||
|
{"name": "hrm31", "url": "/hrm", "publicated": true},
|
||||||
|
{"name": "Trade-2021", "url": "", "publicated": false}
|
||||||
|
],
|
||||||
|
"publications":[
|
||||||
|
{"name": "accounting", "url": "/acc", "publicated": true},
|
||||||
|
{"name": "hrm31", "url": "/hrm", "publicated": true}
|
||||||
],
|
],
|
||||||
"module":{},
|
"module":{},
|
||||||
"config":{}
|
"config":{
|
||||||
|
"url_prefix": "http://localhost"
|
||||||
|
|
||||||
|
},
|
||||||
|
"config-test":{
|
||||||
|
"is_apache_cfg_valid": true,
|
||||||
|
"is_vrd_path_valid": true,
|
||||||
|
"is_dir_path_valid": true,
|
||||||
|
"is_url_base_valid": true,
|
||||||
|
"is_module_valid": true
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,7 +1,5 @@
|
|||||||
{
|
{
|
||||||
"/api/v1/*": "/$1",
|
"/api/v1/*": "/$1",
|
||||||
"/": "/index",
|
"/": "/index",
|
||||||
"": "/index",
|
"": "/index"
|
||||||
"/publications/:name": "/publication/:name",
|
}
|
||||||
"/publications/:name/url": "/publication/:name"
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user