index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  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. <router-view></router-view>
  192. </div>
  193. <main-footer />
  194. </div>
  195. </div>
  196. </div>
  197. <floating-box
  198. id="keyboardShortcutsHelper"
  199. ref="keyboardShortcutsHelper"
  200. >
  201. <template #body>
  202. <div>
  203. <div>
  204. <span class="biggest"
  205. ><b>Keyboard shortcuts helper</b></span
  206. >
  207. <span
  208. ><b>Ctrl + /</b> - Toggles this keyboard shortcuts
  209. helper</span
  210. >
  211. <span
  212. ><b>Ctrl + Shift + /</b> - Resets the position of
  213. this keyboard shortcuts helper</span
  214. >
  215. <hr />
  216. </div>
  217. <div>
  218. <span class="biggest"><b>Table</b></span>
  219. <span class="bigger"><b>Navigation</b></span>
  220. <span
  221. ><b>Up / Down arrow keys</b> - Move between
  222. rows</span
  223. >
  224. <hr />
  225. </div>
  226. <div>
  227. <span class="bigger"><b>Page navigation</b></span>
  228. <span
  229. ><b>Ctrl + Left/Right arrow keys</b> - Previous/next
  230. page</span
  231. >
  232. <span
  233. ><b>Ctrl + Shift + Left/Right arrow keys</b> -
  234. First/last page</span
  235. >
  236. <hr />
  237. </div>
  238. <div>
  239. <span class="bigger"><b>Reset localStorage</b></span>
  240. <span><b>Ctrl + F5</b> - Resets localStorage</span>
  241. <hr />
  242. </div>
  243. <div>
  244. <span class="bigger"><b>Selecting</b></span>
  245. <span><b>Space</b> - Selects/unselects a row</span>
  246. <span><b>Ctrl + A</b> - Selects all rows</span>
  247. <span
  248. ><b>Shift + Up/Down arrow keys</b> - Selects all
  249. rows in between</span
  250. >
  251. <span
  252. ><b>Ctrl + Up/Down arrow keys</b> - Unselects all
  253. rows in between</span
  254. >
  255. <hr />
  256. </div>
  257. <div>
  258. <span class="bigger"><b>Popup actions</b></span>
  259. <span><b>Ctrl + 1-9</b> - Execute action 1-9</span>
  260. <span><b>Ctrl + 0</b> - Select action 1</span>
  261. <hr />
  262. </div>
  263. </div>
  264. </template>
  265. </floating-box>
  266. </div>
  267. </template>
  268. <script>
  269. import { mapState, mapActions, mapGetters } from "vuex";
  270. import keyboardShortcuts from "@/keyboardShortcuts";
  271. import MainHeader from "@/components/layout/MainHeader.vue";
  272. import MainFooter from "@/components/layout/MainFooter.vue";
  273. import FloatingBox from "@/components/FloatingBox.vue";
  274. export default {
  275. components: {
  276. MainHeader,
  277. MainFooter,
  278. FloatingBox
  279. },
  280. data() {
  281. return {
  282. currentTab: "",
  283. siteSettings: {
  284. logo: "",
  285. sitename: ""
  286. },
  287. sidebarActive: true
  288. };
  289. },
  290. computed: {
  291. ...mapGetters({
  292. socket: "websockets/getSocket"
  293. }),
  294. ...mapState("admin", { childrenActive: state => state.childrenActive })
  295. },
  296. watch: {
  297. $route(route) {
  298. if (this.getTabFromPath(route.path)) this.onRouteChange();
  299. }
  300. },
  301. async mounted() {
  302. if (this.getTabFromPath()) {
  303. this.onRouteChange();
  304. } else if (localStorage.getItem("lastAdminPage")) {
  305. this.$router.push(
  306. `/admin/${localStorage.getItem("lastAdminPage")}`
  307. );
  308. } else {
  309. this.$router.push(`/admin/songs`);
  310. }
  311. this.siteSettings = await lofig.get("siteSettings");
  312. this.sidebarActive = JSON.parse(
  313. localStorage.getItem("admin-sidebar-active")
  314. );
  315. if (this.sidebarActive === null)
  316. this.sidebarActive = !(document.body.clientWidth <= 768);
  317. keyboardShortcuts.registerShortcut(
  318. "admin.toggleKeyboardShortcutsHelper",
  319. {
  320. keyCode: 191, // '/' key
  321. ctrl: true,
  322. preventDefault: true,
  323. handler: () => {
  324. this.toggleKeyboardShortcutsHelper();
  325. }
  326. }
  327. );
  328. keyboardShortcuts.registerShortcut(
  329. "admin.resetKeyboardShortcutsHelper",
  330. {
  331. keyCode: 191, // '/' key
  332. ctrl: true,
  333. shift: true,
  334. preventDefault: true,
  335. handler: () => {
  336. this.resetKeyboardShortcutsHelper();
  337. }
  338. }
  339. );
  340. },
  341. beforeUnmount() {
  342. this.socket.dispatch("apis.leaveRooms");
  343. const shortcutNames = [
  344. "admin.toggleKeyboardShortcutsHelper",
  345. "admin.resetKeyboardShortcutsHelper"
  346. ];
  347. shortcutNames.forEach(shortcutName => {
  348. keyboardShortcuts.unregisterShortcut(shortcutName);
  349. });
  350. },
  351. methods: {
  352. onRouteChange() {
  353. if (this.currentTab.startsWith("songs")) {
  354. this.toggleChildren({ child: "songs", force: false });
  355. } else if (this.currentTab.startsWith("users")) {
  356. this.toggleChildren({ child: "users", force: false });
  357. }
  358. this.currentTab = this.getTabFromPath();
  359. if (this.$refs[`${this.currentTab}-tab`])
  360. this.$refs[`${this.currentTab}-tab`].scrollIntoView({
  361. inline: "center",
  362. block: "nearest"
  363. });
  364. localStorage.setItem("lastAdminPage", this.currentTab);
  365. if (this.currentTab.startsWith("songs"))
  366. this.toggleChildren({ child: "songs", force: true });
  367. else if (this.currentTab.startsWith("users"))
  368. this.toggleChildren({ child: "users", force: true });
  369. },
  370. toggleKeyboardShortcutsHelper() {
  371. this.$refs.keyboardShortcutsHelper.toggleBox();
  372. },
  373. resetKeyboardShortcutsHelper() {
  374. this.$refs.keyboardShortcutsHelper.resetBox();
  375. },
  376. toggleSidebar() {
  377. this.sidebarActive = !this.sidebarActive;
  378. localStorage.setItem("admin-sidebar-active", this.sidebarActive);
  379. },
  380. getTabFromPath(path) {
  381. const localPath = path || this.$route.path;
  382. return localPath.substr(0, 7) === "/admin/"
  383. ? localPath.substr(7, localPath.length)
  384. : null;
  385. },
  386. ...mapActions("admin", ["toggleChildren"])
  387. }
  388. };
  389. </script>
  390. <style lang="less" scoped>
  391. .night-mode {
  392. .main-container .admin-area .admin-sidebar .inner {
  393. .top {
  394. background-color: var(--dark-grey-3);
  395. }
  396. .bottom {
  397. background-color: var(--dark-grey-2);
  398. .sidebar-item {
  399. background-color: var(--dark-grey-2);
  400. border-color: var(--dark-grey-3);
  401. color: var(--white);
  402. &.with-children .sidebar-item-child {
  403. color: var(--white);
  404. }
  405. }
  406. }
  407. }
  408. }
  409. .main-container {
  410. height: auto;
  411. .admin-area {
  412. display: flex;
  413. flex-direction: column;
  414. min-height: 100vh;
  415. :deep(.nav) {
  416. .nav-menu.is-active {
  417. left: 45px;
  418. }
  419. &.admin-sidebar-active .nav-menu.is-active {
  420. left: 200px;
  421. }
  422. }
  423. .admin-sidebar {
  424. display: flex;
  425. min-width: 200px;
  426. width: 200px;
  427. @media screen and (max-width: 768px) {
  428. min-width: 45px;
  429. width: 45px;
  430. }
  431. .inner {
  432. display: flex;
  433. flex-direction: column;
  434. max-height: 100vh;
  435. overflow-y: auto;
  436. width: 100%;
  437. max-width: 200px;
  438. position: fixed;
  439. top: 0;
  440. bottom: 0;
  441. left: 0;
  442. z-index: 5;
  443. box-shadow: @box-shadow;
  444. .top {
  445. display: flex;
  446. background-color: var(--primary-color);
  447. height: 64px;
  448. min-height: 64px;
  449. .sidebar-logo {
  450. font-size: 2.1rem !important;
  451. line-height: 38px !important;
  452. font-family: Pacifico, cursive;
  453. display: flex;
  454. align-items: center;
  455. img {
  456. max-height: 38px;
  457. color: var(--primary-color);
  458. user-select: none;
  459. -webkit-user-drag: none;
  460. }
  461. .full-logo {
  462. padding: 0 20px;
  463. }
  464. .minimised-logo {
  465. display: none;
  466. }
  467. }
  468. }
  469. .bottom {
  470. display: flex;
  471. flex-direction: column;
  472. flex: 1 0 auto;
  473. background-color: var(--white);
  474. .sidebar-item {
  475. display: flex;
  476. padding: 0 20px;
  477. line-height: 40px;
  478. font-size: 16px;
  479. font-weight: 600;
  480. color: var(--primary-color);
  481. background-color: var(--white);
  482. border-bottom: 1px solid var(--light-grey-2);
  483. transition: filter 0.2s ease-in-out;
  484. & > .material-icons {
  485. line-height: 40px;
  486. margin-right: 5px;
  487. }
  488. &:hover,
  489. &:focus,
  490. &.router-link-active,
  491. &.is-active {
  492. filter: brightness(95%);
  493. }
  494. &.toggle-sidebar {
  495. cursor: pointer;
  496. font-weight: 400;
  497. }
  498. &.with-children {
  499. flex-direction: column;
  500. & > span {
  501. display: flex;
  502. line-height: 40px;
  503. cursor: pointer;
  504. & > .material-icons {
  505. line-height: 40px;
  506. margin-right: 5px;
  507. }
  508. }
  509. .toggle-sidebar-children {
  510. margin-left: 5px;
  511. }
  512. .sidebar-item-children {
  513. display: none;
  514. }
  515. &.is-active .sidebar-item-children {
  516. display: flex;
  517. flex-direction: column;
  518. .sidebar-item-child {
  519. display: flex;
  520. flex-direction: column;
  521. margin-left: 30px;
  522. font-size: 14px;
  523. line-height: 30px;
  524. position: relative;
  525. &::before {
  526. content: "";
  527. position: absolute;
  528. width: 1px;
  529. height: 30px;
  530. top: 0;
  531. left: -20px;
  532. background-color: var(--light-grey-3);
  533. }
  534. &:last-child::before {
  535. height: 16px;
  536. }
  537. &::after {
  538. content: "";
  539. position: absolute;
  540. width: 15px;
  541. height: 1px;
  542. top: 15px;
  543. left: -20px;
  544. background-color: var(--light-grey-3);
  545. }
  546. }
  547. }
  548. }
  549. }
  550. }
  551. }
  552. &.minimised {
  553. min-width: 45px;
  554. width: 45px;
  555. .inner {
  556. max-width: 45px;
  557. .top {
  558. justify-content: center;
  559. .full-logo {
  560. display: none;
  561. }
  562. .minimised-logo {
  563. display: flex;
  564. }
  565. }
  566. .sidebar-item {
  567. justify-content: center;
  568. padding: 0;
  569. & > span {
  570. display: none;
  571. }
  572. }
  573. }
  574. }
  575. }
  576. .admin-content {
  577. display: flex;
  578. flex-direction: row;
  579. flex-grow: 1;
  580. .admin-container {
  581. display: flex;
  582. flex-direction: column;
  583. flex-grow: 1;
  584. overflow: hidden;
  585. :deep(.admin-tab-container) {
  586. display: flex;
  587. flex-direction: column;
  588. flex: 1 0 auto;
  589. padding: 10px 10px 20px 10px;
  590. .admin-tab {
  591. max-width: 1900px;
  592. margin: 0 auto;
  593. padding: 0 10px;
  594. }
  595. .admin-tab,
  596. .container {
  597. .button-row {
  598. display: flex;
  599. flex-direction: row;
  600. flex-wrap: wrap;
  601. justify-content: center;
  602. margin-bottom: 5px;
  603. & > .button,
  604. & > span {
  605. margin: 5px 0;
  606. &:not(:first-child) {
  607. margin-left: 5px;
  608. }
  609. }
  610. }
  611. }
  612. }
  613. }
  614. }
  615. }
  616. }
  617. :deep(.container) {
  618. position: relative;
  619. }
  620. :deep(.box) {
  621. box-shadow: @box-shadow;
  622. display: block;
  623. &:not(:last-child) {
  624. margin-bottom: 20px;
  625. }
  626. }
  627. #keyboardShortcutsHelper {
  628. .box-body {
  629. .biggest {
  630. font-size: 18px;
  631. }
  632. .bigger {
  633. font-size: 16px;
  634. }
  635. span {
  636. display: block;
  637. }
  638. }
  639. }
  640. @media screen and (min-width: 980px) {
  641. :deep(.container) {
  642. margin: 0 auto;
  643. max-width: 960px;
  644. }
  645. }
  646. @media screen and (min-width: 1180px) {
  647. :deep(.container) {
  648. max-width: 1200px;
  649. }
  650. }
  651. </style>