AdminClassroomAnswerBookList.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <template>
  2. <div class="AdminClassroomAnswerBookList">
  3. <q-skeleton v-if="!classroom.id"
  4. type="text"
  5. width="200px" />
  6. <breadcrumbs v-else
  7. style="margin-top: 29px; margin-bottom: 19px;" />
  8. <div class="flex justify-end">
  9. <q-btn flat
  10. color="grey"
  11. @click="$router.go(-1)">
  12. بازگشت
  13. >
  14. </q-btn>
  15. </div>
  16. <entity-index v-if="mounted"
  17. ref="entityIndex"
  18. v-model:value="inputs"
  19. :title="'لیست ' + classroomTypeTitle"
  20. :api="api"
  21. :table="table"
  22. :table-keys="tableKeys"
  23. :show-expand-button="false"
  24. :show-reload-button="false"
  25. :show-search-button="false"
  26. @onPageChanged="onPageChanged">
  27. <template v-slot:entity-index-table-cell="{inputData}">
  28. <template v-if="inputData.col.name === 'number'">
  29. {{ inputData.rowNumber }}
  30. </template>
  31. <template v-else-if="inputData.col.name === 'actions'">
  32. <div class="action-column-entity-index">
  33. <q-btn size="md"
  34. color="primary"
  35. :label="inputData.props.row.grader ? 'ویرایش تصحیح' : 'تصحیح آزمون'"
  36. :to="{name: 'Admin.Classroom.Test.AnswerBooks.ShowGrade', params: {classroom_id: $route.params.classroom_id, test_id: $route.params.test_id, answer_book_id: inputData.props.row.id}}"
  37. class="q-mr-md" />
  38. </div>
  39. </template>
  40. <template v-else>
  41. {{ inputData.col.value }}
  42. </template>
  43. </template>
  44. </entity-index>
  45. </div>
  46. </template>
  47. <script>
  48. import { shallowRef } from 'vue'
  49. import { EntityIndex } from 'quasar-crud'
  50. import { Test } from 'src/models/Test.js'
  51. import Enums from 'src/assets/Enums/Enums.js'
  52. import { APIGateway } from 'src/api/APIGateway.js'
  53. import { Classroom } from 'src/models/Classroom.js'
  54. import { AnswerBook } from 'src/models/AnswerBook.js'
  55. // import ShamsiDate from 'src/assets/ShamsiDate.js'
  56. import { FormBuilderAssist } from 'quasar-form-builder'
  57. import BtnControl from 'src/components/Control/btn.vue'
  58. import { UnitCategory } from 'src/models/UnitCategory.js'
  59. import { mixinWidget, mixinAuth } from 'src/mixin/Mixins.js'
  60. import Breadcrumbs from 'src/components/Widgets/Breadcrumbs/Breadcrumbs.vue'
  61. import Assist from 'assets/js/Assist'
  62. const BtnControlComp = shallowRef(BtnControl)
  63. export default {
  64. name: 'AdminClassroomAnswerBookList',
  65. components: {
  66. EntityIndex,
  67. Breadcrumbs
  68. },
  69. mixins: [mixinWidget, mixinAuth],
  70. data () {
  71. return {
  72. mounted: false,
  73. entityLoading: true,
  74. test: new Test(),
  75. classroom: new Classroom(),
  76. defaultOptions: {
  77. classroomType: 'TRAINING'
  78. },
  79. api: APIGateway.answerBook.APIAdresses.base,
  80. inputs: [
  81. {
  82. type: 'select',
  83. name: 'status',
  84. options: [
  85. { label: 'جاری', value: 'CREATED,FETCHED,SUBMITTED' },
  86. { label: 'در حال تصحیح', value: 'GRADING' },
  87. { label: 'تصحیح شده', value: 'GRADED' }
  88. ],
  89. label: 'وضعیت',
  90. placeholder: ' ',
  91. value: null,
  92. col: 'col-md-4 col-12'
  93. },
  94. { type: 'hidden', name: 'test', value: this.$route.params.test_id },
  95. { type: 'hidden', name: 'test__classroom', value: this.$route.params.classroom_id },
  96. { type: BtnControlComp, name: 'btn', label: 'جستجو', placeholder: ' ', atClick: () => {}, col: 'col-md-2 col-12' }
  97. ],
  98. table: {
  99. columns: [
  100. {
  101. name: 'number',
  102. required: true,
  103. label: 'شماره',
  104. align: 'left',
  105. field: () => ''
  106. },
  107. {
  108. name: 'id',
  109. required: true,
  110. label: 'شناسه',
  111. align: 'left',
  112. field: row => row.id
  113. },
  114. {
  115. name: 'owner_info.fullname',
  116. required: true,
  117. label: 'نام و نام خانوادگی',
  118. align: 'left',
  119. field: row => row.owner_info.firstname + ' ' + row.owner_info.lastname
  120. },
  121. {
  122. name: 'owner_info.national_code',
  123. required: true,
  124. label: 'کد ملی',
  125. align: 'left',
  126. field: row => row.owner_info.national_code
  127. },
  128. {
  129. name: 'attending_start_time',
  130. required: true,
  131. label: 'زمان شروع',
  132. align: 'left',
  133. field: row => row.attending_start_time ? this.toShamsi(row.attending_start_time) : '-'
  134. },
  135. {
  136. name: 'attending_start_time',
  137. required: true,
  138. label: 'زمان پایان',
  139. align: 'left',
  140. field: row => row.attending_end_time ? this.toShamsi(row.attending_end_time) : '-'
  141. },
  142. {
  143. name: 'grader_info',
  144. required: true,
  145. label: 'مصحح',
  146. align: 'left',
  147. field: row => row.grader_info ? row.grader_info.firstname + ' ' + row.grader_info.lastname : '-'
  148. },
  149. {
  150. name: 'last_modification_time',
  151. required: true,
  152. label: 'زمان آخرین ویرایش تصحیح',
  153. align: 'left',
  154. field: row => row.last_modification_time ? this.toShamsi(row.last_modification_time) : '-'
  155. },
  156. // {
  157. // name: 'title',
  158. // required: true,
  159. // label: 'عنوان آزمون',
  160. // align: 'left',
  161. // field: row => row.test_info.title
  162. // },
  163. // {
  164. // name: 'test_questions_length',
  165. // required: true,
  166. // label: 'تعداد سوالات',
  167. // align: 'left',
  168. // field: row => row.test_info.test_questions_length
  169. // },
  170. {
  171. name: 'status_info',
  172. required: true,
  173. label: 'وضعیت تصحیح',
  174. align: 'left',
  175. field: row => (new AnswerBook(row)).status_info.label
  176. },
  177. {
  178. name: 'test_info_status_info',
  179. required: true,
  180. label: 'وضعیت آزمون',
  181. align: 'left',
  182. field: row => (new Test(row.test_info)).status_info.label
  183. },
  184. {
  185. name: 'actions',
  186. required: true,
  187. label: 'عملیات',
  188. align: 'left',
  189. field: ''
  190. }
  191. ]
  192. },
  193. tableKeys: {
  194. data: 'results',
  195. total: 'count',
  196. currentPage: 'current',
  197. perPage: 'per_page',
  198. pageKey: 'page'
  199. }
  200. }
  201. },
  202. computed: {
  203. classroomTypeTitle () {
  204. const unitCategory = new UnitCategory({ type: this.localOptions.classroomType })
  205. return unitCategory.type_info.label
  206. },
  207. createPageRouteName () {
  208. if (this.localOptions.classroomType === 'TRAINING') {
  209. return 'Admin.Classroom.Create'
  210. }
  211. if (this.localOptions.classroomType === 'EVENT') {
  212. return 'Admin.Event.Create'
  213. }
  214. return 'Admin.Classroom.Create'
  215. },
  216. showPageRouteName () {
  217. if (this.localOptions.classroomType === 'TRAINING') {
  218. return 'Admin.Classroom.Show'
  219. }
  220. if (this.localOptions.classroomType === 'EVENT') {
  221. return 'Admin.Event.Show'
  222. }
  223. return 'Admin.Classroom.Show'
  224. }
  225. },
  226. mounted () {
  227. this.setActionBtn()
  228. this.setClassroomTypeOfInputs()
  229. this.mounted = true
  230. },
  231. methods: {
  232. toShamsi (miladi) {
  233. return Assist.miladiToShamsi(miladi)
  234. },
  235. onPageChanged () {
  236. if (!this.classroom.id) {
  237. this.getClassroom()
  238. }
  239. },
  240. getClassroom () {
  241. this.classroom.loading = true
  242. APIGateway.classroom.get(this.$route.params.classroom_id)
  243. .then((classroom) => {
  244. this.classroom = new Classroom(classroom)
  245. this.classroom.loading = false
  246. this.updateBreadcrumbs()
  247. })
  248. .catch(() => {
  249. this.classroom.loading = false
  250. })
  251. },
  252. updateBreadcrumbs () {
  253. this.$store.commit('AppLayout/updateBreadcrumbs', {
  254. visible: true,
  255. loading: false,
  256. path: [
  257. {
  258. label: 'لیست ' + this.classroomTypeTitle,
  259. to: { name: this.indexPageRouteName }
  260. },
  261. {
  262. label: this.classroom.title,
  263. to: { name: this.showPageRouteName, params: { id: this.$route.params.classroom_id } }
  264. },
  265. {
  266. label: 'تصحیح آزمون'
  267. },
  268. {
  269. label: 'لیست شرکت کنندگان'
  270. }
  271. ]
  272. })
  273. },
  274. setActionBtn () {
  275. FormBuilderAssist.setAttributeByName(this.inputs, 'btn', 'atClick', this.search)
  276. },
  277. setClassroomTypeOfInputs () {
  278. this.table.columns.forEach(col => {
  279. if (col.name === 'title') {
  280. col.label = 'نام ' + this.classroomTypeTitle
  281. }
  282. if (col.name === 'professor_info') {
  283. col.label = (this.localOptions.classroomType === 'TRAINING') ? 'استاد مربوطه' : 'برگزار کننده'
  284. }
  285. })
  286. },
  287. search () {
  288. this.$refs.entityIndex.search()
  289. },
  290. getSelectOptions (result, value, label) {
  291. return result.map(item => {
  292. return {
  293. value: item[value],
  294. label: item[label]
  295. }
  296. })
  297. },
  298. getRemoveMessage (row) {
  299. return 'آیا از حذف ' + row.title + ' اطمینان دارید؟'
  300. },
  301. getClassroomHoldingTypeTitle (type) {
  302. const target = Enums.classroomHoldingTypes.find(item => item.value === type)
  303. if (!target) {
  304. return '-'
  305. }
  306. return target.label
  307. },
  308. getClassroomStatusesTitle (type) {
  309. const target = Enums.classroomStatuses.find(item => item.value === type)
  310. if (!target) {
  311. return '-'
  312. }
  313. return target.label
  314. }
  315. }
  316. }
  317. </script>
  318. <style lang="scss" scoped>
  319. .AdminClassroomAnswerBookList {
  320. .add-new-action-row {
  321. display: flex;
  322. flex-flow: row;
  323. align-items: center;
  324. justify-content: flex-end;
  325. margin-bottom: 22px;
  326. }
  327. .action-column-entity-index {
  328. display: flex;
  329. align-items: center;
  330. justify-content: flex-start;
  331. }
  332. }
  333. </style>