Commit a3f2f818 authored by Anton's avatar Anton
Browse files

Clean up CellAnnotationList a bit, update to async/await

parent f551fdb1
......@@ -71,7 +71,6 @@ export default {
},
async mounted () {
const _this = this
console.log(this.cell)
this.videoUuid = this.cell.sourceUuid
try {
const videoAnnotation = await this.$store.dispatch(
......@@ -84,9 +83,9 @@ export default {
}
}
catch (e) {
console.log('Unable to fetch metadata for annotation')
console.debug('Unable to fetch metadata for annotation')
}
this.fetchAnnotations()
await this.fetchAnnotations()
if (this.messenger) {
this.messenger.$on('video-time-changed', (time, globalTime, origin) => {
if (
......@@ -110,7 +109,6 @@ export default {
},
methods: {
async handleInputChanged () {
const _this = this
const text = this.newAnnotationText && this.newAnnotationText.trim()
if (text && text.length > 0) {
let newAnnotation = {
......@@ -124,7 +122,7 @@ export default {
type: this.video.target.type,
selector: {
type: 'Fragment',
value: DateTime.fromMillis(_this.contextTime).toISO()
value: DateTime.fromMillis(this.contextTime).toISO()
}
}
}
......@@ -132,8 +130,8 @@ export default {
'annotations/post',
newAnnotation
)
console.log(annotation)
_this.fetchAnnotations()
console.debug('CellAnnotationList: post annotation', annotation)
await this.fetchAnnotations()
}
this.newAnnotationText = ''
},
......@@ -159,69 +157,61 @@ export default {
showAnnotationInput (index) {
return index === this.inputIndex
},
fetchAnnotations () {
const _this = this
this.$store
.dispatch('annotations/find', { uuid: this.videoUuid })
.then(result => {
const videoAnnotation = result.items.shift()
if (videoAnnotation) {
_this.video = videoAnnotation
_this.videoTime = DateTime.fromISO(
_this.video.target.selector.value,
{ setZone: true }
)
_this.contextTime = _this.videoTime
const query = {
type: constants.MAP_TYPE_TIMELINE,
uuid: videoAnnotation.target.uuid
}
_this.$store.dispatch('maps/find', query).then(result => {
const map = result.items.shift()
if (map) {
_this.map = map
}
})
const selectorValue = videoAnnotation.target.selector.value
const startDate = DateTime.fromISO(selectorValue, {
setZone: true
})
const endDate = startDate.plus(_this.videoMeta.duration * 1000)
const endDateISO = endDate.toISO()
const annotationsQuery = {
'target.id': videoAnnotation.target.id,
'target.type': constants.MAP_TYPE_TIMELINE,
'body.type': 'TextualBody',
'target.selector.value': {
$gte: selectorValue,
$lte: endDateISO
}
}
_this.$store
.dispatch('annotations/find', annotationsQuery)
.then(result => {
let annotations = result.items.filter(a => {
return Date.parse(a.target.selector.value) >= _this.videoTime
})
annotations = annotations.sort((a, b) => {
let tDiff =
Date.parse(a.target.selector.value) -
Date.parse(b.target.selector.value)
if (tDiff === 0) {
tDiff = Date.parse(b.created) - Date.parse(a.created)
}
return tDiff
})
_this.annotations = annotations
_this.annotationTimes = []
annotations.forEach(a => {
_this.annotationTimes.push(
Date.parse(a.target.selector.value)
)
})
})
} // TODO: else, show not found?
async fetchAnnotations () {
const result = await this.$store.dispatch('annotations/find', { uuid: this.videoUuid })
const videoAnnotation = result.items.shift()
if (videoAnnotation) {
this.video = videoAnnotation
this.videoTime = DateTime.fromISO(
this.video.target.selector.value,
{ setZone: true }
)
this.contextTime = this.videoTime
const query = {
type: constants.MAP_TYPE_TIMELINE,
uuid: videoAnnotation.target.uuid
}
const mapResult = await this.$store.dispatch('maps/find', query)
const map = mapResult.items.shift()
if (map) {
this.map = map
}
const selectorValue = videoAnnotation.target.selector.value
const startDate = DateTime.fromISO(selectorValue, {
setZone: true
})
const endDate = startDate.plus(this.videoMeta.duration * 1000)
const endDateISO = endDate.toISO()
const annotationsQuery = {
'target.id': videoAnnotation.target.id,
'target.type': constants.MAP_TYPE_TIMELINE,
'body.type': 'TextualBody',
'target.selector.value': {
$gte: selectorValue,
$lte: endDateISO
}
}
const annotationsResult = await this.$store.dispatch('annotations/find', annotationsQuery)
let annotations = annotationsResult.items.filter(a => {
return Date.parse(a.target.selector.value) >= this.videoTime
})
annotations = annotations.sort((a, b) => {
let tDiff =
Date.parse(a.target.selector.value) -
Date.parse(b.target.selector.value)
if (tDiff === 0) {
tDiff = Date.parse(b.created) - Date.parse(a.created)
}
return tDiff
})
this.annotations = annotations
this.annotationTimes = []
annotations.forEach(a => {
this.annotationTimes.push(
Date.parse(a.target.selector.value)
)
})
} // TODO: else, show not found?
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment