Playlists.vue 3.7 KB

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