Forráskód Böngészése

[FIX] internet detector

robert 6 éve
szülő
commit
36665bb759

+ 0 - 1
src/components/common/ConnectionStatus.vue

@@ -57,7 +57,6 @@
                 message: 'Estableciendo conexión',
                 isWired: false,
                 polling: true
-                // intevalId: null
             }
         },
         mounted() {

+ 20 - 18
src/store/actions.js

@@ -16,7 +16,7 @@ const actions = {
             commit('setLoading', false)
             return
         }
- 
+
         return axios.get('/eiru_sales/init', {
             params: {
                 mode: getters.mode
@@ -208,7 +208,6 @@ const actions = {
         commit('storeData', data)
 
         dispatch('syncData').then(() => {
-            commit('resetData')
             commit('setLoading', false)
             commit('setCompleted', true)
         })
@@ -218,18 +217,9 @@ const actions = {
 
         if (getters.isWired) {
             dispatch('syncData')
-            commit('resetData')
         }
     },
-    syncData({ getters, dispatch }) {
-        if (getters.data.length == 0) {
-            return
-        }
-
-        if (getters.isSynchronizable) {
-            dispatch('notify', 'Estás conectado nuevamente. Sincronizaremos sus datos en segundo plano')
-        }
-
+    syncData({ getters, commit, dispatch }) {
         return axios.post('/eiru_sales/finish', {
             jsonrpc: '2.0',
             method: 'call',
@@ -237,6 +227,8 @@ const actions = {
                 data: getters.data
             }
         }).then(() => {
+            commit('resetData')
+
             if (getters.isSynchronizable) {
                 dispatch('notify', 'Los datos fueron sincronizados con éxito')
             }
@@ -341,16 +333,26 @@ const actions = {
 
         dispatch('initProcess')
     },
-    changeNetStatus({ commit, dispatch }, isWired) {
-        dispatch('hideTopbar', isWired)
+    changeNetStatus({ commit, dispatch, getters }, isWired) {
         commit('setNetStatus', isWired)
+        dispatch('hideTopbar', isWired)
 
         if (isWired) {
-            dispatch('syncData')
-            return
-        }
+            
+            if (getters.isSynchronizable && getters.hasDataToSync) {
+                dispatch('notify', 'Estás conectado nuevamente. Sus datos serán sincronizados en segundo plano')
+                dispatch('syncData')
+                return
+            }
+
+            if (getters.wasWired) {
+                return
+            }
 
-        dispatch('notify', 'Estás sin conexión. Ocultaremos el menú superior mientras sigas trabajando')
+            dispatch('notify', 'Estás conectado nuevamente')
+        } else {
+            dispatch('notify', 'Estás sin conexión. Ocultaremos el menú superior mientras sigas trabajando')
+        }
     },
     hideTopbar(_, isWired) {
         if (!openerp.eiru_topbar_toggler) {

+ 6 - 0
src/store/getters.js

@@ -5,6 +5,9 @@ const getters = {
     data(state) {
         return state.data
     },
+    hasDataToSync(state) {
+        return state.data.length !== 0
+    },
     isSale(state) {
         return state.mode === 'sale'
     },
@@ -26,6 +29,9 @@ const getters = {
     isWired(state) {
         return state.isWired
     },
+    wasWired(state) {
+        return state.wasWired
+    },
     loading(state) {
         return state.loading
     },

+ 1 - 0
src/store/mutations.js

@@ -24,6 +24,7 @@ const mutations = {
         state.settings = settings
     },
     setNetStatus(state, isWired) {
+        state.wasWired = state.isWired
         state.isWired = isWired
     },
     storeData(state, data) {

+ 2 - 1
src/store/state.js

@@ -9,7 +9,8 @@ const state = {
     result: '',
     askForPrint: false,
     error: false,
-    isWired: false
+    isWired: true,
+    wasWired: true
 }
 
 export default state