Skip to content

Commit

Permalink
Merge branch 'dev' into processing_notes_again
Browse files Browse the repository at this point in the history
  • Loading branch information
knirirr committed Aug 29, 2024
2 parents 52487c4 + e362761 commit 5907099
Show file tree
Hide file tree
Showing 44 changed files with 3,946 additions and 954 deletions.
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
"!src/router/routes.js",
"!views/Records/NetworkGraph.vue",
"!src/components/Records/Search/Input/AdvancedSearch/QueryBuilderComponents/index.js",
"!src/components/Records/Search/SaveSearch/StepperComponents/index.js",
],
testMatch: [
"**/**.spec.js",
Expand Down
58 changes: 54 additions & 4 deletions src/components/Records/Record/Collections.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@
color="accent3"
slider-color="accent3"
class="mb-5"
:hide-slider="tabsData.tabs[Object.keys(tabsData.tabs)[tabsData.selectedTab]].data.length===0"
:hide-slider="tabsData.tabs[Object.keys(tabsData.tabs)[tabsData.selectedTab]].type === 'conforming_resources'? !currentRecord['fairsharingRecord'].savedSearches.length : tabsData.tabs[Object.keys(tabsData.tabs)[tabsData.selectedTab]].data.length===0"
>
<v-tab
v-for="(tabName,tabIndex) in Object.keys(tabsData.tabs)"
:key="tabName+'_'+tabIndex"
:disabled="tabsData.tabs[tabName].data.length===0"
:disabled="tabName === 'conforming_resources' ? !currentRecord['fairsharingRecord'].savedSearches.length : tabsData.tabs[tabName].data.length===0"
@change="selectedValues=null"
>
{{ cleanString(tabName) }} ({{ tabsData.tabs[tabName].count }})
{{ cleanString(tabName) }} ({{ tabName === 'conforming_resources' ? currentRecord['fairsharingRecord'].savedSearches.length : tabsData.tabs[tabName].count }})
</v-tab>
</v-tabs>
<!-- tab content -->
Expand All @@ -63,7 +63,12 @@
v-for="(tabItem,tabItemIndex) in filterList"
:key="tabItem+'_'+tabItemIndex"
>
<SavedSearches
v-if="tabItem.type === 'conforming_resources'"
/>

<v-virtual-scroll
v-else
:items="tabItem.data"
height="400"
item-height="130"
Expand Down Expand Up @@ -117,6 +122,7 @@
<script>
import {mapState} from "vuex";
import SavedSearches from '@/components/Records/Record/GeneralInfo/SavedSearches'
import SectionTitle from '@/components/Records/Record/SectionTitle';
import RecordStatus from "@/components/Records/Shared/RecordStatus";
import recordRelationShipsDefinitions from "@/data/RecordRelationShipsDefinitions.json";
Expand All @@ -128,6 +134,7 @@ export default {
components: {
RecordStatus,
SectionTitle,
SavedSearches
},
mixins: [stringUtils, recordTabUtils],
props:{
Expand All @@ -145,12 +152,42 @@ export default {
tabs: {
in_collections: {relation: 'collects', data: [], count:0}
}
}
},
}
},
computed: {
...mapState("record", ["currentRecord"]),
},
watch:{
currentRecord() {
let _module = this
Object.keys(_module.tabsData.tabs).forEach(tabName => {
//Update the count of the conforming resources after unlinking saved search
if (tabName === 'conforming_resources') {
_module.tabsData.tabs[tabName].count = _module.currentRecord['fairsharingRecord'].savedSearches.length;
}
//If no saved search is available in conforming resources tab
if(!_module.currentRecord['fairsharingRecord'].savedSearches.length) {
//If no conforming resources is available then shift focus to Related Policies tab
if(tabName === "related_policies") {
if(_module.tabsData.tabs[tabName].data.length) {
this.tabsData.selectedTab = 1
}
}
//If no related policies is available then shift focus to In collections tab
else if(tabName === "in_collections") {
if(_module.tabsData.tabs[tabName].data.length) {
this.tabsData.selectedTab = 0
}
}
//If nothing is available make all tabs section disabled with its initial value i.e null
else {
this.selectedValues = null
}
}
})
}
},
methods: {
/** Dynamically sets data for each tabs based on the data received from recordAssociations and reverseAssociations*/
prepareTabsData() {
Expand All @@ -162,6 +199,12 @@ export default {
data: [],
count:0
}
_module.tabsData.tabs.conforming_resources = {
registry: ['Policy'],
data: [],
count:0,
type:'conforming_resources'
}
}
else {
_module.tabsData.tabs.in_policies = {
Expand Down Expand Up @@ -189,6 +232,13 @@ export default {
)
_module.tabsData.tabs[tabName].count = _module.tabsData.tabs[tabName].data.length;
}
//Save searches for the policy
else if (tabName === 'conforming_resources') {
_module.tabsData.tabs[tabName].data =
_module.currentRecord['fairsharingRecord'].savedSearches
_module.tabsData.tabs[tabName].count = _module.currentRecord['fairsharingRecord'].savedSearches.length;
}
// All incoming collections.
else {
_module.tabsData.tabs[tabName].data = _module.prepareAssociations(
Expand Down
180 changes: 180 additions & 0 deletions src/components/Records/Record/GeneralInfo/SavedSearches.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
<template>
<div
v-if="getField('savedSearches') && getField('savedSearches').length"
>
<p>
This policy has certain requirements and recommendations that have been used to create a conformant FAIRsharing search. The searches listed within this section will provide an initial filtering of the FAIRsharing registries. Clicking on a saved search will take you to a set of search results which you may further refine according to your needs and any additional policy requirements. If you are logged in, you may also save any search results to your own profile. More information on Conforming Resources and Saved Searches can be found in our <a
href="https://fairsharing.gitbook.io/fairsharing/how-to/advanced-search"
target="_blank"
>
Gitbook
documentation</a>.
</p>
<div
v-for="search in getSavedSearches"
:key="search.id"
class="d-flex align-center"
>
<v-card
class="pa-4 d-flex flex-column v-card-hover mx-2 height-120 my-3 full-width"
flat
outlined
>
<div class="d-flex align-center">
<record-status
:record="search.fairsharingRecords[0]"
:show-status="false"
/>
<div class="d-flex flex-column">
<div
class="ml-10 underline-effect text-ellipses-height-2lines line-height-20"
>
<a :href="search.url">{{ search.name }}</a>
</div>
<p class="text-body-2 ml-10">
(Created by: <a
class="underline-effect"
:href="`/users/${search.creator['id']}`"
>{{ search.creator["username"] }}</a>)
</p>
</div>
</div>


<p
class="grey--text relation-style text-ellipses-height-2lines line-height-14 pr-5"
>
{{ search.comments }}
</p>
</v-card>
<v-btn
v-if="user().is_super_curator"
rounded
text
@click="confirmUnlinkSavedSearch(search)"
>
<v-icon>mdi-link-off</v-icon>
</v-btn>
</div>


<!-- Unlink dialog box -->
<v-dialog
v-model="confirmUnlink"
max-width="700px"
persistent
>
<!-- Unlink saved search -->
<v-card v-if="unlinkSavedSearchCard">
<v-card-title class="text-h5">
Unlinking saved search
</v-card-title>
<v-card-text>
This is will unlink instance of the search from this policy record.
</v-card-text>
<v-card-actions>
<v-spacer />
<v-btn
class="white--text"
color="accent3"
@click="unlinkSavedSearch(false)"
>
Cancel
</v-btn>
<v-btn
class="white--text"
color="success"
:loading="unlinkLoader"
@click="unlinkSavedSearch(true)"
>
OK
</v-btn>
<v-spacer />
</v-card-actions>
</v-card>
</v-dialog>
</div>
</template>

<script>
import { mapActions, mapGetters, mapState } from "vuex";
import RecordStatus from "@/components/Records/Shared/RecordStatus.vue";
import RestClient from "@/lib/Client/RESTClient.js";
import saveSearch from "@/store";
const restClient = new RestClient();
export default {
name: "SavedSearches",
components: { RecordStatus },
data: () => {
return {
getSavedSearches: [],
confirmUnlink: false,
unlinkSavedSearchCard: false,
selectedItem: {},
unlinkLoader: false,
};
},
computed: {
...mapState("users", ["user"]),
...mapState("record", ["currentRecord"]),
...mapGetters("record", ["getField"]),
},
mounted() {
this.getSavedSearches = this.getField("savedSearches");
},
methods: {
...mapActions("record", ["fetchRecord"]),
/**
* Confirmation dialog to unlink the saved search
*/
confirmUnlinkSavedSearch(item) {
this.selectedItem = item;
this.confirmUnlink = true;
this.unlinkSavedSearchCard = true;
},
/**
* Unlink the saved search
* @param del - Boolean
*/
async unlinkSavedSearch(del) {
if (del) {
this.unlinkLoader = true;
//Filter the currentRecord to unlink
let linkRecord = this.selectedItem.fairsharingRecords.filter(({id}) => id !== this.currentRecord.fairsharingRecord.id);
//Array of id of the remaining record
linkRecord = linkRecord.map(({id}) => id)
let saveSearchObj = {
fairsharing_record_ids: linkRecord,
};
let updatedSearchResult = await restClient.updateSaveSearch(
this.selectedItem["id"],
saveSearchObj,
this.user().credentials.token
);
//Commit the updated result to store
saveSearch.commit("saveSearch/setSaveSearchResult", updatedSearchResult);
//Update the page after unlinking the savedSearch
await this.fetchRecord({
id: this.currentRecord.fairsharingRecord.id,
token: this.user().credentials.token,
});
this.getSavedSearches = this.getField("savedSearches");
}
this.unlinkLoader = false;
this.unlinkSavedSearchCard = false;
this.confirmUnlink = false;
},
},
};
</script>
46 changes: 46 additions & 0 deletions src/components/Records/Search/SaveSearch/SaveSearchButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<template>
<v-btn
class="mb-2 white--text saveSearchResults"
color="accent2"
small
@click="!user().isLoggedIn ? goToLogin() : saveSearchResults()"
>
Save Search Results
</v-btn>
</template>

<script>
import { mapState } from "vuex";
import saveSearch from "@/store";
export default {
name: "SaveSearchButton",
computed: {
...mapState("users", ["user"]),
},
methods: {
/**
* Save the advancedSearch Results
*/
async saveSearchResults() {
saveSearch.commit("saveSearch/setSaveSearchStepperDialog", true);
},
/**
* Goto To login page if user is not loggedIn
*/
async goToLogin() {
if (this.$route.path !== "/accounts/login") {
await this.$router.push({
path: "/accounts/login",
query: {
goTo: this.$route.fullPath,
},
});
}
},
},
};
</script>
Loading

0 comments on commit 5907099

Please sign in to comment.