Skip to content

Commit

Permalink
Merge pull request #174 from lcnetdev/bfp-292-prompt-demote-contribs
Browse files Browse the repository at this point in the history
[BFp 292] Prompt/demote contributors
  • Loading branch information
f-osorio authored Dec 23, 2024
2 parents c71a7ea + 73cbbce commit 7ecf2a5
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 28 deletions.
73 changes: 47 additions & 26 deletions src/components/panels/edit/fields/Ref.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
:nested="true"
:guid="guid"
:inheritedStructure="thisRtTemplate.propertyTemplates[idx]"
:readOnly="readOnly"/>
:readOnly="readOnly" />


<!--
Expand Down Expand Up @@ -219,6 +219,7 @@ export default {
thisRtTemplate(){
console.info("thisRtTemplate")
if (this.manualOverride !== null){
for (let tmpid of this.structure.valueConstraint.valueTemplateRefs){
console.log('tmpid',tmpid)
Expand Down Expand Up @@ -246,8 +247,10 @@ export default {
if (userValue['@type']){
// loop thrugh all the refs and see if there is a URI that matches it better
this.structure.valueConstraint.valueTemplateRefs.forEach((tmpid)=>{
//if tmpid is 'lc:RT:bf2:Agents:Contribution', need to look somehwere else
if (foundBetter) return false
if (this.structure.id != this.rtLookup[tmpid].id && this.rtLookup[tmpid].resourceURI === userValue['@type']){
if (tmpid == "lc:RT:bf2:Agents:Contribution"){
} else if (this.structure.id != this.rtLookup[tmpid].id && this.rtLookup[tmpid].resourceURI === userValue['@type']){
useId = tmpid
foundBetter = true
}
Expand All @@ -265,37 +268,55 @@ export default {
})
} else {
//There's no userValue, we'll use the parent's userValue to check
// if there's a template that might be even better-er
// But, we're only going to look deeper for bf:contribution
let parentUserValue
try {
parentUserValue = this.$parent.$parent.structure.userValue
} catch {
parentUserValue = null
}
for (let idx in this.structure.valueConstraint.valueTemplateRefs){
let template = this.structure.valueConstraint.valueTemplateRefs[idx]
if (parentUserValue && parentUserValue["@root"] == "http://id.loc.gov/ontologies/bibframe/contribution" && parentUserValue["http://id.loc.gov/ontologies/bibframe/contribution"]){
let target = parentUserValue["http://id.loc.gov/ontologies/bibframe/contribution"][0]["http://id.loc.gov/ontologies/bibframe/agent"]
if (target){
let type = target[0]["@type"]
if (type && this.rtLookup[template].resourceURI === type){
useId = template
}
}
}
}
}
//There's no userValue, we'll use the parent's userValue to check
// if there's a template that might be even better-er
// But, we're only going to look deeper for bf:contribution
let parentUserValue
try {
parentUserValue = this.$parent.$parent.structure.userValue
} catch {
parentUserValue = null
}
// resourceURI :: type
const typeMap = {
"http://id.loc.gov/ontologies/bibframe/Person": "lc:RT:bf2:Agent:bfPerson",
"http://id.loc.gov/ontologies/bibframe/Family": "lc:RT:bf2:Agent:bfFamily",
"http://www.loc.gov/mads/rdf/v1#CorporateName": "lc:RT:bf2:Agent:bfCorp",
"http://id.loc.gov/ontologies/bibframe/Jurisdiction": "lc:RT:bf2:Agent:bfJurisdiction",
"http://id.loc.gov/ontologies/bibframe/Meeting": "lc:RT:bf2:Agent:bfConf",
}
for (let idx in this.structure.valueConstraint.valueTemplateRefs){
let template = this.structure.valueConstraint.valueTemplateRefs[idx]
if (parentUserValue && parentUserValue["@root"] == "http://id.loc.gov/ontologies/bibframe/contribution" && parentUserValue["http://id.loc.gov/ontologies/bibframe/contribution"]){
let target = parentUserValue["http://id.loc.gov/ontologies/bibframe/contribution"][0]["http://id.loc.gov/ontologies/bibframe/agent"]
if (target){
let type = target[0]["@type"]
if (type && this.rtLookup[template].resourceURI === type){ // the resourceURIs don't match the types
useId = template
} else if (type && Object.keys(typeMap).includes(type)){
useId = typeMap[type]
}
} else { //there's no user agent
let target = parentUserValue["http://id.loc.gov/ontologies/bibframe/contribution"]
let type = target[0]["@type"]
if (type && this.rtLookup[template].resourceURI === type){
useId = template
}
}
}
}
}
// do not render recursivly if the thing we are trying to render recursivly is one the of the things thAT WER ARE RENDERING TO BEGIN WITHHHHH!!!1
// if (this.parentStructure && this.parentStructure.indexOf(useId) ==-1){
if (this.rtLookup[useId]){
let use = JSON.parse(JSON.stringify(this.rtLookup[useId]))
console.info("use: ", use)
return use
// this.multiTemplateSelect = use.resourceLabel
// this.multiTemplateSelectURI = useId
Expand Down
93 changes: 92 additions & 1 deletion src/components/panels/edit/fields/helpers/ActionButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
Insert Default Values
</button>

<button v-if="isContribComponent()" style="width:100%" class="" :id="`action-button-command-${fieldGuid}-2`" @click="promoteContrib()">
<span class="button-shortcut-label">2</span>
{{ this.profileStore.returnStructureByComponentGuid(this.guid).propertyLabel == "Creator of Work" ? "Demote" : "Promote" }} Contributor
</button>

<button style="width:100%" class="" :id="`action-button-command-${fieldGuid}-3`" @click="deleteComponent()">
<span class="button-shortcut-label">3</span>
Delete Component
Expand All @@ -44,7 +49,7 @@
<template v-if="['lc:RT:bf2:WorkTitle', 'lc:RT:bf2:InstanceTitle', 'lc:RT:bf2:Title:VarTitle', 'lc:RT:bf2:ParallelTitle'].includes(structure.parentId)">
<button style="width:100%" class="" :id="`action-button-command-${fieldGuid}-4`" @click="sendToOtherProfile()">
<span class="button-shortcut-label">4</span>
Send to {{ this.profileStore.returnRtByGUID(this.guid) == "lc:RT:bf2:Monograph:Work" ? "Instance" : (Object.keys(this.profileStore.activeProfile.rt).length > 2 ? "Work/Instance" : "Work") }}
Send to {{ this.profileStore.returnRtByGUID(this.guid).includes(":Work") ? "Instance" : (Object.keys(this.profileStore.activeProfile.rt).length > 2 ? "Work/Instance" : "Work") }}
</button>
</template>

Expand Down Expand Up @@ -751,6 +756,92 @@
this.profileStore.dataChanged()
},
// show the button for de/promotion
isContribComponent: function(){
let parentStructure = this.profileStore.returnStructureByComponentGuid(this.guid)
return parentStructure.id.includes("_contribution_")
},
/**
* Update the contributor component to pro/demotion
* @param contribStructure - the structure of the component that will be updated
* @param contribType - the type of contributor
*/
updateContrib: function(contribStructure, contribType){
const primaryId = "id_loc_gov_ontologies_bibframe_contribution__creator_of_work"
const primaryPrefId = "http://id.loc.gov/ontologies/bibframe/contribution|http://id.loc.gov/ontologies/bibframe/PrimaryContribution"
const primaryType = "http://id.loc.gov/ontologies/bibframe/PrimaryContribution"
const primaryLabel = "Creator of Work"
const contributorId = "id_loc_gov_ontologies_bibframe_contribution__contributors"
const contributorPrefId = "http://id.loc.gov/ontologies/bibframe/contribution|http://id.loc.gov/ontologies/bibframe/Contribution"
const contributorType = "http://id.loc.gov/ontologies/bibframe/Contribution"
const contributorLabel = "Contributors"
let userValue = contribStructure.userValue
if (contribType == contributorId){
contribStructure.id = primaryId
contribStructure.preferenceId = primaryPrefId
contribStructure.propertyLabel = primaryLabel
userValue["http://id.loc.gov/ontologies/bibframe/contribution"][0]["@type"] = primaryType
} else {
contribStructure.id = contributorId
contribStructure.preferenceId = contributorPrefId
contribStructure.propertyLabel = contributorLabel
userValue["http://id.loc.gov/ontologies/bibframe/contribution"][0]["@type"] = contributorType
}
return contribStructure
},
promoteContrib: function(){
const primaryId = "id_loc_gov_ontologies_bibframe_contribution__creator_of_work"
const contributorId = "id_loc_gov_ontologies_bibframe_contribution__contributors"
//get the current active primaryContributor, need to make sure there isn't already one
let activePrimary
let contributors = []
for (let rt in this.activeProfile.rt){
for (let pt in this.activeProfile.rt[rt].pt){
if (pt.includes("creator_of_work")){
const target = this.activeProfile.rt[rt].pt[pt]
if (!target.deleted){
activePrimary = target
}
}
}
}
//Get a list of current contributors, need to update the contribtor id?
let structure = this.profileStore.returnStructureByComponentGuid(this.guid)
let activeStructure = JSON.parse(JSON.stringify(structure))
const currentType = activeStructure.id == primaryId ? primaryId : contributorId
activeStructure["@guid"] = short.generate()
if (currentType == contributorId){
//check the active primary, if there is a value, create an alert for the user
// and swap the two
if (!this.profileStore.isEmptyComponent(activePrimary)){
const swap = confirm("There is already a primary contributor. Continuing will swap the two.")
if (swap){
let activePrimaryStruct = this.profileStore.returnStructureByComponentGuid(JSON.parse(JSON.stringify(activePrimary))["@guid"])
activePrimaryStruct = this.updateContrib(JSON.parse(JSON.stringify(activePrimaryStruct)), primaryId)
this.profileStore.parseActiveInsert(activePrimaryStruct)
this.profileStore.deleteComponent(activePrimary["@guid"])
} else {
return
}
}
}
//update, insert, and delete
activeStructure = this.updateContrib(activeStructure, currentType)
this.profileStore.parseActiveInsert(activeStructure)
this.profileStore.deleteComponent(this.guid)
},
},
watch: {
Expand Down
3 changes: 2 additions & 1 deletion src/stores/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4384,7 +4384,8 @@ export const useProfileStore = defineStore('profile', {
let targetLabel = newComponent.propertyLabel

if (!current.deleted && current.propertyURI.trim() == targetURI.trim() && current.propertyLabel.trim() == targetLabel.trim()){
if (Object.keys(current.userValue).length == 1){
// if (Object.keys(current.userValue).length == 1){
if (this.isEmptyComponent(current)){
current.userValue = newComponent.userValue
break
} else {
Expand Down

0 comments on commit 7ecf2a5

Please sign in to comment.