Notes.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. import NoteFormModal from '../components/NoteFormModal.vue'
  42. export default {
  43. components: {
  44. NoteFormModal,
  45. },
  46. mixins:[dateMixin],
  47. props: {
  48. notes: {
  49. type: Array,
  50. default: [],
  51. },
  52. authusername: {
  53. type: String,
  54. required: true,
  55. },
  56. noteType: {
  57. type: Number,
  58. required: true,
  59. },
  60. woid: {
  61. type: String,
  62. required: true,
  63. }
  64. },
  65. data () {
  66. return {
  67. newNote: {
  68. notetype: this.noteType,
  69. thenote: '',
  70. noteuser: this.authusername,
  71. woid: this.woid
  72. },
  73. }
  74. },
  75. computed: {
  76. noteOrders () {
  77. return this.getNoteOrders(this.notes)
  78. }
  79. },
  80. methods: {
  81. createNote () {
  82. axios.post('/api/workorders/notes', this.newNote)
  83. .then((response) => {
  84. $('#note'+this.noteType+'add').collapse('hide')
  85. this.newNote.thenote = ''
  86. })
  87. },
  88. getNoteOrders(notes) {
  89. let noteOrders = []
  90. notes.forEach((note,index) =>{
  91. if (index === 0) {
  92. noteOrders[index] = 'order-first'
  93. } else if (note.noteuser !== notes[index-1].noteuser) {
  94. if (noteOrders[index-1] === 'order-first') {
  95. noteOrders[index] = 'order-last'
  96. } else {
  97. noteOrders[index] = 'order-first'
  98. }
  99. } else {
  100. noteOrders[index] = noteOrders[index-1]
  101. }
  102. })
  103. return noteOrders
  104. }
  105. }
  106. }
  107. </script>