ali 2 gadi atpakaļ
vecāks
revīzija
cfe4b5c788

+ 2 - 0
src/api/APIGateway.js

@@ -12,6 +12,7 @@ import TicketAPI from 'src/api/models/Ticket.js'
 import WalletAPI from 'src/api/models/Wallet.js'
 import BasketAPI from 'src/api/models/Basket.js'
 import HadithAPI from 'src/api/models/Hadith.js'
+import HashtagAPI from 'src/api/models/Hashtag.js'
 import TestSetAPI from 'src/api/models/TestSet.js'
 import InvoiceAPI from 'src/api/models/Invoice.js'
 import PaymentAPI from 'src/api/models/Payment.js'
@@ -70,6 +71,7 @@ export const APIGateway = {
   wallet: new WalletAPI(),
   basket: new BasketAPI(),
   hadith: new HadithAPI(),
+  hashtag: new HashtagAPI(),
   testSet: new TestSetAPI(),
   project: new ProjectAPI(),
   package: new PackageAPI(),

+ 88 - 0
src/api/models/Hashtag.js

@@ -0,0 +1,88 @@
+import { appApi } from 'src/boot/axios.js'
+import APIRepository from '../classes/APIRepository.js'
+import { Hashtag, HashtagList } from 'src/models/Hashtag.js'
+
+export default class HashtagAPI extends APIRepository {
+  constructor() {
+    super('hashtags', appApi)
+    this.APIAdresses = {
+      base: '/cma/hashtags',
+      byId: (id) => '/cma/hashtags/' + id
+    }
+    this.CacheList = {
+      base: this.name + this.APIAdresses.base
+    }
+    this.restUrl = (id) => this.APIAdresses.base + '/' + id
+    /* Setting the callback functions for the CRUD operations. */
+    this.setCrudCallbacks({
+      get: (response) => { return new Hashtag(response.data) },
+      post: (response) => { return new Hashtag(response.data) },
+      put: (response) => { return new Hashtag(response.data) },
+      delete: (response) => { return response.data }
+    })
+  }
+
+  index(data) {
+    return this.sendRequest({
+      apiMethod: 'get',
+      api: this.api,
+      request: this.APIAdresses.base,
+      data: this.getNormalizedSendData({
+        category: null, // Number
+        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 HashtagList(results),
+          paginate
+          // {
+          //   "count": 1,
+          //   "num_pages": 1,
+          //   "per_page": 10,
+          //   "current": 1,
+          //   "next": null,
+          //   "previous": null,
+          // }
+        }
+      },
+      rejectCallback: (error) => {
+        return error
+      }
+    })
+  }
+
+  get (id) {
+    return this.sendRequest({
+      apiMethod: 'get',
+      api: this.api,
+      request: this.APIAdresses.byId(id),
+      resolveCallback: (response) => {
+        return new Hashtag(response.data)
+      },
+      rejectCallback: (error) => {
+        return error
+      }
+    })
+  }
+
+  create (title) {
+    return this.sendRequest({
+      apiMethod: 'post',
+      api: this.api,
+      request: this.APIAdresses.base,
+      data: this.getNormalizedSendData({
+        title: null // String
+      }, { title }),
+      resolveCallback: (response) => {
+        return new Hashtag(response.data)
+      },
+      rejectCallback: (error) => {
+        return error
+      }
+    })
+  }
+}

+ 1 - 1
src/components/FormBuilderCustumComponents/ContentCategorySelector.vue

@@ -54,7 +54,7 @@ export default {
   props: {
     value: {
       default: () => [],
-      type: [Array, String, Number, Boolean]
+      type: [Array, String, Number, Boolean, Object]
     },
     disable: {
       default: false,

+ 23 - 15
src/components/FormBuilderCustumComponents/Hashtags/HashtagSelector.vue

@@ -11,12 +11,10 @@
               label="کلیدواژه"
               :loading="fetchLoading"
               :options="filteredHashtags"
+              @new-value="addHashtag"
               @update:model-value="onChangeSelected"
               @filter="filterFn">
       <template #prepend>
-        <q-btn icon="add"
-               flat
-               @click="addHashtag" />
         <q-icon name="search" />
       </template>
       <template v-slot:no-option>
@@ -64,6 +62,7 @@ export default {
     return {
       selectedHashtags: [],
       filteredHashtags: [],
+      selectInput: null,
       fetchLoading: false
     }
   },
@@ -79,8 +78,15 @@ export default {
     }
   },
   methods: {
-    addHashtag () {
-      // this.fetchLoading = true
+    addHashtag (val, done) {
+      this.fetchLoading = true
+      APIGateway.hashtag.create(val)
+        .then((hashtag) => {
+          done(hashtag)
+        })
+        .finally(() => {
+          this.fetchLoading = false
+        })
     },
     onChangeSelected () {
       this.emitUpdateValue()
@@ -97,24 +103,27 @@ export default {
       })
     },
     filterFn (val, update) {
+      this.selectInput = val
       if (!val) {
         this.filteredHashtags = []
         return
       }
 
-      update(() => {
-        this.fetchLoading = true
-        this.getHashtags(val)
-          .then((hashtagList) => {
+      this.fetchLoading = true
+      this.getHashtags(val)
+        .then((hashtagList) => {
+          update(() => {
             this.filteredHashtags = hashtagList
           })
-          .catch(() => {
+        })
+        .catch(() => {
+          update(() => {
             this.filteredHashtags = []
           })
-          .finally(() => {
-            this.fetchLoading = false
-          })
-      })
+        })
+        .finally(() => {
+          this.fetchLoading = false
+        })
     },
     onDeleteHashtag(hashtagIndex) {
       this.selectedHashtags.splice(hashtagIndex, 1)
@@ -122,7 +131,6 @@ export default {
     },
     emitUpdateValue () {
       const selectedIds = this.selectedHashtags.map(item => item.id)
-      console.log('selectedIds', selectedIds)
       this.$emit('update:value', selectedIds)
     }
   }

+ 18 - 0
src/models/Hashtag.js

@@ -0,0 +1,18 @@
+import { Model, Collection } from 'js-abstract-model'
+
+class Hashtag extends Model {
+  constructor (data) {
+    super(data, [
+      { key: 'id' },
+      { key: 'title' }
+    ])
+  }
+}
+
+class HashtagList extends Collection {
+  model() {
+    return Hashtag
+  }
+}
+
+export { Hashtag, HashtagList }