list films cited

This commit is contained in:
j 2021-11-01 10:44:09 +00:00
parent d1e1f311f0
commit 6764d53403
3 changed files with 66 additions and 11 deletions

View file

@ -33,7 +33,7 @@
width: 100%;
height: auto;
max-width: var(--container-width);
max-height: 80vh;
max-height: 88vh;
margin: auto;
//transition: opacity 0.4s;
@ -49,7 +49,7 @@
img {
width: 100%;
height: auto;
max-height: 80vh;
max-height: 88vh;
margin: auto;
object-fit: contain;
}

View file

@ -225,7 +225,15 @@ function renderAnnotation(config, video, ascroll, annotation) {
div.style.background = `linear-gradient(to bottom, ${color1}, ${color2})`;
var figcaption = ''
if (annotation.title) {
figcaption = `<figcaption><a href="${baseURL}/${annotation.id}" target="_blank">${annotation.title}</a></figcaption>`
if (config.language == 'zh') {
var title = annotation.title.split('/')[1] || annotation.title
var director = annotation.director[1]
} else {
var title = annotation.title.split('/')[0]
var director = annotation.director[0]
}
var txt = `${title} (${director})`
figcaption = `<figcaption><a href="${baseURL}/${annotation.id}" target="_blank">${txt}</a></figcaption>`
}
annotation.value = annotation.value.replace(/src="\//g, `src="${baseURL}/`).replace(/href="\//g, `href="${baseURL}/`)
div.innerHTML = `
@ -287,16 +295,43 @@ function renderAnnotations(config) {
updatePlayer(video, frame, config.first['in'], config.first['out'], src)
}
}
if (config.item_url) {
var box= document.createElement('div')
if (config.item_url || config.cited) {
var box = document.createElement('div')
var color = config.annotations[config.annotations.length - 1].color2
box.style.background = `hsl(${color.hue}, 70%, 75%)`
var div = document.createElement('div')
div.classList.add('related-film')
if (config.item_url) {
if (config.language == 'zh') {
div.innerHTML = `
Film cited: <a href="${config.item_url}">${config.item_title} - ${config.item_director[0]}</a><br>
引用影片: <a href="${config.item_url}">${config.item_title_zh} - ${config.item_director[1]}</a>
`
} else {
div.innerHTML = `
Film cited: <a href="${config.item_url}">${config.item_title} - ${config.item_director[0]}</a><br>
`
}
} else {
var html = []
config.cited.forEach(film => {
var title_en = film.title.split(' / ')[0]
var title_zh = film.title.split(' / ')[1] || title_en
if (config.language == 'en') {
var director = film.director ? ` (${film.director[0]})` : ''
html.push(`<a href="/polis+film/${film.id}/">${title_en}${director}</a>`)
} else {
var director = film.director ? ` (${film.director[1]})` : ''
html.push(`<a href="/polis+film/${film.id}/">${title_zh}${director}</a>`)
}
})
var films = html.length == 1 ? 'Film' : 'Films'
html= html.join(', ')
if (config.language == 'zh') {
div.innerHTML = ` 引用影片: ${html}`
} else {
div.innerHTML = `${films} cited: ${html}`
}
}
box.appendChild(div)
ascroll.appendChild(box)
}
@ -355,14 +390,22 @@ function loadAnnotations(config) {
})
})
} else {
var cited = {}
pandoraAPI('getEdit', {id: config.edit, keys: []}).then(response => {
var annotations = []
response.data.clips.forEach(clip => {
cited[clip.item] = {
title: clip.title,
director: clip.director,
id: clip.item
}
clip.layers[config.layer].forEach(annotation => {
if (config.user && annotation.user != config.user) {
return
}
annotation.title = clip.title
;['title', 'director', 'date'].forEach(key => {
annotation[key] = clip[key]
})
if (config.only_e) {
if (annotation.value.slice(0, 2) == 'E:') {
annotation.value = annotation.value.slice(2).trim()
@ -377,6 +420,7 @@ function loadAnnotations(config) {
})
loadClips(annotations).then(annotations => {
config.annotations = annotations
config.cited = Object.values(cited)
renderAnnotations(config)
})
})

View file

@ -97,18 +97,28 @@ class Text(models.Model):
return []
clips = r['data']['clips']
annotations = []
cited = {}
layer = self.data.get('layer', None) or DEFAULT_LAYER
for clip in clips:
item_id = clip['item']
cited[item_id] = {
'title': clip['title'],
'director': clip['director'],
'id': item_id,
}
for annotation in clip['layers'][layer]:
if 'user' in self.data and annotation['user'] == self.data['user']:
continue
annotation['title'] = clip['title']
for key in ('title', 'director', 'date'):
if key in clip:
annotation[key] = clip[key]
if self.data.get('only_e'):
if annotation['value'].startswith('E:'):
annotation['value'] = annotation['value'][2:].strip()
annotations.append(annotation)
elif not annotation['value'].startswith('E:'):
annotations.append(annotation)
self.data['cited'] = list(cited.values())
return self.get_clips(api, annotations)
def get_clips(self, api, annotations):
@ -158,6 +168,7 @@ class Text(models.Model):
data['title'] = self.title
data['byline'] = self.byline
data['body'] = self.body
data['language'] = self.language
item_id = self.data.get('related')
if not item_id:
item_id = self.data.get('item')