admin-pages.vue 5.39 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='/_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
NGPixel's avatar
NGPixel committed
11
          v-btn.animated.fadeInDown.wait-p1s(icon, color='grey', outlined, @click='refresh')
12
            v-icon.grey--text mdi-refresh
NGPixel's avatar
NGPixel committed
13
          v-btn.animated.fadeInDown.mx-3(color='primary', outlined, @click='recyclebin', disabled)
14
            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
NGPixel's avatar
NGPixel committed
19 20
        v-card.mt-3.animated.fadeInUp
          .pa-2.d-flex.align-center(:class='$vuetify.theme.dark ? `grey darken-3-d5` : `grey lighten-3`')
21
            v-text-field(
NGPixel's avatar
NGPixel committed
22 23
              solo
              flat
24
              v-model='search'
25
              prepend-inner-icon='mdi-file-search-outline'
26 27
              label='Search Pages...'
              hide-details
NGPixel's avatar
NGPixel committed
28 29
              dense
              style='max-width: 400px;'
30
              )
NGPixel's avatar
NGPixel committed
31
            v-spacer
32
            v-select.ml-2(
NGPixel's avatar
NGPixel committed
33 34
              solo
              flat
35
              hide-details
NGPixel's avatar
NGPixel committed
36
              dense
37
              label='Locale'
38 39
              :items='langs'
              v-model='selectedLang'
NGPixel's avatar
NGPixel committed
40
              style='max-width: 250px;'
41 42
            )
            v-select.ml-2(
NGPixel's avatar
NGPixel committed
43 44
              solo
              flat
45
              hide-details
NGPixel's avatar
NGPixel committed
46
              dense
47
              label='Publish State'
48 49
              :items='states'
              v-model='selectedState'
NGPixel's avatar
NGPixel committed
50
              style='max-width: 250px;'
51 52
            )
          v-divider
53
          v-data-table(
54
            :items='filteredPages'
55 56
            :headers='headers'
            :search='search'
57 58
            :page.sync='pagination'
            :items-per-page='15'
59 60
            :loading='loading'
            must-sort,
61 62
            sort-by='updatedAt',
            sort-desc,
63
            hide-default-footer
64
          )
65
            template(slot='item', slot-scope='props')
66
              tr.is-clickable(:active='props.selected', @click='$router.push(`/pages/` + props.item.id)')
67
                td.text-xs-right {{ props.item.id }}
68
                td
69
                  .body-2: strong {{ props.item.title }}
70 71
                  .caption {{ props.item.description }}
                td.admin-pages-path
72
                  v-chip(label, small, :color='$vuetify.theme.dark ? `grey darken-4` : `grey lighten-4`') {{ props.item.locale }}
73
                  span.ml-2.grey--text(:class='$vuetify.theme.dark ? `text--lighten-1` : `text--darken-2`') / {{ props.item.path }}
74 75 76
                td {{ props.item.createdAt | moment('calendar') }}
                td {{ props.item.updatedAt | moment('calendar') }}
            template(slot='no-data')
77
              v-alert.ma-3(icon='mdi-alert', :value='true', outlined) No pages to display.
78
          .text-center.py-2.animated.fadeInDown(v-if='this.pageTotal > 1')
79
            v-pagination(v-model='pagination', :length='pageTotal')
80 81 82
</template>

<script>
83
import _ from 'lodash'
84
import pagesQuery from 'gql/admin/pages/pages-query-list.gql'
85 86 87 88

export default {
  data() {
    return {
89
      selectedPage: {},
90
      pagination: 1,
91
      pages: [],
92
      headers: [
93
        { text: 'ID', value: 'id', width: 80, sortable: true },
94 95 96 97 98
        { text: 'Title', value: 'title' },
        { text: 'Path', value: 'path' },
        { text: 'Created', value: 'createdAt', width: 250 },
        { text: 'Last Updated', value: 'updatedAt', width: 250 }
      ],
99
      search: '',
100 101 102 103 104 105 106
      selectedLang: null,
      selectedState: null,
      states: [
        { text: 'All Publishing States', value: null },
        { text: 'Published', value: true },
        { text: 'Not Published', value: false }
      ],
107
      loading: false
108 109 110
    }
  },
  computed: {
111
    pageTotal () {
112
      return Math.ceil(this.filteredPages.length / 15)
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
    },
    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
      })))
133 134 135 136
    }
  },
  methods: {
    async refresh() {
137
      await this.$apollo.queries.pages.refetch()
138
      this.$store.commit('showNotification', {
139
        message: 'Page list has been refreshed.',
140 141 142
        style: 'success',
        icon: 'cached'
      })
143 144 145
    },
    newpage() {
      this.pageSelectorShown = true
Nick's avatar
Nick committed
146 147
    },
    recyclebin () { }
148 149 150 151 152 153 154 155 156 157 158
  },
  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')
      }
    }
159 160 161 162 163
  }
}
</script>

<style lang='scss'>
164 165 166 167
.admin-pages-path {
  display: flex;
  justify-content: flex-start;
  align-items: center;
168
  font-family: 'Roboto Mono', monospace;
169
}
170
</style>