Skip to content

Commit

Permalink
Merge pull request #14 from lihelennn/helen/pdf-to-html
Browse files Browse the repository at this point in the history
Try source paths with query params as well if cannot find source
  • Loading branch information
JumanaFM authored Mar 24, 2021
2 parents 2884a49 + d19137f commit 4efa4ad
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
24 changes: 21 additions & 3 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ function embedNbApp () {
:threads-hovered="threadsHovered"
:draft-range="draftRange"
:show-highlights="showHighlights"
:source-url="sourceURL"
@switch-class="onSwitchClass"
@toggle-highlights="onToggleHighlights"
@search-option="onSearchOption"
Expand Down Expand Up @@ -209,7 +210,8 @@ function embedNbApp () {
minUpvotes: 0
},
showHighlights: true,
resizeKey: Date.now() // work around to force redraw highlights
resizeKey: Date.now(), // work around to force redraw highlights,
sourceURL: '',
},
computed: {
style: function () {
Expand Down Expand Up @@ -336,15 +338,31 @@ function embedNbApp () {
if (this.myClasses.length === 1) {
this.activeClass = this.myClasses[0]
}
this.sourceURL = source

} else {
const sourceWithQuery = window.location.href // try the source with query params as well
const configWithQuery = { headers: { Authorization: 'Bearer ' + token }, params: { url: sourceWithQuery }}
const myClassesWithQuery = await axios.get('/api/annotations/myClasses', configWithQuery)
if (myClassesWithQuery.data.length > 0) {
this.myClasses = myClassesWithQuery.data

if (this.myClasses.length === 1) {
this.activeClass = this.myClasses[0]
}
this.sourceURL = sourceWithQuery

} else {
console.log("Sorry you don't have access");
}
}

},
activeClass: async function (newActiveClass) {
if (newActiveClass != {} && this.user) {
const source = window.location.origin + window.location.pathname
let source = window.location.origin + window.location.pathname
if (this.sourceURL.length > 0) {
source = this.sourceURL
}
const token = localStorage.getItem("nb.user");
const config = { headers: { Authorization: 'Bearer ' + token }, params: { url: source, class: newActiveClass.id } }

Expand Down
7 changes: 6 additions & 1 deletion src/components/NbSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ export default {
showHighlights: {
type: Boolean,
default: true
},
sourceUrl: {
type: String,
default: ""
}
},
data () {
Expand Down Expand Up @@ -303,7 +307,8 @@ export default {
upvoteCount: 0,
seenByMe: true
})
comment.submitAnnotation(this.activeClass.id)
let source = this.sourceUrl.length > 0 ? this.sourceUrl : window.location.href.split('?')[0]
comment.submitAnnotation(this.activeClass.id, source)
if (this.draftRange) {
this.$emit('new-thread', comment)
Expand Down
4 changes: 2 additions & 2 deletions src/models/nbcomment.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,12 @@ class NbComment {
* On success, set {@link NbComment#id}. If this is a thread head,
* {@link NbComment#loadReplies} will be called to also load replies.
*/
submitAnnotation (classId) {
submitAnnotation (classId, sourceUrl) {
const token = localStorage.getItem("nb.user");
const headers = { headers: { Authorization: 'Bearer ' + token }}
if (!this.parent) {
return axios.post('/api/annotations/annotation', {
url: window.location.href.split('?')[0],
url: sourceUrl,
class: classId,
content: this.html,
range: this.range.serialize(),
Expand Down

0 comments on commit 4efa4ad

Please sign in to comment.