index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <div class="heroes-page">
  3. <div class="container">
  4. <h1 class="title">Course Heroes</h1>
  5. <portal-target
  6. v-for="hero in heroes"
  7. :key="hero._id"
  8. :name="`modal-view-${hero._id}`" />
  9. <table class="heroes-table table is-responsive">
  10. <thead>
  11. <tr class="main-table-row">
  12. <th>Image</th>
  13. <th>Title</th>
  14. <th>Subtitle</th>
  15. <th>Status</th>
  16. </tr>
  17. </thead>
  18. <tbody>
  19. <tr
  20. v-for="hero in heroes"
  21. :key="hero._id"
  22. @click="openModal(hero._id)"
  23. :class="{'isActive': activeHero._id === hero._id}"
  24. class="table-row"
  25. >
  26. <td>{{hero.image || 'Not Set'}}</td>
  27. <td>{{hero.title || 'Not Set'}}</td>
  28. <td>{{hero.subtitle || 'Not Set'}}</td>
  29. <td>{{activeHero._id === hero._id ? 'Active' : 'Inactive'}}</td>
  30. <td class="modal-td" v-show="false">
  31. <portal :to="`modal-view-${hero._id}`">
  32. <Modal
  33. @submitted="activateHero($event, hero._id)"
  34. :ref="`modal-${hero._id}`"
  35. :showButton="false"
  36. actionTitle="Make Active"
  37. openTitle="Favorite"
  38. title="Make Course Hero">
  39. <div>
  40. <div class="subtitle">
  41. Title: {{hero.title || 'Not Set'}}
  42. </div>
  43. <div class="subtitle">
  44. Subtitle: {{hero.subtitle || 'Not Set'}}
  45. </div>
  46. <figure class="image is-3by1">
  47. <img :src="hero.image">
  48. </figure>
  49. </div>
  50. </Modal>
  51. </portal>
  52. </td>
  53. </tr>
  54. </tbody>
  55. </table>
  56. </div>
  57. </div>
  58. </template>
  59. <script>
  60. import Modal from '~/components/shared/Modal'
  61. export default {
  62. middleware: 'admin',
  63. components: {
  64. Modal
  65. },
  66. computed: {
  67. heroes() {
  68. return this.$store.state.instructor.heroes
  69. },
  70. activeHero() {
  71. return this.$store.state.hero.item
  72. }
  73. },
  74. async fetch({store}) {
  75. await store.dispatch('instructor/fetchHeroes')
  76. },
  77. methods: {
  78. openModal(modalId) {
  79. const modal = this.$refs[`modal-${modalId}`][0]
  80. modal.openModal()
  81. },
  82. async activateHero({ closeModal },heroId) {
  83. try{
  84. const result = await this.$store.dispatch('instructor/activateHero', heroId)
  85. this.$toasted.success('Hero was succesfuly activated!', {duration: 2000})
  86. closeModal()
  87. }catch(error){
  88. this.$toasted.success('Hero was activated fail!', {duration: 2000})
  89. }
  90. }
  91. }
  92. }
  93. </script>
  94. <style scoped lang="scss">
  95. .heroes-page {
  96. max-width: 1000px;
  97. margin: 0 auto 5rem auto;
  98. margin-top: 40px;
  99. }
  100. .title {
  101. font-size: 45px;
  102. font-weight: bold;
  103. }
  104. .table-row {
  105. margin: 20px;
  106. &.isActive {
  107. background-color: #dfffe1
  108. }
  109. &:hover {
  110. cursor: pointer;
  111. background-color: #e4e4e4;
  112. }
  113. }
  114. </style>