You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

163 lines
5.1 KiB

  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', outline, @click='refresh', large)
  12. v-icon.grey--text refresh
  13. v-btn.animated.fadeInDown(color='primary', depressed, large, @click='newpage', disabled)
  14. v-icon(left) add
  15. span New Page
  16. v-card.wiki-form.mt-3.animated.fadeInUp
  17. v-toolbar(flat, :color='$vuetify.dark ? `grey darken-3-d5` : `grey lighten-5`', height='80')
  18. v-spacer
  19. v-text-field(
  20. outline
  21. v-model='search'
  22. append-icon='search'
  23. label='Search Pages...'
  24. single-line
  25. hide-details
  26. )
  27. v-select.ml-2(
  28. outline
  29. hide-details
  30. single-line
  31. label='Locale'
  32. :items='langs'
  33. v-model='selectedLang'
  34. )
  35. v-select.ml-2(
  36. outline
  37. hide-details
  38. single-line
  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. },
  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>