浏览代码

Implements adding and editing notes.

Christopher Leggett 5 年之前
父节点
当前提交
e8b0f3cabe

+ 73 - 0
app/Http/Controllers/Api/WorkOrderNotesController.php

@@ -0,0 +1,73 @@
+<?php
+
+namespace App\Http\Controllers\Api;
+
+use App\Http\Controllers\Controller;
+use App\WorkOrderNote;
+use Illuminate\Http\Request;
+
+class WorkOrderNotesController 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)
+    {
+        $workOrderNote = new WorkOrderNote();
+        $workOrderNote->notetype = $request->input('notetype');
+        $workOrderNote->thenote = $request->input('thenote');
+        $workOrderNote->noteuser = $request->input('noteuser');
+        $workOrderNote->woid = $request->input('woid');
+        $workOrderNote->save();
+        return response()->json($workOrderNote, 200);
+    }
+
+    /**
+     * Display the specified resource.
+     *
+     * @param  \App\WorkOrderNote  $workOrderNote
+     * @return \Illuminate\Http\Response
+     */
+    public function show(WorkOrderNote $workOrderNote)
+    {
+        //
+    }
+
+    /**
+     * Update the specified resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  \App\WorkOrderNote  $workOrderNote
+     * @return \Illuminate\Http\Response
+     */
+    public function update(Request $request, WorkOrderNote $workOrderNote)
+    {
+        $workOrderNote->thenote = $request->input('thenote');
+        $workOrderNote->save();
+        return response()->json($workOrderNote, 200);
+    }
+
+    /**
+     * Remove the specified resource from storage.
+     *
+     * @param  \App\WorkOrderNote  $workOrderNote
+     * @return \Illuminate\Http\Response
+     */
+    public function destroy(WorkOrderNote $workOrderNote)
+    {
+        //
+    }
+}

+ 1 - 1
app/WorkOrderNote.php

@@ -10,7 +10,7 @@ class WorkOrderNote extends Model
     protected $primaryKey = 'noteid';
 
     const CREATED_AT = 'notetime';
-    const MODIFIED_AT = null;
+    const UPDATED_AT = null;
 
     public function workOrder() {
         return $this->belongsTo('App\WorkOrder', 'woid');

+ 340 - 150
public/js/app.js

@@ -2500,16 +2500,15 @@ __webpack_require__.r(__webpack_exports__);
 
 /***/ }),
 
