Browse Source

user panel api

ali 3 years ago
parent
commit
20aa470cf2

+ 2 - 0
src/api/APIGateway.js

@@ -5,6 +5,7 @@ import UnitAPI from 'src/api/models/Unit.js'
 import SessionAPI from 'src/api/models/Session.js'
 import ClassroomAPI from 'src/api/models/Classroom.js'
 import PageSettingAPI from 'src/api/models/PageSetting.js'
+import RegistrationAPI from 'src/api/models/Registration.js'
 import UnitCategoryAPI from 'src/api/models/UnitCategory.js'
 import SessionTemplateAPI from 'src/api/models/SessionTemplate.js'
 import ClassroomRegistrationAPI from 'src/api/models/ClassroomRegistration.js'
@@ -18,6 +19,7 @@ export const APIGateway = {
   session: new SessionAPI(),
   classroom: new ClassroomAPI(),
   pageSetting: new PageSettingAPI(),
+  registration: new RegistrationAPI(),
   unitCategory: new UnitCategoryAPI(),
   sessionTemplate: new SessionTemplateAPI(),
   classroomRegistration: new ClassroomRegistrationAPI()

+ 14 - 0
src/api/models/Classroom.js

@@ -46,4 +46,18 @@ export default class ClassroomAPI extends APIRepository {
       }
     })
   }
+
+  get(id) {
+    return this.sendRequest({
+      apiMethod: 'get',
+      api: this.api,
+      request: this.APIAdresses.byId(id),
+      resolveCallback: (response) => {
+        return new Classroom(response.data)
+      },
+      rejectCallback: (error) => {
+        return error
+      }
+    })
+  }
 }

+ 49 - 0
src/api/models/Registration.js

@@ -0,0 +1,49 @@
+import { appApi } from 'src/boot/axios.js'
+import APIRepository from '../classes/APIRepository.js'
+import { Registration, RegistrationList } from 'src/models/Registration.js'
+
+export default class RegistrationAPI extends APIRepository {
+  constructor() {
+    super('registrations', appApi, '/lma/registrations', Registration)
+    this.APIAdresses = {
+      base: '/lma/registrations',
+      byId: (id) => '/lma/registrations/' + id
+    }
+    this.CacheList = {
+      base: this.name + this.APIAdresses.base,
+      byId: (id) => this.name + this.APIAdresses.byId(id)
+    }
+  }
+
+  index(data) {
+    return this.sendRequest({
+      apiMethod: 'get',
+      api: this.api,
+      request: this.APIAdresses.base,
+      data: this.getNormalizedSendData({
+        per_page: 10, // Number
+        page: 1 // Number
+      }, data),
+      resolveCallback: (response) => {
+        const paginate = response.data
+        const results = response.data.results
+        delete paginate.results
+        return {
+          list: new RegistrationList(results),
+          paginate
+          // {
+          //   "count": 1,
+          //   "num_pages": 1,
+          //   "per_page": 10,
+          //   "current": 1,
+          //   "next": null,
+          //   "previous": null,
+          // }
+        }
+      },
+      rejectCallback: (error) => {
+        return error
+      }
+    })
+  }
+}

+ 7 - 5
src/components/Widgets/Other/ShowClassroomInfo/ShowClassroomInfo.vue

@@ -297,9 +297,10 @@
 
 <script>
 import Enums from 'src/assets/Enums/Enums.js'
-import API_ADDRESS from 'src/api/Addresses.js'
 import ShamsiDate from 'src/assets/ShamsiDate.js'
 import { mixinWidget } from 'src/mixin/Mixins.js'
