Playlists.vue 8.1 KB

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