AdminProjectAttendanceSheetShowOfUser.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template>
  2. <breadcrumbs style="margin-top: 29px; margin-bottom: 19px;" />
  3. <div class="flex justify-end">
  4. <q-btn flat
  5. color="grey"
  6. @click="$router.go(-1)">
  7. بازگشت
  8. >
  9. </q-btn>
  10. </div>
  11. <div>
  12. <q-inner-loading :showing="entityLoading"
  13. class="z-top"
  14. label="کمی صبر کنید..." />
  15. <entity-show v-if="mounted"
  16. ref="projectEntityEdit"
  17. v-model:value="inputs"
  18. title="جزییات پروژه"
  19. :api="api"
  20. :show-index-button="false"
  21. :show-close-button="false"
  22. :show-edit-button="false"
  23. :show-expand-button="false"
  24. :show-save-button="false"
  25. :show-reload-button="false"
  26. :after-load-input-data="afterLoadProject">
  27. <template #after-form-builder>
  28. <q-separator class="q-my-lg" />
  29. <entity-create v-if="projectLoaded && project.is_enabled_answering"
  30. ref="entityCreate"
  31. :key="entityCreateKey"
  32. v-model:value="attendanceSheetsInputs"
  33. :api="attendanceSheetsApi"
  34. :default-layout="false" />
  35. <entity-show v-else-if="projectLoaded"
  36. v-model:value="attendanceSheetsShowInputs"
  37. title="پاسخ کاربر"
  38. :loaded-data="currentUserAttendanceSheet"
  39. :default-layout="false"
  40. :show-expand-button="false"
  41. :show-edit-button="false"
  42. :show-index-button="false"
  43. :show-reload-button="false" />
  44. </template>
  45. </entity-show>
  46. </div>
  47. </template>
  48. <script>
  49. import { shallowRef } from 'vue'
  50. import { Project } from 'src/models/Project.js'
  51. import { APIGateway } from 'src/api/APIGateway.js'
  52. import { Classroom } from 'src/models/Classroom.js'
  53. import { EntityShow, EntityCreate } from 'quasar-crud'
  54. import BtnControl from 'src/components/Control/btn.vue'
  55. import { FormBuilderAssist } from 'quasar-form-builder'
  56. import Breadcrumbs from 'src/components/Widgets/Breadcrumbs/Breadcrumbs.vue'
  57. import { ProjectAttendanceSheets } from 'src/models/ProjectAttendanceSheets.js'
  58. import FormBuilderDateTime from 'src/components/FormBuilderCustumComponents/FormBuilderDateTime.vue'
  59. import ContentsSelector from 'src/components/FormBuilderCustumComponents/ContentsSelector/ContentsSelector.vue'
  60. const BtnControlComp = shallowRef(BtnControl)
  61. const ContentsSelectorComp = shallowRef(ContentsSelector)
  62. const FormBuilderDateTimeComp = shallowRef(FormBuilderDateTime)
  63. export default {
  64. name: 'UserPanel.Profile.ClassroomInfo',
  65. components: {
  66. Breadcrumbs,
  67. EntityShow,
  68. EntityCreate
  69. },
  70. data () {
  71. const userId = parseInt(this.$route.params.user_id)
  72. const projectId = parseInt(this.$route.params.project_id)
  73. return {
  74. mounted: false,
  75. entityLoading: false,
  76. entityCreateKey: Date.now(),
  77. projectLoaded: false,
  78. classroomLoaded: false,
  79. project: new Project(),
  80. projectAttendanceSheets: new ProjectAttendanceSheets(),
  81. classroom: new Classroom(),
  82. api: APIGateway.project.APIAdresses.projectAndCurrentUserAttendanceSheetOfUser(projectId, userId),
  83. inputs: [
  84. { type: 'input', name: 'title', responseKey: 'title', label: 'عنوان پروژه', placeholder: ' ', col: 'col-md-6 col-12' },
  85. {
  86. type: 'select',
  87. name: 'type',
  88. responseKey: 'type',
  89. label: 'نوع پروژه',
  90. options: (new Project()).typeEnums,
  91. placeholder: ' ',
  92. col: 'col-md-3 col-12'
  93. },
  94. { type: FormBuilderDateTimeComp, name: 'beginning_doing_period', responseKey: 'beginning_doing_period', outsideLabel: 'زمان شروع', col: 'col-md-6 col-12' },
  95. { type: FormBuilderDateTimeComp, name: 'ending_doing_period', responseKey: 'ending_doing_period', outsideLabel: 'زمان پایان', col: 'col-md-6 col-12' },
  96. { type: 'separator', name: 'space', size: '0', col: 'col-md-12' },
  97. { type: 'inputEditor', name: 'description', responseKey: 'description', label: 'توضیحات پروژه', placeholder: ' ', col: 'col-12' },
  98. { type: ContentsSelectorComp, name: 'contents', responseKey: 'contents_info', showPageLink: false, showDownloadLink: true, col: 'col-12' },
  99. { type: 'hidden', name: 'id', responseKey: 'id' },
  100. { type: 'hidden', name: 'classroom', responseKey: 'classroom' }
  101. ],
  102. attendanceSheetsApi: APIGateway.projectAttendanceSheets.APIAdresses.base,
  103. attendanceSheetsInputs: [
  104. { type: 'separator', name: 'space', label: 'انجام پروژه', className: 'custom-separator', col: 'col-12' },
  105. { type: 'inputEditor', name: 'answer_text', label: 'متن پاسخ', placeholder: ' ', col: 'col-12' },
  106. { type: 'file', name: 'answer_attachment', label: 'فایل ضمیمه', placeholder: ' ', col: 'col-md-4 col-12' },
  107. { type: BtnControlComp, name: 'btn', responseKey: 'btn', label: 'ارسال پروژه', placeholder: ' ', atClick: () => {}, col: 'col-12' },
  108. { type: 'hidden', name: 'project', value: projectId }
  109. ],
  110. attendanceSheetsShowInputs: [
  111. { type: 'separator', name: 'space', label: 'انجام پروژه', className: 'custom-separator', col: 'col-12' },
  112. { type: 'inputEditor', name: 'answer_text', responseKey: 'answer_text', label: 'متن پاسخ', placeholder: ' ', col: 'col-12' },
  113. { type: 'file', name: 'answer_attachment', responseKey: 'answer_attachment', label: 'فایل ضمیمه', placeholder: ' ', col: 'col-md-4 col-12' }
  114. ]
  115. }
  116. },
  117. computed: {
  118. currentUserAttendanceSheet () {
  119. if (!this.projectAttendanceSheets?.project_attendance_sheets || this.projectAttendanceSheets.project_attendance_sheets.length === 0) {
  120. return {}
  121. }
  122. return this.projectAttendanceSheets.project_attendance_sheets[0]
  123. },
  124. projectAndClassroomLoaded () {
  125. return this.projectLoaded && this.classroomLoaded
  126. }
  127. },
  128. watch: {
  129. projectAndClassroomLoaded (newValue) {
  130. if (!newValue) {
  131. return
  132. }
  133. this.$store.commit('AppLayout/updateBreadcrumbs', {
  134. visible: true,
  135. loading: false,
  136. path: [
  137. {
  138. label: 'دوره های من',
  139. to: { name: 'UserPanel.Profile.AllClassrooms' }
  140. },
  141. {
  142. label: this.classroom.title,
  143. to: { name: 'UserPanel.Profile.ClassroomInfo', params: { id: this.classroom.id } }
  144. },
  145. {
  146. label: this.project.title
  147. }
  148. ]
  149. })
  150. }
  151. },
  152. mounted () {
  153. this.mounted = true
  154. this.getClassroomInfo()
  155. FormBuilderAssist.setAttributeByName(this.attendanceSheetsInputs, 'btn', 'atClick', this.createAttendanceSheet)
  156. },
  157. methods: {
  158. createAttendanceSheet () {
  159. const answerText = FormBuilderAssist.getInputsByName(this.attendanceSheetsInputs, 'answer_text').value
  160. if (!answerText) {
  161. this.$q.notify({
  162. type: 'negative',
  163. message: 'متن پاسخ را کامل کنید.',
  164. position: 'top'
  165. })
  166. return
  167. }
  168. this.entityLoading = true
  169. this.$refs.entityCreate.createEntity(false)
  170. .then(() => {
  171. this.entityLoading = false
  172. // this.reloadProject()
  173. this.$router.go(-1)
  174. })
  175. .catch(() => {
  176. this.entityLoading = false
  177. this.entityCreateKey = Date.now()
  178. this.reloadProject()
  179. })
  180. },
  181. getClassroomInfo () {
  182. const classroomId = this.$route.params.classroom_id
  183. this.classroom.loading = true
  184. APIGateway.classroom.get(classroomId)
  185. .then((classroom) => {
  186. this.classroom = new Classroom(classroom)
  187. this.classroom.loading = false
  188. this.classroomLoaded = true
  189. })
  190. .catch(() => {
  191. this.classroom.loading = false
  192. })
  193. },
  194. afterLoadProject (data) {
  195. this.project = new Project(data)
  196. this.projectAttendanceSheets = new ProjectAttendanceSheets(data)
  197. this.setAttendanceSheetsInputsValues()
  198. this.projectLoaded = true
  199. },
  200. setAttendanceSheetsInputsValues () {
  201. const answerAttachment = this.currentUserAttendanceSheet?.answer_attachment // ? this.currentUserAttendanceSheet.answer_attachment : false
  202. FormBuilderAssist.setAttributeByName(this.attendanceSheetsInputs, 'answer_text', 'value', this.currentUserAttendanceSheet?.answer_text)
  203. FormBuilderAssist.setAttributeByName(this.attendanceSheetsInputs, 'answer_attachment', 'value', answerAttachment)
  204. },
  205. reloadProject () {
  206. this.$refs.projectEntityEdit.getData()
  207. }
  208. }
  209. }
  210. </script>