|
48 | 48 | <v-switch
|
49 | 49 | v-model="searchFilters[filterName]"
|
50 | 50 | inset
|
51 |
| - :label="`${capitalize(filterName)}(s)`" |
| 51 | + :label="`${prepareFilterName(filterName)}`" |
52 | 52 | />
|
53 | 53 | </v-col>
|
54 | 54 | </v-row>
|
|
188 | 188 | <v-switch
|
189 | 189 | v-model="labelsFilter[filterName]"
|
190 | 190 | inset
|
191 |
| - :label="`${capitalize(filterName)}(s)`" |
| 191 | + :label="`${prepareFilterName(filterName)}`" |
192 | 192 | />
|
193 | 193 | </v-col>
|
194 | 194 | </v-row>
|
|
425 | 425 | >
|
426 | 426 | The same record/relation combination may not be added more than once.
|
427 | 427 | </v-snackbar>
|
| 428 | + <v-snackbar |
| 429 | + v-model="multipleRelationship" |
| 430 | + color="warning" |
| 431 | + class="text-body" |
| 432 | + > |
| 433 | + {{ multipleRelationshipMessage }} |
| 434 | + </v-snackbar> |
428 | 435 | </v-card>
|
429 | 436 | </template>
|
430 | 437 |
|
|
462 | 469 | initialized: false,
|
463 | 470 | lastQuery: null,
|
464 | 471 | duplicateRelationship: false,
|
465 |
| - recordsList: [] |
| 472 | + multipleRelationship: false, |
| 473 | + multipleRelationshipMessage: null, |
| 474 | + recordsList: [], |
| 475 | + fairsharingRegistries: [ |
| 476 | + "collection", |
| 477 | + "standard", |
| 478 | + "database", |
| 479 | + "policy", |
| 480 | + "fairassist" |
| 481 | + ] |
466 | 482 | }
|
467 | 483 | },
|
468 | 484 | computed: {
|
469 |
| - ...mapState("record", ["sections", "currentID"]), |
| 485 | + ...mapState("record", ["sections", "currentID", "currentRecord"]), |
470 | 486 | ...mapState("users", ["user"]),
|
471 | 487 | ...mapState("editor", ["availableRecords", "relationsTypes"]),
|
472 | 488 | ...mapGetters("editor", ["allowedRelations", "allowedTargets"]),
|
|
492 | 508 | /* istanbul ignore next */
|
493 | 509 | if ((obj.linkedRecord.name.toLowerCase().includes(searchTerm.toLowerCase()) ||
|
494 | 510 | obj.linkedRecord.abbreviation.toLowerCase().includes(searchTerm.toLowerCase()) )
|
495 |
| - && this.labelsFilter[obj.linkedRecord.registry.toLowerCase()] === true){ |
| 511 | + && (this.labelsFilter[obj.linkedRecord.registry.toLowerCase()] || |
| 512 | + this.labelsFilter[obj.linkedRecord.type.toLowerCase()]) === true){ |
496 | 513 | return obj;
|
497 | 514 | }
|
498 | 515 | }
|
|
563 | 580 | tmpRelation === _module.addingRelation.recordAssocLabel.relation;
|
564 | 581 |
|
565 | 582 | });
|
| 583 | + // Check if a duplicate relation is being added. |
566 | 584 | if (exists) {
|
567 | 585 | _module.duplicateRelationship = true;
|
568 | 586 | return;
|
569 | 587 | }
|
| 588 | + // Check if the user is trying to add multiple examples of FAIRassist relations. |
| 589 | + // https://github.com/FAIRsharing/FAIRsharing-API/issues/1137 |
| 590 | + if (_module.currentRecord.fairsharingRecord.type === "metric" || _module.currentRecord.fairsharingRecord.type === "principle") { |
| 591 | + let parts_of = _module.sections.relations.data.recordAssociations.filter((item) => { |
| 592 | + return item.recordAssocLabel === 'part_of'; |
| 593 | + }) |
| 594 | + if (parts_of.length > 0) { |
| 595 | + _module.multipleRelationship = true; |
| 596 | + _module.multipleRelationshipMessage = "A principle or metric can be part of no more than 1 other of the same type."; |
| 597 | + return; |
| 598 | + } |
| 599 | + } |
| 600 | + if (_module.currentRecord.fairsharingRecord.type === "metric") { |
| 601 | + let measures = _module.sections.relations.data.recordAssociations.filter((item) => { |
| 602 | + return item.recordAssocLabel === 'measures_principle'; |
| 603 | + }) |
| 604 | + if (measures.length > 0) { |
| 605 | + _module.multipleRelationship = true; |
| 606 | + _module.multipleRelationshipMessage = "A metric can only measure one principle."; |
| 607 | + return; |
| 608 | + } |
| 609 | + } |
| 610 | + // Finally get to add the new relation. |
570 | 611 | let newRelation = {
|
571 | 612 | linkedRecord: _module.addingRelation.linkedRecord,
|
572 | 613 | recordAssocLabel: _module.addingRelation.recordAssocLabel,
|
|
606 | 647 | registry: target.registry.toLowerCase(),
|
607 | 648 | type: target.type.toLowerCase()
|
608 | 649 | },
|
609 |
| - sourceType: this.sections.relations.data.registry.toLowerCase(), |
| 650 | + sourceRegistry: this.sections.relations.data.registry.toLowerCase(), |
| 651 | + sourceType: this.sections.relations.data.type.toLowerCase(), |
610 | 652 | prohibited: prohibited
|
611 | 653 | });
|
612 | 654 | this.$nextTick(() => {this.$refs['editRecordAssociation'].validate()});
|
|
616 | 658 | },
|
617 | 659 | getRelations() {
|
618 | 660 | let labelsFilter = {};
|
619 |
| - let allRelations = ['standard', 'database', 'collection', 'policy']; |
620 |
| -
|
| 661 | + let allRegistries = ['standard', 'database', 'collection', 'policy', 'fairassist']; |
| 662 | + let types = []; |
621 | 663 | let allowedRelations = this.allowedRelations({
|
622 | 664 | target: null,
|
623 |
| - sourceType: this.sections.relations.data.registry.toLowerCase(), |
| 665 | + sourceRegistry: this.sections.relations.data.registry.toLowerCase(), |
| 666 | + sourceType: this.sections.relations.data.type.toLowerCase(), |
624 | 667 | prohibited: null
|
625 | 668 | });
|
626 | 669 | allowedRelations.forEach(allowedRelation => {
|
627 | 670 | if (!Object.keys(labelsFilter).includes(allowedRelation.target)){
|
628 | 671 | /* istanbul ignore else */
|
629 |
| - if (allRelations.includes(allowedRelation.target.toLowerCase())) { |
| 672 | + if (allRegistries.includes(allowedRelation.target.toLowerCase())) { |
| 673 | + labelsFilter[allowedRelation.target] = true; |
| 674 | + allRegistries.splice(allRegistries.indexOf(allowedRelation.target.toLowerCase()), 1) |
| 675 | + } |
| 676 | + else { // This must therefore be a record type. |
630 | 677 | labelsFilter[allowedRelation.target] = true;
|
631 |
| - allRelations.splice(allRelations.indexOf(allowedRelation.target.toLowerCase()), 1) |
| 678 | + types.push(allowedRelation.target); |
632 | 679 | }
|
633 | 680 | }
|
634 | 681 | });
|
|
643 | 690 | search = this.search.trim();
|
644 | 691 | }
|
645 | 692 | let registries = [];
|
| 693 | + let types = []; |
646 | 694 | Object.keys(this.searchFilters).forEach(filter => {
|
647 | 695 | if (this.searchFilters[filter]){
|
648 |
| - registries.push(filter); |
| 696 | + // Check if this is a registry or type |
| 697 | + if (this.fairsharingRegistries.indexOf(filter) > -1) { |
| 698 | + registries.push(filter); |
| 699 | + } |
| 700 | + else { |
| 701 | + types.push(filter); |
| 702 | + } |
649 | 703 | }
|
650 | 704 | });
|
651 | 705 | this.lastQuery = search;
|
652 | 706 | await _module.getAvailableRecords({
|
653 | 707 | q: search,
|
654 | 708 | fairsharingRegistry: registries,
|
655 |
| - excludeId: _module.currentID |
| 709 | + recordType: types, |
| 710 | + excludeId: _module.currentID, |
| 711 | + searchAnd: false |
656 | 712 | });
|
657 | 713 | let i = 0;
|
658 | 714 | this.availableRecords.forEach(rec => {
|
|
682 | 738 | if (redirect && !this.message.error){
|
683 | 739 | await this.$router.push({path: '/' + this.$route.params.id})
|
684 | 740 | }
|
| 741 | + }, |
| 742 | + prepareFilterName(name) { |
| 743 | + if (name == 'fairassist') { |
| 744 | + return 'FAIRassist' |
| 745 | + } |
| 746 | + return capitalize(name) + "(s)"; |
685 | 747 | }
|
686 | 748 | }
|
687 | 749 | }
|
|
0 commit comments