admin-users.vue 5.07 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
Nick's avatar
Nick committed
6
          img.animated.fadeInUp(src='/svg/icon-customer.svg', alt='Users', style='width: 80px;')
7
          .admin-header-title
Nick's avatar
Nick committed
8
            .headline.blue--text.text--darken-2.animated.fadeInLeft Users
9
            .subtitle-1.grey--text.animated.fadeInLeft.wait-p2s Manage users
10
          v-spacer
11 12 13 14
          v-btn.animated.fadeInDown.wait-p2s.mr-3(outlined, color='grey', large, @click='refresh')
            v-icon mdi-refresh
          v-btn.animated.fadeInDown(color='primary', large, depressed, @click='createUser')
            v-icon(left) mdi-plus
15
            span New User
Nick's avatar
Nick committed
16
        v-card.wiki-form.mt-3.animated.fadeInUp
17
          v-toolbar(flat, :color='$vuetify.theme.dark ? `grey darken-3-d5` : `grey lighten-5`', height='80')
Nick's avatar
Nick committed
18 19
            v-spacer
            v-text-field(
20
              outlined
Nick's avatar
Nick committed
21
              v-model='search'
22
              prepend-inner-icon='mdi-account-search-outline'
Nick's avatar
Nick committed
23 24 25 26
              label='Search Users...'
              hide-details
              )
            v-select.ml-2(
27
              outlined
Nick's avatar
Nick committed
28 29 30 31 32 33 34 35 36
              hide-details
              label='Identity Provider'
              :items='strategies'
              v-model='filterStrategy'
              item-text='title'
              item-value='key'
            )
            v-spacer
          v-divider
37 38
          v-data-table(
            v-model='selected'
Nick's avatar
Nick committed
39
            :items='usersFiltered',
40 41
            :headers='headers',
            :search='search',
42 43
            :page.sync='pagination'
            :items-per-page='15'
Nick's avatar
Nick committed
44
            :loading='loading'
45 46 47 48
            @page-count='pageCount = $event'
            hide-default-footer
            )
            template(slot='item', slot-scope='props')
49
              tr.is-clickable(:active='props.selected', @click='$router.push("/users/" + props.item.id)')
50
                //- td
51
                  v-checkbox(hide-details, :input-value='props.selected', color='blue darken-2', @click='props.selected = !props.selected')
52
                td {{ props.item.id }}
53
                td: strong {{ props.item.name }}
54
                td {{ props.item.email }}
55 56 57
                td {{ props.item.providerKey }}
                td {{ props.item.createdAt | moment('from') }}
                td
58
                  v-tooltip(left, v-if='props.item.isSystem')
59 60
                    template(v-slot:activator='{ on }')
                      v-icon(v-on='{ on }') mdi-lock-outline
61
                    span System User
62
            template(slot='no-data')
63
              .pa-3
64 65 66
                v-alert.text-left(icon='mdi-alert', outlined, color='grey')
                  em.body-2 No users to display!
          v-card-chin(v-if='pageCount > 1')
67
            v-spacer
68
            v-pagination(v-model='pagination', :length='pageCount')
69
            v-spacer
70

71
    user-create(v-model='isCreateDialogShown', @refresh='refresh(false)')
72 73 74
</template>

<script>
Nick's avatar
Nick committed
75 76
import _ from 'lodash'

77
import usersQuery from 'gql/admin/users/users-query-list.gql'
Nick's avatar
Nick committed
78
import providersQuery from 'gql/admin/users/users-query-strategies.gql'
79 80 81

import UserCreate from './admin-users-create.vue'

82
export default {
83 84 85
  components: {
    UserCreate
  },
86 87 88
  data() {
    return {
      selected: [],
89 90
      pagination: 1,
      pageCount: 0,
91
      users: [],
92
      headers: [
93 94 95 96 97
        { text: 'ID', value: 'id', width: 80, sortable: true },
        { text: 'Name', value: 'name', sortable: true },
        { text: 'Email', value: 'email', sortable: true },
        { text: 'Provider', value: 'provider', sortable: true },
        { text: 'Created', value: 'createdAt', sortable: true },
98
        { text: '', value: 'actions', sortable: false, width: 50 }
99
      ],
Nick's avatar
Nick committed
100 101
      strategies: [],
      filterStrategy: 'all',
102
      search: '',
Nick's avatar
Nick committed
103
      loading: false,
104
      isCreateDialogShown: false
105 106 107
    }
  },
  computed: {
Nick's avatar
Nick committed
108 109 110
    usersFiltered () {
      const all = this.filterStrategy === 'all' || this.filterStrategy === ''
      return _.filter(this.users, u => all || u.providerKey === this.filterStrategy)
111
    }
112 113
  },
  methods: {
114 115 116
    createUser() {
      this.isCreateDialogShown = true
    },
117
    async refresh(notify = true) {
118
      await this.$apollo.queries.users.refetch()
119 120 121 122 123 124
      if (notify) {
        this.$store.commit('showNotification', {
          message: 'Users list has been refreshed.',
          style: 'success',
          icon: 'cached'
        })
125 126
      }
    }
127 128 129 130 131 132 133
  },
  apollo: {
    users: {
      query: usersQuery,
      fetchPolicy: 'network-only',
      update: (data) => data.users.list,
      watchLoading (isLoading) {
Nick's avatar
Nick committed
134
        this.loading = isLoading
135 136
        this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-users-refresh')
      }
Nick's avatar
Nick committed
137 138 139 140 141 142 143 144 145 146 147 148 149
    },
    strategies: {
      query: providersQuery,
      fetchPolicy: 'network-only',
      update: (data) => {
        return _.concat({
          key: 'all',
          title: 'All'
        }, data.authentication.strategies)
      },
      watchLoading (isLoading) {
        this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-users-strategies-refresh')
      }
150
    }
151 152 153 154 155 156 157
  }
}
</script>

<style lang='scss'>

</style>