Kaynağa Gözat

Cleans up broadcasting code to specify channels.

Channels before were too generic, events meant for one WO would to get picked up by all of them, and all would be updated. Channel names now include identifying info so that each resource only gets its own update events.
Christopher Leggett 5 yıl önce
ebeveyn
işleme
40cf04e1c7

+ 2 - 2
app/Events/AssetUpdated.php

@@ -25,7 +25,7 @@ class AssetUpdated implements ShouldBroadcast
      */
     public function __construct($asset)
     {
-        $this->data = $asset->toJson();
+        $this->data = $asset;
         $this->pcextra = json_encode(unserialize($asset->pcextra));
     }
 
@@ -36,6 +36,6 @@ class AssetUpdated implements ShouldBroadcast
      */
     public function broadcastOn()
     {
-        return new Channel('assets');
+        return new Channel('asset.'.$this->data->pcid);
     }
 }

+ 2 - 2
app/Events/WorkOrderUpdated.php

@@ -24,7 +24,7 @@ class WorkOrderUpdated implements ShouldBroadcast
      */
     public function __construct($workOrder)
     {
-        $this->data = $workOrder->toJson();
+        $this->data = $workOrder;
 
     }
 
@@ -35,6 +35,6 @@ class WorkOrderUpdated implements ShouldBroadcast
      */
     public function broadcastOn()
     {
-        return new Channel('work-orders');
+        return new Channel('work-order.'.$this->data->woid);
     }
 }

+ 4 - 4
public/js/app.js

@@ -2008,8 +2008,8 @@ __webpack_require__.r(__webpack_exports__);
   mounted: function mounted() {
     var _this = this;
 
-    Echo.channel('assets').listen('AssetUpdated', function (e) {
-      _this.data = JSON.parse(e.data);
+    Echo.channel('asset.' + this.data.pcid).listen('AssetUpdated', function (e) {
+      _this.data = e.data;
       _this.pcextra = JSON.parse(e.pcextra);
     });
   },
@@ -2650,8 +2650,8 @@ __webpack_require__.r(__webpack_exports__);
   mounted: function mounted() {
     var _this = this;
 
-    Echo.channel('work-orders').listen('WorkOrderUpdated', function (e) {
-      _this.data = JSON.parse(e.data);
+    Echo.channel('work-order.' + this.data.woid).listen('WorkOrderUpdated', function (e) {
+      _this.data = e.data;
     });
   }
 });

+ 2 - 2
resources/js/components/assetinfo.vue

@@ -64,9 +64,9 @@ export default {
         }
     },
     mounted() {
-        Echo.channel('assets')
+        Echo.channel('asset.'+this.data.pcid)
                 .listen('AssetUpdated', (e) => {
-                this.data = JSON.parse(e.data);
+                this.data = e.data;
                 this.pcextra = JSON.parse(e.pcextra);
             });
     },

+ 2 - 2
resources/js/components/woinfo.vue

@@ -38,9 +38,9 @@
             }
         },
         mounted() {
-            Echo.channel('work-orders')
+            Echo.channel('work-order.'+this.data.woid)
                 .listen('WorkOrderUpdated', (e) => {
-                    this.data = JSON.parse(e.data);
+                    this.data = e.data;
                 });
         }
     }