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

[BI-1617] Refactor Ontology table to use Buefy #304

Merged
merged 25 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
50 changes: 12 additions & 38 deletions src/breeding-insight/dao/TraitDAO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import * as api from "@/util/api";
import {PaginationQuery} from "@/breeding-insight/model/PaginationQuery";
import {TraitFilter, TraitSelector} from "@/breeding-insight/model/TraitSelector";
import {OntologySort, SortOrder} from "@/breeding-insight/model/Sort";
import {Result, ResultGenerator} from "@/breeding-insight/model/Result";

export class TraitDAO {
private activeOntologySortOrder!: SortOrder;
Expand All @@ -47,43 +48,17 @@ export class TraitDAO {
}))
}

static getFilteredTraits(programId: string,
{page, pageSize}: PaginationQuery,
full: boolean,
sort: OntologySort,
filters?: TraitFilter[]): Promise<BiResponse> {
const config: any = {
params: {
full,
page,
pageSize,
sortField: sort.field,
sortOrder: sort.order
}
};

if (filters) {
//
// get filtered list of traits
config.url = `${process.env.VUE_APP_BI_API_V1_PATH}/programs/${programId}/traits/search`;
config.method = 'post';
config.data = new TraitSelector(filters);
} else {
// get all traits
config.url = `${process.env.VUE_APP_BI_API_V1_PATH}/programs/${programId}/traits`;
config.method = 'get';
}

return new Promise<BiResponse>(((resolve, reject) => {
api.call(config)
.then((response: any) => {
const biResponse = new BiResponse(response.data);
resolve(biResponse);
}).catch((error) => {
reject(error);
})

}))
static async getFilteredTraits(programId: string, params: object): Promise<Result<Error,BiResponse>> {
try {
const { data } = await api.call({
url: `${process.env.VUE_APP_BI_API_V1_PATH}/programs/${programId}/traits`,
method: 'get',
params
}) as Response;
return ResultGenerator.success(new BiResponse(data));
} catch (error) {
return ResultGenerator.err(error);
}
}

static async createTraits(programId: string, newTraits: Trait[]): Promise<BiResponse> {
Expand Down Expand Up @@ -129,5 +104,4 @@ export class TraitDAO {
}) as Response;
return new BiResponse(data);
}

}
16 changes: 13 additions & 3 deletions src/breeding-insight/model/Sort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* limitations under the License.
*/

import Ontology from "@/views/ontology/Ontology.vue";

