index.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. :ref="`modal-${hero._id}`"
  34. :showButton="false"
  35. actionTitle="Make Active"
  36. openTitle="Favorite"
  37. title="Make Course Hero">
  38. <div>
  39. <div class="subtitle">
  40. Title: {{hero.title || 'Not Set'}}
  41. </div>
  42. <div class="subtitle">
  43. Subtitle: {{hero.subtitle || 'Not Set'}}
  44. </div>
  45. <figure class="image is-3by1">
  46. <img :src="hero.image">
  47. </figure>
  48. </div>
  49. </Modal>
  50. </portal>
  51. </td>
  52. </tr>
  53. </tbody>
  54. </table>
  55. </div>
  56. </div>
  57. </template>
  58. <script>
  59. import Modal from '~/components/shared/Modal'
  60. export default {
  61. middleware: 'admin',
  62. components: {
  63. Modal
  64. },
  65. computed: {
  66. heroes() {
  67. return this.$store.state.instructor.heroes
  68. },
  69. activeHero() {
  70. return this.$store.state.hero.item
  71. }
  72. },
  73. async fetch({store}) {
  74. await store.dispatch('instructor/fetchHeroes')
  75. },
  76. methods: {
  77. openModal(modalId) {
  78. const modal = this.$refs[`modal-${modalId}`][0]
  79. modal.openModal()
  80. }
  81. }
  82. }
  83. </script>
  84. <style scoped lang="scss">
  85. .heroes-page {
  86. max-width: 1000px;
  87. margin: 0 auto 5rem auto;
  88. margin-top: 40px;
  89. }
  90. .title {
  91. font-size: 45px;
  92. font-weight: bold;
  93. }
  94. .table-row {
  95. margin: 20px;
  96. &.isActive {
  97. background-color: #dfffe1
  98. }
  99. &:hover {
  100. cursor: pointer;
  101. background-color: #e4e4e4;
  102. }
  103. }
  104. </style>