Skip to content

Commit

Permalink
fix(VariableGroup): Fixed being able to use variable selector with fi…
Browse files Browse the repository at this point in the history
…lters for VariableGroup update form

OpenSILEX/opensilex-dev!1272
  • Loading branch information
HART Maximilian committed Aug 9, 2024
1 parent 5191849 commit 9aec29f
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import {Component, Prop, PropSync, Ref} from "vue-property-decorator";
import Vue from "vue";
import SelectForm, {SelectableItem} from '../common/forms/SelectForm.vue';
import {GermplasmService} from "opensilex-core/api/germplasm.service";
import OpenSilexVuePlugin from "../../models/OpenSilexVuePlugin";
@Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ export default class GermplasmGroup extends Vue {
showEditForm(uri) {
this.service.getGermplasmGroupWithGermplasms(uri).then((http: HttpResponse<OpenSilexResponse<GermplasmGroupGetWithDetailsDTO>>) => {
this.$nextTick(() => {
let updateDtoAndExtractedGermplasms = this.convertUpdateDtoAndExtractGermplasms(http.response.result);
this.groupGermplasmForm.setSelectorsToFirstTimeOpenAndSetLabels(updateDtoAndExtractedGermplasms.germplasmModels);
let updateDtoAndExtractedGermplasms = this.convertUpdateDtoAndExtractGermplasms(http.response.result);
this.groupGermplasmForm.setSelectorsToFirstTimeOpenAndSetLabels(updateDtoAndExtractedGermplasms.germplasmModels);
this.groupGermplasmForm.showEditForm(updateDtoAndExtractedGermplasms.updateDto);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import {Component, Prop, Ref} from "vue-property-decorator";
import Vue from "vue";
import GermplasmSelectorWithFilter from '../germplasm/GermplasmSelectorWithFilter.vue';
import {GermplasmGroupUpdateDTO} from "../../../../../opensilex-core/front/src/lib";
import {SelectableItem} from "../common/forms/SelectForm.vue";
import {GermplasmGetAllDTO} from "opensilex-core/model/germplasmGetAllDTO";
Expand All @@ -65,7 +64,7 @@ export default class GroupGermplasmForm extends Vue {
@Ref("germplasmSelector") readonly germplasmSelector!: GermplasmSelectorWithFilter;
germplasmsWithLabels : Array<GermplasmGetAllDTO>;
germplasmsWithLabels : Array<GermplasmGetAllDTO>;
setSelectorsToFirstTimeOpenAndSetLabels(germplasmsWithLabels){
this.germplasmSelector.setGermplasmSelectorToFirstTimeOpen();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,12 @@

<!-- Variables -->

<!-- We use the old VariableSelector in editMode because of the edit bug -->
<opensilex-VariableSelector
v-if="editMode"
label="DataView.filter.variables"
:variables.sync="form.variables"
:multiple="true"
></opensilex-VariableSelector>

<opensilex-VariableSelectorWithFilter
v-else
ref="variablesSelectorRef"
placeholder="VariableSelectorWithFilter.placeholder-multiple"
:variables.sync="form.variables"
:variablesWithLabels="variablesWithLabels"
:editMode="this.editMode"
@hideSelector='$emit("hideSelector")'
@shownSelector='$emit("shownSelector")'
></opensilex-VariableSelectorWithFilter>
Expand All @@ -56,6 +50,8 @@ import OpenSilexVuePlugin from "../../models/OpenSilexVuePlugin";
import {VariablesService} from "opensilex-core/api/variables.service";
import {VariablesGroupCreationDTO} from "opensilex-core/model/variablesGroupCreationDTO";
import {VariablesGroupUpdateDTO} from "opensilex-core/model/variablesGroupUpdateDTO";
import VariableSelectorWithFilter from "../../components/variables/views/VariableSelectorWithFilter.vue";
import {NamedResourceDTOVariableModel} from "opensilex-core/model/namedResourceDTOVariableModel";
@Component
Expand All @@ -71,6 +67,7 @@ export default class GroupVariablesForm extends Vue {
uriGenerated;
@Ref("validatorRef") readonly validatorRef!: any;
@Ref("variablesSelectorRef") readonly variablesSelectorRef!: VariableSelectorWithFilter;
get user() {
return this.$store.state.user;
Expand All @@ -79,6 +76,13 @@ export default class GroupVariablesForm extends Vue {
@Prop()
form;
variablesWithLabels : Array<NamedResourceDTOVariableModel> = [];
setSelectorsToFirstTimeOpenAndSetLabels(variablesWithLabels){
this.variablesSelectorRef.setVariableSelectorToFirstTimeOpen();
this.variablesWithLabels = variablesWithLabels;
}
static getEmptyForm(){
return {
uri: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,10 @@ export default class VariableList extends Vue {
this.groupVariableSelection.show();
}
setInitiallySelectedItems(initiallySelectedItems:any){
this.tableRef.setInitiallySelectedItems(initiallySelectedItems);
}
private variableGroupsList = {};
loadVariablesGroupFromVariable(data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ export default class VariableModalList extends Vue {
this.variableSelection.onItemUnselected(row);
}
setInitiallySelectedItems(initiallySelectedItems:Array<any>){
this.variableSelection.setInitiallySelectedItems(initiallySelectedItems);
}
show() {
this.$emit("shown");
this.modalRef.show();
Expand Down
28 changes: 22 additions & 6 deletions opensilex-front/front/src/components/variables/VariablesView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,13 @@ import DTOConverter from "../../models/DTOConverter";
import {VariablesGroupCreationDTO} from "opensilex-core/model/variablesGroupCreationDTO";
import {VariablesGroupUpdateDTO} from "opensilex-core/model/variablesGroupUpdateDTO";
import GroupVariablesForm from "../groupVariable/GroupVariablesForm.vue";
import {VariablesGroupGetDTO} from "opensilex-core/model/variablesGroupGetDTO";
import {NamedResourceDTOVariableModel} from "opensilex-core/model/namedResourceDTOVariableModel";

interface GroupUpdateDtoAndVariableModels {
updateDto: VariablesGroupUpdateDTO,
variableModels: Array<NamedResourceDTOVariableModel>
}

@Component
export default class VariablesView extends Vue {
Expand Down Expand Up @@ -429,23 +435,33 @@ export default class VariablesView extends Vue {
}
}

formatVariablesGroup(dto : any) {
formatVariablesGroup(dto : VariablesGroupGetDTO) : GroupUpdateDtoAndVariableModels{
let copy = JSON.parse(JSON.stringify(dto));
if (copy.variables) {
copy.variables = copy.variables.map(variable => variable.uri);
let variables_uris : Array<String> = [];
let new_variable_list : Array<NamedResourceDTOVariableModel>= [];
if (copy.variables) {
for(let variable of copy.variables){
let variableUri = this.$opensilex.getLongUri(variable.uri);
variables_uris.push(variableUri);
variable.uri = variableUri;
new_variable_list.push(variable);
}
return copy;
copy.variables = variables_uris;
}
return {updateDto : (copy as VariablesGroupUpdateDTO), variableModels : new_variable_list};
}


showEditForm(dto : any){
if (this.elementType == VariablesView.GROUP_VARIABLE_TYPE) {

// ensure that the group form component is loaded
this.loadGroupForm = true;
this.$nextTick(() => {

let formatVariableGroup = this.formatVariablesGroup(dto);
this.getForm().showEditForm(formatVariableGroup);
let updateDtoAndExtractedVariables = this.formatVariablesGroup(dto);
this.getForm().setSelectorsToFirstTimeOpenAndSetLabels(updateDtoAndExtractedVariables.variableModels);
this.getForm().showEditForm(updateDtoAndExtractedVariables.updateDto);
});
}
else{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
:label="label"
:placeholder="placeholder"
:selected.sync="variablesURI"
:selectedInJsonFormat="this.editMode ? variablesAsSelectableItems : null"
:experiment="experiment"
:objects="objects"
:devices="devices"
Expand All @@ -13,7 +14,7 @@
:multiple="true"
:maximumSelectedItems="maximumSelectedRows"
:withAssociatedData="withAssociatedData"
:limit="1"
:limit="4"
@clear="refreshVariableSelector"
@select="select"
@deselect="deselect"
Expand All @@ -28,17 +29,26 @@ import { Component, Prop, PropSync, Ref } from "vue-property-decorator";
import Vue from "vue";
// @ts-ignore
import { NamedResourceDTO, VariableDetailsDTO } from "opensilex-core/index";
import HttpResponse, {OpenSilexResponse} from "opensilex-core/HttpResponse"
import {SelectableItem} from '../../common/forms/SelectForm.vue';
import SelectForm from "../../common/forms/SelectForm.vue";
@Component
export default class VariableSelectorWithFilter extends Vue {
$opensilex: any;
@Ref("variableSelector") readonly variableSelector!: any;
@Ref("variableSelector") readonly variableSelector!: SelectForm;
@PropSync("variables")
variablesURI;
//Needed if elements were already present to correctly show their labels
@PropSync("variablesWithLabels")
variablesAsSelectableItems: Array<SelectableItem>;
//To say if some elements can already be present when we open this selector
@Prop()
editMode: boolean;
@Prop()
placeholder;
Expand Down Expand Up @@ -75,6 +85,11 @@ export default class VariableSelectorWithFilter extends Vue {
this.$emit("validate", value);
}
//Function to load in the already present variables if this is the first time we are opening this selector
setVariableSelectorToFirstTimeOpen(){
this.variableSelector.setSelectorToFirstTimeOpen();
}
refreshVariableSelector() {
this.variableSelector.refreshModalSearch();
}
Expand Down

0 comments on commit 9aec29f

Please sign in to comment.