admin-api.vue 4.41 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(src='/svg/icon-rest-api.svg', alt='API', style='width: 80px;')
7
          .admin-header-title
8
            .headline.blue--text.text--darken-2 API Access
9
            .subtitle-1.grey--text Manage keys to access the API #[v-chip(label, color='primary', small).white--text coming soon]
10
          v-spacer
11
          v-btn(outline, color='grey', large, @click='refresh', disabled)
12
            v-icon refresh
13
          v-btn(color='green', disabled, depressed, large, @click='globalSwitch')
14 15
            v-icon(left) power_settings_new
            | Enable API
16
          v-btn(color='primary', depressed, large, @click='newKey', disabled)
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
            v-icon(left) add
            | New API Key
        v-card.mt-3
          v-data-table(
            v-model='selected'
            :items='items',
            :headers='headers',
            :search='search',
            :pagination.sync='pagination',
            :rows-per-page-items='[15]'
            select-all,
            hide-actions,
            disable-initial-sort
          )
            template(slot='headers', slot-scope='props')
              tr
                th(width='50')
                th.text-xs-right(
                  width='80'
                  :class='[`column sortable`, pagination.descending ? `desc` : `asc`, pagination.sortBy === `id` ? `active` : ``]'
                  @click='changeSort(`id`)'
                )
                  v-icon(small) arrow_upward
                  | ID
                th.text-xs-left(
                  v-for='header in props.headers'
                  :key='header.text'
                  :width='header.width'
                  :class='[`column sortable`, pagination.descending ? `desc` : `asc`, header.value === pagination.sortBy ? `active` : ``]'
                  @click='changeSort(header.value)'
                )
                  | {{ header.text }}
                  v-icon(small) arrow_upward
            template(slot='items', slot-scope='props')
              tr(:active='props.selected')
                td
                  v-checkbox(hide-details, :input-value='props.selected', color='blue darken-2', @click='props.selected = !props.selected')
                td.text-xs-right {{ props.item.id }}
                td {{ props.item.name }}
                td {{ props.item.key }}
                td {{ props.item.createdOn }}
                td {{ props.item.updatedOn }}
                td: v-btn(icon): v-icon.grey--text.text--darken-1 more_horiz
            template(slot='no-data')
61
              v-alert.mt-3(icon='info', :value='true', outline, color='info') No API keys have been generated yet.
62 63
          .text-xs-center.py-2
            v-pagination(v-model='pagination.page', :length='pages')
64 65 66 67 68 69 70 71
</template>

<script>
export default {
  data() {
    return {
      selected: [],
      pagination: {},
72
      items: [],
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
      headers: [
        { text: 'Name', value: 'name' },
        { text: 'Key', value: 'key' },
        { text: 'Created On', value: 'createdOn' },
        { text: 'Updated On', value: 'updatedOn' },
        { text: '', value: 'actions', sortable: false, width: 50 }
      ],
      search: ''
    }
  },
  computed: {
    pages () {
      if (this.pagination.rowsPerPage == null || this.pagination.totalItems == null) {
        return 0
      }

      return Math.ceil(this.pagination.totalItems / this.pagination.rowsPerPage)
    }
  },
  methods: {
    changeSort (column) {
      if (this.pagination.sortBy === column) {
        this.pagination.descending = !this.pagination.descending
      } else {
        this.pagination.sortBy = column
        this.pagination.descending = false
      }
    },
    toggleAll () {
      if (this.selected.length) {
        this.selected = []
      } else {
        this.selected = this.items.slice()
      }
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
    },
    async refresh() {
      this.$store.commit('showNotification', {
        style: 'indigo',
        message: `Coming soon...`,
        icon: 'directions_boat'
      })
    },
    async globalSwitch() {
      this.$store.commit('showNotification', {
        style: 'indigo',
        message: `Coming soon...`,
        icon: 'directions_boat'
      })
    },
    async newKey() {
      this.$store.commit('showNotification', {
        style: 'indigo',
        message: `Coming soon...`,
        icon: 'directions_boat'
      })
128 129 130 131 132 133 134 135
    }
  }
}
</script>

<style lang='scss'>

</style>