Skip to content
Snippets Groups Projects
Select Git revision
  • d6ffc27432bb80fbfab1a5413e270b8da37d10fe
  • master default protected
  • dev protected
  • replication_test
  • release-1.10 protected
  • release-1.9 protected
  • 551-init-broker-service-permissions
  • 549-test-oai-pmh
  • 545-saving-multiple-times-breaks-pid-metadata
  • 499-standalone-compute-service-2
  • 539-load-tests
  • hotfix/helm-chart
  • luca_ba_new_interface
  • 534-bug-when-adding-access-to-user-that-is-not-registered-at-dashboard-service
  • release-1.8 protected
  • 533-integrate-semantic-recommendation
  • feature/openshift
  • 518-spark-doesn-t-map-the-headers-correct
  • 485-fixity-checks
  • 530-various-schema-problems-with-subsets
  • release-1.7 protected
  • v1.10.2 protected
  • v1.10.1 protected
  • v1.10.0-rc13 protected
  • v1.10.0-rc12 protected
  • v1.10.0-rc11 protected
  • v1.10.0-rc10 protected
  • v1.10.0-rc9 protected
  • v1.10.0-rc8 protected
  • v1.10.0-rc7 protected
  • v1.10.0-rc6 protected
  • v1.10.0-rc5 protected
  • v1.10.0-rc4 protected
  • v1.10.0-rc3 protected
  • v1.10.0-rc2 protected
  • v1.10.0rc1 protected
  • v1.10.0rc0 protected
  • v1.10.0 protected
  • v1.9.3 protected
  • v1.9.2 protected
  • v1.9.2-rc0 protected
41 results

Results.vue

Blame
  • Results.vue 3.56 KiB
    <template>
      <v-data-table
        :headers="result.headers"
        :items="result.rows"
        :loading="loading"
        :options.sync="options"
        :server-items-length="total"
        class="elevation-1" />
    </template>
    
    <script>
    import _ from 'lodash'
    
    export default {
      props: {
        value: { type: Number, default: () => 0 }
      },
      data () {
        return {
          parent: null,
          loading: false,
          result: {
            headers: [],
            rows: []
          },
          options: {
            page: 1,
            itemsPerPage: 10
          },
          total: 0
        }
      },
      computed: {
        token () {
          return this.$store.state.token
        },
        headers () {
          if (this.token === null) {
            return null
          }
          return { Authorization: `Bearer ${this.token}` }
        }
      },
      watch: {
        value () {
          if (this.value) {
            this.execute()
          }
        },
        options (newVal, oldVal) {
          if (typeof oldVal.groupBy === 'undefined') {
            // initially, options do not have the groupBy field.
            // don't run the execute method twice, when a new query is created
            return
          }
          if (!this.value) {
            this.$toast.error('Cannot paginate invalidated Query: press Execute')
            return
          }
          this.execute()
        }
      },
      mounted () {
      },
      methods: {
        async executeFirstTime (parent) {
          this.parent = parent
          this.loading = true
          try {
            const data = {
              statement: this.parent.query.sql,
              tables: [_.pick(this.parent.table, ['id', 'name', 'internal_name'])],
              columns: [this.parent.select.map(function (column) {
                return _.pick(column, ['id', 'name', 'internal_name'])
              })]
            }
            console.debug('send data', data)
            const page = 0
            const urlParams = `page=${page}&size=${this.options.itemsPerPage}`
            const res = await this.$axios.put(`/api/container/
    ${this.$route.params.container_id}/database/${this.$route.params.database_id}/query
    ${this.parent.queryId ? `/${this.parent.queryId}` : ''}
    ?${urlParams}`, data, {
              headers: this.headers
            })
            console.debug('query result', res)
            this.$toast.success('Successfully executed query')
            this.loading = false
            this.parent.queryId = res.data.id
            this.result.headers = this.parent.select.map((s) => {
              return { text: s.name, value: s.name, sortable: false }
            })
            this.result.rows = res.data.result
            this.total = res.data.resultNumber
          } catch (err) {
            console.error('query execute', err)
            this.$toast.error('Could not execute query')
            this.loading = false
          }
        },
        buildHeaders (firstLine) {
          return Object.keys(firstLine).map(k => ({
            text: k,
            value: k,
            sortable: false
          }))
        },
        async execute () {
          this.loading = true
          try {
            const page = this.options.page - 1
            const urlParams = `page=${page}&size=${this.options.itemsPerPage}`
            const res = await this.$axios.put(`/api/container/
    ${this.$route.params.container_id}/database/${this.$route.params.database_id}/query
    /${this.value}
    ?${urlParams}`, {}, {
              headers: this.headers
            })
            this.loading = false
            if (res.data.result.length) {
              this.result.headers = this.buildHeaders(res.data.result[0])
            }
            this.result.rows = res.data.result
            this.total = res.data.resultNumber
          } catch (err) {
            console.error('query execute', err)
            this.$toast.error('Could not execute query')
            this.loading = false
          }
        }
      }
    }
    </script>
    
    <style scoped>
    </style>