admin-pages.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. .subheading.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.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. :pagination.sync='pagination'
  50. :rows-per-page-items='[15]'
  51. :loading='loading'
  52. must-sort,
  53. hide-actions
  54. )
  55. template(slot='items', 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.dark ? `grey darken-4` : `grey lighten-4`') {{ props.item.locale }}
  63. span.ml-2.grey--text(:class='$vuetify.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='warning', :value='true', outline) No pages to display.
  68. .text-xs-center.py-2.animated.fadeInDown(v-if='this.pageTotal > 1')
  69. v-pagination(v-model='pagination.page', :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: {},
  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. if (this.pagination.rowsPerPage == null || this.pagination.totalItems == null) {
  101. return 0
  102. }
  103. return Math.ceil(this.filteredPages.length / this.pagination.rowsPerPage)
  104. },
  105. filteredPages () {
  106. return _.filter(this.pages, pg => {
  107. if (this.selectedLang !== null && this.selectedLang !== pg.locale) {
  108. return false
  109. }
  110. if (this.selectedState !== null && this.selectedState !== pg.isPublished) {
  111. return false
  112. }
  113. return true
  114. })
  115. },
  116. langs () {
  117. return _.concat({
  118. text: 'All Locales',
  119. value: null
  120. }, _.uniqBy(this.pages, 'locale').map(pg => ({
  121. text: pg.locale,
  122. value: pg.locale
  123. })))
  124. }
  125. },
  126. methods: {
  127. async refresh() {
  128. await this.$apollo.queries.pages.refetch()
  129. this.$store.commit('showNotification', {
  130. message: 'Page list has been refreshed.',
  131. style: 'success',
  132. icon: 'cached'
  133. })
  134. },
  135. newpage() {
  136. this.pageSelectorShown = true
  137. },
  138. recyclebin () { }
  139. },
  140. apollo: {
  141. pages: {
  142. query: pagesQuery,
  143. fetchPolicy: 'network-only',
  144. update: (data) => data.pages.list,
  145. watchLoading (isLoading) {
  146. this.loading = isLoading
  147. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-pages-refresh')
  148. }
  149. }
  150. }
  151. }
  152. </script>
  153. <style lang='scss'>
  154. .admin-pages-path {
  155. display: flex;
  156. justify-content: flex-start;
  157. align-items: center;
  158. font-family: 'Roboto Mono', monospace;
  159. }
  160. </style>