Commit 10630fa1 authored by Anton's avatar Anton
Browse files

Clean up grid display a bit, update async/await

parent 699201c3
......@@ -38,7 +38,6 @@
}
},
async mounted () {
const _this = this
window.addEventListener('resize', this.updateGridDimensions)
// this.messenger.$on('video-loaded', (/* origin */) => {
// // console.log('video loaded', origin.origin)
......@@ -49,65 +48,74 @@
this.grid = await this.$store.dispatch('maps/get', this.$route.params.id)
await this.fetchMetadataAnnotations()
this.updateGridDimensions()
_this.fetchCellAnnotations()
await this.fetchCellAnnotations()
},
methods: {
fetchCellAnnotations () {
const _this = this,
query = { 'body.type': '2DCell', 'target.id': this.grid.id }
this.$store.dispatch('annotations/find', query)
.then(annotations => {
_this.annotations = annotations.items
_this.cells = _this.annotations.map(annotation => {
let cell = JSON.parse(annotation.body.value)
if (cell) {
cell.uuid = annotation.uuid
return cell
}
return null
}).filter(cell => cell)
})
async fetchCellAnnotations () {
const query = {
'body.type': '2DCell',
'target.id': this.grid.id
}
const annotations = await this.$store.dispatch('annotations/find', query)
if (!annotations || !Array.isArray(annotations.items)) return
const cells = []
for (let annotation of annotations.items) {
let cell
try {
cell = JSON.parse(annotation.body.value)
}
catch (e) {
console.debug('Failed to parse cell annotation body', e)
}
if (cell) {
cell.uuid = annotation.uuid
cell.id = annotation.id
cells.push(cell)
}
}
this.annotations = annotations.items
this.cells = cells
},
async fetchMetadataAnnotations () {
const _this = this
const query = { 'body.type': '2DGridMetadata', 'target.id': this.grid.id }
const annotations = await this.$store.dispatch('annotations/find', query)
let annotation = annotations.items.shift()
if (annotation) {
let metadata = JSON.parse(annotation.body.value)
metadata.uuid = annotation.uuid
let metadata
try {
metadata = JSON.parse(annotation.body.value)
}
catch (e) {
console.debug('Failed to parse grid metadata annotation body', e)
}
if (metadata) {
_this.gridMetadata = metadata
metadata.uuid = annotation.uuid
this.gridMetadata = metadata
}
}
else {
_this.gridMetadata = {
this.gridMetadata = {
columns: 10,
rows: 6,
ratio: 16 / 9.0
}
_this.updateGridMetadataStore()
await this.updateGridMetadataStore()
}
},
async updateCellStore (cell) {
const _this = this
let annotation = this.getGridCellAnnotation(cell)
if (cell.uuid) {
await _this.$store.dispatch('annotations/patch', [cell.uuid, annotation])
}
else {
await _this.$store.dispatch('annotations/post', annotation)
}
if (cell.uuid) await this.$store.dispatch('annotations/patch', [cell.uuid, annotation])
else await this.$store.dispatch('annotations/post', annotation)
},
async updateGridMetadataStore () {
const _this = this
let mapAnnotation = this.getGridMetadataAnnotation(this.grid.id, this.gridMetadata)
if (_this.gridMetadata.uuid) {
await _this.$store.dispatch('annotations/patch', [_this.gridMetadata.uuid, mapAnnotation])
if (this.gridMetadata.uuid) {
await this.$store.dispatch('annotations/patch', [this.gridMetadata.uuid, mapAnnotation])
}
await _this.$store.dispatch('annotations/post', mapAnnotation)
_this.updateGridDimensions()
await this.$store.dispatch('annotations/post', mapAnnotation)
this.updateGridDimensions()
},
updateGridDimensions () {
let elWidth = this.$el.offsetWidth
......@@ -170,7 +178,12 @@
}
},
getCellStyle (cell) {
return { 'grid-column-start': cell.x, 'grid-column-end': `span ${cell.width}`, 'grid-row-start': cell.y, 'grid-row-end': `span ${cell.height}` }
return {
'grid-column-start': cell.x,
'grid-column-end': `span ${cell.width}`,
'grid-row-start': cell.y,
'grid-row-end': `span ${cell.height}`
}
}
}
}
......
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