87 lines
2.7 KiB
JavaScript
87 lines
2.7 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/replication.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
replication: [],
|
|
search_status: false,
|
|
last_id: -1,
|
|
selected_replication: {},
|
|
startslave: []
|
|
},
|
|
mutations: {
|
|
update_replication(state, val) {
|
|
state.replication = val
|
|
},
|
|
update_search_status(state, val) {
|
|
state.search_status = val
|
|
},
|
|
update_last_id(state, val) {
|
|
state.last_id = val
|
|
},
|
|
update_selected_replication(state, val) {
|
|
state.selected_replication = val
|
|
},
|
|
update_startslave(state, val) {
|
|
state.startslave = val
|
|
}
|
|
},
|
|
actions: {
|
|
async status(context) {
|
|
context.commit("update_search_status", true)
|
|
try {
|
|
var prm = {
|
|
token: one_token()
|
|
}
|
|
let resp = await api.status(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_search_status", false)
|
|
console.log(resp.message)
|
|
} else {
|
|
context.commit("update_search_status", false)
|
|
let data = {
|
|
records: resp.data.records
|
|
}
|
|
context.commit("update_replication", data.records)
|
|
if (context.state.last_id == -1) {
|
|
if (resp.data && resp.data.records.length > 0) {
|
|
context.commit("update_selected_replication", resp.data.records[0])
|
|
}
|
|
} else {
|
|
let idx = _.findIndex(resp.data.records, function (o) {
|
|
});
|
|
console.log(idx)
|
|
if (idx >= 0) {
|
|
context.commit("update_selected_replication", resp.data.records[idx]);
|
|
}
|
|
}
|
|
}
|
|
} catch (e) {
|
|
context.commit("update_search_status", false)
|
|
console.log(e)
|
|
}
|
|
},
|
|
|
|
async start_slave(context) {
|
|
try {
|
|
var prm = {
|
|
token: one_token()
|
|
}
|
|
let resp = await api.start_slave(prm)
|
|
if (resp.status != "OK") {
|
|
console.log(resp.message)
|
|
} else {
|
|
let data = {
|
|
data: resp.data
|
|
}
|
|
context.commit("update_startslave", data.data)
|
|
}
|
|
} catch (e) {
|
|
console.log(e)
|
|
}
|
|
}
|
|
}
|
|
} |