notes.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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: {
  44. initialnotes: {
  45. type: Array,
  46. default: [],
  47. },
  48. authusername: {
  49. type: String,
  50. required: true,
  51. },
  52. noteType: {
  53. type: Number,
  54. required: true,
  55. },
  56. woid: {
  57. type: Number,
  58. required: true,
  59. }
  60. },
  61. data () {
  62. return {
  63. notes: this.initialnotes,
  64. newNote: {
  65. notetype: this.noteType,
  66. thenote: '',
  67. noteuser: this.authusername,
  68. woid: this.woid
  69. },
  70. }
  71. },
  72. computed: {
  73. noteOrders () {
  74. return this.getNoteOrders(this.notes)
  75. }
  76. },
  77. mounted () {
  78. Echo.channel('wonotes.'+this.noteType+'.'+this.woid)
  79. .listen('WorkOrderNoteAdded', (e) => {
  80. this.notes.push(e.note)
  81. })
  82. .listen('WorkOrderNoteEdited', (e) => {
  83. let index = this.notes.findIndex((note) => {
  84. return note.noteid === e.note.noteid
  85. })
  86. this.notes[index] = e.note
  87. })
  88. .listen('WorkOrderNoteDeleted', (e) => {
  89. let index = this.notes.findIndex((note) => {
  90. return note.noteid === e.noteid
  91. })
  92. this.notes.splice(index, 1)
  93. })
  94. },
  95. methods: {
  96. createNote () {
  97. axios.post('/api/workorders/notes', this.newNote)
  98. .then((response) => {
  99. $('#note'+this.noteType+'add').collapse('hide')
  100. this.newNote.thenote = ''
  101. })
  102. },
  103. getNoteOrders(notes) {
  104. let noteOrders = []
  105. notes.forEach((note,index) =>{
  106. if (index === 0) {
  107. noteOrders[index] = 'order-first'
  108. } else if (note.noteuser !== notes[index-1].noteuser) {
  109. if (noteOrders[index-1] === 'order-first') {
  110. noteOrders[index] = 'order-last'
  111. } else {
  112. noteOrders[index] = 'order-first'
  113. }
  114. } else {
  115. noteOrders[index] = noteOrders[index-1]
  116. }
  117. })
  118. return noteOrders
  119. }
  120. }
  121. }
  122. </script>