+import { APIGateway } from 'src/api/APIGateway.js'
+import { Classroom } from 'src/models/Classroom.js'
 
 export default {
   name: 'ShowClassroomInfo',
@@ -319,7 +320,7 @@ export default {
     rulesAccept: false,
     rulesDialog: false,
     loading: true,
-    classroom: null
+    classroom: new Classroom()
   }),
   created () {
     this.getClassrooms()
@@ -360,9 +361,10 @@ export default {
     },
     getClassrooms () {
       this.loading = true
-      this.$axios.get(API_ADDRESS.classroom.base + '/' + this.$route.params.id)
-        .then(response => {
-          this.classroom = response.data
+      APIGateway.classroom.get(this.$route.params.id)
+      // this.$axios.get(API_ADDRESS.classroom.base + '/' + this.$route.params.id)
+        .then(classroom => {
+          this.classroom = new Classroom(classroom)
           this.loading = false
         })
         .catch(() => {

+ 50 - 0
src/models/Registration.js

@@ -0,0 +1,50 @@
+import { User } from 'src/models/User.js'
+import { Classroom } from 'src/models/Classroom.js'
+import { Model, Collection } from 'js-abstract-model'
+
+class Registration extends Model {
+  constructor (data) {
+    super(data, [
+      { key: 'id' },
+      { key: 'owner' },
+      {
+        key: 'owner_info',
+        relatedModel: User
+      },
+      { key: 'classroom' },
+      {
+        key: 'classroom_info',
+        relatedModel: Classroom
+      },
+      { key: 'status' }
+    ])
+
+    this.statusEnums = [
+      {
+        label: 'ثبت نام شده',
+        value: 'REGISTERED'
+      }
+    ]
+
+    this.loadStatusInfo()
+  }
+
+  loadStatusInfo () {
+    const target = this.statusEnums.find(type => type.value === this.status)
+    if (!target) {
+      this.status_info = {
+        label: null,
+        value: null
+      }
+    } else {
+      this.status_info = target
+    }
+  }
+}
+
+class RegistrationList extends Collection {
+  model () {
+    return Registration
+  }
+}
+export { Registration, RegistrationList }

+ 8 - 4
src/pages/User/Profile/classroomInfo.vue

@@ -28,7 +28,8 @@
       </q-tab-panel>
 
       <q-tab-panel name="educations">
-        <entity-index ref="entityIndex"
+        <entity-index v-if="mounted"
+                      ref="entityIndex"
                       v-model:value="inputs"
                       title="لیست جلسات"
                       :api="api"
@@ -69,8 +70,8 @@
 <script>
 import { EntityIndex } from 'quasar-crud'
 import Enums from 'src/assets/Enums/Enums.js'
-import API_ADDRESS from 'src/api/Addresses.js'
 import ShamsiDate from 'src/assets/ShamsiDate.js'
+import { APIGateway } from 'src/api/APIGateway.js'
 import ShowClassroomInfo from 'src/components/Widgets/Other/ShowClassroomInfo/ShowClassroomInfo.vue'
 
 export default {
@@ -81,9 +82,10 @@ export default {
   },
   data () {
     return {
+      mounted: false,
       tab: 'classroomInfo',
       inputs: [],
-      api: API_ADDRESS.classroom.base + '/' + this.$route.params.id,
+      api: null,
       table: {
         columns: [
           {
@@ -144,7 +146,9 @@ export default {
       this.getUnits(this.selectedCategoryId)
     }
   },
-  created () {
+  mounted () {
+    this.api = APIGateway.classroom.APIAdresses.byId(this.$route.params.id)
+    this.mounted = true
   },
   methods: {
     search () {

+ 23 - 22
src/pages/User/Profile/classrooms.vue

@@ -8,18 +8,16 @@
                 :show-expand-button="false"
                 :show-reload-button="false"
                 :show-search-button="false">
-    <template #table-cell="{inputData}">
-      <q-td :props="inputData.props">
-        <template v-if="inputData.props.col.name === 'actions'">
-          <q-btn size="md"
-                 color="primary"
-                 label="جزییات"
-                 :to="{name: 'UserPanel.Profile.ClassroomInfo', params: {id: inputData.props.row.classroom_info.id}}" />
-        </template>
-        <template v-else>
-          {{ inputData.props.value }}
-        </template>
-      </q-td>
+    <template v-slot:entity-index-table-cell="{inputData}">
+      <template v-if="inputData.col.name === 'actions'">
+        <q-btn size="md"
+               color="primary"
+               label="جزییات"
+               :to="{name: 'UserPanel.Profile.ClassroomInfo', params: {id: inputData.props.row.classroom_info.id}}" />
+      </template>
+      <template v-else>
+        {{ inputData.col.value }}
+      </template>
     </template>
   </entity-index>
 </template>
@@ -27,9 +25,9 @@
 <script>
 import { shallowRef } from 'vue'
 import { EntityIndex } from 'quasar-crud'
-import Enums from 'assets/Enums/Enums.js'
-import API_ADDRESS from 'src/api/Addresses.js'
+import Enums from 'src/assets/Enums/Enums.js'
 import ShamsiDate from 'src/assets/ShamsiDate.js'
+import { APIGateway } from 'src/api/APIGateway.js'
 import BtnControl from 'src/components/Control/btn.vue'
 
 const BtnControlComp = shallowRef(BtnControl)
@@ -70,7 +68,7 @@ export default {
         { type: 'input', name: 'search', label: 'جستجو', col: 'col-md-2' },
         { type: BtnControlComp, name: 'btn', responseKey: 'btn', label: 'جستجو', props: { atClick: this.search }, col: 'col-md-2' }
       ],
-      api: API_ADDRESS.registrations.base,
+      api: APIGateway.registration.APIAdresses.base,
       table: {
         columns: [
           {
@@ -209,16 +207,19 @@ export default {
       this.getUnits()
     },
     getCategories () {
-      this.$axios.get(API_ADDRESS.category.base)
-        .then(response => {
-          this.loadSelectOptions('category', this.getSelectOptions(response.data.results, 'id', 'title'))
+      APIGateway.classroom.index({ per_page: 9999 })
+        .then(classroomList => {
+          this.loadSelectOptions('category', this.getSelectOptions(classroomList.list.list, 'id', 'title'))
+        })
+        .catch(() => {
         })
     },
     getUnits (selectedcategoryId) {
-      const param = (selectedcategoryId) ? '?category=' + selectedcategoryId : ''
-      this.$axios.get(API_ADDRESS.unit.base + param)
-        .then(response => {
-          this.loadSelectOptions('unit', this.getSelectOptions(response.data.results, 'id', 'title'))
+      APIGateway.unit.index({ category: selectedcategoryId })
+        .then(unitList => {
+          this.loadSelectOptions('unit', this.getSelectOptions(unitList.list.list, 'id', 'title'))
+        })
+        .catch(() => {
         })
     },
     getInputValue (name) {

+ 7 - 2
src/router/routes.js

@@ -92,10 +92,15 @@ const routes = [
         path: 'panel',
         name: 'UserPanel',
         layoutConfig: {
+          layoutView: 'hHh LpR fFf',
+          layoutHeaderType: 'admin',
+          layoutHeaderBordered: true,
           layoutLeftDrawer: true,
           layoutLeftDrawerVisible: true,
-          layoutHeaderType: 'user-panel',
-          layoutLeftSideBarType: 'user-panel'
+          layoutLeftSideBarType: 'admin',
+          layoutLeftDrawerBordered: true,
+          layoutLeftDrawerWidth: 240,
+          layoutFooter: false
         },
         meta: { middlewares: [Authenticated, canSeeUserProfilePanel] },
         component: () => import('src/layouts/bareLayout.vue'),