Browse Source

[IMP] connection polling and offline features

robert 6 years ago
parent
commit
5e62a323dd
3 changed files with 32 additions and 12 deletions
  1. 26 10
      src/components/common/ConnectionStatus.vue
  2. 3 2
      src/components/steps/Customer.vue
  3. 3 0
      src/store/actions.js

+ 26 - 10
src/components/common/ConnectionStatus.vue

@@ -9,18 +9,33 @@
 
     export default {
         methods: {
-            startNetWatcher() {
-                this.intevalId = setInterval(() => {
-                    const url = '/web/static/src/img/favicon.ico?_=' + new Date().getTime()
-                    axios.get(url).then(() => {
+            startPolling() {
+                this.polling = true
+
+                const poll = () => {
+                    if (!this.polling) {
+                        return
+                    }
+
+                    const frame = Math.round(Math.random() * 5000)
+
+                    axios.request({
+                        url: '/web/static/src/img/favicon.ico?_=' + new Date().getTime(),
+                        method: 'get',
+                        timeout: 2000
+                    }).then(() => {
                         this.isWired = true
+                        setTimeout(poll, frame)
                     }).catch(() => {
                         this.isWired = false
+                        setTimeout(poll, frame)
                     })
-                }, 1000)
+                }
+
+                poll()
             },
-            stopNetWatcher() {
-                clearInterval(this.intevalId)
+            stopPolling() {
+                this.polling = false
             },
             notifyNetStatus() {
                 this.$emit('onChangeNet', this.isWired)
@@ -41,14 +56,15 @@
             return {
                 message: 'Estableciendo conexión',
                 isWired: false,
-                intevalId: null
+                polling: true
+                // intevalId: null
             }
         },
         mounted() {
-            this.startNetWatcher()
+            this.startPolling()
         },
         destroyed() {
-            this.stopNetWatcher()
+            this.stopPolling()
         }
     }
 </script>

+ 3 - 2
src/components/steps/Customer.vue

@@ -8,7 +8,7 @@
                     @onSearch='filterCustomers'
                 )
                 card-grid(
-                    canAdd
+                    :canAdd='isWired'
                     :items='visibleCustomers'
                     :loading='loadingCustomers'
                     @onAdd='showCustomerForm'
@@ -47,7 +47,8 @@
             'visibleCustomers',
             'loadingCustomers',
             'showingCustomerForm',
-            'selectedCustomer'
+            'selectedCustomer',
+            'isWired'
         ]),
         methods: mapActions([
             'filterCustomers',

+ 3 - 0
src/store/actions.js

@@ -284,7 +284,10 @@ const actions = {
 
         if (isWired) {
             dispatch('syncData')
+            return
         }
+
+        dispatch('notify', 'Estás trabajando sin conexión. Se ocultará el menú superior mientras sigas sin conexión')
     },
     hideTopbar(_, isWired) {
         if (!openerp.eiru_topbar_toggler) {