Flatten nested repos
This commit is contained in:
259
test/vuex/one-md-location/modules/location.js
Normal file
259
test/vuex/one-md-location/modules/location.js
Normal file
@@ -0,0 +1,259 @@
|
||||
// 1 => LOADING
|
||||
// 2 => DONE
|
||||
// 3 => ERROR
|
||||
import * as api from "../api/location.js";
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: {
|
||||
total_location: 0,
|
||||
total_filter_location: 0,
|
||||
location: [],
|
||||
station: [],
|
||||
act: "new",
|
||||
sorting: {
|
||||
descending: "asc",
|
||||
sortBy: "M_LocationName",
|
||||
},
|
||||
current_page: 1,
|
||||
lookup_location: 0,
|
||||
lookup_station: 0,
|
||||
search_status: false,
|
||||
save_status: 0,
|
||||
save_error_message: "",
|
||||
dialog_form_location: false,
|
||||
dialog_edit_form_location: false,
|
||||
alert_success: false,
|
||||
msg_success: "",
|
||||
x_search: "",
|
||||
errors: [],
|
||||
get_data_status: 0,
|
||||
get_data_error_message: "",
|
||||
selected_item: {},
|
||||
},
|
||||
mutations: {
|
||||
update_location(state, data) {
|
||||
state.location = data.records;
|
||||
state.total_filter_location = data.total_filter;
|
||||
state.total_location = data.total;
|
||||
},
|
||||
update_station(state, data) {
|
||||
state.station = data.records;
|
||||
},
|
||||
update_lookup_location(state, data) {
|
||||
state.lookup_location = data;
|
||||
},
|
||||
update_lookup_station(state, data) {
|
||||
state.lookup_station = data;
|
||||
},
|
||||
update_search_status(state, val) {
|
||||
state.search_status = val;
|
||||
},
|
||||
update_sorting(state, val) {
|
||||
state.sorting = val;
|
||||
},
|
||||
update_x_search(state, val) {
|
||||
state.x_search = val;
|
||||
state.current_page = 1;
|
||||
},
|
||||
update_current_page(state, val) {
|
||||
state.current_page = val;
|
||||
},
|
||||
update_act(state, val) {
|
||||
state.act = val;
|
||||
},
|
||||
update_errors(state, val) {
|
||||
state.errors = val;
|
||||
},
|
||||
update_lookup_error_message(state, status) {
|
||||
state.lookup_error_message = status;
|
||||
},
|
||||
update_selected_item(state, val) {
|
||||
state.selected_item = val;
|
||||
},
|
||||
update_lookup_location(state, status) {
|
||||
state.lookup_location = status;
|
||||
},
|
||||
update_save_status(state, val) {
|
||||
state.save_status = val;
|
||||
},
|
||||
update_save_error_message(state, val) {
|
||||
state.save_error_message = val;
|
||||
},
|
||||
update_dialog_form_location(state, val) {
|
||||
state.dialog_form_location = val;
|
||||
},
|
||||
update_dialog_edit_form_location(state, val) {
|
||||
state.dialog_edit_form_location = val;
|
||||
},
|
||||
update_alert_success(state, val) {
|
||||
state.alert_success = val;
|
||||
},
|
||||
update_msg_success(state, val) {
|
||||
state.msg_success = val;
|
||||
},
|
||||
update_get_data_status(state, val) {
|
||||
state.get_data_status = val;
|
||||
},
|
||||
update_get_data_error_message(state, val) {
|
||||
state.get_data_error_message = val;
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
async lookup(context) {
|
||||
context.commit("update_lookup_location", 1);
|
||||
context.commit("update_search_status", true);
|
||||
try {
|
||||
var param = {
|
||||
token: one_token(),
|
||||
page: context.state.current_page,
|
||||
name: context.state.x_search,
|
||||
order_by: context.state.sorting.sortBy,
|
||||
order: context.state.sorting.descending,
|
||||
};
|
||||
let resp = await api.lookup(param);
|
||||
if (resp.status != "OK") {
|
||||
context.commit("update_search_status", false);
|
||||
context.commit("update_lookup_location", 3);
|
||||
context.commit("update_lookup_error_message", resp.message);
|
||||
} else {
|
||||
context.commit("update_search_status", false);
|
||||
context.commit("update_lookup_location", 2);
|
||||
context.commit("update_lookup_error_message", "");
|
||||
let data = resp.data;
|
||||
context.commit("update_location", data);
|
||||
}
|
||||
} catch (e) {
|
||||
context.commit("update_search_status", false);
|
||||
context.commit("update_lookup_location", 3);
|
||||
context.commit("update_lookup_error_message", e.message);
|
||||
console.log(e);
|
||||
}
|
||||
},
|
||||
async getStaton(context) {
|
||||
context.commit("update_lookup_station", 1);
|
||||
try {
|
||||
var param = {
|
||||
token: one_token(),
|
||||
};
|
||||
let resp = await api.station(param);
|
||||
if (resp.status != "OK") {
|
||||
context.commit("update_lookup_station", 3);
|
||||
context.commit("update_lookup_error_message", resp.message);
|
||||
} else {
|
||||
context.commit("update_lookup_station", 2);
|
||||
context.commit("update_lookup_error_message", "");
|
||||
let data = resp.data;
|
||||
context.commit("update_station", data);
|
||||
}
|
||||
} catch (e) {
|
||||
context.commit("update_lookup_station", 3);
|
||||
context.commit("update_lookup_error_message", e.message);
|
||||
console.log(e);
|
||||
}
|
||||
},
|
||||
async add(context, prm) {
|
||||
context.commit("update_save_status", 1);
|
||||
try {
|
||||
var param = {
|
||||
token: one_token(),
|
||||
stationid: prm.stationid,
|
||||
name: prm.name,
|
||||
priority: prm.priority,
|
||||
};
|
||||
let resp = await api.additem(param);
|
||||
|
||||
if (resp.status != "OK") {
|
||||
context.commit("update_save_status", 3);
|
||||
context.commit("update_save_error_message", resp.message);
|
||||
} else {
|
||||
context.commit("update_save_status", 2);
|
||||
context.commit("update_save_error_message", "");
|
||||
let data = resp.data;
|
||||
if (data.affected_rows !== 0) {
|
||||
context.commit("update_errors", []);
|
||||
context.commit("update_alert_success", true);
|
||||
context.commit("update_dialog_form_location", false);
|
||||
var msg = "Location " + prm.name + " sudah tersimpan dong ...";
|
||||
context.commit("update_msg_success", msg);
|
||||
context.dispatch("lookup");
|
||||
} else {
|
||||
context.commit("update_errors", resp.data.errors);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
context.commit("update_save_status", 3);
|
||||
context.commit("update_save_error_message", e.message);
|
||||
console.log(e);
|
||||
}
|
||||
},
|
||||
async update(context, prm) {
|
||||
context.commit("update_save_status", 1);
|
||||
try {
|
||||
var param = {
|
||||
token: one_token(),
|
||||
id: prm.id,
|
||||
stationid: prm.stationid,
|
||||
name: prm.name,
|
||||
priority: prm.priority,
|
||||
};
|
||||
let resp = await api.update(param);
|
||||
|
||||
if (resp.status != "OK") {
|
||||
context.commit("update_save_status", 3);
|
||||
context.commit("update_save_error_message", resp.message);
|
||||
} else {
|
||||
context.commit("update_save_status", 2);
|
||||
context.commit("update_save_error_message", "");
|
||||
let data = resp.data;
|
||||
if (data.affected_rows !== 0) {
|
||||
context.commit("update_errors", []);
|
||||
context.commit("update_alert_success", true);
|
||||
context.commit("update_dialog_form_location", false);
|
||||
var msg = "Location " + prm.name + " sudah tersimpan dong ...";
|
||||
context.commit("update_msg_success", msg);
|
||||
context.dispatch("lookup");
|
||||
} else {
|
||||
context.commit("update_errors", resp.data.errors);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
context.commit("update_save_status", 3);
|
||||
context.commit("update_save_error_message", e.message);
|
||||
console.log(e);
|
||||
}
|
||||
},
|
||||
async delete(context, prm) {
|
||||
context.commit("update_save_status", 1);
|
||||
try {
|
||||
var param = {
|
||||
token: one_token(),
|
||||
id: prm.id,
|
||||
};
|
||||
let resp = await api.xdelete(param);
|
||||
|
||||
if (resp.status != "OK") {
|
||||
context.commit("update_save_status", 3);
|
||||
context.commit("update_save_error_message", resp.message);
|
||||
} else {
|
||||
context.commit("update_save_status", 2);
|
||||
context.commit("update_save_error_message", "");
|
||||
let data = resp.data;
|
||||
if (data.affected_rows !== 0) {
|
||||
context.commit("update_errors", []);
|
||||
context.commit("update_alert_success", true);
|
||||
context.commit("update_dialog_form_location", false);
|
||||
var msg = "Location " + prm.name + " sudah dihapus dong ...";
|
||||
context.commit("update_msg_success", msg);
|
||||
context.dispatch("lookup");
|
||||
} else {
|
||||
context.commit("update_errors", resp.data.errors);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
context.commit("update_save_status", 3);
|
||||
context.commit("update_save_error_message", e.message);
|
||||
console.log(e);
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user