|
1 | 1 | <script type="text/javascript"> |
2 | | - import {isEmpty, isArray} from 'lodash' |
3 | | - import draggable from 'vuedraggable' |
| 2 | + import draggable from 'vuedraggable' |
| 3 | + import {isArray, isEmpty} from '@/utils.js' |
4 | 4 | import StreamBlock from '@/components/StreamBlock.vue' |
5 | 5 | import AbstractBlock from '@/components/AbstractBlock.vue' |
6 | 6 |
|
7 | | - let |
8 | | - text_area, |
9 | | - delete_blocks_from_db, |
10 | | - popup_size; |
| 7 | + // const _ = require('lodash'); |
11 | 8 |
|
12 | | - function id_to_windowname(text) { |
| 9 | + let |
| 10 | + text_area, |
| 11 | + delete_blocks_from_db, |
| 12 | + popup_size; |
| 13 | +
|
| 14 | + function id_to_windowname(text) { |
13 | 15 | text = text.replace(/\./g, '__dot__'); |
14 | 16 | text = text.replace(/\-/g, '__dash__'); |
15 | 17 | return text; |
16 | 18 | } |
17 | 19 |
|
18 | | - export default { |
19 | | - props: ['app_node'], |
20 | | - components: { |
| 20 | + export default { |
| 21 | + props: ['app_node'], |
| 22 | + components: { |
21 | 23 | draggable, |
22 | 24 | StreamBlock, |
23 | 25 | AbstractBlock |
24 | 26 | }, |
25 | 27 | data () { |
26 | 28 | return { |
27 | | - blocks: {}, // save content of all instances |
28 | | - show_help: false, |
29 | | - show_add_block: false, |
30 | | - will_removed: [], // blocks that will be removed from db |
31 | | - stream: [], // [{model_name: ..., id: ...}, ...] |
32 | | - model_info: {}, // {'model_name': model.__doc__}, |
| 29 | + blocks: {}, // save content of all instances |
| 30 | + show_help: false, |
| 31 | + show_add_block: false, |
| 32 | + will_removed: [], // blocks that will be removed from db |
| 33 | + stream: [], // [{model_name: ..., id: ...}, ...] |
| 34 | + model_info: {}, // {'model_name': model.__doc__}, |
33 | 35 | base_admin_url: "", |
34 | | - stream_texts: window.stream_texts |
| 36 | + stream_texts: window.stream_texts |
35 | 37 | } |
36 | 38 | }, |
37 | 39 | beforeMount: function() { |
38 | | - text_area = this.app_node.querySelector('textarea') |
39 | | - delete_blocks_from_db = Boolean(text_area.hasAttribute('delete_blocks_from_db')) |
40 | | - popup_size = text_area.dataset.popup_size ? JSON.parse(text_area.dataset.popup_size) : [1000, 500] |
| 40 | + text_area = this.app_node.querySelector('textarea') |
| 41 | + delete_blocks_from_db = Boolean(text_area.hasAttribute('delete_blocks_from_db')) |
| 42 | + popup_size = text_area.dataset.popup_size ? JSON.parse(text_area.dataset.popup_size) : [1000, 500] |
41 | 43 |
|
42 | 44 | this.base_admin_url = text_area.getAttribute('base_admin_url') |
43 | | - this.stream = JSON.parse(text_area.innerHTML) |
44 | | - this.model_info = JSON.parse(text_area.getAttribute('model_list_info')) |
| 45 | + this.stream = JSON.parse(text_area.innerHTML) |
| 46 | + this.model_info = JSON.parse(text_area.getAttribute('model_list_info')) |
45 | 47 |
|
46 | 48 | if (this.stream.length && !this.stream[0].hasOwnProperty('collapsed')) { |
47 | 49 | this.setAllCollapsed(false) |
|
89 | 91 | isEmpty: isEmpty, |
90 | 92 | isArray: isArray, |
91 | 93 | setAllCollapsed: function(value) { |
92 | | - _.forEach(this.stream, (v, k) => { |
| 94 | + this.stream.forEach((v, k) => { |
93 | 95 | v.collapsed = value |
94 | 96 | }) |
95 | 97 | }, |
|
102 | 104 | |
103 | 105 | }, |
104 | 106 | getBlockIndex: function(block_unique_id) { |
105 | | - const block = _.find(this.stream, ['unique_id', block_unique_id]) |
| 107 | + const block = this.stream.find(function(o) {return o.unique_id = block_unique_id}) |
106 | 108 | const index = this.stream.indexOf(block) |
107 | 109 | return [index, block] |
108 | 110 | }, |
|
124 | 126 | } |
125 | 127 | } |
126 | 128 | } |
127 | | - |
128 | 129 | }, |
129 | 130 | deleteInstance: function(block_unique_id, instance_id) { |
130 | 131 | let [block_index, block] = this.getBlockIndex(block_unique_id) |
|
151 | 152 | let options = {}; |
152 | 153 | let new_block; |
153 | 154 |
|
154 | | - _.forEach(this.model_info[model_name].options, (option, key) => { |
| 155 | + Object.entries(this.model_info[model_name].options).forEach(([key, option],index) => { |
155 | 156 | options[key] = option.default; |
156 | 157 | }); |
157 | 158 | new_block = { |
|
181 | 182 | }, |
182 | 183 | watch: { |
183 | 184 | stream: { |
184 | | - handler(nv) { |
185 | | - text_area.innerHTML = JSON.stringify(nv.map(function(i){ |
186 | | - // return only fields that in initial data |
187 | | - return { |
| 185 | + handler(nv) { |
| 186 | + text_area.innerHTML = JSON.stringify(nv.map(function(i){ |
| 187 | + // return only fields that in initial data |
| 188 | + return { |
188 | 189 | unique_id: i.unique_id, |
189 | 190 | model_name: i.model_name, |
190 | 191 | id: i.id, |
191 | 192 | options: i.options, |
192 | 193 | collapsed: i.collapsed |
193 | 194 | }; |
194 | | - })); |
195 | | - }, |
196 | | - deep: true |
| 195 | + })); |
| 196 | + }, |
| 197 | + deep: true |
197 | 198 | } |
198 | 199 | } |
199 | 200 | } |
|
212 | 213 |
|
213 | 214 | <div class="streamfield-models"> |
214 | 215 | <draggable v-model="stream" group="stream" handle=".block-move" item-key="unique_id"> |
215 | | - <template #item="{element: block}"> |
216 | | - <StreamBlock v-if="!isAbstract(block)" :block="block" :ref="block.unique_id"/> |
| 216 | + <template #item="{element: block}"> |
| 217 | + <StreamBlock v-if="!isAbstract(block)" :block="block" :ref="block.unique_id"/> |
217 | 218 | <AbstractBlock v-else :block="block" /> |
218 | | - </template> |
| 219 | + </template> |
219 | 220 | </draggable> |
220 | 221 | <div class="stream-insert-new-block"> |
221 | 222 | <div class="add-new-block-button" @click="show_add_block=!show_add_block" v-text="stream_texts['AddNewBlock']"></div> |
|
0 commit comments