Skip to content

Commit

Permalink
help for poems
Browse files Browse the repository at this point in the history
  • Loading branch information
cubap committed Jan 21, 2025
1 parent 01fd667 commit e4e06e8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion public/javascripts/deer/components/view/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class CollectionLabel extends DeerView {

constructor() {
super()
this.template = (obj={}) => `<a href="../${[...collections].find(r=>r.name === obj.targetCollection)?.id.split('/').pop()}">${UTILS.getValue(obj.targetCollection)}</a>`
this.template = (obj={}) => `<a href="../${[...collections].find(r=>r.name === UTILS.getValue(obj.targetCollection))?.id.split('/').pop()}">${UTILS.getValue(obj.targetCollection)}</a>`
}

connectedCallback() {
Expand Down
17 changes: 15 additions & 2 deletions public/javascripts/deer/components/view/poem.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,15 @@ h1+.publication-info {
</row>
`
export default class DlaPoemDetail extends DeerView {
static get observedAttributes() { return [DEER.ID, DEER.LAZY] }
static get observedAttributes() { return [DEER.ID, DEER.LAZY, DEER.FINAL] }

// loadCards after the Entity is loaded and deer-final is set to true
async attributeChangedCallback(name, oldValue, newValue) {
super.attributeChangedCallback(name, oldValue, newValue)
if (oldValue !== newValue && this.getAttribute(DEER.FINAL) === "true") {
this.loadCards()
}
}

constructor() {
super()
Expand All @@ -102,6 +110,11 @@ export default class DlaPoemDetail extends DeerView {

connectedCallback() {
super.connectedCallback()
this.addEventListener(DEER.EVENTS.LOADED, this.loadCards.bind(this))
}

loadCards() {
if(!this.Entity) return
this.classList.remove(this.dataset.spinner)
const historyWildcard = { "$exists": true, "$size": 0 }
const exprQuery = {
Expand Down Expand Up @@ -251,7 +264,7 @@ class DlaSimpleExpression extends DeerView {
case "reload":
case "update":
this.Entity = msg.payload
this.innerHTML = this.template(msg.payload?.assertions) ?? this.innerHTML
if( msg.payload?.assertions ) this.innerHTML = this.template(msg.payload.assertions)
break
case "error":
// this.#handleErrors(msg.payload)
Expand Down
2 changes: 1 addition & 1 deletion public/javascripts/deer/components/view/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class DeerView extends HTMLElement {
case "update":
case "reload":
this.Entity = Object.assign(this.Entity ?? {},msg.payload)
this.innerHTML = this.template(msg.payload?.assertions) ?? this.innerHTML
if( msg.payload?.assertions ) this.innerHTML = this.template(msg.payload.assertions)
break
case "error":
this.#handleErrors(msg.payload)
Expand Down
5 changes: 4 additions & 1 deletion public/javascripts/deer/deer-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ const utils = {
}
if (Array.isArray(property)) {
// It is an array of things, we can only presume that we want the array. If it needs to become a string, local functions take on that responsibility.
return property
if(property.length === 1){
return this.getValue(property[0], alsoPeek, asType)
}
return property.map(p => this.getValue(p, alsoPeek, asType))
} else {
if (typeof property === "object") {
// TODO: JSON-LD insists on "@value", but this is simplified in a lot
Expand Down

0 comments on commit e4e06e8

Please sign in to comment.