Skip to content

Commit

Permalink
Merge pull request #151 from lcnetdev/hubs-stub-creation
Browse files Browse the repository at this point in the history
Hubs stub creation
  • Loading branch information
thisismattmiller authored Dec 4, 2024
2 parents 9601c49 + 02a9303 commit 20fd9ac
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/components/panels/edit/fields/LookupComplex.vue
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
<Transition name="action">
<div class="lookup-action" v-if="showActionButton && myGuid == activeField">
<action-button :type="'lookupComplex'" :id="`action-button-${structure['@guid']}`" :structure="structure" :guid="guid" @action-button-command="actionButtonCommand" />
<action-button :type="'lookupComplex'" :id="`action-button-${structure['@guid']}`" :structure="structure" :guid="guid" :propertyPath="propertyPath" @action-button-command="actionButtonCommand" />
</div>
</Transition>
Expand Down
21 changes: 20 additions & 1 deletion src/components/panels/edit/fields/helpers/ActionButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@
clickmode: Boolean,
small: Boolean,
fieldGuid: String,
structure: Object
structure: Object,
propertyPath: Array,
},
data () {
Expand Down Expand Up @@ -241,6 +242,10 @@
showBuildHubStub(){
if (!this.propertyPath) return false;
if (this.propertyPath && this.propertyPath.length==0) return false;
let pt = this.profileStore.returnStructureByComponentGuid(this.guid)
if (pt && pt.propertyURI && pt.propertyURI == "http://id.loc.gov/ontologies/bibframe/relation"){
return true
Expand All @@ -255,6 +260,20 @@
console.log(this.guid)
let info = this.profileStore.returnLccInfo(this.guid)
this.profileStore.activeHubStubData = info
this.profileStore.activeHubStubComponent = {
type: this.type,
guid: this.guid,
fieldGuid: this.fieldGuid,
structure: this.structure,
type: this.type,
propertyPath:this.propertyPath
}
this.profileStore.showHubStubCreateModal = true
},
Expand Down
23 changes: 19 additions & 4 deletions src/components/panels/edit/modals/HubStubCreateModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@
...mapStores(useConfigStore),
...mapStores(useProfileStore),
...mapWritableState(useProfileStore, ['activeProfile','showHubStubCreateModal','activeHubStubData']),
...mapWritableState(useProfileStore, ['activeProfile','showHubStubCreateModal','activeHubStubData','activeHubStubComponent']),
Expand Down Expand Up @@ -113,6 +115,7 @@
this.hubCreator.uri = null
this.hubCreator.typeFull = null
console.log("value",value)
if (value.title){
if (Array.isArray(value.title)){
Expand Down Expand Up @@ -152,7 +155,7 @@
console.log(this.hubCreator)
},
Expand All @@ -169,9 +172,20 @@
}
},
buildHub(){
async buildHub(){
let results = await this.profileStore.buildPostHubStub(this.hubCreator,this.hubTitle,this.hubLang,this.preferenceStore.catCode)
this.profileStore.buildPostHubStub(this.hubCreator,this.hubTitle,this.hubLang)
// this.profileStore.setValueComplex(this.guid, null, this.propertyPath, contextValue.uri, contextValue.title, contextValue.typeFull, contextValue.nodeMap, contextValue.marcKey)
console.log(results)
// this.profileStore.setValueComplex(this.guid, null, this.propertyPath, contextValue.uri, contextValue.title, contextValue.typeFull, contextValue.nodeMap, contextValue.marcKey)
Expand Down Expand Up @@ -263,6 +277,7 @@
</template>
</div>


<div style="margin-bottom: 1em;">
<span class="creator-label" v-if="!hubCreator.label">[No Hub Creator]</span>
<span class="creator-label" v-if="hubCreator.label">{{hubCreator.label }}</span>
Expand Down
127 changes: 122 additions & 5 deletions src/lib/utils_export.js
Original file line number Diff line number Diff line change
Expand Up @@ -1755,11 +1755,11 @@ const utilsExport = {
* @param {string} langUri - uri to language
* @return {string}
*/
createHubStubXML: async function(hubCreatorObj,title,langUri){
createHubStubXML: async function(hubCreatorObj,title,langUri,catalogerId){

console.log(hubCreatorObj,title,langUri,catalogerId)


console.log(hubCreatorObj,title,langUri)


// we are creating the xml in two formats, create the root node for both
let rdf = document.createElementNS(this.namespace.rdf, "RDF");
Expand Down Expand Up @@ -1812,12 +1812,16 @@ const utilsExport = {

let elAgentProperty = document.createElementNS(this.namespace.bf ,'bf:agent')
let elAgentClass = document.createElementNS(this.namespace.bf ,'bf:Agent')
elAgentProperty.appendChild(elAgentClass)
elAgentClass.setAttributeNS(this.namespace.rdf, 'rdf:about', hubCreatorObj.uri)



elAgentProperty.appendChild(elAgentClass)

// let elAgentType = document.createElementNS(this.namespace.bf ,'bf:agent')
let AgentRdftype = this.createElByBestNS('rdf:type')
AgentRdftype.setAttributeNS(this.namespace.rdf, 'rdf:resource', hubCreatorObj.typeFull)

elAgentClass.appendChild(AgentRdftype)
let elAgentLabel = document.createElementNS(this.namespace.rdfs ,'rdfs:label')
elAgentLabel.innerHTML = hubCreatorObj.label
Expand All @@ -1832,6 +1836,119 @@ const utilsExport = {
elHub.appendChild(elContributionProperty)


let elLanguageProperty = document.createElementNS(this.namespace.bf ,'bf:language')
let elLanguageClass = document.createElementNS(this.namespace.bf ,'bf:Language')
elLanguageClass.setAttributeNS(this.namespace.rdf, 'rdf:about', langUri)

let elCodeProperty = document.createElementNS(this.namespace.bf ,'bf:code')
elCodeProperty.innerHTML = langUri.split("/").pop();
elLanguageClass.appendChild(elCodeProperty)
elLanguageProperty.appendChild(elLanguageClass)
elHub.appendChild(elLanguageProperty)


// // uri
// let elTitleProperty = document.createElementNS(this.namespace.bf ,'bf:title')
// let elTitleClass = document.createElementNS(this.namespace.bf ,'bf:Title')

let elAdminProperty = document.createElementNS(this.namespace.bf ,'bf:adminMetadata')
let elAdminClass = document.createElementNS(this.namespace.bf ,'bf:AdminMetadata')

let elStatusProperty = document.createElementNS(this.namespace.bf ,'bf:status')
let elStatusClass = document.createElementNS(this.namespace.bf ,'bf:Status')

elStatusClass.setAttributeNS(this.namespace.rdf, 'rdf:about', 'http://id.loc.gov/vocabulary/mstatus/n')
let elStatusLabel = document.createElementNS(this.namespace.rdfs ,'rdfs:label')
elStatusLabel.innerHTML='new'
let elStatusCode = document.createElementNS(this.namespace.bf ,'bf:code')
elStatusCode.innerHTML='n'
elStatusClass.appendChild(elStatusLabel)
elStatusClass.appendChild(elStatusCode)
elStatusProperty.appendChild(elStatusClass)

elAdminClass.appendChild(elStatusProperty)

let elDate = document.createElementNS(this.namespace.bf ,'bf:date')
elDate.setAttributeNS(this.namespace.rdf, 'rdf:datatype', 'http://www.w3.org/2001/XMLSchema#date')
elDate.innerHTML = (new Date()).toISOString().split("T")[0]

elAdminClass.appendChild(elDate)



let elAdminAgentProperty = document.createElementNS(this.namespace.bf ,'bf:agent')
let elAdminAgentClass = document.createElementNS(this.namespace.bf ,'bf:Agent')

elAdminAgentClass.setAttributeNS(this.namespace.rdf, 'rdf:about', 'http://id.loc.gov/vocabulary/organizations/dlc')

let elAdminAgentType = document.createElementNS(this.namespace.rdf ,'rdf:type')
elAdminAgentType.setAttributeNS(this.namespace.rdf, 'rdf:resource', 'http://id.loc.gov/ontologies/bibframe/Organization')
let elAdminAgentLabel = document.createElementNS(this.namespace.rdfs ,'rdfs:label')
elAdminAgentLabel.innerHTML='United States, Library of Congress'

elAdminAgentClass.appendChild(elAdminAgentType)
elAdminAgentClass.appendChild(elAdminAgentLabel)

let elAdminAgentCode1 = document.createElementNS(this.namespace.rdfs ,'bf:code')
elAdminAgentCode1.setAttributeNS(this.namespace.rdf, 'rdf:datatype', 'http://id.loc.gov/datatypes/orgs/code')
elAdminAgentCode1.innerHTML='DLC'

let elAdminAgentCode2 = document.createElementNS(this.namespace.rdfs ,'bf:code')
elAdminAgentCode1.setAttributeNS(this.namespace.rdf, 'rdf:datatype', 'http://id.loc.gov/datatypes/orgs/normalized')
elAdminAgentCode1.innerHTML='dlc'

let elAdminAgentCode3 = document.createElementNS(this.namespace.rdfs ,'bf:code')
elAdminAgentCode1.setAttributeNS(this.namespace.rdf, 'rdf:datatype', 'http://id.loc.gov/datatypes/orgs/iso15511')
elAdminAgentCode1.innerHTML='US-dlc'

elAdminAgentClass.appendChild(elAdminAgentCode1)
elAdminAgentClass.appendChild(elAdminAgentCode2)
elAdminAgentClass.appendChild(elAdminAgentCode3)




elAdminAgentProperty.appendChild(elAdminAgentClass)
elAdminClass.appendChild(elAdminAgentProperty)


let catalogerIdProperty = document.createElementNS(this.namespace.bflc ,'bflc:catalogerId')
catalogerIdProperty.innerHTML=catalogerId



elAdminClass.appendChild(catalogerIdProperty)


elAdminProperty.appendChild(elAdminClass)

elHub.appendChild(elAdminProperty)



// <bf:adminMetadata>
// <bf:AdminMetadata>
// <bf:status>
// <bf:Status rdf:about="http://id.loc.gov/vocabulary/mstatus/n">
// <rdfs:label>new</rdfs:label>
// <bf:code>n</bf:code>
// </bf:Status>
// </bf:status>
// <bf:date rdf:datatype="http://www.w3.org/2001/XMLSchema#date">1996-05-16</bf:date>
// <bf:agent>
// <bf:Agent rdf:about="http://id.loc.gov/vocabulary/organizations/dlc">
// <rdf:type rdf:resource="http://id.loc.gov/ontologies/bibframe/Organization"/>
// <rdfs:label>United States, Library of Congress</rdfs:label>
// <bf:code rdf:datatype="http://id.loc.gov/datatypes/orgs/code">DLC</bf:code>
// <bf:code rdf:datatype="http://id.loc.gov/datatypes/orgs/normalized">dlc</bf:code>
// <bf:code rdf:datatype="http://id.loc.gov/datatypes/orgs/iso15511">US-dlc</bf:code>
// </bf:Agent>
// </bf:agent>
// </bf:AdminMetadata>
// </bf:adminMetadata>



rdf.appendChild(elHub)


Expand Down
25 changes: 19 additions & 6 deletions src/stores/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ export const useProfileStore = defineStore('profile', {
showValidateModal: false,
showHubStubCreateModal: false,
activeHubStubData:{
},
activeHubStubComponent:{

},
showShelfListingModal: false,
Expand Down Expand Up @@ -4456,21 +4458,32 @@ export const useProfileStore = defineStore('profile', {
* @param {object} hubCreatorObj - obj with creator label, uri,marcKey
* @param {string} title - title string
* @param {string} langUri - uri to language
* @return {String}
*/
async buildPostHubStub(hubCreatorObj,title,langUri){
async buildPostHubStub(hubCreatorObj,title,langUri,catCode){

console.log("hubCreatorObj",hubCreatorObj)
let xml = await utilsExport.createHubStubXML(hubCreatorObj,title,langUri)
let xml = await utilsExport.createHubStubXML(hubCreatorObj,title,langUri,catCode)

console.log(xml)
let eid = 'e' + decimalTranslator.new()
eid = eid.substring(0,8)

// pass a fake activeprofile with id == Hub to trigger hub protocols
let pubResuts = await utilsNetwork.publish(xml, eid, {id: 'Hub'})
console.log(pubResuts.status)
// pass a fake activeprofile with id == Hub to trigger hub protocols
let pubResuts
try{
pubResuts = await utilsNetwork.publish(xml, eid, {id: 'Hub'})
console.log(pubResuts)
pubResuts = await pubResuts.json()
console.log(pubResuts)
}catch{
alert("There was an error creating your Hub. Please report this issue.")
}

// pubResuts = {'location': 'http://id.loc.gov/resources/hubs/1111-111-111-111'}

return pubResuts



},
Expand Down

0 comments on commit 20fd9ac

Please sign in to comment.