/
AdminVideoShow.vue
63 lines (57 loc) · 1.79 KB
/
AdminVideoShow.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<template>
<div>
<div class="display-1 pt-3">{{video.name}}</div>
<div v-html="video.description"></div>
<v-combobox :items="tags"
item-text="name"
v-model="videoTags"
multiple
chips
deletable-chips
hide-selected
return-object>
</v-combobox>
</div>
</template>
<script>
import { mapState, mapGetters } from 'vuex';
import _ from 'lodash';
export default {
computed: {
...mapState({
videos: 'videos',
tags: state => state.tags.tags
}),
...mapGetters({
getTag: 'tags/get'
}),
video(){
return this.videos.find(v => v.id == this.$route.params.id) || {};
},
videoTags: {
get(){
let tagIds = this.video.tag_ids;
return tagIds && tagIds.map(id => this.getTag(id));
},
async set(newTags) {
let createdTag = newTags.find(t => typeof t == 'string')
if(createdTag){
createdTag = await this.$store.dispatch('tags/create', {name: createdTag});
this.$store.dispatch('tags/connectToVideo', {tag: createdTag, video: this.video})
} else {
let addedTags = _.differenceBy(newTags, this.videoTags, 'id');
let removedTags = _.differenceBy(this.videoTags, newTags, 'id');
if(addedTags.length > 0) {
this.$store.dispatch('tags/connectToVideo', {tag: addedTags[0], video: this.video})
}
if(removedTags.length > 0) {
this.$store.dispatch('tags/disconnectFromVideo', {tag: removedTags[0], video: this.video})
}
}
}
}
}
}
</script>
<style lang="scss" scoped>
</style>