-/***/ "./node_modules/babel-loader/lib/index.js?!./node_modules/vue-loader/lib/index.js?!./resources/js/components/notes.vue?vue&type=script&lang=js&":
-/*!****************************************************************************************************************************************************************!*\
-  !*** ./node_modules/babel-loader/lib??ref--4-0!./node_modules/vue-loader/lib??vue-loader-options!./resources/js/components/notes.vue?vue&type=script&lang=js& ***!
-  \****************************************************************************************************************************************************************/
+/***/ "./node_modules/babel-loader/lib/index.js?!./node_modules/vue-loader/lib/index.js?!./resources/js/components/note-form-modal.vue?vue&type=script&lang=js&":
+/*!**************************************************************************************************************************************************************************!*\
+  !*** ./node_modules/babel-loader/lib??ref--4-0!./node_modules/vue-loader/lib??vue-loader-options!./resources/js/components/note-form-modal.vue?vue&type=script&lang=js& ***!
+  \**************************************************************************************************************************************************************************/
 /*! exports provided: default */
 /***/ (function(module, __webpack_exports__, __webpack_require__) {
 
 "use strict";
 __webpack_require__.r(__webpack_exports__);
-/* harmony import */ var _mixins_dateMixin__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../mixins/dateMixin */ "./resources/js/mixins/dateMixin.js");
 //
 //
 //
@@ -2527,6 +2526,77 @@ __webpack_require__.r(__webpack_exports__);
 //
 //
 //
+/* harmony default export */ __webpack_exports__["default"] = ({
+  props: {
+    populateWith: {
+      type: Object
+    },
+    modalId: {
+      type: String,
+      require: true
+    },
+    noteType: {
+      type: Number
+    },
+    noteUser: {
+      type: String
+    },
+    woid: {
+      type: Number
+    }
+  },
+  data: function data() {
+    return {
+      note: {}
+    };
+  },
+  mounted: function mounted() {
+    if (!this.populateWith) {
+      this.note = {
+        thenote: '',
+        notetype: this.noteType,
+        noteuser: this.noteUser,
+        woid: this.woid
+      };
+    } else {
+      this.note = JSON.parse(JSON.stringify(this.populateWith));
+    }
+  },
+  methods: {
+    updateNote: function updateNote(note) {
+      if (this.populateWith) {
+        axios.put('/api/workorders/notes/' + note.noteid, note).then(function (response) {
+          hideModal();
+        });
+      } else {
+        axios.post('/api/workorders/notes', note).then(function (response) {
+          hideModal();
+        });
+      }
+    },
+    hideModal: function hideModal() {
+      $('#' + this.modalId).modal('hide');
+    }
+  }
+});
+
+/***/ }),
+
+/***/ "./node_modules/babel-loader/lib/index.js?!./node_modules/vue-loader/lib/index.js?!./resources/js/components/notes.vue?vue&type=script&lang=js&":
+/*!****************************************************************************************************************************************************************!*\
+  !*** ./node_modules/babel-loader/lib??ref--4-0!./node_modules/vue-loader/lib??vue-loader-options!./resources/js/components/notes.vue?vue&type=script&lang=js& ***!
+  \****************************************************************************************************************************************************************/
+/*! exports provided: default */
+/***/ (function(module, __webpack_exports__, __webpack_require__) {
+
+"use strict";
+__webpack_require__.r(__webpack_exports__);
+/* harmony import */ var _mixins_dateMixin__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../mixins/dateMixin */ "./resources/js/mixins/dateMixin.js");
+//
+//
+//
+//
+//
 //
 //
 //
@@ -2552,10 +2622,11 @@ __webpack_require__.r(__webpack_exports__);
 
 /* harmony default export */ __webpack_exports__["default"] = ({
   mixins: [_mixins_dateMixin__WEBPACK_IMPORTED_MODULE_0__["default"]],
-  props: ['initialnotes', 'authusername'],
+  props: ['initialnotes', 'authusername', 'noteType', 'woid'],
   data: function data() {
     return {
-      notes: Object.values(this.initialnotes)
+      notes: Object.values(this.initialnotes),
+      noteWoid: this.woid
     };
   },
   methods: {
@@ -49894,6 +49965,107 @@ render._withStripped = true
 
 
 
+/***/ }),
+
+/***/ "./node_modules/vue-loader/lib/loaders/templateLoader.js?!./node_modules/vue-loader/lib/index.js?!./resources/js/components/note-form-modal.vue?vue&type=template&id=0435c624&":
+/*!******************************************************************************************************************************************************************************************************************!*\
+  !*** ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./resources/js/components/note-form-modal.vue?vue&type=template&id=0435c624& ***!
+  \******************************************************************************************************************************************************************************************************************/
+/*! exports provided: render, staticRenderFns */
+/***/ (function(module, __webpack_exports__, __webpack_require__) {
+
+"use strict";
+__webpack_require__.r(__webpack_exports__);
+/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "render", function() { return render; });
+/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "staticRenderFns", function() { return staticRenderFns; });
+var render = function() {
+  var _vm = this
+  var _h = _vm.$createElement
+  var _c = _vm._self._c || _h
+  return _c(
+    "modal",
+    {
+      attrs: {
+        id: _vm.modalId,
+        tabindex: "-1",
+        role: "dialog",
+        "aria-labelledby": _vm.modalId + "Label"
+      }
+    },
+    [
+      _c(
+        "h5",
+        {
+          staticClass: "modal-title",
+          attrs: { slot: "header", id: _vm.modalId + "Label" },
+          slot: "header"
+        },
+        [_vm._v("\n                Edit Note\n            ")]
+      ),
+      _vm._v(" "),
+      _c("div", { attrs: { slot: "body" }, slot: "body" }, [
+        _c("div", { staticClass: "form-group" }, [
+          _c("label", { attrs: { for: "content" } }, [_vm._v("Content")]),
+          _vm._v(" "),
+          _c("textarea", {
+            directives: [
+              {
+                name: "model",
+                rawName: "v-model",
+                value: _vm.note.thenote,
+                expression: "note.thenote"
+              }
+            ],
+            staticClass: "form-control",
+            attrs: {
+              name: "content" + _vm.note.noteid,
+              id: "content" + _vm.note.noteid
+            },
+            domProps: { value: _vm.note.thenote },
+            on: {
+              input: function($event) {
+                if ($event.target.composing) {
+                  return
+                }
+                _vm.$set(_vm.note, "thenote", $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.updateNote(_vm.note)
+              }
+            }
+          },
+          [_vm._v("Save")]
+        )
+      ])
+    ]
+  )
+}
+var staticRenderFns = []
+render._withStripped = true
+
+
+
 /***/ }),
 
 /***/ "./node_modules/vue-loader/lib/loaders/templateLoader.js?!./node_modules/vue-loader/lib/index.js?!./resources/js/components/notes.vue?vue&type=template&id=73d141f4&":
@@ -49914,158 +50086,106 @@ var render = function() {
   return _c(
     "ul",
     { staticClass: "list-unstyled" },
-    _vm._l(this.notes, function(note, index) {
-      return _c(
-        "li",
-        { key: note.noteid, staticClass: "row no-gutters mb-2" },
-        [
-          _c(
-            "modal",
-            {
+    [
+      _c("note-form-modal", {
+        attrs: {
+          "modal-id": "note" + _vm.noteType + "CreateModal",
+          "note-type": _vm.noteType,
+          woid: _vm.noteWoid,
+          "note-user": _vm.authusername
+        }
+      }),
+      _vm._v(" "),
+      _c(
+        "button",
+        {
+          staticClass: "btn btn-primary",
+          attrs: {
+            type: "button",
+            "data-toggle": "modal",
+            "data-target": "#note" + _vm.noteType + "CreateModal"
+          }
+        },
+        [_c("i", { staticClass: "fas fa-fw fa-plus" }), _vm._v(" Add New Note")]
+      ),
+      _vm._v(" "),
+      _vm._l(this.notes, function(note, index) {
+        return _c(
+          "li",
+          { key: note.noteid, staticClass: "row no-gutters mb-2" },
+          [
+            _c("note-form-modal", {
               attrs: {
-                id: "note" + note.noteid + "editModal",
-                tabindex: "-1",
-                role: "dialog",
-                "aria-labelledby": "note" + note.noteid + "editModalLabel"
+                "modal-id": "note" + note.noteid + "editModal",
+                "populate-with": note
               }
-            },
-            [
-              _c(
-                "h5",
-                {
-                  staticClass: "modal-title",
-                  attrs: {
-                    slot: "header",
-                    id: "note" + note.noteid + "editModalLabel"
-                  },
-                  slot: "header"
-                },
-                [_vm._v("\n                Edit Note\n            ")]
-              ),
-              _vm._v(" "),
-              _c("div", { attrs: { slot: "body" }, slot: "body" }, [
-                _c("div", { staticClass: "form-group" }, [
-                  _c("label", { attrs: { for: "content" } }, [
-                    _vm._v("Content")
-                  ]),
-                  _vm._v(" "),
-                  _c("textarea", {
-                    directives: [
-                      {
-                        name: "model",
-                        rawName: "v-model",
-                        value: note.thenote,
-                        expression: "note.thenote"
-                      }
-                    ],
-                    staticClass: "form-control",
-                    attrs: {
-                      name: "content" + note.noteid,
-                      id: "content" + note.noteid
-                    },
-                    domProps: { value: note.thenote },
-                    on: {
-                      input: function($event) {
-                        if ($event.target.composing) {
-                          return
-                        }
-                        _vm.$set(note, "thenote", $event.target.value)
-                      }
-                    }
-                  })
-                ])
-              ]),
-              _vm._v(" "),
-              _c("div", { attrs: { slot: "footer" }, slot: "footer" }, [
+            }),
+            _vm._v(" "),
+            _c(
+              "div",
+              {
+                staticClass: "col-md-1 d-flex flex-column mx-md-3",
+                class: { "order-last": _vm.userChanged(index) }
+              },
+              [
+                _c("div", { staticClass: "text-center p-0 m-0" }, [
+                  _vm._v(_vm._s(note.noteuser))
+                ]),
+                _vm._v(" "),
                 _c(
-                  "button",
-                  {
-                    staticClass: "btn btn-secondary",
-                    attrs: { type: "button", "data-dismiss": "modal" }
-                  },
-                  [_vm._v("Close")]
+                  "div",
+                  { staticClass: "text-muted text-small text-center p-0 m-0" },
+                  [_vm._v(_vm._s(_vm.getHRDate(note.notetime)))]
                 ),
                 _vm._v(" "),
                 _c(
-                  "button",
-                  {
-                    staticClass: "btn btn-primary",
-                    attrs: { type: "button" },
-                    on: {
-                      click: function($event) {
-                        return _vm.updateNote(note.noteid)
-                      }
-                    }
-                  },
-                  [_vm._v("Save")]
-                )
-              ])
-            ]
-          ),
-          _vm._v(" "),
-          _c(
-            "div",
-            {
-              staticClass: "col-md-1 d-flex flex-column mx-md-3",
-              class: { "order-last": _vm.userChanged(index) }
-            },
-            [
-              _c("div", { staticClass: "text-center p-0 m-0" }, [
-                _vm._v(_vm._s(note.noteuser))
-              ]),
-              _vm._v(" "),
-              _c(
-                "div",
-                { staticClass: "text-muted text-small text-center p-0 m-0" },
-                [_vm._v(_vm._s(_vm.getHRDate(note.notetime)))]
-              ),
-              _vm._v(" "),
-              _c(
-                "div",
-                { staticClass: "btn-group justify-content-center p-0 m-0" },
-                [
-                  _vm.authusername === note.noteuser ||
-                  _vm.authusername === "admin"
-                    ? [
-                        _c(
-                          "button",
-                          {
-                            staticClass: "btn btn-sm btn-primary m-1",
-                            attrs: {
-                              "data-toggle": "modal",
-                              "data-target": "#note" + note.noteid + "editModal"
-                            }
-                          },
-                          [_c("i", { staticClass: "fas fa-fw fa-edit" })]
-                        ),
-                        _vm._v(" "),
-                        _vm._m(0, true),
-                        _vm._v(" "),
-                        _vm._m(1, true)
-                      ]
-                    : _vm._e()
-                ],
-                2
-              )
-            ]
-          ),
-          _vm._v(" "),
-          _c("div", { staticClass: "col-md-10" }, [
-            _c("div", { staticClass: "card m-2" }, [
-              _c("div", { staticClass: "card-body p-2" }, [
-                _vm._v(
-                  "\n                    " +
-                    _vm._s(note.thenote) +
-                    "\n                "
+                  "div",
+                  { staticClass: "btn-group justify-content-center p-0 m-0" },
+                  [
+                    _vm.authusername === note.noteuser ||
+                    _vm.authusername === "admin"
+                      ? [
+                          _c(
+                            "button",
+                            {
+                              staticClass: "btn btn-sm btn-primary m-1",
+                              attrs: {
+                                "data-toggle": "modal",
+                                "data-target":
+                                  "#note" + note.noteid + "editModal"
+                              }
+                            },
+                            [_c("i", { staticClass: "fas fa-fw fa-edit" })]
+                          ),
+                          _vm._v(" "),
+                          _vm._m(0, true),
+                          _vm._v(" "),
+                          _vm._m(1, true)
+                        ]
+                      : _vm._e()
+                  ],
+                  2
                 )
+              ]
+            ),
+            _vm._v(" "),
+            _c("div", { staticClass: "col-md-10" }, [
+              _c("div", { staticClass: "card m-2" }, [
+                _c("div", { staticClass: "card-body p-2" }, [
+                  _vm._v(
+                    "\n                    " +
+                      _vm._s(note.thenote) +
+                      "\n                "
+                  )
+                ])
               ])
             ])
-          ])
-        ],
-        1
-      )
-    }),
-    0
+          ],
+          1
+        )
+      })
+    ],
+    2
   )
 }
 var staticRenderFns = [
@@ -62580,6 +62700,7 @@ Vue.component('errorlist', __webpack_require__(/*! ./components/errorlist.vue */
 Vue.component('credential-form-modal', __webpack_require__(/*! ./components/credential-form-modal.vue */ "./resources/js/components/credential-form-modal.vue")["default"]);
 Vue.component('autocomplete-custom-dropdown', __webpack_require__(/*! ./components/autocomplete-custom-dropdown.vue */ "./resources/js/components/autocomplete-custom-dropdown.vue")["default"]);
 Vue.component('credential-list', __webpack_require__(/*! ./components/credential-list.vue */ "./resources/js/components/credential-list.vue")["default"]);
+Vue.component('note-form-modal', __webpack_require__(/*! ./components/note-form-modal.vue */ "./resources/js/components/note-form-modal.vue")["default"]);
 /**
  * Next, we will create a fresh Vue application instance and attach it to
  * the page. Then, you may begin adding components to this application
@@ -63188,6 +63309,75 @@ __webpack_require__.r(__webpack_exports__);
 
 
 
+/***/ }),
+
+/***/ "./resources/js/components/note-form-modal.vue":
+/*!*****************************************************!*\
+  !*** ./resources/js/components/note-form-modal.vue ***!
+  \*****************************************************/
+/*! exports provided: default */
+/***/ (function(module, __webpack_exports__, __webpack_require__) {
+
+"use strict";
+__webpack_require__.r(__webpack_exports__);
+/* harmony import */ var _note_form_modal_vue_vue_type_template_id_0435c624___WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./note-form-modal.vue?vue&type=template&id=0435c624& */ "./resources/js/components/note-form-modal.vue?vue&type=template&id=0435c624&");
+/* harmony import */ var _note_form_modal_vue_vue_type_script_lang_js___WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./note-form-modal.vue?vue&type=script&lang=js& */ "./resources/js/components/note-form-modal.vue?vue&type=script&lang=js&");
+/* empty/unused harmony star reexport *//* harmony import */ var _node_modules_vue_loader_lib_runtime_componentNormalizer_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../../node_modules/vue-loader/lib/runtime/componentNormalizer.js */ "./node_modules/vue-loader/lib/runtime/componentNormalizer.js");
+
+
+
+
+
+/* normalize component */
+
+var component = Object(_node_modules_vue_loader_lib_runtime_componentNormalizer_js__WEBPACK_IMPORTED_MODULE_2__["default"])(
+  _note_form_modal_vue_vue_type_script_lang_js___WEBPACK_IMPORTED_MODULE_1__["default"],
+  _note_form_modal_vue_vue_type_template_id_0435c624___WEBPACK_IMPORTED_MODULE_0__["render"],
+  _note_form_modal_vue_vue_type_template_id_0435c624___WEBPACK_IMPORTED_MODULE_0__["staticRenderFns"],
+  false,
+  null,
+  null,
+  null
+  
+)
+
+/* hot reload */
+if (false) { var api; }
+component.options.__file = "resources/js/components/note-form-modal.vue"
+/* harmony default export */ __webpack_exports__["default"] = (component.exports);
+
+/***/ }),
+
+/***/ "./resources/js/components/note-form-modal.vue?vue&type=script&lang=js&":
+/*!******************************************************************************!*\
+  !*** ./resources/js/components/note-form-modal.vue?vue&type=script&lang=js& ***!
+  \******************************************************************************/
+/*! exports provided: default */
+/***/ (function(module, __webpack_exports__, __webpack_require__) {
+
+"use strict";
+__webpack_require__.r(__webpack_exports__);
+/* harmony import */ var _node_modules_babel_loader_lib_index_js_ref_4_0_node_modules_vue_loader_lib_index_js_vue_loader_options_note_form_modal_vue_vue_type_script_lang_js___WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! -!../../../node_modules/babel-loader/lib??ref--4-0!../../../node_modules/vue-loader/lib??vue-loader-options!./note-form-modal.vue?vue&type=script&lang=js& */ "./node_modules/babel-loader/lib/index.js?!./node_modules/vue-loader/lib/index.js?!./resources/js/components/note-form-modal.vue?vue&type=script&lang=js&");
+/* empty/unused harmony star reexport */ /* harmony default export */ __webpack_exports__["default"] = (_node_modules_babel_loader_lib_index_js_ref_4_0_node_modules_vue_loader_lib_index_js_vue_loader_options_note_form_modal_vue_vue_type_script_lang_js___WEBPACK_IMPORTED_MODULE_0__["default"]); 
+
+/***/ }),
+
+/***/ "./resources/js/components/note-form-modal.vue?vue&type=template&id=0435c624&":
+/*!************************************************************************************!*\
+  !*** ./resources/js/components/note-form-modal.vue?vue&type=template&id=0435c624& ***!
+  \************************************************************************************/
+/*! exports provided: render, staticRenderFns */
+/***/ (function(module, __webpack_exports__, __webpack_require__) {
+
+"use strict";
+__webpack_require__.r(__webpack_exports__);
+/* harmony import */ var _node_modules_vue_loader_lib_loaders_templateLoader_js_vue_loader_options_node_modules_vue_loader_lib_index_js_vue_loader_options_note_form_modal_vue_vue_type_template_id_0435c624___WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! -!../../../node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!../../../node_modules/vue-loader/lib??vue-loader-options!./note-form-modal.vue?vue&type=template&id=0435c624& */ "./node_modules/vue-loader/lib/loaders/templateLoader.js?!./node_modules/vue-loader/lib/index.js?!./resources/js/components/note-form-modal.vue?vue&type=template&id=0435c624&");
+/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "render", function() { return _node_modules_vue_loader_lib_loaders_templateLoader_js_vue_loader_options_node_modules_vue_loader_lib_index_js_vue_loader_options_note_form_modal_vue_vue_type_template_id_0435c624___WEBPACK_IMPORTED_MODULE_0__["render"]; });
+
+/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "staticRenderFns", function() { return _node_modules_vue_loader_lib_loaders_templateLoader_js_vue_loader_options_node_modules_vue_loader_lib_index_js_vue_loader_options_note_form_modal_vue_vue_type_template_id_0435c624___WEBPACK_IMPORTED_MODULE_0__["staticRenderFns"]; });
+
+
+
 /***/ }),
 
 /***/ "./resources/js/components/notes.vue":

+ 1 - 0
resources/js/app.js

@@ -33,6 +33,7 @@ Vue.component('errorlist', require('./components/errorlist.vue').default);
 Vue.component('credential-form-modal', require('./components/credential-form-modal.vue').default);
 Vue.component('autocomplete-custom-dropdown', require('./components/autocomplete-custom-dropdown.vue').default);
 Vue.component('credential-list', require('./components/credential-list.vue').default);
+Vue.component('note-form-modal', require('./components/note-form-modal.vue').default);
 
 /**
  * Next, we will create a fresh Vue application instance and attach it to

+ 74 - 0
resources/js/components/note-form-modal.vue

@@ -0,0 +1,74 @@
+<template>
+    <modal :id="modalId" tabindex="-1" role="dialog" :aria-labelledby="modalId+'Label'">
+                <h5 slot="header" class="modal-title" :id="modalId+'Label'">
+                    Edit Note
+                </h5>
+                <div slot="body">
+                    <div class="form-group">
+                        <label for="content">Content</label>
+                        <textarea :name="'content'+note.noteid" :id="'content'+note.noteid" class="form-control" v-model="note.thenote"></textarea>
+                    </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="updateNote(note)">Save</button>
+                </div>
+            </modal>
+</template>
+<script>
+export default {
+    props: {
+        populateWith: {
+            type: Object,
+        },
+        modalId: {
+            type: String,
+            require: true
+        },
+        noteType: {
+            type: Number
+        },
+        noteUser: {
+            type: String
+        },
+        woid: {
+            type: Number
+        }
+    },
+    data () {
+        return {
+            note: {}
+        }
+    },
+    mounted () {
+        if(!this.populateWith) {
+            this.note = {
+                thenote: '',
+                notetype: this.noteType,
+                noteuser: this.noteUser,
+                woid: this.woid,
+            }
+        } else {
+            this.note = JSON.parse(JSON.stringify(this.populateWith))
+        }
+    },
+    methods: {
+        updateNote (note) {
+            if (this.populateWith) {
+                axios.put('/api/workorders/notes/' + note.noteid, note)
+                    .then((response) => {
+                        hideModal()
+                    })
+            } else {
+                axios.post('/api/workorders/notes', note)
+                    .then((response) => {
+                        hideModal()
+                    })
+            }
+        },
+        hideModal () {
+            $('#'+this.modalId).modal('hide')
+        }
+    }
+}
+</script>

+ 5 - 17
resources/js/components/notes.vue

@@ -1,21 +1,9 @@
 <template>
     <ul class="list-unstyled">
+        <note-form-modal :modal-id="'note'+noteType+'CreateModal'" :note-type="noteType" :woid="noteWoid" :note-user="authusername"></note-form-modal>
+        <button type="button" data-toggle="modal" :data-target="'#note'+noteType+'CreateModal'" class="btn btn-primary"><i class="fas fa-fw fa-plus"></i> Add New Note</button>
         <li class="row no-gutters mb-2" v-bind:key="note.noteid" v-for="(note, index) in this.notes">
-            <modal :id="'note'+note.noteid+'editModal'" tabindex="-1" role="dialog" :aria-labelledby="'note'+note.noteid+'editModalLabel'">
-                <h5 slot="header" class="modal-title" :id="'note'+note.noteid+'editModalLabel'">
-                    Edit Note
-                </h5>
-                <div slot="body">
-                    <div class="form-group">
-                        <label for="content">Content</label>
-                        <textarea :name="'content'+note.noteid" :id="'content'+note.noteid" class="form-control" v-model="note.thenote"></textarea>
-                    </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="updateNote(note.noteid)">Save</button>
-                </div>
-            </modal>
+            <note-form-modal :modal-id="'note'+note.noteid+'editModal'" :populate-with="note"></note-form-modal>
             <div class="col-md-1 d-flex flex-column mx-md-3" :class="{ 'order-last': userChanged(index) }">
                 <div class="text-center p-0 m-0">{{note.noteuser}}</div>
                 <div class="text-muted text-small text-center p-0 m-0">{{getHRDate(note.notetime)}}</div>
@@ -41,10 +29,11 @@
 import dateMixin from '../mixins/dateMixin'
 export default {
     mixins:[dateMixin],
-    props: ['initialnotes', 'authusername'],
+    props: ['initialnotes', 'authusername', 'noteType', 'woid'],
     data () {
         return {
             notes: Object.values(this.initialnotes),
+            noteWoid: this.woid
         }
     },
     methods: {
@@ -55,7 +44,6 @@ export default {
                 return this.notes[index].noteuser !== this.notes[index-1].noteuser
             }
         }
-        
     }
 }
 </script>

+ 2 - 2
resources/views/workorders/show.blade.php

@@ -81,7 +81,7 @@
             <div class="card">
                 <div class="card-body">
                     <h5 class="card-title">Customer Notes</h5>
-                    <notes :initialnotes="{{$workOrder->notes->where('notetype', '0')}}" authusername="{{Auth::user()->username}}"></notes>
+                    <notes :initialnotes="{{$workOrder->notes->where('notetype', '0')}}" authusername="{{Auth::user()->username}}" :note-type="0" woid="{{$workOrder->woid}}"></notes>
                 </div>
             </div>
         </div>
@@ -91,7 +91,7 @@
             <div class="card">
                 <div class="card-body">
                     <h5 class="card-title">Private/Billing Notes</h5>
-                    <notes :initialnotes="{{$workOrder->notes->where('notetype', '1')}}" authusername="{{Auth::user()->username}}"></notes>
+                    <notes :initialnotes="{{$workOrder->notes->where('notetype', '1')}}" authusername="{{Auth::user()->username}}" :note-type="1" woid="{{$workOrder->woid}}"></notes>
                 </div>
             </div>
         </div>

+ 3 - 0
routes/api.php

@@ -21,6 +21,9 @@ Route::middleware('auth:api')->group( function() {
     Route::get('/workorders/{workOrder}', 'Api\WorkOrdersController@show');
     Route::put('/workorders/{workOrder}', 'Api\WorkOrdersController@update');
 
+    Route::post('/workorders/notes', 'Api\WorkOrderNotesController@store');
+    Route::put('/workorders/notes/{workOrderNote}', 'Api\WorkOrderNotesController@update');
+
     Route::put('/assets/{asset}', 'Api\AssetsController@update');
 
     Route::get('/stores', 'Api\StoresController@index');