Playlists.vue 7.7 KB

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