Playlists.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <script setup lang="ts">
  2. import { defineAsyncComponent, ref } from "vue";
  3. import { useModalsStore } from "@/stores/modals";
  4. import utils from "@/utils";
  5. const AdvancedTable = defineAsyncComponent(
  6. () => import("@/components/AdvancedTable.vue")
  7. );
  8. const RunJobDropdown = defineAsyncComponent(
  9. () => import("@/components/RunJobDropdown.vue")
  10. );
  11. const columnDefault = ref({
  12. sortable: true,
  13. hidable: true,
  14. defaultVisibility: "shown",
  15. draggable: true,
  16. resizable: true,
  17. minWidth: 150,
  18. maxWidth: 600
  19. });
  20. const columns = ref([
  21. {
  22. name: "options",
  23. displayName: "Options",
  24. properties: ["_id"],
  25. sortable: false,
  26. hidable: false,
  27. resizable: false,
  28. minWidth: 76,
  29. defaultWidth: 76
  30. },
  31. {
  32. name: "displayName",
  33. displayName: "Display Name",
  34. properties: ["displayName"],
  35. sortProperty: "displayName"
  36. },
  37. {
  38. name: "type",
  39. displayName: "Type",
  40. properties: ["type"],
  41. sortProperty: "type"
  42. },
  43. {
  44. name: "privacy",
  45. displayName: "Privacy",
  46. properties: ["privacy"],
  47. sortProperty: "privacy"
  48. },
  49. {
  50. name: "songsCount",
  51. displayName: "Songs #",
  52. properties: ["songsCount"],
  53. sortProperty: "songsCount",
  54. minWidth: 100,
  55. defaultWidth: 100
  56. },
  57. {
  58. name: "totalLength",
  59. displayName: "Total Length",
  60. properties: ["totalLength"],
  61. sortProperty: "totalLength",
  62. minWidth: 250,
  63. defaultWidth: 250
  64. },
  65. {
  66. name: "createdBy",
  67. displayName: "Created By",
  68. properties: ["createdBy"],
  69. sortProperty: "createdBy",
  70. defaultWidth: 150
  71. },
  72. {
  73. name: "createdAt",
  74. displayName: "Created At",
  75. properties: ["createdAt"],
  76. sortProperty: "createdAt",
  77. defaultWidth: 150
  78. },
  79. {
  80. name: "createdFor",
  81. displayName: "Created For",
  82. properties: ["createdFor"],
  83. sortProperty: "createdFor",
  84. minWidth: 230,
  85. defaultWidth: 230
  86. },
  87. {
  88. name: "_id",
  89. displayName: "Playlist ID",
  90. properties: ["_id"],
  91. sortProperty: "_id",
  92. minWidth: 230,
  93. defaultWidth: 230
  94. }
  95. ]);
  96. const filters = ref([
  97. {
  98. name: "_id",
  99. displayName: "Playlist ID",
  100. property: "_id",
  101. filterTypes: ["exact"],
  102. defaultFilterType: "exact"
  103. },
  104. {
  105. name: "displayName",
  106. displayName: "Display Name",
  107. property: "displayName",
  108. filterTypes: ["contains", "exact", "regex"],
  109. defaultFilterType: "contains"
  110. },
  111. {
  112. name: "type",
  113. displayName: "Type",
  114. property: "type",
  115. filterTypes: ["exact"],
  116. defaultFilterType: "exact",
  117. dropdown: [
  118. ["genre", "Genre"],
  119. ["station", "Station"],
  120. ["user", "User"],
  121. ["user-disliked", "User Disliked"],
  122. ["user-liked", "User Liked"]
  123. ]
  124. },
  125. {
  126. name: "privacy",
  127. displayName: "Privacy",
  128. property: "privacy",
  129. filterTypes: ["exact"],
  130. defaultFilterType: "exact",
  131. dropdown: [
  132. ["public", "Public"],
  133. ["private", "Private"]
  134. ]
  135. },
  136. {
  137. name: "songsCount",
  138. displayName: "Songs Count",
  139. property: "songsCount",
  140. filterTypes: [
  141. "numberLesserEqual",
  142. "numberLesser",
  143. "numberGreater",
  144. "numberGreaterEqual",
  145. "numberEquals"
  146. ],
  147. defaultFilterType: "numberLesser"
  148. },
  149. {
  150. name: "totalLength",
  151. displayName: "Total Length",
  152. property: "totalLength",
  153. filterTypes: [
  154. "numberLesserEqual",
  155. "numberLesser",
  156. "numberGreater",
  157. "numberGreaterEqual",
  158. "numberEquals"
  159. ],
  160. defaultFilterType: "numberLesser"
  161. },
  162. {
  163. name: "createdBy",
  164. displayName: "Created By",
  165. property: "createdBy",
  166. filterTypes: ["contains", "exact", "regex"],
  167. defaultFilterType: "contains"
  168. },
  169. {
  170. name: "createdAt",
  171. displayName: "Created At",
  172. property: "createdAt",
  173. filterTypes: ["datetimeBefore", "datetimeAfter"],
  174. defaultFilterType: "datetimeBefore"
  175. },
  176. {
  177. name: "createdFor",
  178. displayName: "Created For",
  179. property: "createdFor",
  180. filterTypes: ["contains", "exact", "regex"],
  181. defaultFilterType: "contains"
  182. }
  183. ]);
  184. const events = ref({
  185. adminRoom: "playlists",
  186. updated: {
  187. event: "admin.playlist.updated",
  188. id: "playlist._id",
  189. item: "playlist"
  190. },
  191. removed: {
  192. event: "admin.playlist.deleted",
  193. id: "playlistId"
  194. }
  195. });
  196. const jobs = ref([
  197. {
  198. name: "Delete orphaned station playlists",
  199. socket: "playlists.deleteOrphanedStationPlaylists"
  200. },
  201. {
  202. name: "Delete orphaned genre playlists",
  203. socket: "playlists.deleteOrphanedGenrePlaylists"
  204. },
  205. {
  206. name: "Request orphaned playlist songs",
  207. socket: "playlists.requestOrphanedPlaylistSongs"
  208. },
  209. {
  210. name: "Clear and refill all station playlists",
  211. socket: "playlists.clearAndRefillAllStationPlaylists"
  212. },
  213. {
  214. name: "Clear and refill all genre playlists",
  215. socket: "playlists.clearAndRefillAllGenrePlaylists"
  216. },
  217. {
  218. name: "Create missing genre playlists",
  219. socket: "playlists.createMissingGenrePlaylists"
  220. }
  221. ]);
  222. const { openModal } = useModalsStore();
  223. const getDateFormatted = createdAt => {
  224. const date = new Date(createdAt);
  225. const year = date.getFullYear();
  226. const month = `${date.getMonth() + 1}`.padStart(2, 0);
  227. const day = `${date.getDate()}`.padStart(2, 0);
  228. const hour = `${date.getHours()}`.padStart(2, 0);
  229. const minute = `${date.getMinutes()}`.padStart(2, 0);
  230. return `${year}-${month}-${day} ${hour}:${minute}`;
  231. };
  232. const formatTimeLong = length => utils.formatTimeLong(length);
  233. </script>
  234. <template>
  235. <div class="admin-tab">
  236. <page-metadata title="Admin | Playlists" />
  237. <div class="card tab-info">
  238. <div class="info-row">
  239. <h1>Playlist</h1>
  240. <p>Manage playlists</p>
  241. </div>
  242. <div class="button-row">
  243. <run-job-dropdown :jobs="jobs" />
  244. </div>
  245. </div>
  246. <advanced-table
  247. :column-default="columnDefault"
  248. :columns="columns"
  249. :filters="filters"
  250. data-action="playlists.getData"
  251. name="admin-playlists"
  252. :events="events"
  253. >
  254. <template #column-options="slotProps">
  255. <div class="row-options">
  256. <button
  257. class="button is-primary icon-with-button material-icons"
  258. @click="
  259. openModal({
  260. modal: 'editPlaylist',
  261. data: { playlistId: slotProps.item._id }
  262. })
  263. "
  264. :disabled="slotProps.item.removed"
  265. content="Edit Playlist"
  266. v-tippy
  267. >
  268. edit
  269. </button>
  270. </div>
  271. </template>
  272. <template #column-displayName="slotProps">
  273. <span :title="slotProps.item.displayName">{{
  274. slotProps.item.displayName
  275. }}</span>
  276. </template>
  277. <template #column-type="slotProps">
  278. <span :title="slotProps.item.type">{{
  279. slotProps.item.type
  280. }}</span>
  281. </template>
  282. <template #column-privacy="slotProps">
  283. <span :title="slotProps.item.privacy">{{
  284. slotProps.item.privacy
  285. }}</span>
  286. </template>
  287. <template #column-songsCount="slotProps">
  288. <span :title="slotProps.item.songsCount">{{
  289. slotProps.item.songsCount
  290. }}</span>
  291. </template>
  292. <template #column-totalLength="slotProps">
  293. <span :title="formatTimeLong(slotProps.item.totalLength)">{{
  294. formatTimeLong(slotProps.item.totalLength)
  295. }}</span>
  296. </template>
  297. <template #column-createdBy="slotProps">
  298. <span v-if="slotProps.item.createdBy === 'Musare'">Musare</span>
  299. <user-link v-else :user-id="slotProps.item.createdBy" />
  300. </template>
  301. <template #column-createdAt="slotProps">
  302. <span :title="new Date(slotProps.item.createdAt)">{{
  303. getDateFormatted(slotProps.item.createdAt)
  304. }}</span>
  305. </template>
  306. <template #column-createdFor="slotProps">
  307. <span :title="slotProps.item.createdFor">{{
  308. slotProps.item.createdFor
  309. }}</span>
  310. </template>
  311. <template #column-_id="slotProps">
  312. <span :title="slotProps.item._id">{{
  313. slotProps.item._id
  314. }}</span>
  315. </template>
  316. </advanced-table>
  317. </div>
  318. </template>