Kaynağa Gözat

Adds modal dialog for editing asset info.

Christopher Leggett 5 yıl önce
ebeveyn
işleme
ab000a6e61

+ 2 - 0
app/Events/AssetUpdated.php

@@ -16,6 +16,7 @@ class AssetUpdated implements ShouldBroadcast
     use Dispatchable, InteractsWithSockets, SerializesModels;
 
     public $data;
+    public $pcextra;
 
     /**
      * Create a new event instance.
@@ -25,6 +26,7 @@ class AssetUpdated implements ShouldBroadcast
     public function __construct($asset)
     {
         $this->data = $asset->toJson();
+        $this->pcextra = json_encode(unserialize($asset->pcextra));
     }
 
     /**

+ 71 - 0
app/Http/Controllers/Api/AssetsController.php

@@ -0,0 +1,71 @@
+<?php
+
+namespace App\Http\Controllers\Api;
+
+use App\Asset;
+use App\Http\Controllers\Controller;
+use Illuminate\Http\Request;
+
+class AssetsController extends Controller
+{
+    /**
+     * Display a listing of the resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function index()
+    {
+        //
+    }
+
+    /**
+     * Store a newly created resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @return \Illuminate\Http\Response
+     */
+    public function store(Request $request)
+    {
+        //
+    }
+
+    /**
+     * Display the specified resource.
+     *
+     * @param  \App\Asset  $asset
+     * @return \Illuminate\Http\Response
+     */
+    public function show(Asset $asset)
+    {
+        //
+    }
+
+    /**
+     * Update the specified resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  \App\Asset  $asset
+     * @return \Illuminate\Http\Response
+     */
+    public function update(Request $request, Asset $asset)
+    {
+        $asset->pcmanu = $request->input('pcmanu');
+        $asset->pcmake = $request->input('pcmake');
+        $asset->pcnickname = $request->input('pcnickname');
+        $asset->pcextra = serialize($request->input('pcextra'));
+        $asset->save();
+        event(new \App\Events\AssetUpdated($asset));
+        return response()->json($asset, 200);
+    }
+
+    /**
+     * Remove the specified resource from storage.
+     *
+     * @param  \App\Asset  $asset
+     * @return \Illuminate\Http\Response
+     */
+    public function destroy(Asset $asset)
+    {
+        //
+    }
+}

+ 357 - 19
public/js/app.js

