admin-pages.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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='/_assets/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, to='pages/visualize')
  17. v-icon(left) mdi-graph
  18. span Visualize
  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. sort-by='updatedAt',
  54. sort-desc,
  55. hide-default-footer
  56. )
  57. template(slot='item', slot-scope='props')
  58. tr.is-clickable(:active='props.selected', @click='$router.push(`/pages/` + props.item.id)')
  59. td.text-xs-right {{ props.item.id }}
  60. td
  61. .body-2: strong {{ props.item.title }}
  62. .caption {{ props.item.description }}
  63. td.admin-pages-path
  64. v-chip(label, small, :color='$vuetify.theme.dark ? `grey darken-4` : `grey lighten-4`') {{ props.item.locale }}
  65. span.ml-2.grey--text(:class='$vuetify.theme.dark ? `text--lighten-1` : `text--darken-2`') / {{ props.item.path }}
  66. td {{ props.item.createdAt | moment('calendar') }}
  67. td {{ props.item.updatedAt | moment('calendar') }}
  68. template(slot='no-data')
  69. v-alert.ma-3(icon='mdi-alert', :value='true', outlined) No pages to display.
  70. .text-center.py-2.animated.fadeInDown(v-if='this.pageTotal > 1')
  71. v-pagination(v-model='pagination', :length='pageTotal')
  72. </template>
  73. <script>
  74. import _ from 'lodash'
  75. import pagesQuery from 'gql/admin/pages/pages-query-list.gql'
  76. export default {
  77. data() {
  78. return {
  79. selectedPage: {},
  80. pagination: 1,
  81. pages: [],
  82. headers: [
  83. { text: 'ID', value: 'id', width: 80, sortable: true },
  84. { text: 'Title', value: 'title' },
  85. { text: 'Path', value: 'path' },
  86. { text: 'Created', value: 'createdAt', width: 250 },
  87. { text: 'Last Updated', value: 'updatedAt', width: 250 }
  88. ],
  89. search: '',
  90. selectedLang: null,
  91. selectedState: null,
  92. states: [
  93. { text: 'All Publishing States', value: null },
  94. { text: 'Published', value: true },
  95. { text: 'Not Published', value: false }
  96. ],
  97. loading: false
  98. }
  99. },
  100. computed: {
  101. pageTotal () {
  102. return Math.ceil(this.filteredPages.length / 15)
  103. },
  104. filteredPages () {
  105. return _.filter(this.pages, pg => {
  106. if (this.selectedLang !== null && this.selectedLang !== pg.locale) {
  107. return false
  108. }
  109. if (this.selectedState !== null && this.selectedState !== pg.isPublished) {
  110. return false
  111. }
  112. return true
  113. })
  114. },
  115. langs () {
  116. return _.concat({
  117. text: 'All Locales',
  118. value: null
  119. }, _.uniqBy(this.pages, 'locale').map(pg => ({
  120. text: pg.locale,
  121. value: pg.locale
  122. })))
  123. }
  124. },
  125. methods: {
  126. async refresh() {
  127. await this.$apollo.queries.pages.refetch()
  128. this.$store.commit('showNotification', {
  129. message: 'Page list has been refreshed.',
  130. style: 'success',
  131. icon: 'cached'
  132. })
  133. },
  134. newpage() {
  135. this.pageSelectorShown = true
  136. },
  137. recyclebin () { }
  138. },
  139. apollo: {
  140. pages: {
  141. query: pagesQuery,
  142. fetchPolicy: 'network-only',
  143. update: (data) => data.pages.list,
  144. watchLoading (isLoading) {
  145. this.loading = isLoading
  146. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-pages-refresh')
  147. }
  148. }
  149. }
  150. }
  151. </script>
  152. <style lang='scss'>
  153. .admin-pages-path {
  154. display: flex;
  155. justify-content: flex-start;
  156. align-items: center;
  157. font-family: 'Roboto Mono', monospace;
  158. }
  159. </style>