Просмотр исходного кода

تغییر آدرس و مدل های نوتیف در پنل کاربر

HgH 2 лет назад
Родитель
Сommit
07807b6f4a

+ 2 - 0
src/api/APIGateway.js

@@ -8,6 +8,7 @@ import TestAPI from 'src/api/models/Test.js'
 import EventAPI from 'src/api/models/Event.js'
 import MediaAPI from 'src/api/models/Media.js'
 import NoticeAPI from 'src/api/models/Notice.js'
+import NoticeReceiverAPI from 'src/api/models/NoticeReceiver'
 import TicketAPI from 'src/api/models/Ticket.js'
 import WalletAPI from 'src/api/models/Wallet.js'
 import TestSetAPI from 'src/api/models/TestSet.js'
@@ -56,6 +57,7 @@ export const APIGateway = {
   event: new EventAPI(),
   media: new MediaAPI(),
   notice: new NoticeAPI(),
+  noticeReceiver: new NoticeReceiverAPI(),
   ticket: new TicketAPI(),
   wallet: new WalletAPI(),
   testSet: new TestSetAPI(),

+ 85 - 0
src/api/models/NoticeReceiver.js

@@ -0,0 +1,85 @@
+import { appApi } from 'src/boot/axios.js'
+import APIRepository from '../classes/APIRepository.js'
+import { NoticeReceiver, NoticeReceiverList } from 'src/models/NoticeReceiver.js'
+
+export default class NoticeReceiverAPI extends APIRepository {
+  constructor() {
+    super('ticket', appApi)
+    this.APIAdresses = {
+      base: '/mma/notice_receivers',
+      myNotSeenNotificationsCount: '/mma/notice_receivers/my_not_seen_notifications_count',
+      byId: (id) => '/mma/notice_receivers/' + id,
+      readNotification: (id) => '/mma/notice_receivers/' + id + '/read'
+    }
+    this.restUrl = (id) => this.url + '/' + id
+    /* Setting the callback functions for the CRUD operations. */
+    this.setCrudCallbacks({
+      get: (response) => { return new NoticeReceiver(response.data) },
+      post: (response) => { return new NoticeReceiver(response.data) },
+      put: (response) => { return new NoticeReceiver(response.data) },
+      delete: (response) => { return response.data }
+    })
+  }
+
+  index(data) {
+    return this.sendRequest({
+      apiMethod: 'get',
+      api: this.api,
+      request: this.APIAdresses.base,
+      data: this.getNormalizedSendData({
+        page: 1 // Number
+      }, data),
+      resolveCallback: (response) => {
+        const paginate = response.data
+        const results = response.data.results
+        delete paginate.results
+        return {
+          list: new NoticeReceiverList(results),
+          paginate
+          // {
+          //   "count": 1,
+          //   "num_pages": 1,
+          //   "per_page": 10,
+          //   "current": 1,
+          //   "next": null,
+          //   "previous": null,
+          // }
+        }
+      },
+      rejectCallback: (error) => {
+        return error
+      }
+    })
+  }
+
+  myNotSeenNotificationsCount(data) {
+    return this.sendRequest({
+      apiMethod: 'get',
+      api: this.api,
+      request: this.APIAdresses.myNotSeenNotificationsCount,
+      resolveCallback: (response) => {
+        return response.data.count // number
+      },
+      rejectCallback: (error) => {
+        return error
+      }
+    })
+  }
+
+  seen(id) {
+    return this.sendRequest({
+      apiMethod: 'put',
+      api: this.api,
+      request: this.APIAdresses.readNotification(id),
+      data: {
+
+      },
+      resolveCallback: (response) => {
+        return new NoticeReceiver(response.data)
+      },
+      rejectCallback: (error) => {
+        return error
+      }
+    })
+  }
+}

+ 24 - 23
src/components/Widgets/Notice/NoticeList/NoticeList.vue

@@ -55,29 +55,29 @@
           </template>
           <template #entity-index-table-item-cell="{inputData}">
             <div class="entity-index-grid-item"
-                 :class="{'notice--read': getNoticeModel(inputData.props.row).state === 'READ'}">
+                 :class="{'notice--read': getNoticeReceiverModel(inputData.props.row).is_seen === 'true'}">
               <div class="entity-index-grid-item__header">
                 <div class="entity-index-grid-item__header-title">
-                  {{ inputData.props.row.title }}
+                  {{ inputData.props.row.notice_info.title }}
                 </div>
                 <div class="entity-index-grid-item__header-meta">
-                  <div v-if="getNoticeModel(inputData.props.row).state"
+                  <div v-if="getNoticeReceiverModel(inputData.props.row).is_seen"
                        class="entity-index-grid-item__header-state"
-                       :class="getNoticeModel(inputData.props.row).state">
-                    {{ getNoticeModel(inputData.props.row).state_info.label }}
+                       :class="getNoticeReceiverModel(inputData.props.row).is_seen ? 'read': ''">
+                    {{ getNoticeReceiverModel(inputData.props.row).is_seen ? 'خوانده شده': 'خوانده نشده' }}
                   </div>
                   <div class="entity-index-grid-item__header-creation-time">
-                    {{ getNoticeModel(inputData.props.row).shamsiDate('creation_time').dateTime }}
+                    {{ getNoticeReceiverModel(inputData.props.row.notice).shamsiDate('creation_time').dateTime }}
                   </div>
                 </div>
               </div>
               <div class="entity-index-grid-item__content"
-                   v-html="inputData.props.row.body" />
-              <div v-if="getNoticeModel(inputData.props.row).state !== 'READ'"
+                   v-html="inputData.props.row.notice_info.body" />
+              <div v-if="!getNoticeReceiverModel(inputData.props.row).is_seen"
                    class="entity-index-grid-item__action">
                 <q-btn color="primary"
                        outline
-                       @click="updateNoticeToSeen(inputData.props.row.id)">
+                       @click="updateNoticeReceiverToSeen(inputData.props.row.id)">
                   خوانده شود
                 </q-btn>
               </div>
@@ -91,7 +91,7 @@
 
 <script>
 import { EntityIndex } from 'quasar-crud'
-import { Notice } from 'src/models/Notice.js'
+import { NoticeReceiver } from 'src/models/NoticeReceiver.js'
 import { mixinWidget } from 'src/mixin/Mixins.js'
 import { APIGateway } from 'src/api/APIGateway.js'
 import { FormBuilderAssist } from 'quasar-form-builder'
@@ -105,7 +105,7 @@ export default {
     return {
       filterType: 'all',
       myNotSeenNotificationsCount: 0,
-      api: APIGateway.notice.APIAdresses.base,
+      api: APIGateway.noticeReceiver.APIAdresses.base,
       tableKeys: {
         data: 'results',
         total: 'count',
@@ -114,7 +114,7 @@ export default {
         pageKey: 'page'
       },
       inputs: [
-        { type: 'hidden', name: 'state', value: null }
+        { type: 'hidden', name: 'is_seen', value: null }
       ],
       table: {
         columns: [
@@ -123,21 +123,21 @@ export default {
             required: true,
             label: 'موضوع اعلان',
             align: 'left',
-            field: row => row.title
+            field: row => row.notice_info.title
           },
           {
             name: 'sender',
             required: true,
             label: 'فرستنده',
             align: 'left',
-            field: row => row.creator_info ? row.creator_info.firstname + ' ' + row.creator_info.lastname : ''
+            field: row => row.notice_info.creator_info ? row.notice_info.creator_info.firstname + ' ' + row.notice_info.creator_info.lastname : ''
           },
           {
             name: 'status',
             required: true,
             label: 'وضعیت',
             align: 'left',
-            field: row => (new Notice(row)).status_info.label
+            field: row => row.is_seen ? 'خوانده شده' : 'خوانده نشده'
           },
           {
             name: 'action',
@@ -170,17 +170,18 @@ export default {
         ]
       })
     },
-    getNoticeModel (data) {
-      return new Notice(data)
+    getNoticeReceiverModel (data) {
+      return new NoticeReceiver(data)
     },
-    updateNoticeToSeen (noticeId) {
-      APIGateway.notice.seen(noticeId)
+    updateNoticeReceiverToSeen (noticeReceiverId) {
+      APIGateway.noticeReceiver.seen(noticeReceiverId)
         .finally(() => {
+          this.getMyNotSeenNotificationsCount()
           this.$refs.entityIndex.search()
         })
     },
     getMyNotSeenNotificationsCount () {
-      APIGateway.notice.myNotSeenNotificationsCount()
+      APIGateway.noticeReceiver.myNotSeenNotificationsCount()
         .then((count) => {
           this.myNotSeenNotificationsCount = count
         })
@@ -190,17 +191,17 @@ export default {
     },
     setFilterToRead () {
       this.filterType = 'read'
-      FormBuilderAssist.setAttributeByName(this.inputs, 'state', 'value', 'READ')
+      FormBuilderAssist.setAttributeByName(this.inputs, 'is_seen', 'value', 'false')
       this.$refs.entityIndex.search()
     },
     setFilterToNotRead () {
       this.filterType = 'not-read'
-      FormBuilderAssist.setAttributeByName(this.inputs, 'state', 'value', 'NOT-READ')
+      FormBuilderAssist.setAttributeByName(this.inputs, 'is_seen', 'value', 'true')
       this.$refs.entityIndex.search()
     },
     setFilterToAll () {
       this.filterType = 'all'
-      FormBuilderAssist.setAttributeByName(this.inputs, 'state', 'value', null)
+      FormBuilderAssist.setAttributeByName(this.inputs, 'is_seen', 'value', null)
       this.$refs.entityIndex.search()
     }
   }

+ 32 - 0
src/models/NoticeReceiver.js

@@ -0,0 +1,32 @@
+import { User } from 'src/models/User.js'
+import { Notice } from 'src/models/Notice.js'
+import { Collection, Model } from 'js-abstract-model'
+
+class NoticeReceiver extends Model {
+  constructor (data) {
+    super(data, [
+      { key: 'id' },
+      { key: 'notice' },
+      {
+        key: 'notice_info',
+        relatedModel: Notice
+      },
+      { key: 'receiver' },
+      {
+        key: 'receiver_info',
+        relatedModel: User
+      },
+      { key: 'is_seen' },
+      { key: 'creation_time' }
+    ]
+    )
+  }
+}
+
+class NoticeReceiverList extends Collection {
+  model () {
+    return NoticeReceiver
+  }
+}
+
+export { NoticeReceiver, NoticeReceiverList }