2
0

admin-pages.vue 5.3 KB

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