Flatten nested repos
This commit is contained in:
282
test/vuex/one-admin-mcu/modules/admin.js
Normal file
282
test/vuex/one-admin-mcu/modules/admin.js
Normal file
@@ -0,0 +1,282 @@
|
||||
// 1 => LOADING
|
||||
// 2 => DONE
|
||||
// 3 => ERROR
|
||||
import * as api from "../api/admin.js"
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: {
|
||||
mcu: [],
|
||||
total_mcu: 0,
|
||||
selected_mcu: {},
|
||||
search_status: false,
|
||||
error_message: "",
|
||||
last_id: -1,
|
||||
current_page: 1,
|
||||
x_search: "",
|
||||
act: "",
|
||||
dialog_form: false,
|
||||
loading_save: false,
|
||||
start_date:moment(new Date()).format('YYYY-MM-DD'),
|
||||
end_date:moment(new Date()).format('YYYY-MM-DD'),
|
||||
autocomplete_status: 0,
|
||||
companys: [],
|
||||
selected_company: {},
|
||||
// mous: [],
|
||||
selected_mou_multiple: [],
|
||||
save_status: 2,
|
||||
alert_error: false,
|
||||
dialog_error: false,
|
||||
msg_success: "",
|
||||
alert_success: false
|
||||
},
|
||||
mutations: {
|
||||
update_mcu(state, val) {
|
||||
state.mcu = val
|
||||
},
|
||||
update_total_mcu(state, val) {
|
||||
state.total_mcu = val
|
||||
},
|
||||
update_selected_mcu(state, val) {
|
||||
state.selected_mcu = val
|
||||
},
|
||||
update_search_status(state, val) {
|
||||
state.search_status = val
|
||||
},
|
||||
update_error_message(state, val) {
|
||||
state.error_message = val
|
||||
},
|
||||
update_last_id(state, val) {
|
||||
state.last_id = val
|
||||
},
|
||||
update_current_page(state, val) {
|
||||
state.current_page = val
|
||||
},
|
||||
update_x_search(state, val) {
|
||||
state.x_search = val
|
||||
state.current_page = 1
|
||||
},
|
||||
update_act(state, val) {
|
||||
state.act = val
|
||||
},
|
||||
update_dialog_form(state, val) {
|
||||
state.dialog_form = val
|
||||
},
|
||||
update_loading_save(state, val) {
|
||||
state.loading_save = val
|
||||
},
|
||||
update_start_date(state, val) {
|
||||
state.start_date = val
|
||||
},
|
||||
update_end_date(state, val) {
|
||||
state.end_date = val
|
||||
},
|
||||
update_autocomplete_status(state, val) {
|
||||
state.autocomplete_status = val
|
||||
},
|
||||
update_companys(state, val) {
|
||||
state.companys = val
|
||||
},
|
||||
update_selected_company(state, val) {
|
||||
state.selected_company = val
|
||||
state.selected_mou_multiple = ''
|
||||
},
|
||||
// update_mous(state, val) {
|
||||
// state.mous = val
|
||||
// },
|
||||
update_selected_mou_multiple(state, val) {
|
||||
state.selected_mou_multiple = val
|
||||
},
|
||||
update_save_status(state, val) {
|
||||
state.save_status = val
|
||||
},
|
||||
update_alert_error(state, val) {
|
||||
state.alert_error = val
|
||||
},
|
||||
update_dialog_error(state, val) {
|
||||
state.dialog_error = val
|
||||
},
|
||||
update_msg_success(state, val) {
|
||||
state.msg_success = val
|
||||
},
|
||||
update_alert_success(state, val) {
|
||||
state.alert_success = val
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
async search(context) {
|
||||
context.commit("update_search_status", true)
|
||||
try {
|
||||
var prm = {
|
||||
token: one_token(),
|
||||
search: context.state.x_search,
|
||||
current_page: context.state.current_page,
|
||||
last_id: context.state.last_id
|
||||
}
|
||||
let resp = await api.search(prm)
|
||||
if (resp.status != "OK") {
|
||||
context.commit("update_search_status", false)
|
||||
context.commit("update_error_message", resp.message)
|
||||
} else {
|
||||
context.commit("update_search_status", false)
|
||||
context.commit("update_error_message", "")
|
||||
let data = {
|
||||
records: resp.data.records,
|
||||
total: resp.data.total,
|
||||
total_page: resp.data.total_page
|
||||
}
|
||||
context.commit("update_mcu", data.records)
|
||||
context.commit("update_total_mcu", data.total_page)
|
||||
if (
|
||||
!(
|
||||
Object.keys(context.state.selected_mcu).length === 0 &&
|
||||
context.state.selected_mcu.constructor === Object
|
||||
)
|
||||
) {
|
||||
let idx = _.findIndex(resp.data.records, function (o) {
|
||||
return o.Mgm_McuID == context.state.selected_mcu.Mgm_McuID
|
||||
});
|
||||
if (idx >= 0) {
|
||||
context.commit("update_selected_mcu", resp.data.records[idx]);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
context.commit("update_search_status", false)
|
||||
context.commit("update_error_message", e.message)
|
||||
}
|
||||
},
|
||||
|
||||
async search_company(context, prm) {
|
||||
context.commit("update_autocomplete_status", 1)
|
||||
try {
|
||||
let resp = await api.search_company(one_token(), prm)
|
||||
if (resp.status != "OK") {
|
||||
context.commit("update_autocomplete_status", 3)
|
||||
} else {
|
||||
context.commit("update_autocomplete_status", 2)
|
||||
let data = {
|
||||
records: resp.data.records
|
||||
}
|
||||
context.commit("update_companys", resp.data.records)
|
||||
}
|
||||
} catch (e) {
|
||||
context.commit("update_autocomplete_status", 3)
|
||||
}
|
||||
},
|
||||
|
||||
// async search_mou_multiple(context, companyId) {
|
||||
// context.commit("update_autocomplete_status", 1)
|
||||
// try {
|
||||
// let resp = await api.search_mou_multiple(one_token(), companyId)
|
||||
// if (resp.status != "OK") {
|
||||
// context.commit("update_autocomplete_status", 3)
|
||||
// } else {
|
||||
// context.commit("update_autocomplete_status", 2)
|
||||
// let data = {
|
||||
// records: resp.data.records
|
||||
// }
|
||||
// context.commit("update_mous", resp.data.records)
|
||||
// }
|
||||
// } catch (e) {
|
||||
// context.commit("update_autocomplete_status", 3)
|
||||
// }
|
||||
// },
|
||||
|
||||
async addMcu(context, prm) {
|
||||
context.commit("update_save_status", 1)
|
||||
try {
|
||||
context.commit("update_loading_save", true)
|
||||
prm.token = one_token()
|
||||
let resp = await api.addMcu(prm)
|
||||
if (resp.status != "OK") {
|
||||
context.commit("update_save_status", 3)
|
||||
context.commit("update_loading_save", false)
|
||||
context.commit("update_error_message", resp.message)
|
||||
context.commit("update_alert_error", true)
|
||||
context.commit("update_dialog_error", true)
|
||||
} else {
|
||||
context.commit("update_save_status", 2)
|
||||
context.commit("update_loading_save", false)
|
||||
context.commit("update_error_message", "")
|
||||
context.commit("update_dialog_error", false)
|
||||
context.commit("update_dialog_form", false)
|
||||
let data = resp.data
|
||||
var msg = "Berhasil disimpan"
|
||||
context.commit("update_msg_success", msg)
|
||||
context.commit("update_alert_success", true)
|
||||
context.dispatch("search")
|
||||
}
|
||||
} catch (e) {
|
||||
context.commit("update_save_status", 3)
|
||||
context.commit("update_loading_save", false)
|
||||
context.commit("update_error_message", e.message)
|
||||
context.commit("update_alert_error", true)
|
||||
}
|
||||
},
|
||||
|
||||
async editMcu(context, prm) {
|
||||
context.commit("update_save_status", 1)
|
||||
try {
|
||||
context.commit("update_loading_save", true)
|
||||
prm.token = one_token()
|
||||
let resp = await api.editMcu(prm)
|
||||
if (resp.status != "OK") {
|
||||
context.commit("update_save_status", 3)
|
||||
context.commit("update_loading_save", false)
|
||||
context.commit("update_error_message", resp.message)
|
||||
context.commit("update_alert_error", true)
|
||||
context.commit("update_dialog_error", true)
|
||||
} else {
|
||||
context.commit("update_save_status", 2)
|
||||
context.commit("update_loading_save", false)
|
||||
context.commit("update_error_message", "")
|
||||
context.commit("update_dialog_error", false)
|
||||
context.commit("update_dialog_form", false)
|
||||
let data = resp.data
|
||||
var msg = "Berhasil diedit"
|
||||
context.commit("update_msg_success", msg)
|
||||
context.commit("update_alert_success", true)
|
||||
context.dispatch("search")
|
||||
}
|
||||
} catch (e) {
|
||||
context.commit("update_save_status", 3)
|
||||
context.commit("update_loading_save", false)
|
||||
context.commit("update_error_message", e.message)
|
||||
context.commit("update_alert_error", true)
|
||||
}
|
||||
},
|
||||
|
||||
async deleteMcu(context, prm) {
|
||||
context.commit("update_save_status", 1)
|
||||
try {
|
||||
context.commit("update_loading_save", true)
|
||||
prm.token = one_token()
|
||||
let resp = await api.deleteMcu(prm)
|
||||
if (resp.status != "OK") {
|
||||
context.commit("update_save_status", 3)
|
||||
context.commit("update_loading_save", false)
|
||||
context.commit("update_error_message", resp.message)
|
||||
context.commit("update_alert_error", true)
|
||||
context.commit("update_dialog_error", true)
|
||||
} else {
|
||||
context.commit("update_save_status", 2)
|
||||
context.commit("update_loading_save", false)
|
||||
context.commit("update_error_message", "")
|
||||
context.commit("update_dialog_error", false)
|
||||
context.commit("update_dialog_form", false)
|
||||
let data = resp.data
|
||||
var msg = "Berhasil dihapus"
|
||||
context.commit("update_msg_success", msg)
|
||||
context.commit("update_alert_success", true)
|
||||
context.dispatch("search")
|
||||
}
|
||||
} catch (e) {
|
||||
context.commit("update_save_status", 3)
|
||||
context.commit("update_loading_save", false)
|
||||
context.commit("update_error_message", e.message)
|
||||
context.commit("update_alert_error", true)
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user