admin-pages.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template lang='pug'>
  2. v-container(fluid, grid-list-lg)
  3. v-layout(row wrap)
  4. v-flex(xs12)
  5. .admin-header
  6. img.animated.fadeInUp(src='/svg/icon-file.svg', alt='Page', style='width: 80px;')
  7. .admin-header-title
  8. .headline.blue--text.text--darken-2.animated.fadeInLeft Pages
  9. .subtitle-1.grey--text.animated.fadeInLeft.wait-p2s Manage pages
  10. v-spacer
  11. v-btn.animated.fadeInDown.wait-p1s(color='grey', outlined, @click='refresh', large)
  12. v-icon.grey--text mdi-refresh
  13. v-btn.animated.fadeInDown.mx-3(color='primary', outlined, large, @click='recyclebin', disabled)
  14. v-icon(left) mdi-delete-outline
  15. span Recycle Bin
  16. v-btn.animated.fadeInDown(color='primary', depressed, large, @click='newpage', disabled)
  17. v-icon(left) mdi-plus
  18. span New Page
  19. v-card.wiki-form.mt-3.animated.fadeInUp
  20. v-toolbar(flat, :color='$vuetify.theme.dark ? `grey darken-3-d5` : `grey lighten-5`', height='80')
  21. v-spacer
  22. v-text-field(
  23. outlined
  24. v-model='search'
  25. prepend-inner-icon='mdi-file-search-outline'
  26. label='Search Pages...'
  27. hide-details
  28. )
  29. v-select.ml-2(
  30. outlined
  31. hide-details
  32. label='Locale'
  33. :items='langs'
  34. v-model='selectedLang'
  35. )
  36. v-select.ml-2(
  37. outlined
  38. hide-details
  39. label='Publish State'
  40. :items='states'
  41. v-model='selectedState'
  42. )
  43. v-spacer
  44. v-divider
  45. v-data-table(
  46. :items='filteredPages'
  47. :headers='headers'
  48. :search='search'
  49. :page.sync='pagination'
  50. :items-per-page='15'
  51. :loading='loading'
  52. must-sort,
  53. hide-default-footer
  54. )
  55. template(slot='item', slot-scope='props')
  56. tr.is-clickable(:active='props.selected', @click='$router.push(`/pages/` + props.item.id)')
  57. td.text-xs-right {{ props.item.id }}
  58. td
  59. .body-2 {{ props.item.title }}
  60. .caption {{ props.item.description }}
  61. td.admin-pages-path
  62. v-chip(label, small, :color='$vuetify.theme.dark ? `grey darken-4` : `grey lighten-4`') {{ props.item.locale }}
  63. span.ml-2.grey--text(:class='$vuetify.theme.dark ? `text--lighten-1` : `text--darken-2`') {{ props.item.path }}
  64. td {{ props.item.createdAt | moment('calendar') }}
  65. td {{ props.item.updatedAt | moment('calendar') }}
  66. template(slot='no-data')
  67. v-alert.ma-3(icon='mdi-alert', :value='true', outlined) No pages to display.
  68. .text-xs-center.py-2.animated.fadeInDown(v-if='this.pageTotal > 1')
  69. v-pagination(v-model='pagination', :length='pageTotal')
  70. </template>
  71. <script>
  72. import _ from 'lodash'
  73. import pagesQuery from 'gql/admin/pages/pages-query-list.gql'
  74. export default {
  75. data() {
  76. return {
  77. selectedPage: {},
  78. pagination: 1,
  79. pages: [],
  80. headers: [
  81. { text: 'ID', value: 'id', width: 50, align: 'right' },
  82. { text: 'Title', value: 'title' },
  83. { text: 'Path', value: 'path' },
  84. { text: 'Created', value: 'createdAt', width: 250 },
  85. { text: 'Last Updated', value: 'updatedAt', width: 250 }
  86. ],
  87. search: '',
  88. selectedLang: null,
  89. selectedState: null,
  90. states: [
  91. { text: 'All Publishing States', value: null },
  92. { text: 'Published', value: true },
  93. { text: 'Not Published', value: false }
  94. ],
  95. loading: false
  96. }
  97. },
  98. computed: {
  99. pageTotal () {
  100. return Math.ceil(this.filteredPages.length / 15)
  101. },
  102. filteredPages () {
  103. return _.filter(this.pages, pg => {
  104. if (this.selectedLang !== null && this.selectedLang !== pg.locale) {
  105. return false
  106. }
  107. if (this.selectedState !== null && this.selectedState !== pg.isPublished) {
  108. return false
  109. }
  110. return true
  111. })
  112. },
  113. langs () {
  114. return _.concat({
  115. text: 'All Locales',
  116. value: null
  117. }, _.uniqBy(this.pages, 'locale').map(pg => ({
  118. text: pg.locale,
  119. value: pg.locale
  120. })))
  121. }
  122. },
  123. methods: {
  124. async refresh() {
  125. await this.$apollo.queries.pages.refetch()
  126. this.$store.commit('showNotification', {
  127. message: 'Page list has been refreshed.',
  128. style: 'success',
  129. icon: 'cached'
  130. })
  131. },
  132. newpage() {
  133. this.pageSelectorShown = true
  134. },
  135. recyclebin () { }
  136. },
  137. apollo: {
  138. pages: {
  139. query: pagesQuery,
  140. fetchPolicy: 'network-only',
  141. update: (data) => data.pages.list,
  142. watchLoading (isLoading) {
  143. this.loading = isLoading
  144. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-pages-refresh')
  145. }
  146. }
  147. }
  148. }
  149. </script>
  150. <style lang='scss'>
  151. .admin-pages-path {
  152. display: flex;
  153. justify-content: flex-start;
  154. align-items: center;
  155. font-family: 'Roboto Mono', monospace;
  156. }
  157. </style>