-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle NAC edge-case #46
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
<script> | ||
/* | ||
This widget contains customizations for Explore Homer that handle | ||
special-case queries tothe New Alexandria Commentary API. | ||
|
||
In the future, we may want to take this type of customization | ||
into consideration when implementing hooks / extensibility points | ||
within `scaife-widgets`. | ||
|
||
We may also find that the Vue Composition API | ||
(https://composition-api.vuejs.org/) lends itself to these types of | ||
customizations. | ||
*/ | ||
import gql from 'graphql-tag'; | ||
|
||
import WIDGETS_NS, { | ||
NewAlexandriaWidget, | ||
} from '@scaife-viewer/scaife-widgets'; | ||
|
||
export default { | ||
extends: NewAlexandriaWidget, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is cool. Didn't know it was possible to do this. |
||
name: 'NewAlexandriaWidget', | ||
scaifeConfig: { | ||
displayName: 'New Alexandria Commentary', | ||
}, | ||
data: () => ({ | ||
passageTextParts: [], | ||
healedPassage: '', | ||
}), | ||
computed: { | ||
originalPassage() { | ||
// the passage retrieved from the store | ||
return this.$store.getters[`${WIDGETS_NS}/passage`]; | ||
}, | ||
passage() { | ||
// overrides `NewAlexandriaWidget.computed.passage` | ||
// so that only the healedPassage is passed to NAC | ||
// via the `passage` watcher | ||
return this.healedPassage; | ||
}, | ||
}, | ||
watch: { | ||
originalPassage: { | ||
immediate: true, | ||
handler() { | ||
// special-case handling for the Folios version of | ||
// the Iliad | ||
if ( | ||
this.originalPassage.version === | ||
'urn:cts:greekLit:tlg0012.tlg001.msA-folios:' | ||
jacobwegner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) { | ||
this.healFolioURN(); | ||
} else { | ||
this.healedPassage = this.originalPassage.toString(); | ||
} | ||
}, | ||
}, | ||
passageTextParts() { | ||
// after we have retrieved passage text parts, | ||
// extract the refs and populate healedPassage | ||
const refs = this.extractPassageTextPartRefs(); | ||
const healedRefs = this.extractHealedRefs(refs); | ||
this.updateHealedPassage(healedRefs); | ||
}, | ||
}, | ||
methods: { | ||
hasLinesInRef(ref) { | ||
// good: 2r.1.1 | ||
// bad: 12r, 12r.1 | ||
return ref.split('.').length === 3; | ||
}, | ||
healFolioURN() { | ||
const refs = this.originalPassage.reference.split('-'); | ||
if (this.hasLinesInRef(refs[0])) { | ||
const healedRefs = this.extractHealedRefs(refs); | ||
this.updateHealedPassage(healedRefs); | ||
} else { | ||
this.fetchPassageTextParts(); | ||
} | ||
}, | ||
extractHealedRefs(refs) { | ||
// pops the folio off of refs, | ||
// e.g. 12r.1.1-12r.1.7 --> 1.1-1.7 | ||
const healedRefs = []; | ||
refs.forEach(ref => { | ||
const refParts = ref.split('.'); | ||
healedRefs.push(refParts.slice(1).join('.')); | ||
}); | ||
return healedRefs; | ||
}, | ||
updateHealedPassage(refs) { | ||
if (refs.length > 0) { | ||
const refPart = refs.join('-'); | ||
this.healedPassage = `${this.originalPassage.version}${refPart}`; | ||
} | ||
}, | ||
fetchPassageTextParts() { | ||
// retrieves the lowest text parts for a folio level reference, | ||
// e.g. 12r --> 12r.1.1-12.r.1.25 | ||
const query = gql` | ||
{ | ||
passageTextParts( | ||
reference: "${this.originalPassage}" | ||
) { | ||
edges { | ||
node { | ||
id | ||
ref | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
this.$gql(query).then(data => { | ||
this.passageTextParts = data.passageTextParts.edges.map(edge => { | ||
const { node } = edge; | ||
return node; | ||
}); | ||
}); | ||
return query; | ||
}, | ||
extractPassageTextPartRefs() { | ||
// extracts the ref(s) from the text parts | ||
const refs = []; | ||
// start ref | ||
refs.push(this.passageTextParts.slice(0, 1)[0].ref); | ||
if (this.passageTextParts.length > 1) { | ||
// end ref | ||
refs.push(this.passageTextParts.slice(-1)[0].ref); | ||
} | ||
return refs; | ||
}, | ||
}, | ||
}; | ||
</script> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! composition API is going to change everything for us on Scaife.