notes.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <ul class="list-unstyled">
  3. <div class="row">
  4. <div class="col-md-2 d-flex justify-content-center justify-content-md-start">
  5. <button type="button" data-toggle="collapse" :data-target="'#note'+noteType+'add'" class="btn btn-primary m-2"><i class="fas fa-fw fa-plus"></i> Add New Note</button>
  6. </div>
  7. <div class="col-md-10">
  8. <div class="collapse" :id="'note'+noteType+'add'">
  9. <div class="d-flex flex-wrap flex-md-nowrap justify-content-center">
  10. <textarea :name="'newnote'+noteType" :id="'newnote'+noteType" class="form-control" v-model="newNote.thenote"></textarea>
  11. <button type="button" class="btn btn-secondary m-2" @click="createNote()">Save</button>
  12. </div>
  13. </div>
  14. </div>
  15. </div>
  16. <li class="row no-gutters mb-2" v-bind:key="index" v-for="(note, index) in this.notes">
  17. <note-form-modal :modal-id="'note'+note.noteid+'editModal'" :populate-with="note"></note-form-modal>
  18. <div class="col-md-1 d-flex flex-column mx-md-3" :class="noteOrders[index]">
  19. <div class="text-center p-0 m-0">{{note.noteuser}}</div>
  20. <div class="text-muted text-small text-center p-0 m-0">{{getHRDate(note.notetime)}}</div>
  21. <div class="btn-group justify-content-center p-0 m-0">
  22. <template v-if="authusername === note.noteuser || authusername === 'admin'">
  23. <button class="btn btn-sm btn-primary m-1" data-toggle="modal" :data-target="'#note'+note.noteid+'editModal'"><i class="fas fa-fw fa-edit"></i></button>
  24. <button class="btn btn-sm btn-danger m-1"><i class="fas fa-fw fa-trash-alt"></i></button>
  25. <button class="btn btn-sm btn-primary m-1"><i class="fa fa-fw fa-random"></i></button>
  26. </template>
  27. </div>
  28. </div>
  29. <div class="col-md-10">
  30. <div class="card m-2">
  31. <div class="card-body p-2">
  32. {{ note.thenote }}
  33. </div>
  34. </div>
  35. </div>
  36. </li>
  37. </ul>
  38. </template>
  39. <script>
  40. import dateMixin from '../mixins/dateMixin'
  41. export default {
  42. mixins:[dateMixin],
  43. props: ['initialnotes', 'authusername', 'noteType', 'woid'],
  44. data () {
  45. return {
  46. notes: this.initialnotes,
  47. newNote: {
  48. notetype: this.noteType,
  49. thenote: '',
  50. noteuser: this.authusername,
  51. woid: this.woid
  52. },
  53. }
  54. },
  55. computed: {
  56. noteOrders () {
  57. return this.getNoteOrders(this.notes)
  58. }
  59. },
  60. mounted () {
  61. Echo.channel('wonotes.'+this.noteType+'.'+this.woid)
  62. .listen('WorkOrderNoteAdded', (e) => {
  63. this.notes.push(e.note)
  64. })
  65. .listen('WorkOrderNoteEdited', (e) => {
  66. let index = this.notes.findIndex((note) => {
  67. return note.noteid === e.note.noteid
  68. })
  69. this.notes[index] = e.note
  70. })
  71. .listen('WorkOrderNoteDeleted', (e) => {
  72. let index = this.notes.findIndex((note) => {
  73. return note.noteid === e.noteid
  74. })
  75. this.notes.splice(index, 1)
  76. })
  77. },
  78. methods: {
  79. createNote () {
  80. axios.post('/api/workorders/notes', this.newNote)
  81. .then((response) => {
  82. $('#note'+this.noteType+'add').collapse('hide')
  83. this.newNote.thenote = ''
  84. })
  85. },
  86. getNoteOrders(notes) {
  87. let noteOrders = []
  88. notes.forEach((note,index) =>{
  89. if (index === 0) {
  90. noteOrders[index] = 'order-first'
  91. } else if (note.noteuser !== notes[index-1].noteuser) {
  92. if (noteOrders[index-1] === 'order-first') {
  93. noteOrders[index] = 'order-last'
  94. } else {
  95. noteOrders[index] = 'order-first'
  96. }
  97. } else {
  98. noteOrders[index] = noteOrders[index-1]
  99. }
  100. })
  101. return noteOrders
  102. }
  103. }
  104. }
  105. </script>