ali 3 роки тому
батько
коміт
78fac7f9d7

+ 54 - 158
src/components/Widgets/Other/AllClassrooms/AllClassrooms.vue → src/components/Widgets/Classroom/AllClassrooms/AllClassrooms.vue

@@ -80,115 +80,37 @@
     <q-dialog v-model="filterDialog"
               :position="'top'"
               full-width>
-      <q-card class="filter-card all-classroom-widget">
-        <q-card-section class="filter-card-header filter-card-section">
-          <div class="flex justify-between">
-            <q-banner class="banner">
-              فیلتر
-            </q-banner>
-            <q-btn flat
-                   @click="cancelFilter">
-              <svg id="close_black_24dp"
-                   xmlns="http://www.w3.org/2000/svg"
-                   width="32"
-                   height="32"
-                   viewBox="0 0 32 32">
-                <path id="Path_29089"
-                      data-name="Path 29089"
-                      d="M0,0H32V32H0Z"
-                      fill="none" />
-                <path id="Path_29090"
-                      data-name="Path 29090"
-                      d="M22.412,5.806a1.314,1.314,0,0,0-1.86,0L14.1,12.243l-6.45-6.45a1.315,1.315,0,1,0-1.86,1.86l6.45,6.45-6.45,6.45a1.315,1.315,0,0,0,1.86,1.86l6.45-6.45,6.45,6.45a1.315,1.315,0,0,0,1.86-1.86l-6.45-6.45,6.45-6.45A1.322,1.322,0,0,0,22.412,5.806Z"
-                      transform="translate(1.897 1.897)"
-                      fill="#ababab" />
-              </svg>
-            </q-btn>
-          </div>
-        </q-card-section>
-        <q-card-section class="filter-card-filter-section filter-card-section">
-          <div class="row q-col-gutter-md">
-            <div class="col-md-3">
-              <select-control v-model:value="filter.category"
-                              :options="categories.list"
-                              :disable="categories.loading"
-                              :loading="categories.loading"
-                              optionValue="id"
-                              optionLabel="title"
-                              label="گروه آموزشی"
-                              @update:model-value="getUnits" />
-            </div>
-            <div class="col-md-3">
-              <select-control v-model:value="filter.unit"
-                              :options="units.list"
-                              :disable="units.loading"
-                              :loading="units.loading"
-                              optionValue="id"
-                              optionLabel="title"
-                              label="درس" />
-            </div>
-            <div class="col-md-3">
-              <select-control v-model:value="filter.classroomStatus"
-                              :options="classroomStatuses"
-                              optionValue="value"
-                              optionLabel="label"
-                              label="وضعیت دوره" />
-            </div>
-            <div class="col-md-3">
-              <select-control v-model:value="filter.classroomHoldingTypes"
-                              :options="classroomHoldingTypes"
-                              optionValue="value"
-                              optionLabel="label"
-                              label="نوع برگزاری" />
-            </div>
-            <div class="col-md-3">
-              <select-control v-model:value="filter.professor"
-                              :options="professors"
-                              :disable="professorsLoading"
-                              :loading="professorsLoading"
-                              optionValue="value"
-                              optionLabel="label"
-                              label="استاد" />
-            </div>
-          </div>
-        </q-card-section>
-        <q-card-actions class="filter-card-filter-actions filter-card-section">
-          <q-btn color="primary"
-                 outline
-                 label="لغو فیلتر"
-                 @click="cancelFilter" />
-          <q-btn color="primary"
-                 label="فیلتر کردن"
-                 @click="doFilter" />
-        </q-card-actions>
-      </q-card>
+      <filters v-model:filters="filter"
+               :units="units"
+               :professors="professors"
+               :categories="categories"
+               @doFilter="doFilter"
+               @cancelFilter="cancelFilter"
+               @onChangeCategory="onChangeCategory" />
     </q-dialog>
   </div>
 </template>
 
 <script>
-import { User } from 'src/models/User.js'
 import { UnitList } from 'src/models/Unit.js'
-import Enums from 'src/assets/Enums/Enums.js'
-import API_ADDRESS from 'src/api/Addresses.js'
-import ShamsiDate from 'src/assets/ShamsiDate.js'
+import Filters from './components/Filters.vue'
+import { mixinAuth } from 'src/mixin/Mixins.js'
 import { APIGateway } from 'src/api/APIGateway.js'
-import { ClassroomList } from 'src/models/Classroom.js'
+import { Classroom, ClassroomList } from 'src/models/Classroom.js'
 import ClassroomItem from 'src/components/ClassroomItem.vue'
