Skip to content

Commit f6b2f6a

Browse files
committed
fix js find method
1 parent b49a06d commit f6b2f6a

7 files changed

Lines changed: 18 additions & 13 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Django StreamField
22

33
This is a simple realisation of StreamField's idea of Wagtail CMS for plain Django admin or with Grappelli skin.
4-
Stable version: 2.0.4
4+
Stable version: 2.0.5
55

66
[Major changes (1.4.5 > 2)](changes2.0.md)
77

frontend/src/components/AbstractBlock.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script>
2+
import {find} from '@/utils.js'
23
import BlockHeader from '@/components/BlockHeader.vue'
34
import BlockOptions from '@/components/BlockOptions.vue'
45
import AddBlockHere from '@/components/AddBlockHere.vue'
@@ -19,10 +20,11 @@
1920
return '/streamfield/abstract-block/' + this.model_name_lower + '/';
2021
},
2122
getContent() {
22-
const block = this.$root.stream.find((o) => {return o.unique_id = this.block.unique_id})
23-
window.ax.get(this.render_url(this.block)).then((response) => {
23+
const block = find(this.$root.stream, {'unique_id': this.block.unique_id })
24+
window.ax.get(this.render_url(block)).then((response) => {
2425
this.$root.blocks[this.block.model_name] = response.data;
2526
});
27+
2628
}
2729
}
2830
}

frontend/src/components/App.vue

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
<script type="text/javascript">
22
import draggable from 'vuedraggable'
3-
import {isArray, isEmpty} from '@/utils.js'
3+
import {isArray, isEmpty, find} from '@/utils.js'
44
import StreamBlock from '@/components/StreamBlock.vue'
55
import AbstractBlock from '@/components/AbstractBlock.vue'
66
7-
// const _ = require('lodash');
8-
97
let
108
text_area,
119
delete_blocks_from_db,
@@ -100,11 +98,11 @@
10098
if (this.model_info[block.model_name]) {
10199
title = this.model_info[block.model_name].model_doc
102100
}
103-
return title;
101+
return title
104102
105103
},
106104
getBlockIndex: function(block_unique_id) {
107-
const block = this.stream.find(function(o) {return o.unique_id = block_unique_id})
105+
const block = find(this.stream, {"unique_id": block_unique_id})
108106
const index = this.stream.indexOf(block)
109107
return [index, block]
110108
},
@@ -215,7 +213,7 @@
215213
<draggable v-model="stream" group="stream" handle=".block-move" item-key="unique_id">
216214
<template #item="{element: block}">
217215
<StreamBlock v-if="!isAbstract(block)" :block="block" :ref="block.unique_id"/>
218-
<AbstractBlock v-else :block="block" />
216+
<AbstractBlock v-else :block="block" :ref="block.unique_id" />
219217
</template>
220218
</draggable>
221219
<div class="stream-insert-new-block">

frontend/src/utils.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
const isArray = Array.isArray;
22
const isEmpty = obj => [Object, Array].includes((obj || {}).constructor) && !Object.entries((obj || {})).length;
3+
const find = function(arr, obj) {
4+
return arr.find((elem) => {
5+
return obj && Object.keys(obj).every(key => elem[key] === obj[key]);
6+
}) || arr[0];
7+
}
38

4-
export {isArray, isEmpty}
9+
export {isArray, isEmpty, find}

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="django-streamfield",
8-
version="2.0.4",
8+
version="2.0.5",
99
author="Yury Lapshinov",
1010
author_email="y.raagin@gmail.com",
1111
description="StreamField for native Django Admin or with Grappelli",

streamfield/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
name = "streamfield"
2-
VERSION = "2.0.4"
2+
VERSION = "2.0.5"

streamfield/static/streamfield/streamfield_widget.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)