@@ -1951,6 +1951,52 @@ __webpack_require__.r(__webpack_exports__);
 //
 //
 //
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
 /* harmony default export */ __webpack_exports__["default"] = ({
   props: ['asset', 'pcextraStart'],
   data: function data() {
@@ -1962,10 +2008,17 @@ __webpack_require__.r(__webpack_exports__);
   mounted: function mounted() {
     var _this = this;
 
-    console.log(this.pcextra);
     Echo.channel('assets').listen('AssetUpdated', function (e) {
       _this.data = JSON.parse(e.data);
+      _this.pcextra = JSON.parse(e.pcextra);
     });
+  },
+  methods: {
+    updateAsset: function updateAsset() {
+      this.data.pcextra = this.pcextra;
+      axios.put('/api/asset/' + this.data.pcid, this.data).then(function (response) {})["catch"](function (error) {});
+      $('#asseteditModal').modal('hide');
+    }
   }
 });
 
@@ -48413,24 +48466,309 @@ var render = function() {
   var _vm = this
   var _h = _vm.$createElement
   var _c = _vm._self._c || _h
-  return _c("div", [
-    _c("h4", { staticClass: "text-center" }, [
-      _vm._v(_vm._s(this.data.pcmanu) + " " + _vm._s(this.data.pcmake) + " - "),
-      _c("small", { staticClass: "text-muted" }, [
-        _vm._v(_vm._s(this.data.pcnickname))
-      ])
-    ]),
-    _vm._v(" "),
-    _c("p", [_vm._v("OS: " + _vm._s(this.pcextra[2]))]),
-    _vm._v(" "),
-    _c("p", [_vm._v("S/N: " + _vm._s(this.pcextra[104]))]),
-    _vm._v(" "),
-    _c("p", [_vm._v("CPU: " + _vm._s(this.pcextra[101]))]),
-    _vm._v(" "),
-    _c("p", [_vm._v("RAM: " + _vm._s(this.pcextra[100]))]),
-    _vm._v(" "),
-    _c("p", [_vm._v("Graphics: " + _vm._s(this.pcextra[4]))])
-  ])
+  return _c(
+    "div",
+    [
+      _c(
+        "modal",
+        {
+          attrs: {
+            id: "asseteditModal",
+            tabindex: "-1",
+            role: "dialog",
+            "aria-labelledby": "asseteditModalLabel"
+          }
+        },
+        [
+          _c(
+            "h5",
+            {
+              staticClass: "modal-title",
+              attrs: { slot: "header", id: "asseteditModalLabel" },
+              slot: "header"
+            },
+            [_vm._v("\n            Edit Work Order Information\n        ")]
+          ),
+          _vm._v(" "),
+          _c("div", { attrs: { slot: "body" }, slot: "body" }, [
+            _c("div", { staticClass: "form-group" }, [
+              _c("label", { attrs: { for: "manufacturer" } }, [
+                _vm._v("Manufacturer")
+              ]),
+              _vm._v(" "),
+              _c("input", {
+                directives: [
+                  {
+                    name: "model",
+                    rawName: "v-model",
+                    value: _vm.data.pcmanu,
+                    expression: "data.pcmanu"
+                  }
+                ],
+                staticClass: "form-control",
+                attrs: {
+                  type: "text",
+                  name: "manufacturer",
+                  id: "manufacturer"
+                },
+                domProps: { value: _vm.data.pcmanu },
+                on: {
+                  input: function($event) {
+                    if ($event.target.composing) {
+                      return
+                    }
+                    _vm.$set(_vm.data, "pcmanu", $event.target.value)
+                  }
+                }
+              })
+            ]),
+            _vm._v(" "),
+            _c("div", { staticClass: "form-group" }, [
+              _c("label", { attrs: { for: "make" } }, [_vm._v("Make")]),
+              _vm._v(" "),
+              _c("input", {
+                directives: [
+                  {
+                    name: "model",
+                    rawName: "v-model",
+                    value: _vm.data.pcmake,
+                    expression: "data.pcmake"
+                  }
+                ],
+                staticClass: "form-control",
+                attrs: { type: "text", name: "make", id: "make" },
+                domProps: { value: _vm.data.pcmake },
+                on: {
+                  input: function($event) {
+                    if ($event.target.composing) {
+                      return
+                    }
+                    _vm.$set(_vm.data, "pcmake", $event.target.value)
+                  }
+                }
+              })
+            ]),
+            _vm._v(" "),
+            _c("div", { staticClass: "form-group" }, [
+              _c("label", { attrs: { for: "nickname" } }, [_vm._v("Nickname")]),
+              _vm._v(" "),
+              _c("input", {
+                directives: [
+                  {
+                    name: "model",
+                    rawName: "v-model",
+                    value: _vm.data.pcnickname,
+                    expression: "data.pcnickname"
+                  }
+                ],
+                staticClass: "form-control",
+                attrs: { type: "text", name: "nickname", id: "nickname" },
+                domProps: { value: _vm.data.pcnickname },
+                on: {
+                  input: function($event) {
+                    if ($event.target.composing) {
+                      return
+                    }
+                    _vm.$set(_vm.data, "pcnickname", $event.target.value)
+                  }
+                }
+              })
+            ]),
+            _vm._v(" "),
+            _c("div", { staticClass: "form-group" }, [
+              _c("label", { attrs: { for: "os" } }, [_vm._v("OS")]),
+              _vm._v(" "),
+              _c("input", {
+                directives: [
+                  {
+                    name: "model",
+                    rawName: "v-model",
+                    value: _vm.pcextra[2],
+                    expression: "pcextra[2]"
+                  }
+                ],
+                staticClass: "form-control",
+                attrs: { type: "text", name: "os", id: "os" },
+                domProps: { value: _vm.pcextra[2] },
+                on: {
+                  input: function($event) {
+                    if ($event.target.composing) {
+                      return
+                    }
+                    _vm.$set(_vm.pcextra, 2, $event.target.value)
+                  }
+                }
+              })
+            ]),
+            _vm._v(" "),
+            _c("div", { staticClass: "form-group" }, [
+              _c("label", { attrs: { for: "serial" } }, [
+                _vm._v("Serial Number")
+              ]),
+              _vm._v(" "),
+              _c("input", {
+                directives: [
+                  {
+                    name: "model",
+                    rawName: "v-model",
+                    value: _vm.pcextra[104],
+                    expression: "pcextra[104]"
+                  }
+                ],
+                staticClass: "form-control",
+                attrs: { type: "text", id: "serial", name: "serial" },
+                domProps: { value: _vm.pcextra[104] },
+                on: {
+                  input: function($event) {
+                    if ($event.target.composing) {
+                      return
+                    }
+                    _vm.$set(_vm.pcextra, 104, $event.target.value)
+                  }
+                }
+              })
+            ]),
+            _vm._v(" "),
+            _c("div", { staticClass: "form-group" }, [
+              _c("label", { attrs: { for: "cpu" } }, [_vm._v("CPU")]),
+              _vm._v(" "),
+              _c("input", {
+                directives: [
+                  {
+                    name: "model",
+                    rawName: "v-model",
+                    value: _vm.pcextra[101],
+                    expression: "pcextra[101]"
+                  }
+                ],
+                staticClass: "form-control",
+                attrs: { type: "text", id: "cpu", name: "cpu" },
+                domProps: { value: _vm.pcextra[101] },
+                on: {
+                  input: function($event) {
+                    if ($event.target.composing) {
+                      return
+                    }
+                    _vm.$set(_vm.pcextra, 101, $event.target.value)
+                  }
+                }
+              })
+            ]),
+            _vm._v(" "),
+            _c("div", { staticClass: "form-group" }, [
+              _c("label", { attrs: { for: "ram" } }, [_vm._v("RAM")]),
+              _vm._v(" "),
+              _c("input", {
+                directives: [
+                  {
+                    name: "model",
+                    rawName: "v-model",
+                    value: _vm.pcextra[100],
+                    expression: "pcextra[100]"
+                  }
+                ],
+                staticClass: "form-control",
+                attrs: { type: "text", name: "ram", id: "ram" },
+                domProps: { value: _vm.pcextra[100] },
+                on: {
+                  input: function($event) {
+                    if ($event.target.composing) {
+                      return
+                    }
+                    _vm.$set(_vm.pcextra, 100, $event.target.value)
+                  }
+                }
+              })
+            ]),
+            _vm._v(" "),
+            _c("div", { staticClass: "form-group" }, [
+              _c("label", { attrs: { for: "graphics" } }, [_vm._v("Graphics")]),
+              _vm._v(" "),
+              _c("input", {
+                directives: [
+                  {
+                    name: "model",
+                    rawName: "v-model",
+                    value: _vm.pcextra[4],
+                    expression: "pcextra[4]"
+                  }
+                ],
+                staticClass: "form-control",
+                attrs: { type: "text", name: "graphics", id: "grapics" },
+                domProps: { value: _vm.pcextra[4] },
+                on: {
+                  input: function($event) {
+                    if ($event.target.composing) {
+                      return
+                    }
+                    _vm.$set(_vm.pcextra, 4, $event.target.value)
+                  }
+                }
+              })
+            ])
+          ]),
+          _vm._v(" "),
+          _c("div", { attrs: { slot: "footer" }, slot: "footer" }, [
+            _c(
+              "button",
+              {
+                staticClass: "btn btn-secondary",
+                attrs: { type: "button", "data-dismiss": "modal" }
+              },
+              [_vm._v("Close")]
+            ),
+            _vm._v(" "),
+            _c(
+              "button",
+              {
+                staticClass: "btn btn-primary",
+                attrs: { type: "button" },
+                on: {
+                  click: function($event) {
+                    return _vm.updateAsset()
+                  }
+                }
+              },
+              [_vm._v("Save")]
+            )
+          ])
+        ]
+      ),
+      _vm._v(" "),
+      _c("h4", { staticClass: "text-center" }, [
+        _vm._v(
+          _vm._s(this.data.pcmanu) + " " + _vm._s(this.data.pcmake) + " - "
+        ),
+        _c("small", { staticClass: "text-muted" }, [
+          _vm._v(_vm._s(this.data.pcnickname))
+        ])
+      ]),
+      _vm._v(" "),
+      _c("p", [_vm._v("OS: " + _vm._s(this.pcextra[2]))]),
+      _vm._v(" "),
+      _c("p", [_vm._v("S/N: " + _vm._s(this.pcextra[104]))]),
+      _vm._v(" "),
+      _c("p", [_vm._v("CPU: " + _vm._s(this.pcextra[101]))]),
+      _vm._v(" "),
+      _c("p", [_vm._v("RAM: " + _vm._s(this.pcextra[100]))]),
+      _vm._v(" "),
+      _c("p", [_vm._v("Graphics: " + _vm._s(this.pcextra[4]))]),
+      _vm._v(" "),
+      _c(
+        "button",
+        {
+          staticClass: "btn btn-primary",
+          attrs: {
+            type: "button",
+            "data-toggle": "modal",
+            "data-target": "#asseteditModal"
+          }
+        },
+        [_vm._v("Edit")]
+      )
+    ],
+    1
+  )
 }
 var staticRenderFns = []
 render._withStripped = true

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

@@ -1,11 +1,57 @@
 <template>
     <div>
+        <modal id="asseteditModal" tabindex="-1" role="dialog" aria-labelledby="asseteditModalLabel">
+            <h5 slot="header" class="modal-title" id="asseteditModalLabel">
+                Edit Work Order Information
+            </h5>
+            <div slot="body">
+                <div class="form-group">
+                    <label for="manufacturer">Manufacturer</label>
+                    <input type="text" name="manufacturer" id="manufacturer" class="form-control" v-model="data.pcmanu">
+                </div>
+                <div class="form-group">
+                    <label for="make">Make</label>
+                    <input type="text" name="make" id="make" class="form-control" v-model="data.pcmake">
+                </div>
+                <div class="form-group">
+                    <label for="nickname">Nickname</label>
+                    <input type="text" name="nickname" id="nickname" class="form-control" v-model="data.pcnickname">
+                </div>
+                <div class="form-group">
+                    <label for="os">OS</label>
+                    <input type="text" name="os" id="os" class="form-control" v-model="pcextra[2]">
+                </div>
+                <div class="form-group">
+                    <label for="serial">Serial Number</label>
+                    <input type="text" id="serial" name="serial" class="form-control" v-model="pcextra[104]">
+                </div>
+                <div class="form-group">
+                    <label for="cpu">CPU</label>
+                    <input type="text" id="cpu" name="cpu" class="form-control" v-model="pcextra[101]">
+                </div>
+                <div class="form-group">
+                    <label for="ram">RAM</label>
+                    <input type="text" name="ram" id="ram" class="form-control" v-model="pcextra[100]">
+                </div>
+                <div class="form-group">
+                    <label for="graphics">Graphics</label>
+                    <input type="text" name="graphics" id="grapics" class="form-control" v-model="pcextra[4]">
+                </div>
+            </div>
+
+            <div slot="footer">
+                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
+                <button type="button" class="btn btn-primary" @click="updateAsset()">Save</button>
+            </div>
+        </modal>
         <h4 class="text-center">{{ this.data.pcmanu }} {{ this.data.pcmake }} - <small class="text-muted">{{this.data.pcnickname}}</small></h4>
         <p>OS: {{this.pcextra[2]}}</p>
         <p>S/N: {{ this.pcextra[104] }}</p>
         <p>CPU: {{ this.pcextra[101]}}</p>
         <p>RAM: {{ this.pcextra[100] }}</p>
         <p>Graphics: {{this.pcextra[4]}}</p>
+
+        <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#asseteditModal">Edit</button>
     </div>
 </template>
 <script>
@@ -18,11 +64,20 @@ export default {
         }
     },
     mounted() {
-        console.log(this.pcextra);
         Echo.channel('assets')
-            .listen('AssetUpdated', (e) => {
+                .listen('AssetUpdated', (e) => {
                 this.data = JSON.parse(e.data);
+                this.pcextra = JSON.parse(e.pcextra);
             });
+    },
+    methods: {
+        updateAsset() {
+            this.data.pcextra = this.pcextra;
+            axios.put('/api/asset/' + this.data.pcid, this.data)
+                    .then((response) => {})
+                    .catch((error) => {});
+                $('#asseteditModal').modal('hide');
+        }
     }
 }
 </script>

+ 0 - 1
resources/views/workorders/show.blade.php

@@ -32,7 +32,6 @@
                     <div class="tab-content">
                         <div class="tab-pane active" id="assetinfo" role="tabpanel" aria-labelledby="assetinfo-tab">
                             <assetinfo asset="{{$workOrder->asset}}" pcextra-start="{{json_encode(unserialize($workOrder->asset->pcextra))}}"></assetinfo>
-                            <a href="{{ route('editasset', ['asset' => $workOrder->asset]) }}" class="btn btn-primary">Edit</a>
                         </div>
                         @if($workOrder->asset->group !== null)
                         <div class="tab-pane" id="group" role="tabpanel" aria-labelledby="group-tab">

+ 2 - 0
routes/api.php

@@ -19,3 +19,5 @@ Route::middleware('auth:api')->get('/user', function (Request $request) {
 
 Route::get('/workorder/{workOrder}', 'Api\WorkOrdersController@show');
 Route::put('/workorder/{workOrder}', 'Api\WorkOrdersController@update');
+
+Route::put('/asset/{asset}', 'Api\AssetsController@update');