index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  1. <template>
  2. <div class="app">
  3. <div class="admin-area">
  4. <main-header
  5. :hide-logo="true"
  6. :class="{ 'admin-sidebar-active': sidebarActive }"
  7. />
  8. <div class="admin-content">
  9. <div
  10. class="admin-sidebar"
  11. :class="{ minimised: !sidebarActive }"
  12. >
  13. <div class="inner">
  14. <div class="top">
  15. <router-link class="sidebar-logo" to="/">
  16. <img
  17. class="full-logo"
  18. :src="siteSettings.logo_white"
  19. :alt="siteSettings.sitename || `Musare`"
  20. />
  21. <img
  22. class="minimised-logo"
  23. :src="siteSettings.logo_small"
  24. :alt="siteSettings.sitename[0] || `M`"
  25. />
  26. </router-link>
  27. </div>
  28. <div class="bottom">
  29. <div
  30. class="sidebar-item toggle-sidebar"
  31. @click="toggleSidebar()"
  32. content="Expand"
  33. v-tippy="{ onShow: () => !sidebarActive }"
  34. >
  35. <i class="material-icons">menu_open</i>
  36. <span>Minimise</span>
  37. </div>
  38. <div
  39. v-if="sidebarActive"
  40. class="sidebar-item with-children"
  41. :class="{ 'is-active': childrenActive.songs }"
  42. >
  43. <span
  44. @click="toggleChildren({ child: 'songs' })"
  45. >
  46. <i class="material-icons">music_note</i>
  47. <span>Songs</span>
  48. <i
  49. class="material-icons toggle-sidebar-children"
  50. >{{
  51. childrenActive.songs
  52. ? "expand_less"
  53. : "expand_more"
  54. }}</i
  55. >
  56. </span>
  57. <div class="sidebar-item-children">
  58. <router-link
  59. class="sidebar-item-child"
  60. to="/admin/songs"
  61. >
  62. Songs
  63. </router-link>
  64. <router-link
  65. class="sidebar-item-child"
  66. to="/admin/songs/reports"
  67. >
  68. Reports
  69. </router-link>
  70. </div>
  71. </div>
  72. <router-link
  73. v-else
  74. class="sidebar-item songs"
  75. to="/admin/songs"
  76. content="Songs"
  77. v-tippy="{
  78. theme: 'info',
  79. onShow: () => !sidebarActive
  80. }"
  81. >
  82. <i class="material-icons">music_note</i>
  83. <span>Songs</span>
  84. </router-link>
  85. <router-link
  86. class="sidebar-item stations"
  87. to="/admin/stations"
  88. content="Stations"
  89. v-tippy="{
  90. theme: 'info',
  91. onShow: () => !sidebarActive
  92. }"
  93. >
  94. <i class="material-icons">radio</i>
  95. <span>Stations</span>
  96. </router-link>
  97. <router-link
  98. class="sidebar-item playlists"
  99. to="/admin/playlists"
  100. content="Playlists"
  101. v-tippy="{
  102. theme: 'info',
  103. onShow: () => !sidebarActive
  104. }"
  105. >
  106. <i class="material-icons">library_music</i>
  107. <span>Playlists</span>
  108. </router-link>
  109. <div
  110. v-if="sidebarActive"
  111. class="sidebar-item with-children"
  112. :class="{ 'is-active': childrenActive.users }"
  113. >
  114. <span
  115. @click="toggleChildren({ child: 'users' })"
  116. >
  117. <i class="material-icons">people</i>
  118. <span>Users</span>
  119. <i
  120. class="material-icons toggle-sidebar-children"
  121. >{{
  122. childrenActive.users
  123. ? "expand_less"
  124. : "expand_more"
  125. }}</i
  126. >
  127. </span>
  128. <div class="sidebar-item-children">
  129. <router-link
  130. class="sidebar-item-child"
  131. to="/admin/users"
  132. >
  133. Users
  134. </router-link>
  135. <router-link
  136. class="sidebar-item-child"
  137. to="/admin/users/data-requests"
  138. >
  139. Data Requests
  140. </router-link>
  141. <router-link
  142. class="sidebar-item-child"
  143. to="/admin/users/punishments"
  144. >
  145. Punishments
  146. </router-link>
  147. </div>
  148. </div>
  149. <router-link
  150. v-else
  151. class="sidebar-item users"
  152. to="/admin/users"
  153. content="Users"
  154. v-tippy="{
  155. theme: 'info',
  156. onShow: () => !sidebarActive
  157. }"
  158. >
  159. <i class="material-icons">people</i>
  160. <span>Users</span>
  161. </router-link>
  162. <router-link
  163. class="sidebar-item news"
  164. to="/admin/news"
  165. content="News"
  166. v-tippy="{
  167. theme: 'info',
  168. onShow: () => !sidebarActive
  169. }"
  170. >
  171. <i class="material-icons">chrome_reader_mode</i>
  172. <span>News</span>
  173. </router-link>
  174. <router-link
  175. class="sidebar-item statistics"
  176. to="/admin/statistics"
  177. content="Statistics"
  178. v-tippy="{
  179. theme: 'info',
  180. onShow: () => !sidebarActive
  181. }"
  182. >
  183. <i class="material-icons">show_chart</i>
  184. <span>Statistics</span>
  185. </router-link>
  186. </div>
  187. </div>
  188. </div>
  189. <div class="admin-container">
  190. <div class="admin-tab-container">
  191. <songs v-if="currentTab == 'songs'" />
  192. <reports v-if="currentTab == 'songs/reports'" />
  193. <stations v-if="currentTab == 'stations'" />
  194. <playlists v-if="currentTab == 'playlists'" />
  195. <news v-if="currentTab == 'news'" />
  196. <users v-if="currentTab == 'users'" />
  197. <punishments v-if="currentTab == 'users/punishments'" />
  198. <data-requests
  199. v-if="currentTab == 'users/data-requests'"
  200. />
  201. <statistics v-if="currentTab == 'statistics'" />
  202. </div>
  203. <main-footer />
  204. </div>
  205. </div>
  206. </div>
  207. <floating-box
  208. id="keyboardShortcutsHelper"
  209. ref="keyboardShortcutsHelper"
  210. >
  211. <template #body>
  212. <div>
  213. <div>
  214. <span class="biggest"
  215. ><b>Keyboard shortcuts helper</b></span
  216. >
  217. <span
  218. ><b>Ctrl + /</b> - Toggles this keyboard shortcuts
  219. helper</span
  220. >
  221. <span
  222. ><b>Ctrl + Shift + /</b> - Resets the position of
  223. this keyboard shortcuts helper</span
  224. >
  225. <hr />
  226. </div>
  227. <div>
  228. <span class="biggest"><b>Table</b></span>
  229. <span class="bigger"><b>Navigation</b></span>
  230. <span
  231. ><b>Up / Down arrow keys</b> - Move between
  232. rows</span
  233. >
  234. <hr />
  235. </div>
  236. <div>
  237. <span class="bigger"><b>Page navigation</b></span>
  238. <span
  239. ><b>Ctrl + Left/Right arrow keys</b> - Previous/next
  240. page</span
  241. >
  242. <span
  243. ><b>Ctrl + Shift + Left/Right arrow keys</b> -
  244. First/last page</span
  245. >
  246. <hr />
  247. </div>
  248. <div>
  249. <span class="bigger"><b>Reset localStorage</b></span>
  250. <span><b>Ctrl + F5</b> - Resets localStorage</span>
  251. <hr />
  252. </div>
  253. <div>
  254. <span class="bigger"><b>Selecting</b></span>
  255. <span><b>Space</b> - Selects/unselects a row</span>
  256. <span><b>Ctrl + A</b> - Selects all rows</span>
  257. <span
  258. ><b>Shift + Up/Down arrow keys</b> - Selects all
  259. rows in between</span
  260. >
  261. <span
  262. ><b>Ctrl + Up/Down arrow keys</b> - Unselects all
  263. rows in between</span
  264. >
  265. <hr />
  266. </div>
  267. <div>
  268. <span class="bigger"><b>Popup actions</b></span>
  269. <span><b>Ctrl + 1-9</b> - Execute action 1-9</span>
  270. <span><b>Ctrl + 0</b> - Select action 1</span>
  271. <hr />
  272. </div>
  273. </div>
  274. </template>
  275. </floating-box>
  276. </div>
  277. </template>
  278. <script>
  279. import { mapState, mapActions, mapGetters } from "vuex";
  280. import { defineAsyncComponent } from "vue";
  281. import keyboardShortcuts from "@/keyboardShortcuts";
  282. import MainHeader from "@/components/layout/MainHeader.vue";
  283. import MainFooter from "@/components/layout/MainFooter.vue";
  284. import FloatingBox from "@/components/FloatingBox.vue";
  285. export default {
  286. components: {
  287. MainHeader,
  288. MainFooter,
  289. FloatingBox,
  290. Songs: defineAsyncComponent(() => import("./Songs/index.vue")),
  291. Reports: defineAsyncComponent(() => import("./Songs/Reports.vue")),
  292. Stations: defineAsyncComponent(() => import("./Stations.vue")),
  293. Playlists: defineAsyncComponent(() => import("./Playlists.vue")),
  294. News: defineAsyncComponent(() => import("./News.vue")),
  295. Users: defineAsyncComponent(() => import("./Users/index.vue")),
  296. DataRequests: defineAsyncComponent(() =>
  297. import("./Users/DataRequests.vue")
  298. ),
  299. Punishments: defineAsyncComponent(() =>
  300. import("./Users/Punishments.vue")
  301. ),
  302. Statistics: defineAsyncComponent(() => import("./Statistics.vue"))
  303. },
  304. data() {
  305. return {
  306. currentTab: "",
  307. siteSettings: {
  308. logo: "",
  309. sitename: ""
  310. },
  311. sidebarActive: true
  312. };
  313. },
  314. computed: {
  315. ...mapGetters({
  316. socket: "websockets/getSocket"
  317. }),
  318. ...mapState("admin", { childrenActive: state => state.childrenActive })
  319. },
  320. watch: {
  321. $route(route) {
  322. this.changeTab(route.path);
  323. }
  324. },
  325. async mounted() {
  326. this.changeTab(this.$route.path);
  327. this.siteSettings = await lofig.get("siteSettings");
  328. this.sidebarActive = JSON.parse(
  329. localStorage.getItem("admin-sidebar-active")
  330. );
  331. if (this.sidebarActive === null)
  332. this.sidebarActive = !(document.body.clientWidth <= 768);
  333. keyboardShortcuts.registerShortcut(
  334. "admin.toggleKeyboardShortcutsHelper",
  335. {
  336. keyCode: 191, // '/' key
  337. ctrl: true,
  338. preventDefault: true,
  339. handler: () => {
  340. this.toggleKeyboardShortcutsHelper();
  341. }
  342. }
  343. );
  344. keyboardShortcuts.registerShortcut(
  345. "admin.resetKeyboardShortcutsHelper",
  346. {
  347. keyCode: 191, // '/' key
  348. ctrl: true,
  349. shift: true,
  350. preventDefault: true,
  351. handler: () => {
  352. this.resetKeyboardShortcutsHelper();
  353. }
  354. }
  355. );
  356. },
  357. beforeUnmount() {
  358. this.socket.dispatch("apis.leaveRooms");
  359. const shortcutNames = [
  360. "admin.toggleKeyboardShortcutsHelper",
  361. "admin.resetKeyboardShortcutsHelper"
  362. ];
  363. shortcutNames.forEach(shortcutName => {
  364. keyboardShortcuts.unregisterShortcut(shortcutName);
  365. });
  366. },
  367. methods: {
  368. changeTab(path) {
  369. switch (path) {
  370. case "/admin/songs/reports":
  371. this.showTab("songs/reports");
  372. break;
  373. case "/admin/songs":
  374. this.showTab("songs");
  375. break;
  376. case "/admin/stations":
  377. this.showTab("stations");
  378. break;
  379. case "/admin/playlists":
  380. this.showTab("playlists");
  381. break;
  382. case "/admin/news":
  383. this.showTab("news");
  384. break;
  385. case "/admin/users/data-requests":
  386. this.showTab("users/data-requests");
  387. break;
  388. case "/admin/users/punishments":
  389. this.showTab("users/punishments");
  390. break;
  391. case "/admin/users":
  392. this.showTab("users");
  393. break;
  394. case "/admin/statistics":
  395. this.showTab("statistics");
  396. break;
  397. default:
  398. if (path.startsWith("/admin")) {
  399. if (localStorage.getItem("lastAdminPage")) {
  400. this.$router.push(
  401. `/admin/${localStorage.getItem(
  402. "lastAdminPage"
  403. )}`
  404. );
  405. } else {
  406. this.$router.push(`/admin/songs`);
  407. }
  408. }
  409. }
  410. },
  411. showTab(tab) {
  412. if (this.currentTab.startsWith("songs"))
  413. this.toggleChildren({ child: "songs", force: false });
  414. else if (this.currentTab.startsWith("users"))
  415. this.toggleChildren({ child: "users", force: false });
  416. if (this.$refs[`${tab}-tab`])
  417. this.$refs[`${tab}-tab`].scrollIntoView({
  418. inline: "center",
  419. block: "nearest"
  420. });
  421. this.currentTab = tab;
  422. localStorage.setItem("lastAdminPage", tab);
  423. if (tab.startsWith("songs"))
  424. this.toggleChildren({ child: "songs", force: true });
  425. else if (tab.startsWith("users"))
  426. this.toggleChildren({ child: "users", force: true });
  427. },
  428. toggleKeyboardShortcutsHelper() {
  429. this.$refs.keyboardShortcutsHelper.toggleBox();
  430. },
  431. resetKeyboardShortcutsHelper() {
  432. this.$refs.keyboardShortcutsHelper.resetBox();
  433. },
  434. toggleSidebar() {
  435. this.sidebarActive = !this.sidebarActive;
  436. localStorage.setItem("admin-sidebar-active", this.sidebarActive);
  437. },
  438. ...mapActions("admin", ["toggleChildren"])
  439. }
  440. };
  441. </script>
  442. <style lang="less" scoped>
  443. .night-mode {
  444. .main-container .admin-area .admin-sidebar .inner {
  445. .top {
  446. background-color: var(--dark-grey-3);
  447. }
  448. .bottom {
  449. background-color: var(--dark-grey-2);
  450. .sidebar-item {
  451. background-color: var(--dark-grey-2);
  452. border-color: var(--dark-grey-3);
  453. color: var(--white);
  454. &.with-children .sidebar-item-child {
  455. color: var(--white);
  456. }
  457. }
  458. }
  459. }
  460. }
  461. .main-container {
  462. height: auto;
  463. .admin-area {
  464. display: flex;
  465. flex-direction: column;
  466. min-height: 100vh;
  467. :deep(.nav) {
  468. .nav-menu.is-active {
  469. left: 45px;
  470. }
  471. &.admin-sidebar-active .nav-menu.is-active {
  472. left: 200px;
  473. }
  474. }
  475. .admin-sidebar {
  476. display: flex;
  477. min-width: 200px;
  478. width: 200px;
  479. @media screen and (max-width: 768px) {
  480. min-width: 45px;
  481. width: 45px;
  482. }
  483. .inner {
  484. display: flex;
  485. flex-direction: column;
  486. max-height: 100vh;
  487. overflow-y: auto;
  488. width: 100%;
  489. max-width: 200px;
  490. position: fixed;
  491. top: 0;
  492. bottom: 0;
  493. left: 0;
  494. z-index: 5;
  495. box-shadow: @box-shadow;
  496. .top {
  497. display: flex;
  498. background-color: var(--primary-color);
  499. height: 64px;
  500. min-height: 64px;
  501. .sidebar-logo {
  502. font-size: 2.1rem !important;
  503. line-height: 38px !important;
  504. font-family: Pacifico, cursive;
  505. display: flex;
  506. align-items: center;
  507. img {
  508. max-height: 38px;
  509. color: var(--primary-color);
  510. user-select: none;
  511. -webkit-user-drag: none;
  512. }
  513. .full-logo {
  514. padding: 0 20px;
  515. }
  516. .minimised-logo {
  517. display: none;
  518. }
  519. }
  520. }
  521. .bottom {
  522. display: flex;
  523. flex-direction: column;
  524. flex: 1 0 auto;
  525. background-color: var(--white);
  526. .sidebar-item {
  527. display: flex;
  528. padding: 0 20px;
  529. line-height: 40px;
  530. font-size: 16px;
  531. font-weight: 600;
  532. color: var(--primary-color);
  533. background-color: var(--white);
  534. border-bottom: 1px solid var(--light-grey-2);
  535. transition: filter 0.2s ease-in-out;
  536. & > .material-icons {
  537. line-height: 40px;
  538. margin-right: 5px;
  539. }
  540. &:hover,
  541. &:focus,
  542. &.router-link-active,
  543. &.is-active {
  544. filter: brightness(95%);
  545. }
  546. &.toggle-sidebar {
  547. cursor: pointer;
  548. font-weight: 400;
  549. }
  550. &.with-children {
  551. flex-direction: column;
  552. & > span {
  553. display: flex;
  554. line-height: 40px;
  555. cursor: pointer;
  556. & > .material-icons {
  557. line-height: 40px;
  558. margin-right: 5px;
  559. }
  560. }
  561. .toggle-sidebar-children {
  562. margin-left: 5px;
  563. }
  564. .sidebar-item-children {
  565. display: none;
  566. }
  567. &.is-active .sidebar-item-children {
  568. display: flex;
  569. flex-direction: column;
  570. .sidebar-item-child {
  571. display: flex;
  572. flex-direction: column;
  573. margin-left: 30px;
  574. font-size: 14px;
  575. line-height: 30px;
  576. position: relative;
  577. &::before {
  578. content: "";
  579. position: absolute;
  580. width: 1px;
  581. height: 30px;
  582. top: 0;
  583. left: -20px;
  584. background-color: var(--light-grey-3);
  585. }
  586. &:last-child::before {
  587. height: 16px;
  588. }
  589. &::after {
  590. content: "";
  591. position: absolute;
  592. width: 15px;
  593. height: 1px;
  594. top: 15px;
  595. left: -20px;
  596. background-color: var(--light-grey-3);
  597. }
  598. }
  599. }
  600. }
  601. }
  602. }
  603. }
  604. &.minimised {
  605. min-width: 45px;
  606. width: 45px;
  607. .inner {
  608. max-width: 45px;
  609. .top {
  610. justify-content: center;
  611. .full-logo {
  612. display: none;
  613. }
  614. .minimised-logo {
  615. display: flex;
  616. }
  617. }
  618. .sidebar-item {
  619. justify-content: center;
  620. padding: 0;
  621. & > span {
  622. display: none;
  623. }
  624. }
  625. }
  626. }
  627. }
  628. .admin-content {
  629. display: flex;
  630. flex-direction: row;
  631. flex-grow: 1;
  632. .admin-container {
  633. display: flex;
  634. flex-direction: column;
  635. flex-grow: 1;
  636. overflow: hidden;
  637. :deep(.admin-tab-container) {
  638. display: flex;
  639. flex-direction: column;
  640. flex: 1 0 auto;
  641. padding: 10px 10px 20px 10px;
  642. .admin-tab {
  643. max-width: 1900px;
  644. margin: 0 auto;
  645. padding: 0 10px;
  646. }
  647. .admin-tab,
  648. .container {
  649. .button-row {
  650. display: flex;
  651. flex-direction: row;
  652. flex-wrap: wrap;
  653. justify-content: center;
  654. margin-bottom: 5px;
  655. & > .button,
  656. & > span {
  657. margin: 5px 0;
  658. &:not(:first-child) {
  659. margin-left: 5px;
  660. }
  661. }
  662. }
  663. }
  664. }
  665. }
  666. }
  667. }
  668. }
  669. :deep(.container) {
  670. position: relative;
  671. }
  672. :deep(.box) {
  673. box-shadow: @box-shadow;
  674. display: block;
  675. &:not(:last-child) {
  676. margin-bottom: 20px;
  677. }
  678. }
  679. #keyboardShortcutsHelper {
  680. .box-body {
  681. .biggest {
  682. font-size: 18px;
  683. }
  684. .bigger {
  685. font-size: 16px;
  686. }
  687. span {
  688. display: block;
  689. }
  690. }
  691. }
  692. @media screen and (min-width: 980px) {
  693. :deep(.container) {
  694. margin: 0 auto;
  695. max-width: 960px;
  696. }
  697. }
  698. @media screen and (min-width: 1180px) {
  699. :deep(.container) {
  700. max-width: 1200px;
  701. }
  702. }
  703. </style>