Media.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { Collection, Model } from 'js-abstract-model'
  2. import { CelebrityList } from 'src/models/Celebrity.js'
  3. import { MediaHashtagList } from 'src/models/MediaHashtag.js'
  4. import { MediaCategory } from 'src/models/MediaCategory.js'
  5. class Media extends Model {
  6. constructor (data) {
  7. super(data, [
  8. { key: 'id' },
  9. { key: 'title' },
  10. { key: 'type' }, // VIDEO - TEXT - SOUND - IMAGE
  11. { key: 'source_type' }, // CONTENT - SETTING
  12. { key: 'url' },
  13. { key: 'iframe_code' },
  14. { key: 'script_code' },
  15. { key: 'is_live_streaming' },
  16. { key: 'category' },
  17. {
  18. key: 'category_info',
  19. relatedModel: MediaCategory
  20. },
  21. { key: 'description' },
  22. {
  23. key: 'celebrities',
  24. relatedModel: CelebrityList
  25. },
  26. { key: 'hashtags' },
  27. {
  28. key: 'hashtags_info',
  29. relatedModel: MediaHashtagList
  30. },
  31. { key: 'file' }
  32. ])
  33. this.typeEnums = [
  34. {
  35. label: 'ویدیو',
  36. value: 'VIDEO'
  37. },
  38. // {
  39. // label: 'متن',
  40. // value: 'TEXT'
  41. // },
  42. {
  43. label: 'صوت',
  44. value: 'SOUND'
  45. },
  46. {
  47. label: 'تصویر',
  48. value: 'IMAGE'
  49. },
  50. {
  51. label: 'سند',
  52. value: 'DOCUMENT'
  53. }
  54. ]
  55. this.loadTypeInfo()
  56. }
  57. loadTypeInfo () {
  58. const target = this.typeEnums.find(type => type.value === this.type)
  59. if (!target) {
  60. this.type_info = null
  61. } else {
  62. this.type_info = target
  63. }
  64. }
  65. }
  66. class MediaList extends Collection {
  67. model () {
  68. return Media
  69. }
  70. getType (type) {
  71. return this.list.filter(item => item.type === type)
  72. }
  73. }
  74. export { Media, MediaList }