Playlists.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <div>
  3. <metadata title="Admin | Playlists" />
  4. <div class="container">
  5. <table class="table is-striped">
  6. <thead>
  7. <tr>
  8. <td>Display name</td>
  9. <td>Type</td>
  10. <td>Is user modifiable</td>
  11. <td>Songs #</td>
  12. <td>Playlist length</td>
  13. <td>Created by</td>
  14. <td>Created at</td>
  15. <td>Created for</td>
  16. <td>Playlist id</td>
  17. <!-- <td>Options</td> -->
  18. </tr>
  19. </thead>
  20. <tbody>
  21. <tr v-for="playlist in playlists" :key="playlist._id">
  22. <td>{{ playlist.displayName }}</td>
  23. <td>{{ playlist.type }}</td>
  24. <td>{{ playlist.isUserModifiable }}</td>
  25. <td>{{ playlist.songs.length }}</td>
  26. <td>{{ totalLengthForPlaylist(playlist.songs) }}</td>
  27. <td v-if="playlist.createdBy === 'Musare'">Musare</td>
  28. <td v-else>
  29. <user-id-to-username
  30. :user-id="playlist.createdBy"
  31. :link="true"
  32. />
  33. </td>
  34. <td :title="new Date(playlist.createdAt)">
  35. {{ getDateFormatted(playlist.createdAt) }}
  36. </td>
  37. <td>{{ playlist.createdFor }}</td>
  38. <td>{{ playlist._id }}</td>
  39. <!-- <td>
  40. <button
  41. class="button is-primary"
  42. @click="edit(playlist)"
  43. >
  44. Edit
  45. </button>
  46. </td> -->
  47. </tr>
  48. </tbody>
  49. </table>
  50. </div>
  51. <!-- <edit-playlist
  52. v-if="modals.editPlaylist"
  53. :user-id="editingPlaylistId"
  54. sector="admin"
  55. /> -->
  56. </div>
  57. </template>
  58. <script>
  59. import { mapState, mapActions } from "vuex";
  60. // import EditPlaylist from "../../../components/modals/EditPlaylist/index.vue";
  61. import UserIdToUsername from "../../../components/common/UserIdToUsername.vue";
  62. import io from "../../../io";
  63. import utils from "../../../../js/utils";
  64. export default {
  65. components: { /* EditPlaylist, */ UserIdToUsername },
  66. data() {
  67. return {
  68. utils,
  69. // editingPlaylistId: "",
  70. playlists: []
  71. };
  72. },
  73. computed: {
  74. ...mapState("modalVisibility", {
  75. modals: state => state.modals.admin
  76. })
  77. },
  78. mounted() {
  79. io.getSocket(socket => {
  80. this.socket = socket;
  81. if (this.socket.readyState === 1) this.init();
  82. io.onConnect(() => this.init());
  83. });
  84. },
  85. methods: {
  86. // edit(playlist) {
  87. // this.editingPlaylistId = playlist._id;
  88. // this.openModal({ sector: "admin", modal: "editPlaylist" });
  89. // },
  90. init() {
  91. this.socket.dispatch("playlists.index", res => {
  92. console.log(res);
  93. if (res.status === "success") {
  94. this.playlists = res.data;
  95. // if (this.$route.query.userId) {
  96. // const user = this.users.find(
  97. // user => user._id === this.$route.query.userId
  98. // );
  99. // if (user) this.edit(user);
  100. // }
  101. }
  102. });
  103. this.socket.dispatch("apis.joinAdminRoom", "playlists", () => {});
  104. },
  105. getDateFormatted(createdAt) {
  106. const date = new Date(createdAt);
  107. const year = date.getFullYear();
  108. const month = `${date.getMonth() + 1}`.padStart(2, 0);
  109. const day = `${date.getDate()}`.padStart(2, 0);
  110. const hour = `${date.getHours()}`.padStart(2, 0);
  111. const minute = `${date.getMinutes()}`.padStart(2, 0);
  112. return `${year}-${month}-${day} ${hour}:${minute}`;
  113. },
  114. totalLengthForPlaylist(songs) {
  115. let length = 0;
  116. songs.forEach(song => {
  117. length += song.duration;
  118. });
  119. return this.utils.formatTimeLong(length);
  120. },
  121. ...mapActions("modalVisibility", ["openModal"])
  122. }
  123. };
  124. </script>
  125. <style lang="scss" scoped>
  126. .night-mode {
  127. .table {
  128. color: var(--light-grey-2);
  129. background-color: var(--dark-grey-3);
  130. thead tr {
  131. background: var(--dark-grey-3);
  132. td {
  133. color: var(--white);
  134. }
  135. }
  136. tbody tr:hover {
  137. background-color: var(--dark-grey-4) !important;
  138. }
  139. tbody tr:nth-child(even) {
  140. background-color: var(--dark-grey-2);
  141. }
  142. strong {
  143. color: var(--light-grey-2);
  144. }
  145. }
  146. }
  147. body {
  148. font-family: "Hind", sans-serif;
  149. }
  150. td {
  151. vertical-align: middle;
  152. }
  153. .is-primary:focus {
  154. background-color: var(--primary-color) !important;
  155. }
  156. </style>