|
| 1 | +<!-- |
| 2 | + - See the NOTICE file distributed with this work for additional information |
| 3 | + - regarding copyright ownership. |
| 4 | + - |
| 5 | + - Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + - you may not use this file except in compliance with the License. |
| 7 | + - You may obtain a copy of the License at |
| 8 | + - |
| 9 | + - http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + - |
| 11 | + - Unless required by applicable law or agreed to in writing, software |
| 12 | + - distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + - See the License for the specific language governing permissions and |
| 15 | + - limitations under the License. |
| 16 | + --> |
| 17 | + |
| 18 | +<template> |
| 19 | + <section id="experimentsObservationsTableLabel"> |
| 20 | + |
| 21 | + <div class="is-clearfix"></div> |
| 22 | + |
| 23 | + <ExpandableTable |
| 24 | + v-bind:records.sync="experiments" |
| 25 | + v-bind:loading="this.experimentsLoading" |
| 26 | + v-bind:pagination="experimentsPagination" |
| 27 | + v-on:show-error-notification="$emit('show-error-notification', $event)" |
| 28 | + v-on:paginate="paginationController.updatePage($event)" |
| 29 | + v-on:paginate-toggle-all="paginationController.toggleShowAll()" |
| 30 | + v-on:paginate-page-size="paginationController.updatePageSize($event)" |
| 31 | + > |
| 32 | + <b-table-column label="Title" cell-class="fixed-width-wrapped" sortable v-slot="props" :th-attrs="(column) => ({scope:'col'})"> |
| 33 | + {{ props.row.data.trialName }} |
| 34 | + </b-table-column> |
| 35 | + <b-table-column label="Status" sortable v-slot="props" :th-attrs="(column) => ({scope:'col'})"> |
| 36 | + {{ getStatus(props.row.data.active) }} |
| 37 | + </b-table-column> |
| 38 | + <b-table-column label="Date Created" sortable v-slot="props" :th-attrs="(column) => ({scope:'col'})"> |
| 39 | + {{ }} |
| 40 | + </b-table-column> |
| 41 | + <b-table-column label="Created By" sortable v-slot="props" :th-attrs="(column) => ({scope:'col'})"> |
| 42 | + {{ }} |
| 43 | + </b-table-column> |
| 44 | + <b-table-column label="Datasets" cell-class="fixed-width-wrapped" sortable v-slot="props" :th-attrs="(column) => ({scope:'col'})"> |
| 45 | + <template v-for="dataset in props.row.data.additionalInfo.datasets"> |
| 46 | + <span v-bind:key="dataset" class="tag is-info is-normal mr-1">{{ dataset }}</span> |
| 47 | + </template> |
| 48 | + </b-table-column> |
| 49 | + <b-table-column field="data.listDbId" sortable v-slot="props" :th-attrs="(column) => ({scope:'col'})"> |
| 50 | + <a href="#" v-on:click="activateExtensionSelect(props.row.data.listDbId)"> |
| 51 | + Download |
| 52 | + </a> |
| 53 | + </b-table-column> |
| 54 | + |
| 55 | + <template v-slot:emptyMessage> |
| 56 | + <p class="has-text-weight-bold"> |
| 57 | + No experiments and observations are currently defined for this program. |
| 58 | + </p> |
| 59 | + </template> |
| 60 | + </ExpandableTable> |
| 61 | + </section> |
| 62 | +</template> |
| 63 | + |
| 64 | +<script lang="ts"> |
| 65 | +import {Component, Prop, Vue, Watch} from 'vue-property-decorator' |
| 66 | +import {validationMixin} from 'vuelidate'; |
| 67 | +import { mapGetters } from 'vuex' |
| 68 | +import {Program} from "@/breeding-insight/model/Program"; |
| 69 | +import {TrialService} from "@/breeding-insight/service/TrialService"; |
| 70 | +import EmptyTableMessage from "@/components/tables/EmtpyTableMessage.vue"; |
| 71 | +import TableColumn from "@/components/tables/TableColumn.vue"; |
| 72 | +import {Metadata, Pagination} from "@/breeding-insight/model/BiResponse"; |
| 73 | +import {PaginationController} from "@/breeding-insight/model/view_models/PaginationController"; |
| 74 | +import {PaginationQuery} from "@/breeding-insight/model/PaginationQuery"; |
| 75 | +import {Trial} from '@/breeding-insight/model/Trial' |
| 76 | +import {Result, Err, Success, ResultGenerator } from "@/breeding-insight/model/Result"; |
| 77 | +import ExpandableTable from '@/components/tables/expandableTable/ExpandableTable.vue'; |
| 78 | +import {FileType} from "@/breeding-insight/model/FileType"; |
| 79 | +import SelectModal from "@/components/modals/SelectModal.vue"; |
| 80 | +
|
| 81 | +@Component({ |
| 82 | + mixins: [validationMixin], |
| 83 | + components: { ExpandableTable, EmptyTableMessage, TableColumn, SelectModal}, |
| 84 | + computed: { |
| 85 | + ...mapGetters([ |
| 86 | + 'activeProgram' |
| 87 | + ]) |
| 88 | + } |
| 89 | +}) |
| 90 | +export default class ExperimentsObservationsTable extends Vue { |
| 91 | +
|
| 92 | + private activeProgram?: Program; |
| 93 | + private experiments: Trial[] = []; |
| 94 | + private experimentsPagination?: Pagination = new Pagination(); |
| 95 | + private programName: string = "Program Name"; |
| 96 | +
|
| 97 | + private experimentsLoading = true; |
| 98 | +
|
| 99 | + private paginationController: PaginationController = new PaginationController(); |
| 100 | +
|
| 101 | + private experimentDownloadTitle = 'Download Experiment'; |
| 102 | + private experimentDownloadSubtitle = 'File Format'; |
| 103 | + private modalActive: boolean = false; |
| 104 | + //private fileExtension: string; |
| 105 | + //private selectedExperimentDbId: string; |
| 106 | + private fileOptions = Object.values(FileType); |
| 107 | +
|
| 108 | + mounted() { |
| 109 | + this.getExperiments(); |
| 110 | + } |
| 111 | +
|
| 112 | + @Watch('paginationController', { deep: true}) |
| 113 | + async getExperiments() { |
| 114 | + let paginationQuery: PaginationQuery = PaginationController.getPaginationSelections( |
| 115 | + this.paginationController.currentPage, |
| 116 | + this.paginationController.pageSize, |
| 117 | + this.paginationController.showAll); |
| 118 | +
|
| 119 | + this.paginationController.setCurrentCall(paginationQuery); |
| 120 | +
|
| 121 | + try { |
| 122 | + const response: Result<Error, [Trial[], Metadata]> = await TrialService.getAll(this.activeProgram!.id!, paginationQuery); |
| 123 | + if(response.isErr()) throw response.value; |
| 124 | + let [experiments, metadata] = response.value; |
| 125 | +
|
| 126 | + if (this.paginationController.matchesCurrentRequest(metadata.pagination)) { |
| 127 | + this.experiments = experiments; |
| 128 | + this.experimentsPagination = metadata.pagination; |
| 129 | + } |
| 130 | + } catch (err) { |
| 131 | + // Display error that experiments cannot be loaded |
| 132 | + this.$emit('show-error-notification', 'Error while trying to load experiments'); |
| 133 | + } finally { |
| 134 | + this.experimentsLoading=false; |
| 135 | + } |
| 136 | + } |
| 137 | +
|
| 138 | + activateExtensionSelect(experimentDbId: string){ |
| 139 | + this.modalActive = true; |
| 140 | + this.selectedExperimentDbId = experimentDbId; |
| 141 | + } |
| 142 | +
|
| 143 | + cancelDownload(){ |
| 144 | + this.modalActive = false; |
| 145 | + this.selectedExperimentDbId = ""; |
| 146 | + this.fileExtension = ""; |
| 147 | + } |
| 148 | +
|
| 149 | + setFileExtension(value){ |
| 150 | + this.fileExtension = value; |
| 151 | + } |
| 152 | +
|
| 153 | + getStatus(active){ |
| 154 | + if (active) { |
| 155 | + return "active"; |
| 156 | + } else { |
| 157 | + return "archived"; |
| 158 | + } |
| 159 | + } |
| 160 | +
|
| 161 | +} |
| 162 | +
|
| 163 | +</script> |
0 commit comments