Skip to content

Commit

Permalink
add "make primary subject heading" option to the action button
Browse files Browse the repository at this point in the history
  • Loading branch information
thisismattmiller committed Aug 23, 2024
1 parent 905c2f2 commit 2686a94
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/components/panels/edit/fields/LookupComplex.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
<span v-if="!avl.needsDereference" style="padding-right: 0.3em; font-weight: bold">
<!-- <a v-if="!this.configStore.useSubjectEditor.includes(this.structure.propertyURI)" href="#" @click="openAuthority()" ref="el">{{avl.label}}</a>
<span v-else>{{avl.label}}</span> -->
<span v-if="avl.source && avl.source=='FAST'" style="font-weight: bold;">(FAST) </span>
<a href="#" @click="openAuthority()" ref="el">{{avl.label}}</a>
<span class="uncontrolled" v-if="avl.isLiteral">
(uncontrolled)
Expand Down
22 changes: 20 additions & 2 deletions src/components/panels/edit/fields/helpers/ActionButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</div>
-->

<VMenu ref="action-button-menu" :triggers="useOpenModes" @show="shortCutPressed" v-model:shown="isMenuShown" @hide="menuClosed">
<VMenu ref="action-button-menu" :triggers="useOpenModes" @show="shortCutPressed" v-model:shown="isMenuShown" @hide="menuClosed">
<button tabindex="-1" :id="`action-button-${fieldGuid}`" :class="{'action-button':true,'small-mode': small }"><span class="material-icons action-button-icon">{{preferenceStore.returnValue('--s-edit-general-action-button-icon')}}</span></button>

<template #popper>
Expand All @@ -32,6 +32,19 @@
Delete Component
</button>


<template v-if="structure.propertyURI == 'http://id.loc.gov/ontologies/bibframe/subject' || structure.propertyURI == 'http://www.loc.gov/mads/rdf/v1#Topic'">
<button style="width:100%" class="" :id="`action-button-command-${fieldGuid}-4`" @click="makeSubjectHeadingPrimary()">
<span class="button-shortcut-label">4</span>
Make Primary Heading
</button>


</template>




<hr>

<template v-if="type=='literal'">
Expand Down Expand Up @@ -273,7 +286,12 @@
this.profileStore.deleteComponent(this.profileStore.returnStructureByComponentGuid(this.guid)['@guid'])
},
makeSubjectHeadingPrimary: function(){
this.profileStore.makeSubjectHeadingPrimary(this.profileStore.returnStructureByComponentGuid(this.guid)['@guid'])
},
addComponent: function(){
Expand Down
69 changes: 65 additions & 4 deletions src/stores/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -1725,13 +1725,19 @@ export const useProfileStore = defineStore('profile', {
}
}

let source = null
if (URI && URI.indexOf('/fast/') >1){
source = 'FAST'
}



if (URI && label){
values.push({
'@guid':v['@guid'],
URI: URI,
label: label,
source: source,
needsDereference: false,
isLiteral: false,
type:v['@type']
Expand All @@ -1741,6 +1747,7 @@ export const useProfileStore = defineStore('profile', {
'@guid':v['@guid'],
URI: URI,
label: label,
source: source,
needsDereference: true,
isLiteral: false,
type:v['@type']
Expand All @@ -1750,6 +1757,7 @@ export const useProfileStore = defineStore('profile', {
'@guid':v['@guid'],
URI: URI,
label: label,
source: source,
needsDereference: false,
isLiteral: true,
type:v['@type']
Expand Down Expand Up @@ -2750,18 +2758,71 @@ export const useProfileStore = defineStore('profile', {
return false

},


/**
* Duplicate / create new component
* Moves the passed heading the first of the subjects in the PT order
*
* @param {string} componentGuid - the guid of the component (the parent of all fields)
* @param {boolean} createEmpty - if true make the component have no pre-populated data, if false "duplicate" the data from the source component
* @return {void}
*/

makeSubjectHeadingPrimary: async function(componentGuid){

let pt = utilsProfile.returnPt(this.activeProfile,componentGuid)

if (pt !== false){

console.log(pt)

// loop through all the headings and find the place the headings start
let firstHeading = null
let workRtId = null
for (let rtId in this.activeProfile.rt){
if (rtId.indexOf(":Work") > -1){
workRtId = rtId
for (let ptId of this.activeProfile.rt[rtId].ptOrder){
if (this.activeProfile.rt[rtId].pt[ptId].propertyURI == 'http://id.loc.gov/ontologies/bibframe/subject'){
firstHeading=ptId
break
}
}
}
if (firstHeading){break}
}

if (firstHeading){

let firstHeadingPos = this.activeProfile.rt[workRtId].ptOrder.indexOf(firstHeading)
let currentHeadingPos = this.activeProfile.rt[workRtId].ptOrder.indexOf(pt.id)

// remove the current heading from its position
this.activeProfile.rt[workRtId].ptOrder.splice(currentHeadingPos, 1);
// insert where the first heading is
this.activeProfile.rt[workRtId].ptOrder.splice(firstHeadingPos, 0, pt.id);

this.dataChanged()
}



}

},


/**
* Set the default values of the component fields
*
* @param {string} componentGuid - the guid of the component (the parent of all fields)
* @param {object} structure - passed from the UI, the structure object
* @return {void}
*/

insertDefaultValuesComponent: async function(componentGuid, structure){

console.log(componentGuid)
console.log("structure",structure)
// console.log(componentGuid)
// console.log("structure",structure)

// locate the correct pt to work on in the activeProfile
let pt = utilsProfile.returnPt(this.activeProfile,componentGuid)
Expand Down

0 comments on commit 2686a94

Please sign in to comment.