blob: d4af0648dc82d88ac5ab1f6ad09bcee6e1649d3e [file] [log] [blame]
SurenNeware61859092020-10-01 09:37:32 +05301import api from '@/store/api';
SurenNeware31bf55a2020-06-22 21:53:33 +05302import i18n from '@/i18n';
SurenNeware090c2d42020-04-01 14:07:27 +05303
4const ServerLedStore = {
5 namespaced: true,
6 state: {
Derick Montague64835442020-11-29 12:31:20 -06007 indicatorLedActiveState: false,
SurenNeware090c2d42020-04-01 14:07:27 +05308 },
9 getters: {
Derick Montague64835442020-11-29 12:31:20 -060010 getIndicatorLedActiveState: (state) => state.indicatorLedActiveState,
SurenNeware090c2d42020-04-01 14:07:27 +053011 },
12 mutations: {
Derick Montague64835442020-11-29 12:31:20 -060013 setIndicatorLedActiveState(state, indicatorLedActiveState) {
14 state.indicatorLedActiveState = indicatorLedActiveState;
Derick Montague602e98a2020-10-21 16:20:00 -050015 },
SurenNeware090c2d42020-04-01 14:07:27 +053016 },
17 actions: {
Derick Montague64835442020-11-29 12:31:20 -060018 async getIndicatorLedActiveState({ commit }) {
SurenNeware31bf55a2020-06-22 21:53:33 +053019 return await api
Sean Zhang8841b7d2024-06-15 08:42:41 +030020 .get(`${await this.dispatch('global/getSystemPath')}`)
Derick Montague602e98a2020-10-21 16:20:00 -050021 .then((response) => {
Derick Montague64835442020-11-29 12:31:20 -060022 commit(
23 'setIndicatorLedActiveState',
Ed Tanous81323992024-02-27 11:26:24 -080024 response.data.LocationIndicatorActive,
Derick Montague64835442020-11-29 12:31:20 -060025 );
SurenNeware090c2d42020-04-01 14:07:27 +053026 })
Derick Montague602e98a2020-10-21 16:20:00 -050027 .catch((error) => console.log(error));
SurenNeware090c2d42020-04-01 14:07:27 +053028 },
Derick Montague64835442020-11-29 12:31:20 -060029 async saveIndicatorLedActiveState({ commit }, payload) {
Yoshie Muranaka11bafca2020-12-01 16:38:47 -080030 commit('setIndicatorLedActiveState', payload);
SurenNeware31bf55a2020-06-22 21:53:33 +053031 return await api
Sean Zhang8841b7d2024-06-15 08:42:41 +030032 .patch(`${await this.dispatch('global/getSystemPath')}`, {
SurenNeware2aac4d32020-11-24 16:32:14 +053033 LocationIndicatorActive: payload,
34 })
Derick Montague602e98a2020-10-21 16:20:00 -050035 .catch((error) => {
SurenNeware31bf55a2020-06-22 21:53:33 +053036 console.log(error);
Yoshie Muranaka11bafca2020-12-01 16:38:47 -080037 commit('setIndicatorLedActiveState', !payload);
SurenNeware2aac4d32020-11-24 16:32:14 +053038 if (payload) {
Sandeepa Singh68cbbe92021-07-14 16:02:22 +053039 throw new Error(
Ed Tanous81323992024-02-27 11:26:24 -080040 i18n.t('pageInventory.toast.errorEnableIdentifyLed'),
Sandeepa Singh68cbbe92021-07-14 16:02:22 +053041 );
SurenNeware31bf55a2020-06-22 21:53:33 +053042 } else {
Sandeepa Singh68cbbe92021-07-14 16:02:22 +053043 throw new Error(
Ed Tanous81323992024-02-27 11:26:24 -080044 i18n.t('pageInventory.toast.errorDisableIdentifyLed'),
Sandeepa Singh68cbbe92021-07-14 16:02:22 +053045 );
SurenNeware31bf55a2020-06-22 21:53:33 +053046 }
47 });
Derick Montague602e98a2020-10-21 16:20:00 -050048 },
49 },
SurenNeware090c2d42020-04-01 14:07:27 +053050};
51
52export default ServerLedStore;