Skip to content

Commit

Permalink
Merge pull request #2460 from FAIRsharing/new_registry_2458
Browse files Browse the repository at this point in the history
New registry 2458
  • Loading branch information
knirirr authored Feb 4, 2025
2 parents 7425f8e + 5b2cecc commit a5aa988
Show file tree
Hide file tree
Showing 10 changed files with 301 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ <h1 class="page-title">Source: components/Records/Record/RelatedContent.vue</h1>
if (_module.currentRecord['fairsharingRecord'].registry === 'Policy') {
_module.$set(_module.tabsData.tabs, 'related_collections', {registry: ["Collection"], data: [], count:0});
}
if (_module.currentRecord['fairsharingRecord'].registry === 'FAIRassist' ||
_module.currentRecord['fairsharingRecord'].registry === 'Standard') {
_module.$set(_module.tabsData.tabs, 'related_fairassist_components', {registry: ["FAIRassist"], data: [], count:0});
}
if (Object.keys(_module.currentRecord['fairsharingRecord']).includes('recordAssociations') ||
Object.keys(_module.currentRecord['fairsharingRecord']).includes('reverseRecordAssociations')) {
Object.keys(_module.tabsData.tabs).forEach(tabName => {
Expand Down
2 changes: 1 addition & 1 deletion documentation/html/quicksearch.html

Large diffs are not rendered by default.

88 changes: 75 additions & 13 deletions src/components/Editor/EditRelationships.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<v-switch
v-model="searchFilters[filterName]"
inset
:label="`${capitalize(filterName)}(s)`"
:label="`${prepareFilterName(filterName)}`"
/>
</v-col>
</v-row>
Expand Down Expand Up @@ -188,7 +188,7 @@
<v-switch
v-model="labelsFilter[filterName]"
inset
:label="`${capitalize(filterName)}(s)`"
:label="`${prepareFilterName(filterName)}`"
/>
</v-col>
</v-row>
Expand Down Expand Up @@ -425,6 +425,13 @@
>
The same record/relation combination may not be added more than once.
</v-snackbar>
<v-snackbar
v-model="multipleRelationship"
color="warning"
class="text-body"
>
{{ multipleRelationshipMessage }}
</v-snackbar>
</v-card>
</template>

Expand Down Expand Up @@ -462,11 +469,20 @@
initialized: false,
lastQuery: null,
duplicateRelationship: false,
recordsList: []
multipleRelationship: false,
multipleRelationshipMessage: null,
recordsList: [],
fairsharingRegistries: [
"collection",
"standard",
"database",
"policy",
"fairassist"
]
}
},
computed: {
...mapState("record", ["sections", "currentID"]),
...mapState("record", ["sections", "currentID", "currentRecord"]),
...mapState("users", ["user"]),
...mapState("editor", ["availableRecords", "relationsTypes"]),
...mapGetters("editor", ["allowedRelations", "allowedTargets"]),
Expand All @@ -492,7 +508,8 @@
/* istanbul ignore next */
if ((obj.linkedRecord.name.toLowerCase().includes(searchTerm.toLowerCase()) ||
obj.linkedRecord.abbreviation.toLowerCase().includes(searchTerm.toLowerCase()) )
&& this.labelsFilter[obj.linkedRecord.registry.toLowerCase()] === true){
&& (this.labelsFilter[obj.linkedRecord.registry.toLowerCase()] ||
this.labelsFilter[obj.linkedRecord.type.toLowerCase()]) === true){
return obj;
}
}
Expand Down Expand Up @@ -563,10 +580,34 @@
tmpRelation === _module.addingRelation.recordAssocLabel.relation;
});
// Check if a duplicate relation is being added.
if (exists) {
_module.duplicateRelationship = true;
return;
}
// Check if the user is trying to add multiple examples of FAIRassist relations.
// https://github.com/FAIRsharing/FAIRsharing-API/issues/1137
if (_module.currentRecord.fairsharingRecord.type === "metric" || _module.currentRecord.fairsharingRecord.type === "principle") {
let parts_of = _module.sections.relations.data.recordAssociations.filter((item) => {
return item.recordAssocLabel === 'part_of';
})
if (parts_of.length > 0) {
_module.multipleRelationship = true;
_module.multipleRelationshipMessage = "A principle or metric can be part of no more than 1 other of the same type.";
return;
}
}
if (_module.currentRecord.fairsharingRecord.type === "metric") {
let measures = _module.sections.relations.data.recordAssociations.filter((item) => {
return item.recordAssocLabel === 'measures_principle';
})
if (measures.length > 0) {
_module.multipleRelationship = true;
_module.multipleRelationshipMessage = "A metric can only measure one principle.";
return;
}
}
// Finally get to add the new relation.
let newRelation = {
linkedRecord: _module.addingRelation.linkedRecord,
recordAssocLabel: _module.addingRelation.recordAssocLabel,
Expand Down Expand Up @@ -606,7 +647,8 @@
registry: target.registry.toLowerCase(),
type: target.type.toLowerCase()
},
sourceType: this.sections.relations.data.registry.toLowerCase(),
sourceRegistry: this.sections.relations.data.registry.toLowerCase(),
sourceType: this.sections.relations.data.type.toLowerCase(),
prohibited: prohibited
});
this.$nextTick(() => {this.$refs['editRecordAssociation'].validate()});
Expand All @@ -616,19 +658,24 @@
},
getRelations() {
let labelsFilter = {};
let allRelations = ['standard', 'database', 'collection', 'policy'];
let allRegistries = ['standard', 'database', 'collection', 'policy', 'fairassist'];
let types = [];
let allowedRelations = this.allowedRelations({
target: null,
sourceType: this.sections.relations.data.registry.toLowerCase(),
sourceRegistry: this.sections.relations.data.registry.toLowerCase(),
sourceType: this.sections.relations.data.type.toLowerCase(),
prohibited: null
});
allowedRelations.forEach(allowedRelation => {
if (!Object.keys(labelsFilter).includes(allowedRelation.target)){
/* istanbul ignore else */
if (allRelations.includes(allowedRelation.target.toLowerCase())) {
if (allRegistries.includes(allowedRelation.target.toLowerCase())) {
labelsFilter[allowedRelation.target] = true;
allRegistries.splice(allRegistries.indexOf(allowedRelation.target.toLowerCase()), 1)
}
else { // This must therefore be a record type.
labelsFilter[allowedRelation.target] = true;
allRelations.splice(allRelations.indexOf(allowedRelation.target.toLowerCase()), 1)
types.push(allowedRelation.target);
}
}
});
Expand All @@ -643,16 +690,25 @@
search = this.search.trim();
}
let registries = [];
let types = [];
Object.keys(this.searchFilters).forEach(filter => {
if (this.searchFilters[filter]){
registries.push(filter);
// Check if this is a registry or type
if (this.fairsharingRegistries.indexOf(filter) > -1) {
registries.push(filter);
}
else {
types.push(filter);
}
}
});
this.lastQuery = search;
await _module.getAvailableRecords({
q: search,
fairsharingRegistry: registries,
excludeId: _module.currentID
recordType: types,
excludeId: _module.currentID,
searchAnd: false
});
let i = 0;
this.availableRecords.forEach(rec => {
Expand Down Expand Up @@ -682,6 +738,12 @@
if (redirect && !this.message.error){
await this.$router.push({path: '/' + this.$route.params.id})
}
},
prepareFilterName(name) {
if (name == 'fairassist') {
return 'FAIRassist'
}
return capitalize(name) + "(s)";
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Editor/GeneralInformation/BaseFields.vue
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@
<v-autocomplete
ref="editRecordType"
v-model="fields.type"
label="Registry type"
label="Registry and type"
:rules="[rules.isRequired()]"
:items="recordTypes"
item-text="name"
Expand Down
4 changes: 4 additions & 0 deletions src/components/Records/Record/RelatedContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ export default {
if (_module.currentRecord['fairsharingRecord'].registry === 'Policy') {
_module.$set(_module.tabsData.tabs, 'related_collections', {registry: ["Collection"], data: [], count:0});
}
if (_module.currentRecord['fairsharingRecord'].registry === 'FAIRassist' ||
_module.currentRecord['fairsharingRecord'].registry === 'Standard') {
_module.$set(_module.tabsData.tabs, 'related_fairassist_components', {registry: ["FAIRassist"], data: [], count:0});
}
if (Object.keys(_module.currentRecord['fairsharingRecord']).includes('recordAssociations') ||
Object.keys(_module.currentRecord['fairsharingRecord']).includes('reverseRecordAssociations')) {
Object.keys(_module.tabsData.tabs).forEach(tabName => {
Expand Down
4 changes: 3 additions & 1 deletion src/data/RecordRelationShipsDefinitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
"shares data with": "This database shares a portion of data with another database",
"shares code with": "This database shares a portion of code with another database",
"accepts": "This database accepts data that follows a particular standard",
"outputs": "This database outputs data that follows a particular standard"
"outputs": "This database outputs data that follows a particular standard",
"measures principle": "Used to show which 'owning' principle any given metric belongs to",
"part of": "Allows composition of metrics within other metrics, or shows what 'parent' principle a principle bleongs to"
}
5 changes: 5 additions & 0 deletions src/plugins/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ const customIcons = {
icon: "/assets/records/benchmark.svg",
tooltip: "Benchmark",
},
principle: {
type: "img",
icon: "/assets/records/principle.svg",
tooltip: "Principle",
},
repository: {
type: "img",
icon: "/assets/records/db-icon.svg",
Expand Down
38 changes: 27 additions & 11 deletions src/store/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ let editorStore = {
getRecordsQuery.queryParam = {perPage: 100};
if (options.q) getRecordsQuery.queryParam.q = options.q;
getRecordsQuery.queryParam.fairsharingRegistry = options.fairsharingRegistry;
getRecordsQuery.queryParam.recordType = options.recordType;
getRecordsQuery.queryParam.searchAnd = false;
getRecordsQuery.queryParam.excludeId = options.excludeId;
let data = await graphClient.executeQuery(getRecordsQuery);
Expand All @@ -205,10 +206,11 @@ let editorStore = {
async getAvailableRelationsTypes({commit}){
let types = await restClient.getRelationsTypes();
let allowed = {};
let relationTypes = ['standard', 'database', 'policy', 'collection'];
let relationTypes = ['standard', 'database', 'policy', 'collection', 'fairassist'];
for (let typeObject of types) {
let relationName = typeObject.name,
id = typeObject.id;
/* istanbul ignore else */
if (typeObject['allowed_associations'].length > 0) {
typeObject['allowed_associations'].forEach(allowed_association => {
let relationParent = allowed_association.from;
Expand Down Expand Up @@ -263,21 +265,35 @@ let editorStore = {
},
allowedRelations: (state) => (options) => {
let output = [];
state.relationsTypes[options.sourceType].forEach(relation => {
if ((options.target && options.prohibited) &&
(relation.target === options.target.registry || relation.target === options.target.type) &&
!options.prohibited.includes(relation.relation)){
output.push(relation)
}
if (!options.target && !options.prohibited){
output.push(relation);
let seen = [];
[options.sourceType, options.sourceRegistry].forEach(type => {
// This undefined check prevents allowed relations from being pushed to the array twice,
// as we're checking for both registry and record type here.
/* istanbul ignore else */
if (state.relationsTypes[type] !== undefined) {
state.relationsTypes[type].forEach(relation => {
if ((options.target && options.prohibited) &&
(relation.target === options.target.registry || relation.target === options.target.type) &&
!options.prohibited.includes(relation.relation)) {
if (!seen.includes(relation.id)) {
output.push(relation)
seen.push(relation.id);
}
}
if (!options.target && !options.prohibited) {
if (!seen.includes(relation.id)) {
output.push(relation);
seen.push(relation.id);
}
}
});
}
});
})
return output;
},
allowedTargets: (state) => (source) => {
let output = [];
let allowed = ["standard", "database", "policy", "collection"];
let allowed = ["standard", "database", "policy", "collection", "fairassist"];
state.relationsTypes[source.toLowerCase()].forEach(relation => {
/* istanbul ignore else */
if (allowed.includes(relation.target)) output.push(relation.target);
Expand Down
Loading

0 comments on commit a5aa988

Please sign in to comment.