Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds results table context #46

Merged
merged 2 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/store/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const useAppStore = defineStore('app', {
program_map: {},
carton_map: {},
db_info: {},
flat_db: {},
theme: '',
}),
actions: {
Expand Down Expand Up @@ -74,6 +75,15 @@ export const useAppStore = defineStore('app', {
is_allowed() {
// checks if a user is logged in or if the release is public
return this.logged_in || (!this.logged_in && this.release.startsWith("DR"))
},

get_field_from_db(column: string, field: string) {
// looks up a db column description from the flattened db metadata

// set default value to the column name if the field is display_name, otherwise null
let default_val = (this.flat_db[column] === undefined && field === 'display_name') ? column : null

return this.flat_db[column] ? this.flat_db[column][field] : default_val;
}

},
Expand Down
38 changes: 32 additions & 6 deletions src/views/Results.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<template>
<v-container fluid>
<v-row>
<v-col md=12>
<h1>Results</h1>
<v-row dense no-gutters class="d-flex align-center">
<v-col cols="auto" class="d-flex align-center">
<v-btn variant='plain' density="compact" @mouseover="dialog = true" icon="mdi-help-circle-outline"></v-btn>
<h1 class="ml-2">Results</h1>
</v-col>
</v-row>
<v-row dense>
Expand All @@ -23,6 +24,7 @@
</v-col>
</v-row>

<!-- results data table -->
<v-row dense>
<v-col md="12">
<v-data-table
Expand All @@ -38,6 +40,7 @@
density="compact"
:search="search"
>
<!-- table toolbar -->
<template v-slot:top>
<v-toolbar flat density="compact" color="surface">
<v-card color="surface" variant="flat" class="ma-1">
Expand All @@ -52,7 +55,7 @@
<v-spacer></v-spacer>
<v-text-field
v-model="search"
label="Filter results"
label="Filter table"
prepend-inner-icon="mdi-magnify"
single-line
variant="outlined"
Expand All @@ -63,6 +66,11 @@
</v-toolbar>
</template>

<!-- add hover tooltip to column ; retains column sorting -->
<template v-for="h in headers" v-slot:[`header.${h.key}`]="{ column }">
<span v-tippy="`${h.description}`">{{h.title}}</span>
</template>

<!-- adds a target page link to the sdss id column -->
<template v-slot:item.sdss_id="{ item }">
<router-link :to="{ name: 'target', params: { sdss_id: item.sdss_id } }" target="_blank">{{ item.sdss_id }}</router-link>
Expand Down Expand Up @@ -101,6 +109,24 @@
</v-col>
</v-row>
</v-container>

<!-- Results page help dialog window -->
<v-dialog v-model="dialog" max-width="500px">
<v-card>
<v-card-title class="text-h5">Information</v-card-title>
<v-divider class="mb-4"></v-divider>
<v-card-text>
Examine search results in the data-table on this page. Click on a column to sort the table.
Export the table, or subset, to a CSV or JSON file. Type in the Filter Box to filter
results by any row value.
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn color="primary" text @click="dialog = false">Close</v-btn>
</v-card-actions>
</v-card>
</v-dialog>

</template>

<script setup lang="ts">
Expand All @@ -120,6 +146,7 @@ const nodata = ref(false)
const msg = ref('')
const exportas = ref(null)
const search = ref('')
const dialog = ref(false)

// 315.014, 25.299 (one row)
// 278.232, 3.788, (19 rows) 0.05
Expand Down Expand Up @@ -331,8 +358,7 @@ onMounted(() => {
msg.value = 'No search results returned'
} else {
data.value = results
//headers.value = Object.keys(results.value[0]).map((name) => ({ title: name, key: name }))
headers.value = Object.entries(data.value[0]).map((item)=> ({title: item[0], key: item[0], type: typeof item[1]}))
headers.value = Object.entries(data.value[0]).map((item)=> ({title: store.get_field_from_db(item[0], 'display_name'), key: item[0], type: typeof item[1], description: store.get_field_from_db(item[0], 'description')}))
console.log('data', data.value)
console.log('headers', headers.value)

Expand Down
4 changes: 4 additions & 0 deletions src/views/Target.vue
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ async function get_db_info() {
console.log('db info', response.data)
// store the db metadata
store.db_info = response.data

// flatten the db_info object
store.flat_db = Object.fromEntries(Object.entries(store.db_info).flatMap(([schema, table])=>Object.entries(table)))

})
.catch((error) => {
console.error(error.toJSON())
Expand Down
Loading