index.vue 15 KB

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