浏览代码

fixed #34

ali 3 年之前
父节点
当前提交
337f9ddea5

+ 35 - 48
src/pages/Admin/Classroom/create.vue

@@ -1,5 +1,7 @@
 <template>
   <div class="AdminClassroomCreate">
+    <q-linear-progress v-if="unitsLoading"
+                       indeterminate />
     <entity-create v-if="mounted"
                    ref="classroomEntityCreate"
                    :key="classroomEntityCreateKey"
@@ -28,7 +30,8 @@
 <script>
 import { EntityCreate } from 'quasar-crud'
 import Enums from 'src/assets/Enums/Enums.js'
-import { APIGateway } from 'src/api/APIGateway'
+import { APIGateway } from 'src/api/APIGateway.js'
+import { FormBuilderAssist } from 'quasar-form-builder'
 
 export default {
   name: 'Admin.Classroom.Create',
@@ -38,6 +41,7 @@ export default {
   data () {
     return {
       mounted: false,
+      unitsLoading: false,
       classroomEntityCreateKey: Date.now(),
       newUnitLoading: false,
       newUnitName: null,
@@ -140,44 +144,47 @@ export default {
   },
   computed: {
     selectedCategoryId () {
-      return this.getInputValue('category')
+      return FormBuilderAssist.getInputsByName(this.inputs, 'category')?.value
     }
   },
   watch: {
     selectedCategoryId () {
-      this.setInputValue('unit', null)
+      FormBuilderAssist.setAttributeByName(this.inputs, 'unit', 'value', null)
+      FormBuilderAssist.setAttributeByName(this.inputs, 'unit', 'options', [])
       this.getUnits(this.selectedCategoryId)
     }
   },
   mounted () {
-    this.mounted = true
     this.preLoadData()
+      .then(() => {
+        this.mounted = true
+      })
+      .catch(() => {
+      })
   },
   methods: {
     setInputAttr (name, attr, value) {
       this.$refs.classroomEntityCreate.setInputAttributeByName(name, attr, value)
     },
     preLoadData () {
-      this.beforeLoadInputData()
-    },
-    beforeLoadInputData () {
-      const promise1 = this.getProfessors()
-      const promise2 = this.getCategories()
-      const promise3 = this.getUnits()
-      this.$nextTick(() => {
-        Promise.all([promise1, promise2, promise3])
-          .then(() => {
-            // this.setInputAttr('category', 'value', responseData.unit_info.category)
-            // this.setInputAttr('unit', 'value', responseData.unit)
-            this.classroomEntityCreateKey = Date.now()
-          })
-          .catch(() => {})
+      return new Promise((resolve, reject) => {
+        const promise1 = this.getProfessors()
+        const promise2 = this.getCategories()
+        this.$nextTick(() => {
+          Promise.all([promise1, promise2])
+            .then(() => {
+              resolve()
+            })
+            .catch(() => {
+              reject()
+            })
+        })
       })
     },
     getProfessors () {
       return APIGateway.user.index({ per_page: 9999, role: 'professor' })
         .then((users) => {
-          this.setInputAttr('professor', 'options', users.list.list.map(item => {
+          FormBuilderAssist.setAttributeByName(this.inputs, 'professor', 'options', users.list.list.map(item => {
             return {
               value: item.id,
               label: this.getUserFullname(item)
@@ -187,9 +194,9 @@ export default {
         .catch(() => {})
     },
     getCategories () {
-      return APIGateway.unitCategory.index({ per_page: 9999, type: 'DISCUSSION_CIRCLE' })
+      return APIGateway.unitCategory.index({ per_page: 9999, type: 'TRAINING' })
         .then((categories) => {
-          this.setInputAttr('category', 'options', categories.list.list.map(item => {
+          FormBuilderAssist.setAttributeByName(this.inputs, 'category', 'options', categories.list.list.map(item => {
             return {
               value: item.id,
               label: item.title
@@ -199,46 +206,26 @@ export default {
         .catch(() => {})
     },
     getUnits (selectedcategoryId = null) {
-      return APIGateway.unit.index({ per_page: 9999, category: selectedcategoryId })
+      this.unitsLoading = true
+      APIGateway.unit.index({ per_page: 9999, category: selectedcategoryId })
         .then((units) => {
-          this.setInputAttr('unit', 'options', units.list.list.map(item => {
+          FormBuilderAssist.setAttributeByName(this.inputs, 'unit', 'options', units.list.list.map(item => {
             return {
               value: item.id,
               label: item.title
             }
           }))
+          this.unitsLoading = false
+        })
+        .catch(() => {
+          this.unitsLoading = false
         })
-        .catch(() => {})
     },
-
     getUserFullname (user) {
       return user.firstname + ' ' + user.lastname
     },
-    getSelectOptions (result, value, label) {
-      return result.map(item => {
-        return {
-          value: item[value],
-          label: item[label]
-        }
-      })
-    },
-    setInputValue (name, value) {
-      const inputIndex = this.inputs.findIndex(input => input.name === name)
-      this.inputs[inputIndex].value = value
-    },
-    loadSelectOptions (name, value, setNewInputData) {
-      const inputIndex = this.inputs.findIndex(input => input.name === name)
-      this.inputs[inputIndex].options = value
-      if (typeof setNewInputData === 'function') {
-        setNewInputData(this.inputs)
-      }
-    },
     createClassroom () {
       this.$refs.classroomEntityCreate.createEntity()
-    },
-    getInputValue (name) {
-      const inputIndex = this.inputs.findIndex(input => input.name === name)
-      return this.inputs[inputIndex].value
     }
   }
 }

+ 44 - 57
src/pages/Admin/DiscussionCirclesClassroom/create.vue

@@ -1,5 +1,7 @@
 <template>
   <div class="AdminClassroomCreate">
+    <q-linear-progress v-if="unitsLoading"
+                       indeterminate />
     <entity-create v-if="mounted"
                    ref="classroomEntityCreate"
                    :key="classroomEntityCreateKey"
@@ -28,16 +30,18 @@
 <script>
 import { EntityCreate } from 'quasar-crud'
 import Enums from 'src/assets/Enums/Enums.js'
-import { APIGateway } from 'src/api/APIGateway'
+import { APIGateway } from 'src/api/APIGateway.js'
+import { FormBuilderAssist } from 'quasar-form-builder'
 
 export default {
-  name: 'Admin.Classroom.Create',
+  name: 'Admin.Classroom.DiscussionCircles.Create',
   components: {
     EntityCreate
   },
   data () {
     return {
       mounted: false,
+      unitsLoading: false,
       classroomEntityCreateKey: Date.now(),
       newUnitLoading: false,
       newUnitName: null,
@@ -47,22 +51,22 @@ export default {
       entityParamKey: 'id',
       showRouteName: 'Admin.Classroom.Show',
       inputs: [
-        { type: 'separator', name: 'space', label: 'مشخصات دوره', className: 'custom-separator', col: 'col-12' },
-        { type: 'file', name: 'thumbnail', responseKey: 'thumbnail', label: 'آپلود عکس دوره', col: 'col-md-3 col-12' },
+        { type: 'separator', name: 'space', label: 'مشخصات حلقه', className: 'custom-separator', col: 'col-12' },
+        { type: 'file', name: 'thumbnail', responseKey: 'thumbnail', label: 'آپلود عکس حلقه', col: 'col-md-3 col-12' },
         { type: 'separator', name: 'space', size: '0', col: 'col-md-12' },
         { type: 'select', name: 'category', responseKey: 'unit_info.category', options: [], value: null, placeholder: ' ', label: 'دسته بندی', col: 'col-md-3 col-12' },
         { type: 'select', name: 'unit', responseKey: 'unit', options: [], value: null, placeholder: ' ', label: 'درس', col: 'col-md-3 col-12' },
         { type: 'select', name: 'holding_type', responseKey: 'holding_type', options: Enums.classroomHoldingTypes, value: null, placeholder: ' ', label: 'نوع برگزاری', col: 'col-md-3 col-12' },
         { type: 'input', name: 'price', responseKey: 'price', placeholder: ' ', label: 'هزینه برگزاری', col: 'col-md-3 col-12' },
-        { type: 'input', name: 'live_streaming_url', responseKey: 'live_streaming_url', placeholder: ' ', label: 'لینک مکان مجازی دوره', col: 'col-12' },
-        { type: 'inputEditor', name: 'classroom_address', responseKey: 'classroom_address', placeholder: ' ', label: 'آدرس مکان فیزیکی دوره', col: 'col-12' },
+        { type: 'input', name: 'live_streaming_url', responseKey: 'live_streaming_url', placeholder: ' ', label: 'لینک مکان مجازی حلقه', col: 'col-12' },
+        { type: 'inputEditor', name: 'classroom_address', responseKey: 'classroom_address', placeholder: ' ', label: 'آدرس مکان فیزیکی حلقه', col: 'col-12' },
         {
           type: 'select',
           name: 'holding_year',
           responseKey: 'holding_year',
           options: [1402, 1403, 1404, 1405, 1406, 1407, 1408, 1409, 1410],
           value: null,
-          label: 'انتخاب سال دوره',
+          label: 'انتخاب سال حلقه',
           placeholder: ' ',
           col: 'col-md-3'
         },
@@ -85,12 +89,12 @@ export default {
             'اسفند'
           ],
           value: null,
-          label: 'انتخاب ماه دوره',
+          label: 'انتخاب ماه حلقه',
           placeholder: ' ',
           col: 'col-md-3'
         },
         { type: 'input', name: 'sessions_frequency', responseKey: 'sessions_frequency', placeholder: ' ', label: 'دوره تناوب', col: 'col-12' },
-        { type: 'select', name: 'professor', responseKey: 'professor', options: [], value: null, placeholder: ' ', label: 'استاد دوره', col: 'col-md-3 col-12' },
+        { type: 'select', name: 'professor', responseKey: 'professor', options: [], value: null, placeholder: ' ', label: 'استاد حلقه', col: 'col-md-3 col-12' },
 
         { type: 'separator', name: 'space', label: 'مشخصات اندیشه جو', className: 'custom-separator', col: 'col-12' },
         { type: 'select', name: 'audience_status_wwwww', responseKey: 'audience_status_wwwww', options: [], placeholder: ' ', label: 'وضعیت(؟)', col: 'col-md-3 col-12' },
@@ -98,7 +102,7 @@ export default {
         { type: 'select', name: 'audience_gender_type', responseKey: 'audience_gender_type', options: Enums.genders, placeholder: ' ', label: 'جنسیت', col: 'col-md-3 col-12' },
         { type: 'select', name: 'audience_bashgah_wwwww', responseKey: 'audience_bashgah_wwwww', options: [], placeholder: ' ', label: 'باشگاه(؟)', col: 'col-md-3 col-12' },
 
-        { type: 'separator', name: 'space', label: 'تنظیمات دوره', className: 'custom-separator', col: 'col-12' },
+        { type: 'separator', name: 'space', label: 'تنظیمات حلقه', className: 'custom-separator', col: 'col-12' },
         { type: 'input', name: 'capacity', responseKey: 'capacity', placeholder: ' ', label: 'ظرفیت گروه درسی', col: 'col-md-3 col-12' },
         { type: 'input', name: 'allowed_absence_count', responseKey: 'allowed_absence_count', placeholder: ' ', label: 'تعداد مجاز غیبت', col: 'col-md-3 col-12' },
         { type: 'input', name: 'effective_absence_coefficient', responseKey: 'effective_absence_coefficient', placeholder: ' ', label: 'ضریب نمره حضور و غیاب', col: 'col-md-3 col-12' },
@@ -127,7 +131,7 @@ export default {
         { type: 'dateTime', name: 'publish_time', responseKey: 'publish_time', placeholder: ' ', label: 'تاریخ انتشار', col: 'col-md-6 col-12' },
 
         { type: 'separator', name: 'space', label: 'قوانین', className: 'custom-separator', col: 'col-12' },
-        { type: 'inputEditor', name: 'rules', responseKey: 'rules', label: 'قوانین دوره آموزشی', col: 'col-12' },
+        { type: 'inputEditor', name: 'rules', responseKey: 'rules', label: 'قوانین حلقه آموزشی', col: 'col-12' },
         // -----------------------------------------------------------------------------------------------------------
 
         { type: 'separator', name: 'space', label: 'موارد زیر در طرح نبودند', className: 'custom-separator', col: 'col-12' },
@@ -140,44 +144,47 @@ export default {
   },
   computed: {
     selectedCategoryId () {
-      return this.getInputValue('category')
+      return FormBuilderAssist.getInputsByName(this.inputs, 'category')?.value
     }
   },
   watch: {
     selectedCategoryId () {
-      this.setInputValue('unit', null)
+      FormBuilderAssist.setAttributeByName(this.inputs, 'unit', 'value', null)
+      FormBuilderAssist.setAttributeByName(this.inputs, 'unit', 'options', [])
       this.getUnits(this.selectedCategoryId)
     }
   },
   mounted () {
-    this.mounted = true
     this.preLoadData()
+      .then(() => {
+        this.mounted = true
+      })
+      .catch(() => {
+      })
   },
   methods: {
     setInputAttr (name, attr, value) {
       this.$refs.classroomEntityCreate.setInputAttributeByName(name, attr, value)
     },
     preLoadData () {
-      this.beforeLoadInputData()
-    },
-    beforeLoadInputData () {
-      const promise1 = this.getProfessors()
-      const promise2 = this.getCategories()
-      const promise3 = this.getUnits()
-      this.$nextTick(() => {
-        Promise.all([promise1, promise2, promise3])
-          .then(() => {
-            // this.setInputAttr('category', 'value', responseData.unit_info.category)
-            // this.setInputAttr('unit', 'value', responseData.unit)
-            this.classroomEntityCreateKey = Date.now()
-          })
-          .catch(() => {})
+      return new Promise((resolve, reject) => {
+        const promise1 = this.getProfessors()
+        const promise2 = this.getCategories()
+        this.$nextTick(() => {
+          Promise.all([promise1, promise2])
+            .then(() => {
+              resolve()
+            })
+            .catch(() => {
+              reject()
+            })
+        })
       })
     },
     getProfessors () {
       return APIGateway.user.index({ per_page: 9999, role: 'professor' })
         .then((users) => {
-          this.setInputAttr('professor', 'options', users.list.list.map(item => {
+          FormBuilderAssist.setAttributeByName(this.inputs, 'professor', 'options', users.list.list.map(item => {
             return {
               value: item.id,
               label: this.getUserFullname(item)
@@ -189,7 +196,7 @@ export default {
     getCategories () {
       return APIGateway.unitCategory.index({ per_page: 9999, type: 'DISCUSSION_CIRCLE' })
         .then((categories) => {
-          this.setInputAttr('category', 'options', categories.list.list.map(item => {
+          FormBuilderAssist.setAttributeByName(this.inputs, 'category', 'options', categories.list.list.map(item => {
             return {
               value: item.id,
               label: item.title
@@ -199,46 +206,26 @@ export default {
         .catch(() => {})
     },
     getUnits (selectedcategoryId = null) {
-      return APIGateway.unit.index({ per_page: 9999, category: selectedcategoryId })
+      this.unitsLoading = true
+      APIGateway.unit.index({ per_page: 9999, category: selectedcategoryId })
         .then((units) => {
-          this.setInputAttr('unit', 'options', units.list.list.map(item => {
+          FormBuilderAssist.setAttributeByName(this.inputs, 'unit', 'options', units.list.list.map(item => {
             return {
               value: item.id,
               label: item.title
             }
           }))
+          this.unitsLoading = false
+        })
+        .catch(() => {
+          this.unitsLoading = false
         })
-        .catch(() => {})
     },
-
     getUserFullname (user) {
       return user.firstname + ' ' + user.lastname
     },
-    getSelectOptions (result, value, label) {
-      return result.map(item => {
-        return {
-          value: item[value],
-          label: item[label]
-        }
-      })
-    },
-    setInputValue (name, value) {
-      const inputIndex = this.inputs.findIndex(input => input.name === name)
-      this.inputs[inputIndex].value = value
-    },
-    loadSelectOptions (name, value, setNewInputData) {
-      const inputIndex = this.inputs.findIndex(input => input.name === name)
-      this.inputs[inputIndex].options = value
-      if (typeof setNewInputData === 'function') {
-        setNewInputData(this.inputs)
-      }
-    },
     createClassroom () {
       this.$refs.classroomEntityCreate.createEntity()
-    },
-    getInputValue (name) {
-      const inputIndex = this.inputs.findIndex(input => input.name === name)
-      return this.inputs[inputIndex].value
     }
   }
 }

+ 1 - 1
src/pages/Admin/DiscussionCirclesClassroom/index.vue

@@ -14,7 +14,7 @@
                 d="M5.665,20C2.276,20,0,17.623,0,14.084V5.916C0,2.377,2.276,0,5.665,0h8.67C17.723,0,20,2.377,20,5.916v8.168C20,17.623,17.723,20,14.333,20ZM1.5,5.916v8.168c0,2.683,1.634,4.416,4.164,4.416h8.669c2.532,0,4.167-1.733,4.167-4.416V5.916c0-2.682-1.635-4.415-4.166-4.415H5.665C3.135,1.5,1.5,3.234,1.5,5.916Zm7.968,8a.747.747,0,0,1-.22-.53V10.741H6.611a.75.75,0,0,1-.75-.75.749.749,0,0,1,.75-.75H9.249V6.6a.75.75,0,1,1,1.5,0V9.241h2.639a.75.75,0,0,1,0,1.5H10.748v2.642a.75.75,0,0,1-1.28.53Z"
                 fill="#fff" />
         </svg>
-        ایجاد دوره آموزشی جدید
+        ایجاد حلقه جدید
       </q-btn>
     </div>
     <entity-index v-if="mounted"