-import SelectControl from 'src/components/Control/Select.vue'
 import { UnitCategoryList } from 'src/models/UnitCategory.js'
 import { ClassroomRegistrationList } from 'src/models/ClassroomRegistration.js'
 
 export default {
   name: 'AllClassrooms',
-  components: { SelectControl, ClassroomItem },
+  components: { ClassroomItem, Filters },
+  mixins: [mixinAuth],
   data: () => ({
     loading: false,
-    user: new User(),
     units: new UnitList(),
     classroomsKey: Date.now(),
-    userRegistrations: new ClassroomRegistrationList(),
     categories: new UnitCategoryList(),
+    userRegistrations: new ClassroomRegistrationList(),
     professors: [],
     professorsLoading: false,
     filter: {
@@ -203,26 +125,32 @@ export default {
   }),
   computed: {
     classroomStatuses () {
-      return Enums.classroomStatuses
+      return (new Classroom()).statusEnums
     },
     classroomHoldingTypes () {
-      return Enums.classroomHoldingTypes
+      return (new Classroom()).holding_typeEnums
     },
     displayTitleFilters () {
       const filters = []
       if (this.filter.category) {
-        filters.push({
-          filterKey: 'category',
-          value: this.filter.category,
-          label: this.categories.list.find(item => item.id === this.filter.category).title
-        })
+        const targetCategory = this.categories.list.find(item => item.id === this.filter.category)
+        if (targetCategory) {
+          filters.push({
+            filterKey: 'category',
+            value: this.filter.category,
+            label: targetCategory.title
+          })
+        }
       }
       if (this.filter.unit) {
-        filters.push({
-          filterKey: 'unit',
-          value: this.filter.unit,
-          label: this.units.list.find(item => item.id === this.filter.unit).title
-        })
+        const targetUnit = this.units.list.find(item => item.id === this.filter.unit)
+        if (targetUnit) {
+          filters.push({
+            filterKey: 'unit',
+            value: this.filter.unit,
+            label: targetUnit.title
+          })
+        }
       }
       if (this.filter.classroomStatus) {
         filters.push({
@@ -239,11 +167,11 @@ export default {
         })
       }
       if (this.filter.professor) {
-        const fullname = this.getUserFullname(this.professors.find(item => item.id === this.filter.professor))
+        const targetProfessor = this.professors.find(item => item.value === this.filter.professor)
         filters.push({
           filterKey: 'professor',
           value: this.filter.professor,
-          label: fullname
+          label: targetProfessor.label
         })
       }
 
@@ -251,18 +179,15 @@ export default {
     }
   },
   mounted () {
-    this.loadAuthData()
     if (this.user && this.user.id !== null) {
       this.getUserRegistrations()
     }
     this.getClassrooms()
     this.getCategories()
     this.getUnits()
+    this.getProfessors()
   },
   methods: {
-    loadAuthData () {
-      this.user = this.$store.getters['Auth/user']
-    },
     getUserRegistrations () {
       this.userRegistrations.loading = true
       APIGateway.classroomRegistration.index()
@@ -278,53 +203,10 @@ export default {
     isClassroomRegistered (classroomId) {
       return !!this.userRegistrations.list.find(item => item.classroom === classroomId && (item.status === 'REGISTERED' || item.status === 'ENROLLED'))
     },
-    getTerm (classroom) {
-      if (!classroom.beginning_registration_period) {
-        return '-'
-      }
-      return ShamsiDate.getTerm(classroom.beginning_registration_period)
-    },
-    getProfessors () {
-      this.$axios.get(API_ADDRESS.user.base + '?per_page=9999&role=professor')
-        .then(response => {
-          this.professors = response.data.results.map(item => {
-            return {
-              value: item.id,
-              label: this.getUserFullname(item)
-            }
-          })
-        })
-    },
-    getUserFullname (user) {
-      return user.firstname + ' ' + user.lastname
-    },
-    getFilters () {
-      let filters = ''
-      if (this.filter.category) {
-        filters += '&category=' + this.filter.category
-      }
-      if (this.filter.unit) {
-        filters += '&unit=' + this.filter.unit
-      }
-      if (this.filter.classroomStatus) {
-        filters += '&classroomStatus=' + this.filter.classroomStatus
-      }
-      if (this.filter.classroomHoldingTypes) {
-        filters += '&holding_type=' + this.filter.classroomHoldingTypes
-      }
-      if (this.filter.professor) {
-        filters += '&professor=' + this.filter.professor
-      }
-
-      // if (filters) {
-      //   filters = filters.slice(1)
-      // }
-
-      return filters
-    },
     getClassrooms () {
       this.classrooms.loading = true
-      APIGateway.classroom.index({ per_page: 9999 })
+      this.filter.per_page = 9999
+      APIGateway.classroom.index(this.filter)
         .then(classroomList => {
           this.classrooms = new ClassroomList(classroomList.list)
           this.classrooms.loading = false
@@ -344,12 +226,22 @@ export default {
           this.categories.loading = false
         })
     },
+    getProfessors () {
+      APIGateway.user.index({ per_page: 9999, role: 'professor' })
+        .then(({ list }) => {
+          this.professors = list.list.map(item => {
+            return {
+              value: item.id,
+              label: this.getUserFullname(item)
+            }
+          })
+        })
+    },
+    getUserFullname (user) {
+      return user.firstname + ' ' + user.lastname
+    },
     getUnits (categoryId) {
       this.units.loading = true
-      // let address = API_ADDRESS.unit.base
-      // if (categoryId) {
-      //   address = API_ADDRESS.unit.base + '?category=' + categoryId
-      // }
       APIGateway.unit.index({ category: categoryId })
         .then(unitList => {
           this.units.loading = false
@@ -359,6 +251,10 @@ export default {
           this.units.loading = false
         })
     },
+    onChangeCategory () {
+      this.filter.unit = null
+      this.getUnits(this.filter.category)
+    },
     openFilterDialog () {
       this.filterDialog = true
     },

+ 0 - 0
src/components/Widgets/Other/AllClassrooms/OptionPanel.vue → src/components/Widgets/Classroom/AllClassrooms/OptionPanel.vue


+ 173 - 0
src/components/Widgets/Classroom/AllClassrooms/components/Filters.vue

@@ -0,0 +1,173 @@
+<template>
+  <q-card class="filter-card all-classroom-widget">
+    <q-card-section class="filter-card-header filter-card-section">
+      <div class="flex justify-between">
+        <q-banner class="banner">
+          فیلتر
+        </q-banner>
+        <q-btn flat
+               @click="cancelFilter">
+          <svg id="close_black_24dp"
+               xmlns="http://www.w3.org/2000/svg"
+               width="32"
+               height="32"
+               viewBox="0 0 32 32">
+            <path id="Path_29089"
+                  data-name="Path 29089"
+                  d="M0,0H32V32H0Z"
+                  fill="none" />
+            <path id="Path_29090"
+                  data-name="Path 29090"
+                  d="M22.412,5.806a1.314,1.314,0,0,0-1.86,0L14.1,12.243l-6.45-6.45a1.315,1.315,0,1,0-1.86,1.86l6.45,6.45-6.45,6.45a1.315,1.315,0,0,0,1.86,1.86l6.45-6.45,6.45,6.45a1.315,1.315,0,0,0,1.86-1.86l-6.45-6.45,6.45-6.45A1.322,1.322,0,0,0,22.412,5.806Z"
+                  transform="translate(1.897 1.897)"
+                  fill="#ababab" />
+          </svg>
+        </q-btn>
+      </div>
+    </q-card-section>
+    <q-card-section class="filter-card-filter-section filter-card-section">
+      <div class="row q-col-gutter-md">
+        <div class="col-md-3">
+          <div>گروه آموزشی</div>
+          <select-control v-model:value="localFilters.category"
+                          :options="categories.list"
+                          :disable="categories.loading"
+                          :loading="categories.loading"
+                          optionValue="id"
+                          optionLabel="title"
+                          @update:model-value="onChangeCategory" />
+        </div>
+        <div class="col-md-3">
+          <div>درس</div>
+          <select-control v-model:value="localFilters.unit"
+                          :options="units.list"
+                          :disable="units.loading"
+                          :loading="units.loading"
+                          optionValue="id"
+                          optionLabel="title" />
+        </div>
+        <div class="col-md-3">
+          <div>وضعیت دوره</div>
+          <select-control v-model:value="localFilters.classroomStatus"
+                          :options="classroomStatuses"
+                          optionValue="value"
+                          optionLabel="label" />
+        </div>
+        <div class="col-md-3">
+          <div>نوع برگزاری</div>
+          <select-control v-model:value="localFilters.classroomHoldingTypes"
+                          :options="classroomHoldingTypes"
+                          optionValue="value"
+                          optionLabel="label" />
+        </div>
+        <div class="col-md-3">
+          <div>استاد</div>
+          <select-control v-model:value="localFilters.professor"
+                          :options="professors"
+                          :disable="professorsLoading"
+                          :loading="professorsLoading"
+                          optionValue="value"
+                          optionLabel="label" />
+        </div>
+      </div>
+    </q-card-section>
+    <q-card-actions class="filter-card-filter-actions filter-card-section">
+      <q-btn color="primary"
+             outline
+             label="لغو فیلتر"
+             @click="cancelFilter" />
+      <q-btn color="primary"
+             label="فیلتر کردن"
+             @click="doFilter" />
+    </q-card-actions>
+  </q-card>
+</template>
+
+<script>
+import Enums from 'assets/Enums/Enums.js'
+import { UnitList } from 'src/models/Unit.js'
+import { mixinAuth } from 'src/mixin/Mixins.js'
+import { UnitCategoryList } from 'src/models/UnitCategory.js'
+import SelectControl from 'src/components/Control/Select.vue'
+
+export default {
+  name: 'Filters',
+  components: { SelectControl },
+  mixins: [mixinAuth],
+  props: {
+    filters: {
+      type: Object,
+      default () {
+        return {
+          category: null,
+          unit: null,
+          classroomStatus: null,
+          classroomHoldingTypes: null,
+          professor: null
+        }
+      }
+    },
+    professors: {
+      type: Array,
+      default: () => []
+    },
+    categories: {
+      type: UnitCategoryList,
+      default: new UnitCategoryList()
+    },
+    units: {
+      type: UnitList,
+      default: new UnitList()
+    }
+  },
+  emits: ['doFilter', 'cancelFilter', 'onChangeCategory', 'update:filters'],
+  data () {
+    return {
+      professorsLoading: false
+    }
+  },
+  computed: {
+    localFilters: {
+      get () {
+        return this.filters
+      },
+      set (neValue) {
+        this.$emit('update:filters', neValue)
+      }
+    },
+    classroomStatuses () {
+      return Enums.classroomStatuses
+    },
+    classroomHoldingTypes () {
+      return Enums.classroomHoldingTypes
+    }
+  },
+  methods: {
+    cancelFilter () {
+      this.$emit('cancelFilter')
+    },
+    doFilter () {
+      this.$emit('doFilter')
+    },
+    onChangeCategory () {
+      this.$emit('onChangeCategory')
+    }
+  }
+}
+</script>
+
+<style scoped lang="scss">
+.filter-card {
+  :deep(.q-field) {
+    &.q-select {
+      .q-field__inner {
+        .q-field__control {
+          .q-field__control-container {
+            padding-top: 6px;
+          }
+        }
+      }
+    }
+  }
+}
+</style>

+ 10 - 3
src/components/Widgets/Registration/RegistrationList/RegistrationList.vue

@@ -5,9 +5,8 @@
       <q-banner class="q-mb-md">
         دوره های شما
       </q-banner>
-      <q-linear-progress v-if="registrations.loading"
-                         indeterminate />
-      <template v-else>
+
+      <template v-if="!registrations.loading && registrations.list.length > 0">
         <div class="row q-col-gutter-md">
           <div v-for="registration in registrations.list"
                :key="registration.id"
@@ -16,6 +15,14 @@
           </div>
         </div>
       </template>
+      <div v-else-if="!registrations.loading && registrations.list.length === 0">
+        دوره ای یافت نشد.
+      </div>
+      <div v-else-if="registrations.loading">
+        <q-linear-progress v-if="registrations.loading"
+                           indeterminate />
+        کمی صبر کنید ...
+      </div>
     </template>
   </div>
 </template>

+ 9 - 8
src/models/Classroom.js

@@ -81,14 +81,15 @@ class Classroom extends Model {
         infoKey: 'status_info',
         enumListKey: 'statusEnums',
         enums: [
-          {
-            label: 'قبل از دوره حذف و اضافه',
-            value: 'BEFORE_DROP_ADD_PERIOD'
-          },
-          {
-            label: 'در دوره حذف و اضافه',
-            value: 'IN_REGISTRATION_PERIOD'
-          }
+          { label: 'منتشر نشده', value: 'NOT_PUBLISHED_YET' },
+          { label: 'قبل از مرحله پیش ثبت نام', value: 'BEFORE_ENROLLMENT_PERIOD' },
+          { label: 'مرحله پیش ثبت نام', value: 'IN_ENROLLMENT_PERIOD' },
+          { label: 'قبل از مرحله ثبت نام', value: 'BEFORE_REGISTRATION_PERIOD' },
+          { label: 'مرحله ثبت نام', value: 'IN_REGISTRATION_PERIOD' },
+          { label: 'قبل از مرحله حذف و اضافه', value: 'BEFORE_DROP_ADD_PERIOD' },
+          { label: 'مرحله حذف و اضافه', value: 'IN_DROP_ADD_PERIOD' },
+          { label: 'جاری', value: 'ONGOING' },
+          { label: 'پایان یافته', value: 'FINISHED' }
         ]
       },
       holding_type: {