SessionList.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <entity-index v-if="mounted"
  3. ref="sessionList"
  4. v-model:value="sessionListInputs"
  5. title="لیست جلسات"
  6. :api="sessionListApi"
  7. :table="sessionListTable"
  8. :table-keys="sessionListTableKeys"
  9. :show-search-button="false"
  10. :show-reload-button="false"
  11. :show-expand-button="false">
  12. <template #toolbar>
  13. <q-btn color="primary"
  14. outline
  15. :loading="addNewSessionLoading"
  16. @click="addNewSession">
  17. افزودن جلسه
  18. </q-btn>
  19. </template>
  20. <template v-slot:entity-index-table-cell="{inputData, showConfirmRemoveDialog}">
  21. <template v-if="inputData.col.name === 'number'">
  22. {{ inputData.rowNumber }}
  23. </template>
  24. <template v-else-if="inputData.col.name === 'actions'">
  25. <div class="action-column-entity-index">
  26. <q-btn size="md"
  27. outline
  28. color="primary"
  29. label="بررسی"
  30. :to="{name: 'Admin.Classroom.Session.AttendanceSheetList', params: {classroom_id: classroomId, session_id: inputData.props.row.id}}"
  31. class="q-mr-md" />
  32. <q-btn size="md"
  33. color="primary"
  34. label="جزییات"
  35. :to="{name: 'Admin.Session.Show', params: {id: inputData.props.row.id}}"
  36. class="q-mr-md" />
  37. <delete-btn @click="showConfirmRemoveDialog(inputData.props.row, 'id', getRemoveMessage(inputData.props.row))" />
  38. </div>
  39. </template>
  40. <template v-else>
  41. {{ inputData.col.value }}
  42. </template>
  43. </template>
  44. </entity-index>
  45. <q-skeleton v-else
  46. type="rect"
  47. height="200px" />
  48. </template>
  49. <script>
  50. import { EntityIndex } from 'quasar-crud'
  51. import ShamsiDate from 'src/assets/ShamsiDate.js'
  52. import { APIGateway } from 'src/api/APIGateway.js'
  53. import DeleteBtn from 'src/components/Control/DeleteBtn.vue'
  54. export default {
  55. name: 'SessionList',
  56. components: {
  57. DeleteBtn,
  58. EntityIndex
  59. },
  60. props: {
  61. classroomId: {
  62. type: Number,
  63. default: null
  64. }
  65. },
  66. data () {
  67. const classroomId = this.classroomId
  68. return {
  69. mounted: false,
  70. addNewSessionLoading: false,
  71. sessionListInputs: [
  72. { type: 'hidden', name: 'classroom', value: classroomId, label: 'نام دوره', col: 'col-12' }
  73. ],
  74. sessionListApi: APIGateway.session.APIAdresses.base,
  75. sessionListTable: {
  76. columns: [
  77. {
  78. name: 'number',
  79. required: true,
  80. label: 'شماره',
  81. align: 'left',
  82. field: () => ''
  83. },
  84. {
  85. name: 'id',
  86. required: true,
  87. label: 'شناسه',
  88. align: 'left',
  89. field: row => row.id
  90. },
  91. {
  92. name: 'title',
  93. required: true,
  94. label: 'عنوان جلسه',
  95. align: 'left',
  96. field: row => row.title
  97. },
  98. {
  99. name: 'creation_time',
  100. required: true,
  101. label: 'زمان شروع جلسه',
  102. align: 'left',
  103. field: row => row.beginning_time ? ShamsiDate.getDateTime(row.beginning_time) : '-'
  104. },
  105. {
  106. name: 'last_modification_time',
  107. required: true,
  108. label: 'زمان پایان جلسه',
  109. align: 'left',
  110. field: row => row.ending_time ? ShamsiDate.getDateTime(row.ending_time) : '-'
  111. },
  112. {
  113. name: 'actions',
  114. required: true,
  115. label: 'عملیات',
  116. align: 'left',
  117. field: ''
  118. }
  119. ]
  120. },
  121. sessionListTableKeys: {
  122. data: 'results',
  123. total: 'count',
  124. currentPage: 'current',
  125. perPage: 'per_page',
  126. pageKey: 'page'
  127. }
  128. }
  129. },
  130. mounted () {
  131. this.mounted = true
  132. },
  133. methods: {
  134. addNewSession () {
  135. this.addNewSessionLoading = true
  136. APIGateway.session.create({
  137. title: '-',
  138. classroom: this.classroomId
  139. })
  140. .then(() => {
  141. this.$refs.sessionList.search()
  142. this.addNewSessionLoading = false
  143. })
  144. .catch(() => {
  145. this.addNewSessionLoading = false
  146. })
  147. },
  148. getRemoveMessage (row) {
  149. return 'آیا از حذف ' + row.title + ' اطمینان دارید؟'
  150. }
  151. }
  152. }
  153. </script>