Stations.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. <script setup lang="ts">
  2. import { defineAsyncComponent, ref } from "vue";
  3. import Toast from "toasters";
  4. import { useWebsocketsStore } from "@/stores/websockets";
  5. import { useModalsStore } from "@/stores/modals";
  6. import { useUserAuthStore } from "@/stores/userAuth";
  7. import { TableColumn, TableFilter } from "@/types/advancedTable";
  8. const AdvancedTable = defineAsyncComponent(
  9. () => import("@/components/AdvancedTable.vue")
  10. );
  11. const RunJobDropdown = defineAsyncComponent(
  12. () => import("@/components/RunJobDropdown.vue")
  13. );
  14. const QuickConfirm = defineAsyncComponent(
  15. () => import("@/components/QuickConfirm.vue")
  16. );
  17. const UserLink = defineAsyncComponent(
  18. () => import("@/components/UserLink.vue")
  19. );
  20. const { socket } = useWebsocketsStore();
  21. const { hasPermission } = useUserAuthStore();
  22. const columnDefault = ref<TableColumn>({
  23. sortable: true,
  24. hidable: true,
  25. defaultVisibility: "shown",
  26. draggable: true,
  27. resizable: true,
  28. minWidth: 150,
  29. maxWidth: 600
  30. });
  31. const columns = ref<TableColumn[]>([
  32. {
  33. name: "options",
  34. displayName: "Options",
  35. properties: ["_id", "name"],
  36. sortable: false,
  37. hidable: false,
  38. resizable: false,
  39. minWidth: hasPermission("stations.remove") ? 129 : 85,
  40. defaultWidth: hasPermission("stations.remove") ? 129 : 85
  41. },
  42. {
  43. name: "_id",
  44. displayName: "Station ID",
  45. properties: ["_id"],
  46. sortProperty: "_id",
  47. minWidth: 230,
  48. defaultWidth: 230
  49. },
  50. {
  51. name: "name",
  52. displayName: "Name",
  53. properties: ["name"],
  54. sortProperty: "name"
  55. },
  56. {
  57. name: "displayName",
  58. displayName: "Display Name",
  59. properties: ["displayName"],
  60. sortProperty: "displayName"
  61. },
  62. {
  63. name: "description",
  64. displayName: "Description",
  65. properties: ["description"],
  66. sortProperty: "description",
  67. defaultVisibility: "hidden"
  68. },
  69. {
  70. name: "type",
  71. displayName: "Type",
  72. properties: ["type"],
  73. sortProperty: "type"
  74. },
  75. {
  76. name: "privacy",
  77. displayName: "Privacy",
  78. properties: ["privacy"],
  79. sortProperty: "privacy"
  80. },
  81. {
  82. name: "owner",
  83. displayName: "Owner",
  84. properties: ["owner", "type"],
  85. sortProperty: "owner",
  86. defaultWidth: 150
  87. },
  88. {
  89. name: "theme",
  90. displayName: "Theme",
  91. properties: ["theme"],
  92. sortProperty: "theme",
  93. defaultVisibility: "hidden"
  94. },
  95. {
  96. name: "requestsEnabled",
  97. displayName: "Requests Enabled",
  98. properties: ["requests.enabled"],
  99. sortProperty: "requests.enabled",
  100. minWidth: 180,
  101. defaultWidth: 180,
  102. defaultVisibility: "hidden"
  103. },
  104. {
  105. name: "requestsAccess",
  106. displayName: "Requests Access",
  107. properties: ["requests.access"],
  108. sortProperty: "requests.access",
  109. minWidth: 180,
  110. defaultWidth: 180,
  111. defaultVisibility: "hidden"
  112. },
  113. {
  114. name: "requestsLimit",
  115. displayName: "Requests Limit",
  116. properties: ["requests.limit"],
  117. sortProperty: "requests.limit",
  118. minWidth: 180,
  119. defaultWidth: 180,
  120. defaultVisibility: "hidden"
  121. },
  122. {
  123. name: "autofillEnabled",
  124. displayName: "Autofill Enabled",
  125. properties: ["autofill.enabled"],
  126. sortProperty: "autofill.enabled",
  127. minWidth: 180,
  128. defaultWidth: 180,
  129. defaultVisibility: "hidden"
  130. },
  131. {
  132. name: "autofillLimit",
  133. displayName: "Autofill Limit",
  134. properties: ["autofill.limit"],
  135. sortProperty: "autofill.limit",
  136. minWidth: 180,
  137. defaultWidth: 180,
  138. defaultVisibility: "hidden"
  139. },
  140. {
  141. name: "autofillMode",
  142. displayName: "Autofill Mode",
  143. properties: ["autofill.mode"],
  144. sortProperty: "autofill.mode",
  145. minWidth: 180,
  146. defaultWidth: 180,
  147. defaultVisibility: "hidden"
  148. }
  149. ]);
  150. const filters = ref<TableFilter[]>([
  151. {
  152. name: "_id",
  153. displayName: "Station ID",
  154. property: "_id",
  155. filterTypes: ["exact"],
  156. defaultFilterType: "exact"
  157. },
  158. {
  159. name: "name",
  160. displayName: "Name",
  161. property: "name",
  162. filterTypes: ["contains", "exact", "regex"],
  163. defaultFilterType: "contains"
  164. },
  165. {
  166. name: "displayName",
  167. displayName: "Display Name",
  168. property: "displayName",
  169. filterTypes: ["contains", "exact", "regex"],
  170. defaultFilterType: "contains"
  171. },
  172. {
  173. name: "description",
  174. displayName: "Description",
  175. property: "description",
  176. filterTypes: ["contains", "exact", "regex"],
  177. defaultFilterType: "contains"
  178. },
  179. {
  180. name: "type",
  181. displayName: "Type",
  182. property: "type",
  183. filterTypes: ["exact"],
  184. defaultFilterType: "exact",
  185. dropdown: [
  186. ["official", "Official"],
  187. ["community", "Community"]
  188. ]
  189. },
  190. {
  191. name: "privacy",
  192. displayName: "Privacy",
  193. property: "privacy",
  194. filterTypes: ["exact"],
  195. defaultFilterType: "exact",
  196. dropdown: [
  197. ["public", "Public"],
  198. ["unlisted", "Unlisted"],
  199. ["private", "Private"]
  200. ]
  201. },
  202. {
  203. name: "owner",
  204. displayName: "Owner",
  205. property: "owner",
  206. filterTypes: ["contains", "exact", "regex"],
  207. defaultFilterType: "contains"
  208. },
  209. {
  210. name: "theme",
  211. displayName: "Theme",
  212. property: "theme",
  213. filterTypes: ["exact"],
  214. defaultFilterType: "exact",
  215. dropdown: [
  216. ["blue", "Blue"],
  217. ["purple", "Purple"],
  218. ["teal", "Teal"],
  219. ["orange", "Orange"],
  220. ["red", "Red"]
  221. ]
  222. },
  223. {
  224. name: "requestsEnabled",
  225. displayName: "Requests Enabled",
  226. property: "requests.enabled",
  227. filterTypes: ["boolean"],
  228. defaultFilterType: "boolean"
  229. },
  230. {
  231. name: "requestsAccess",
  232. displayName: "Requests Access",
  233. property: "requests.access",
  234. filterTypes: ["exact"],
  235. defaultFilterType: "exact",
  236. dropdown: [
  237. ["owner", "Owner"],
  238. ["user", "User"]
  239. ]
  240. },
  241. {
  242. name: "requestsLimit",
  243. displayName: "Requests Limit",
  244. property: "requests.limit",
  245. filterTypes: [
  246. "numberLesserEqual",
  247. "numberLesser",
  248. "numberGreater",
  249. "numberGreaterEqual",
  250. "numberEquals"
  251. ],
  252. defaultFilterType: "numberLesser"
  253. },
  254. {
  255. name: "autofillEnabled",
  256. displayName: "Autofill Enabled",
  257. property: "autofill.enabled",
  258. filterTypes: ["boolean"],
  259. defaultFilterType: "boolean"
  260. },
  261. {
  262. name: "autofillLimit",
  263. displayName: "Autofill Limit",
  264. property: "autofill.limit",
  265. filterTypes: [
  266. "numberLesserEqual",
  267. "numberLesser",
  268. "numberGreater",
  269. "numberGreaterEqual",
  270. "numberEquals"
  271. ],
  272. defaultFilterType: "numberLesser"
  273. },
  274. {
  275. name: "autofillMode",
  276. displayName: "Autofill Mode",
  277. property: "autofill.mode",
  278. filterTypes: ["exact"],
  279. defaultFilterType: "exact",
  280. dropdown: [
  281. ["random", "Random"],
  282. ["sequential", "Sequential"]
  283. ]
  284. }
  285. ]);
  286. const jobs = ref([]);
  287. if (hasPermission("stations.clearEveryStationQueue"))
  288. jobs.value.push({
  289. name: "Clear every station queue",
  290. socket: "stations.clearEveryStationQueue"
  291. });
  292. const { openModal } = useModalsStore();
  293. const remove = stationId => {
  294. socket.dispatch(
  295. "stations.remove",
  296. stationId,
  297. res => new Toast(res.message)
  298. );
  299. };
  300. </script>
  301. <template>
  302. <div class="admin-tab">
  303. <page-metadata title="Admin | Stations" />
  304. <div class="card tab-info">
  305. <div class="info-row">
  306. <h1>Stations</h1>
  307. <p>Manage stations or create an official station</p>
  308. </div>
  309. <div class="button-row">
  310. <button
  311. v-if="hasPermission('stations.create.official')"
  312. class="button is-primary"
  313. @click="
  314. openModal({
  315. modal: 'createStation',
  316. props: { official: true }
  317. })
  318. "
  319. >
  320. Create Station
  321. </button>
  322. <run-job-dropdown :jobs="jobs" />
  323. </div>
  324. </div>
  325. <advanced-table
  326. :column-default="columnDefault"
  327. :columns="columns"
  328. :filters="filters"
  329. model="stations"
  330. >
  331. <template #column-options="slotProps">
  332. <div class="row-options">
  333. <button
  334. class="button is-primary icon-with-button material-icons"
  335. @click="
  336. openModal({
  337. modal: 'manageStation',
  338. props: {
  339. stationId: slotProps.item._id,
  340. sector: 'admin'
  341. }
  342. })
  343. "
  344. :disabled="slotProps.item.removed"
  345. content="Manage Station"
  346. v-tippy
  347. >
  348. settings
  349. </button>
  350. <quick-confirm
  351. v-if="hasPermission('stations.remove')"
  352. @confirm="remove(slotProps.item._id)"
  353. :disabled="slotProps.item.removed"
  354. >
  355. <button
  356. class="button is-danger icon-with-button material-icons"
  357. content="Remove Station"
  358. v-tippy
  359. >
  360. delete_forever
  361. </button>
  362. </quick-confirm>
  363. <router-link
  364. :to="{ path: `/${slotProps.item.name}` }"
  365. target="_blank"
  366. class="button is-primary icon-with-button material-icons"
  367. :disabled="slotProps.item.removed"
  368. content="View Station"
  369. v-tippy
  370. >
  371. radio
  372. </router-link>
  373. </div>
  374. </template>
  375. <template #column-_id="slotProps">
  376. <span :title="slotProps.item._id">{{
  377. slotProps.item._id
  378. }}</span>
  379. </template>
  380. <template #column-name="slotProps">
  381. <span :title="slotProps.item.name">{{
  382. slotProps.item.name
  383. }}</span>
  384. </template>
  385. <template #column-displayName="slotProps">
  386. <span :title="slotProps.item.displayName">{{
  387. slotProps.item.displayName
  388. }}</span>
  389. </template>
  390. <template #column-type="slotProps">
  391. <span :title="slotProps.item.type">{{
  392. slotProps.item.type
  393. }}</span>
  394. </template>
  395. <template #column-description="slotProps">
  396. <span :title="slotProps.item.description">{{
  397. slotProps.item.description
  398. }}</span>
  399. </template>
  400. <template #column-privacy="slotProps">
  401. <span :title="slotProps.item.privacy">{{
  402. slotProps.item.privacy
  403. }}</span>
  404. </template>
  405. <template #column-owner="slotProps">
  406. <span v-if="slotProps.item.type === 'official'">Musare</span>
  407. <user-link v-else :user-id="slotProps.item.owner._id" />
  408. </template>
  409. <template #column-theme="slotProps">
  410. <span :title="slotProps.item.theme">{{
  411. slotProps.item.theme
  412. }}</span>
  413. </template>
  414. <template #column-requestsEnabled="slotProps">
  415. <span :title="slotProps.item.requests.enabled">{{
  416. slotProps.item.requests.enabled
  417. }}</span>
  418. </template>
  419. <template #column-requestsAccess="slotProps">
  420. <span :title="slotProps.item.requests.access">{{
  421. slotProps.item.requests.access
  422. }}</span>
  423. </template>
  424. <template #column-requestsLimit="slotProps">
  425. <span :title="slotProps.item.requests.limit">{{
  426. slotProps.item.requests.limit
  427. }}</span>
  428. </template>
  429. <template #column-autofillEnabled="slotProps">
  430. <span :title="slotProps.item.autofill.enabled">{{
  431. slotProps.item.autofill.enabled
  432. }}</span>
  433. </template>
  434. <template #column-autofillLimit="slotProps">
  435. <span :title="slotProps.item.autofill.limit">{{
  436. slotProps.item.autofill.limit
  437. }}</span>
  438. </template>
  439. <template #column-autofillMode="slotProps">
  440. <span :title="slotProps.item.autofill.mode">{{
  441. slotProps.item.autofill.mode
  442. }}</span>
  443. </template>
  444. </advanced-table>
  445. </div>
  446. </template>