add/remove publication
This commit is contained in:
parent
1bb3bdb24a
commit
833995e739
@ -100,18 +100,16 @@ export default {
|
||||
methods: {
|
||||
...mapMutations({
|
||||
//set_url: "setInfobaseURL",
|
||||
set_publication: "setInfobasePublication",
|
||||
//set_publication: "setInfobasePublication",
|
||||
}),
|
||||
...mapActions({
|
||||
set_url: "updateInfobaseURL",
|
||||
}),
|
||||
add_publication() {
|
||||
let name = this.name;
|
||||
this.set_publication({ name, publicated: true });
|
||||
this.$store.dispatch("addInfobasePublication", this.name);
|
||||
},
|
||||
remove_publication() {
|
||||
let name = this.name;
|
||||
this.set_publication({ name, publicated: false });
|
||||
this.$store.dispatch("removeInfobasePublication", this.name);
|
||||
},
|
||||
start_edit_url() {
|
||||
this.url_edit = true;
|
||||
|
@ -1,7 +1,7 @@
|
||||
import axios from "axios";
|
||||
|
||||
//const api_base = "http://localhost:5000/api/v1"; // test1
|
||||
const api_base = "http://localhost:17653/api/v1"; // test2 - mock
|
||||
const api_base = "http://localhost:17653"; // test2 - mock
|
||||
|
||||
const LoadingStatus = Object.freeze({
|
||||
Loaded: { loading: false, error: false },
|
||||
@ -9,11 +9,11 @@ const LoadingStatus = Object.freeze({
|
||||
Error: { loading: false, error: true },
|
||||
});
|
||||
|
||||
const new_infobase = (name) => ({
|
||||
name,
|
||||
url: "",
|
||||
publicated: false,
|
||||
});
|
||||
// const new_infobase = (name) => ({
|
||||
// name,
|
||||
// url: "",
|
||||
// publicated: false,
|
||||
// });
|
||||
|
||||
const infobaseByName = (state) => (name) =>
|
||||
state.infobases.find((infobase) => name === infobase.name);
|
||||
@ -25,7 +25,7 @@ function setInfobaseLock(state, { name, lock }) {
|
||||
state.locked_bases.push(name);
|
||||
} else {
|
||||
const idx = state.locked_bases.findIndex((x) => name === x);
|
||||
delete state.locked_bases[idx];
|
||||
state.locked_bases.splice(idx, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,17 +59,17 @@ export default {
|
||||
unlockInfobase(state, name) {
|
||||
setInfobaseLock(state, { name, lock: false });
|
||||
},
|
||||
setInfobase(state, { name, infobase_new }) {
|
||||
const idx = state.infobases.findIndex(
|
||||
(infobase) => name === infobase.name
|
||||
);
|
||||
setInfobase(state, { name, infobase }) {
|
||||
const idx = state.infobases.findIndex((x) => name === x.name);
|
||||
if (-1 === idx) {
|
||||
state.infobases.push(infobase_new);
|
||||
state.infobases.push(infobase);
|
||||
} else {
|
||||
if (null == infobase_new) {
|
||||
delete state.infobases[idx];
|
||||
if (null == infobase) {
|
||||
state.infobases.splice(idx, 1);
|
||||
setInfobaseLock(state, { name, lock: false });
|
||||
} else {
|
||||
state.infobases[idx] = infobase_new;
|
||||
infobase.publicated = true;
|
||||
state.infobases[idx] = infobase;
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -104,42 +104,24 @@ export default {
|
||||
ctx.commit("setLoadingStatus", LoadingStatus.Error);
|
||||
}
|
||||
},
|
||||
async fetchInfobaseAvailable(ctx, { name }) {
|
||||
async fetchInfobase(ctx, name) {
|
||||
ctx.commit("lockInfobase", name);
|
||||
try {
|
||||
const list = await axios.get(`${api_base}/infobases-available`);
|
||||
if (!list) {
|
||||
return;
|
||||
}
|
||||
if (!Array.isArray(list)) {
|
||||
return;
|
||||
}
|
||||
const available = name in list;
|
||||
let infobase = null;
|
||||
if (available) {
|
||||
infobase = new_infobase(name);
|
||||
}
|
||||
ctx.commit("setInfobase", { name, infobase });
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
} finally {
|
||||
ctx.commit("unlockInfobase", name);
|
||||
}
|
||||
},
|
||||
async fetchPublication(ctx, { name }) {
|
||||
ctx.commit("lockInfobase", name);
|
||||
try {
|
||||
const res = await axios.get(`${api_base}/publications`);
|
||||
const res = await axios.get(`${api_base}/infobases-all`);
|
||||
if (!res) {
|
||||
return;
|
||||
}
|
||||
const infobase = res.data;
|
||||
const infobase = res.data.find((i) => name === i.name);
|
||||
ctx.commit("setInfobase", { name, infobase });
|
||||
ctx.commit("unlockInfobase", name);
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 404) {
|
||||
ctx.dispatch("fetchInfobaseAvailable", { name });
|
||||
}
|
||||
ctx.commit(
|
||||
"setErrorMessage",
|
||||
`Ошибка получения информации о базе: ${name}`
|
||||
);
|
||||
ctx.commit("setInfobase", { name, infobase: null });
|
||||
} finally {
|
||||
ctx.commit("unlockInfobase", name);
|
||||
}
|
||||
},
|
||||
async updateInfobaseURL(ctx, { name, url }) {
|
||||
@ -161,6 +143,34 @@ export default {
|
||||
ctx.commit("unlockInfobase", name);
|
||||
}
|
||||
},
|
||||
async addInfobasePublication(ctx, name) {
|
||||
const infobase = ctx.getters.getInfobaseByName(name);
|
||||
if (infobase.publicated) return;
|
||||
|
||||
ctx.commit("lockInfobase", name);
|
||||
try {
|
||||
await axios.put(`${api_base}/publications`, { id:name, name });
|
||||
ctx.commit("setErrorMessage", "");
|
||||
ctx.dispatch("fetchInfobase", name);
|
||||
} catch (err) {
|
||||
ctx.commit("setErrorMessage", `Ошибка публикации базы ${name}`);
|
||||
ctx.commit("unlockInfobase", name);
|
||||
}
|
||||
},
|
||||
async removeInfobasePublication(ctx, name) {
|
||||
const infobase = ctx.getters.getInfobaseByName(name);
|
||||
if (!infobase.publicated) return;
|
||||
|
||||
ctx.commit("lockInfobase", name);
|
||||
try {
|
||||
await axios.delete(`${api_base}/publications/${name}`);
|
||||
ctx.commit("setErrorMessage", "");
|
||||
ctx.dispatch("fetchInfobase", name);
|
||||
} catch (err) {
|
||||
ctx.commit("setErrorMessage", `Ошибка отмены публикации базы ${name}`);
|
||||
ctx.commit("unlockInfobase", name);
|
||||
}
|
||||
},
|
||||
},
|
||||
getters: {
|
||||
errorMessage(state) {
|
||||
|
Loading…
Reference in New Issue
Block a user