export enum SortOrder {
Ascending = 'ASC',
Descending = 'DESC'
Expand Down Expand Up @@ -63,9 +65,17 @@ export class OntologySort {
field: OntologySortField;
order: SortOrder;

constructor(field: OntologySortField, order: SortOrder) {
this.field = field;
this.order = order;
constructor(field: string, order: SortOrder) {
this.field = OntologySortField.Name;
this.order = SortOrder.Ascending;
if (this.isSortField(field)) {
this.field = field;
this.order = order;
}
}

private isSortField(field: string): field is OntologySortField {
return Object.values(OntologySortField).includes(field);
}
}

Expand Down
21 changes: 19 additions & 2 deletions src/breeding-insight/model/TraitSelector.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {OntologySortField} from "@/breeding-insight/model/Sort";

export enum TraitField {
NAME = 'name',
MAIN_ABBREVIATION = 'mainAbbreviation',
Expand All @@ -7,6 +9,7 @@ export enum TraitField {
METHOD_DESCRIPTION = 'methodDescription',
METHOD_CLASS = 'methodClass',
METHOD_FORMULA = 'methodFormula',
METHOD_HANDLE = 'methodHandle',
SCALE_NAME = 'scaleName',
SCALE_CLASS = 'scaleClass',
SCALE_DECIMAL_PLACES = 'scaleDecimalPlaces',
Expand All @@ -19,7 +22,8 @@ export enum TraitField {
CREATED_BY_USER_NAME = 'createdByUserName',
UPDATED_BY_USER_ID = 'updatedByUserId',
UPDATED_BY_USER_NAME = 'updatedByUserName',
TERM_TYPE = 'termType'
TERM_TYPE = 'termType',
ENTITY_ATTRIBUTE = 'entityAttribute'
}

export enum TermType {
Expand All @@ -31,6 +35,17 @@ export enum TermType {
export class TraitFilter {
field?: TraitField;
value?: string | number | boolean;

constructor(field: string, value: any) {
if (this.isTraitField(field)) {
this.field = field;
this.value = value;
}
}

private isTraitField(field: string): field is TraitField {
return Object.values(TraitField).includes(field);
}
}

export class TraitSelector {
Expand All @@ -41,7 +56,9 @@ export class TraitSelector {
}

addFilter(filter: TraitFilter) {
this.filters.push(filter);
if (filter.field && filter.value !== '') {
this.filters.push(filter);
}
}

}
70 changes: 46 additions & 24 deletions src/breeding-insight/service/TraitService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@

import {TraitDAO} from "@/breeding-insight/dao/TraitDAO";
import {Trait} from "@/breeding-insight/model/Trait";
import {Metadata} from "@/breeding-insight/model/BiResponse";
import {BiResponse, Metadata, Response} from "@/breeding-insight/model/BiResponse";
import {PaginationQuery} from "@/breeding-insight/model/PaginationQuery";
import {ValidationErrorService} from "@/breeding-insight/service/ValidationErrorService";
import {TraitFilter} from "@/breeding-insight/model/TraitSelector";
import {TraitField, TraitFilter, TraitSelector} from "@/breeding-insight/model/TraitSelector";
import {OntologySort, OntologySortField, SortOrder} from "@/breeding-insight/model/Sort";
import * as api from "@/util/api";
import {Result, ResultGenerator} from "@/breeding-insight/model/Result";

export class TraitService {

Expand Down Expand Up @@ -114,32 +116,29 @@ export class TraitService {
}));
}

static getFilteredTraits(programId: string,
paginationQuery: PaginationQuery = new PaginationQuery(1, 50, true),
full: boolean = false,
filters?: TraitFilter[],
sort: OntologySort = new OntologySort(OntologySortField.Name, SortOrder.Ascending)): Promise<[Trait[], Metadata]> {
return new Promise<[Trait[], Metadata]>(((resolve, reject) => {

if (programId) {
TraitDAO.getFilteredTraits(programId, paginationQuery, full, sort, filters).then((biResponse) => {

let traits: Trait[] = [];
static async getTraits(programId: string,
sort: OntologySort,
pagination: {pageSize: number, page: number},
filters?: any): Promise<Result<Error, BiResponse>>{
if (!programId) {
throw 'Program ID required';
}

if (biResponse.result.data) {
traits = biResponse.result.data.map((trait: any) => {
return trait as Trait;
});
}
try {
let response: Result<Error, BiResponse> = await TraitDAO.getFilteredTraits(programId,
this.makeTraitParams(sort, pagination, filters));

resolve([traits, biResponse.metadata]);
if (response.isErr()) {
throw response.value;
}

}).catch((error) => reject(error));
return response.applyResult(biRes => {
return biRes;
});

} else {
reject();
}
}));
} catch (error) {
return ResultGenerator.err(error);
}
}

static async getTraitEditable(programId: string, traitId: string): Promise<[boolean, Metadata]> {
Expand Down Expand Up @@ -185,4 +184,27 @@ export class TraitService {
}
else throw 'Unable to get trait editable info';
}

private static makeTraitParams(sort: OntologySort, pagination: {pageSize: number, page: number}, filters?: any) {
let params: any = {};

if (filters) {
params = filters;
}
if (sort.field) {
params['sortField'] = sort.field;
}
if (sort.order) {
params['sortOrder'] = sort.order;
}
if (pagination.page || pagination.page == 0) { //have to account for 0-index pagination since 0 falsy
params ['page'] = pagination.page;
}
if (pagination.pageSize) {
params['pageSize'] = pagination.pageSize;
}
params.full = true;

return params;
}
}
1 change: 1 addition & 0 deletions src/components/germplasm/GermplasmTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export default class GermplasmTable extends Vue {
}

initSearch(filters: any) {

this.filters = filters;

// When filtering the list, set a page to the first page.
Expand Down
36 changes: 24 additions & 12 deletions src/components/ontology/OntologyActiveTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
<ontology-table
v-bind:active="true"
v-bind:ontologySort="activeOntologySort"
v-on:newSortColumn="newSortColumn"
v-on:toggleSortOrder="toggleSortOrder"
v-bind:ontologyFetch="ontologyFetch"
v-on:updateSort="updateSort"
@show-success-notification="$emit('show-success-notification', $event)"
@show-info-notification="$emit('show-info-notification', $event)"
@show-error-notification="$emit('show-error-notification', $event)"
Expand All @@ -31,12 +31,14 @@
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import OntologyTable from "@/components/ontology/OntologyTable.vue";
import {mapGetters, mapMutations} from 'vuex'
import {
ACTIVE_ONT_NEW_SORT_COLUMN,
ACTIVE_ONT_TOGGLE_SORT_ORDER
} from "@/store/sorting/mutation-types";
import {OntologySort, OntologySortField} from "@/breeding-insight/model/Sort";
import { mapGetters, mapMutations } from 'vuex'
import { UPDATE_ACTIVE_ONT_SORT } from "@/store/sorting/mutation-types";
import { OntologySort } from "@/breeding-insight/model/Sort";
import { BackendPaginationController } from "@/breeding-insight/model/view_models/BackendPaginationController";
import { BiResponse } from "@/breeding-insight/model/BiResponse";
import { TraitService } from '@/breeding-insight/service/TraitService';
import { TraitField } from '@/breeding-insight/model/TraitSelector';
import { Result } from '@/breeding-insight/model/Result';

@Component({
components: {OntologyTable},
Expand All @@ -47,16 +49,26 @@ import {OntologySort, OntologySortField} from "@/breeding-insight/model/Sort";
},
methods: {
...mapMutations('sorting', {
newSortColumn: ACTIVE_ONT_NEW_SORT_COLUMN,
toggleSortOrder: ACTIVE_ONT_TOGGLE_SORT_ORDER
updateSort: UPDATE_ACTIVE_ONT_SORT
})
}
})

export default class OntologyActiveTable extends Vue {

private activeOntologySort!: OntologySort;
private newSortColumn!: (field: OntologySortField) => void;
private toggleSortOrder!: () => void;

// Set the method used to populate the active ontology table
private ontologyFetch: (programId: string, sort: OntologySort, paginationController: BackendPaginationController) => (filters: any) => Promise<Result<Error, BiResponse>> =
function (programId: string, sort: OntologySort, paginationController: BackendPaginationController) {
return function (filters: any) {
filters[TraitField.STATUS] = true; // only request active traits
return TraitService.getTraits(
programId,
sort,
{ pageSize: paginationController.pageSize, page: paginationController.currentPage },
filters)
};
};
}
</script>
39 changes: 26 additions & 13 deletions src/components/ontology/OntologyArchivedTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
<ontology-table
v-bind:active="false"
v-bind:ontologySort="archivedOntologySort"
v-on:newSortColumn="newSortColumn"
v-on:toggleSortOrder="toggleSortOrder"
v-bind:ontologyFetch="ontologyFetch"
v-on:updateSort="updateSort"
@show-success-notification="$emit('show-success-notification', $event)"
@show-info-notification="$emit('show-info-notification', $event)"
@show-error-notification="$emit('show-error-notification', $event)"
Expand All @@ -29,14 +29,16 @@
</template>

<script lang="ts">
import { Prop, Component, Vue } from 'vue-property-decorator'
import { Component, Vue } from 'vue-property-decorator'
import OntologyTable from "@/components/ontology/OntologyTable.vue";
import {mapGetters, mapMutations} from 'vuex'
import {
ARCHIVED_ONT_NEW_SORT_COLUMN,
ARCHIVED_ONT_TOGGLE_SORT_ORDER
} from "@/store/sorting/mutation-types";
import {OntologySort, OntologySortField} from "@/breeding-insight/model/Sort";
import { mapGetters, mapMutations } from 'vuex'
import { UPDATE_ARCHIVED_ONT_SORT } from "@/store/sorting/mutation-types";
import { OntologySort } from "@/breeding-insight/model/Sort";
import { BackendPaginationController } from "@/breeding-insight/model/view_models/BackendPaginationController";
import { BiResponse } from "@/breeding-insight/model/BiResponse";
import { TraitField } from "@/breeding-insight/model/TraitSelector";
import {TraitService } from "@/breeding-insight/service/TraitService";
import { Result } from '@/breeding-insight/model/Result';


@Component({
Expand All @@ -48,15 +50,26 @@ import {OntologySort, OntologySortField} from "@/breeding-insight/model/Sort";
},
methods: {
...mapMutations('sorting', {
newSortColumn: ARCHIVED_ONT_NEW_SORT_COLUMN,
toggleSortOrder: ARCHIVED_ONT_TOGGLE_SORT_ORDER
updateSort: UPDATE_ARCHIVED_ONT_SORT
})
}
})
export default class OntologyArchivedTable extends Vue {

private archivedOntologySort!: OntologySort;
private newSortColumn!: (field: OntologySortField) => void;
private toggleSortOrder!: () => void;

// Set the method used to populate the archived ontology table
private ontologyFetch: (programId: string, sort: OntologySort, paginationController: BackendPaginationController) => (filters: any) => Promise<Result<Error, BiResponse>> =
function (programId: string, sort: OntologySort, paginationController: BackendPaginationController) {
return function (filters: any) {
filters[TraitField.STATUS] = false; // only request archived traits
return TraitService.getTraits(
programId,
sort,
{ pageSize: paginationController.pageSize, page: paginationController.currentPage },
filters)
};
};

}
</script>
Loading