admin-pages.vue 5.2 KB
Newer Older
1
<template lang='pug'>
2 3 4 5
  v-container(fluid, grid-list-lg)
    v-layout(row wrap)
      v-flex(xs12)
        .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 12 13 14
          v-btn.animated.fadeInDown.wait-p1s(color='grey', outlined, @click='refresh', large)
            v-icon.grey--text mdi-refresh
          v-btn.animated.fadeInDown.mx-3(color='primary', outlined, large, @click='recyclebin', disabled)
            v-icon(left) mdi-delete-outline
Nick's avatar
Nick committed
15
            span Recycle Bin
16 17 18
          v-btn.animated.fadeInDown(color='primary', depressed, large, to='pages/visualize')
            v-icon(left) mdi-graph
            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 22
            v-spacer
            v-text-field(
23
              outlined
24
              v-model='search'
25
              prepend-inner-icon='mdi-file-search-outline'
26 27 28 29
              label='Search Pages...'
              hide-details
              )
            v-select.ml-2(
30
              outlined
31 32
              hide-details
              label='Locale'
33 34
              :items='langs'
              v-model='selectedLang'
35 36
            )
            v-select.ml-2(
37
              outlined
38 39
              hide-details
              label='Publish State'
40 41
              :items='states'
              v-model='selectedState'
42 43 44
            )
            v-spacer
          v-divider
45
          v-data-table(
46
            :items='filteredPages'
47 48
            :headers='headers'
            :search='search'
49 50
            :page.sync='pagination'
            :items-per-page='15'
51 52
            :loading='loading'
            must-sort,
53 54
            sort-by='updatedAt',
            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 63
                  .caption {{ props.item.description }}
                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 67 68
                td {{ props.item.createdAt | moment('calendar') }}
                td {{ props.item.updatedAt | moment('calendar') }}
            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 73 74
</template>

<script>
75
import _ from 'lodash'
76
import pagesQuery from 'gql/admin/pages/pages-query-list.gql'
77 78 79 80

export default {
  data() {
    return {
81
      selectedPage: {},
82
      pagination: 1,
83
      pages: [],
84
      headers: [
85
        { text: 'ID', value: 'id', width: 80, sortable: true },
86 87 88 89 90
        { text: 'Title', value: 'title' },
        { text: 'Path', value: 'path' },
        { text: 'Created', value: 'createdAt', width: 250 },
        { text: 'Last Updated', value: 'updatedAt', width: 250 }
      ],
91
      search: '',
92 93 94 95 96 97 98
      selectedLang: null,
      selectedState: null,
      states: [
        { text: 'All Publishing States', value: null },
        { text: 'Published', value: true },
        { text: 'Not Published', value: false }
      ],
99
      loading: false
100 101 102
    }
  },
  computed: {
103
    pageTotal () {
104
      return Math.ceil(this.filteredPages.length / 15)
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
    },
    filteredPages () {
      return _.filter(this.pages, pg => {
        if (this.selectedLang !== null && this.selectedLang !== pg.locale) {
          return false
        }
        if (this.selectedState !== null && this.selectedState !== pg.isPublished) {
          return false
        }
        return true
      })
    },
    langs () {
      return _.concat({
        text: 'All Locales',
        value: null
      }, _.uniqBy(this.pages, 'locale').map(pg => ({
        text: pg.locale,
        value: pg.locale
      })))
125 126 127 128
    }
  },
  methods: {
    async refresh() {
129
      await this.$apollo.queries.pages.refetch()
130
      this.$store.commit('showNotification', {
131
        message: 'Page list has been refreshed.',
132 133 134
        style: 'success',
        icon: 'cached'
      })
135 136 137
    },
    newpage() {
      this.pageSelectorShown = true
Nick's avatar
Nick committed
138 139
    },
    recyclebin () { }
140 141 142 143 144 145 146 147 148 149 150
  },
  apollo: {
    pages: {
      query: pagesQuery,
      fetchPolicy: 'network-only',
      update: (data) => data.pages.list,
      watchLoading (isLoading) {
        this.loading = isLoading
        this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-pages-refresh')
      }
    }
151 152 153 154 155
  }
}
</script>

<style lang='scss'>
156 157 158 159
.admin-pages-path {
  display: flex;
  justify-content: flex-start;
  align-items: center;
160
  font-family: 'Roboto Mono', monospace;
161
}
162
</style>