-
Notifications
You must be signed in to change notification settings - Fork 25
/
main.vue
157 lines (151 loc) · 3.92 KB
/
main.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<template>
<div class="content_annotator">
<smart-selector
name="topic"
:options="Object.keys(options)"
v-model="view"/>
<div class="separate-bottom">
<template v-if="options['all'] && options['all'].length">
<topic-item
v-for="item in options[view]"
v-if="!topicAlreadyCreated(item)"
:class="{ 'button-data' : content.topic_id != item.id }"
:key="item.id"
:topic="item"
@select="content.topic_id = $event.id"/>
</template>
<template v-else>
<a
target="blank"
href="/controlled_vocabulary_terms/new">
Create a topic first.
</a>
</template>
</div>
<div class="separate-bottom">
<textarea
v-model="content.text"
placeholder="Text..."/>
</div>
<div>
<button
type="button"
:disabled="!validate"
class="button normal-input button-submit"
@click="createNew">
Create
</button>
</div>
<table-list
:header="['Text', 'Topic', '']"
:attributes="['text', ['topic', 'name']]"
:list="shortList"
@delete="removeItem"
class="list">
<template v-slot:options="slotProps">
<a
class="circle-button btn-edit"
:href="`/tasks/content/editor/index?otu_id=${slotProps.item.otu_id}&topic_id=${slotProps.item.topic_id}`"></a>
</template>
</table-list>
</div>
</template>
<script>
import CRUD from '../../request/crud.js'
import annotatorExtend from '../../components/annotatorExtend.js'
import SmartSelector from 'components/switch.vue'
import TopicItem from '../citations/topicItem.vue'
import TableList from 'components/table_list.vue'
import { shorten } from 'helpers/strings.js'
export default {
mixins: [CRUD, annotatorExtend],
components: {
SmartSelector,
TopicItem,
TableList
},
computed: {
validate () {
return (this.content.text.length > 1 && this.content.topic_id != undefined)
},
shortList () {
return this.list.map(content => {
content.text = shorten(content.text, 150)
return content
})
}
},
data() {
return {
view: '',
options: [],
content: this.newContent()
}
},
mounted() {
this.loadTabList('Topic')
},
methods: {
createNew() {
this.create('/contents', { content: this.content }).then(response => {
this.list.push(response.body)
this.content = this.newContent()
})
},
newContent() {
return {
text: '',
topic_id: undefined,
otu_id: this.metadata.object_id,
type: this.objectType
}
},
topicAlreadyCreated(topic) {
return this.list.find(item => { return topic.id == item.topic_id })
},
setViewWithTopics(listView) {
let keys = Object.keys(listView)
let that = this
keys.some(function(key) {
if(listView[key].find(item => { return !that.topicAlreadyCreated(item) })) {
that.view = key
return true
}
})
},
loadTabList (type) {
let tabList
let allList
let promises = []
let that = this
promises.push(this.getList(`/topics/select_options?klass=${this.objectType}&target=Citation`).then(response => {
tabList = response.body
}))
promises.push(this.getList(`/controlled_vocabulary_terms.json?type[]=${type}`).then(response => {
allList = response.body
}))
Promise.all(promises).then(() => {
tabList['all'] = allList
Object.keys(tabList).forEach(key => (!tabList[key].length) && delete tabList[key])
that.options = tabList
that.setViewWithTopics(tabList);
})
}
}
}
</script>
<style lang="scss">
.radial-annotator {
.content_annotator {
button {
min-width: 100px;
}
textarea {
padding-top: 14px;
padding-bottom: 14px;
width: 100%;
height: 100px;
}
}
}
</style>