Playlists.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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.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. console.log("mounted");
  80. io.getSocket(socket => {
  81. this.socket = socket;
  82. if (this.socket.connected) this.init();
  83. io.onConnect(() => this.init());
  84. });
  85. },
  86. methods: {
  87. // edit(playlist) {
  88. // this.editingPlaylistId = playlist._id;
  89. // this.openModal({ sector: "admin", modal: "editPlaylist" });
  90. // },
  91. init() {
  92. this.socket.emit("playlists.index", res => {
  93. console.log(res);
  94. if (res.status === "success") {
  95. this.playlists = res.data;
  96. // if (this.$route.query.userId) {
  97. // const user = this.users.find(
  98. // user => user._id === this.$route.query.userId
  99. // );
  100. // if (user) this.edit(user);
  101. // }
  102. }
  103. });
  104. this.socket.emit("apis.joinAdminRoom", "playlists", () => {});
  105. },
  106. getDateFormatted(createdAt) {
  107. const date = new Date(createdAt);
  108. const year = date.getFullYear();
  109. const month = `${date.getMonth() + 1}`.padStart(2, 0);
  110. const day = `${date.getDate()}`.padStart(2, 0);
  111. const hour = `${date.getHours()}`.padStart(2, 0);
  112. const minute = `${date.getMinutes()}`.padStart(2, 0);
  113. return `${year}-${month}-${day} ${hour}:${minute}`;
  114. },
  115. totalLengthForPlaylist(songs) {
  116. let length = 0;
  117. songs.forEach(song => {
  118. length += song.duration;
  119. });
  120. return this.utils.formatTimeLong(length);
  121. },
  122. ...mapActions("modalVisibility", ["openModal"])
  123. }
  124. };
  125. </script>
  126. <style lang="scss" scoped>
  127. @import "../../../styles/global.scss";
  128. .night-mode {
  129. .table {
  130. color: $night-mode-text;
  131. background-color: $night-mode-bg-secondary;
  132. thead tr {
  133. background: $night-mode-bg-secondary;
  134. td {
  135. color: #fff;
  136. }
  137. }
  138. tbody tr:hover {
  139. background-color: #111 !important;
  140. }
  141. tbody tr:nth-child(even) {
  142. background-color: #444;
  143. }
  144. strong {
  145. color: $night-mode-text;
  146. }
  147. }
  148. }
  149. body {
  150. font-family: "Hind", sans-serif;
  151. }
  152. td {
  153. vertical-align: middle;
  154. }
  155. .is-primary:focus {
  156. background-color: $primary-color !important;
  157. }
  158. </style>