Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/limit collection #1019

Merged
merged 1 commit into from Feb 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion assets/js/app/editor/Components/Collection.vue
Expand Up @@ -16,6 +16,7 @@
<button
class="btn btn-secondary"
type="button"
:disabled="!allowMore"
@click="addCollectionItem"
>
<i class="fas fa-fw fa-plus"></i>
Expand All @@ -31,7 +32,7 @@ var uniqid = require('locutus/php/misc/uniqid');

export default {
name: 'EditorCollection',
props: ['templates', 'existingFields', 'labels'],
props: ['templates', 'existingFields', 'labels', 'limit'],
data() {
let elements = [];
this.existingFields.forEach(function(field) {
Expand All @@ -49,6 +50,7 @@ export default {

return {
elements: elements,
counter: elements.length,
templateSelectName: 'templateSelect' + this.id,
templateSelectOptions: templateSelectOptions,
selector: {
Expand All @@ -64,6 +66,9 @@ export default {
initialSelectValue() {
return this.templateSelectOptions[0].key;
},
allowMore: function() {
return this.counter < this.limit;
},
},
mounted() {
let vueThis = this;
Expand All @@ -79,6 +84,7 @@ export default {
.closest(vueThis.selector.collectionContainer);
vueThis.getCollectionItemFromPressedButton(this).remove();
vueThis.setAllButtonsStates(collectionContainer);
vueThis.counter--;
});

window.$(document).on('click', vueThis.selector.moveUp, function(e) {
Expand Down Expand Up @@ -167,6 +173,7 @@ export default {
);
let res = Vue.compile(html);
this.elements.push(res);
this.counter++;
},
getSelectedTemplate() {
let selectValue = this.$refs.templateSelect.selected;
Expand Down
8 changes: 5 additions & 3 deletions templates/_partials/fields/collection.html.twig
Expand Up @@ -5,6 +5,7 @@
{% set labels = {
'add_collection_item': 'collection.add_item'|trans({'%name%': field.definition.label}),
} %}
{% set limit = field.definition.get('limit')|default(200) %}

{# get the html for all collection field already in the database #}
{% set existing_fields = []|json_encode %}
Expand All @@ -19,9 +20,10 @@
{% endif %}

<editor-collection
:existing-fields='{{ existing_fields }}'
:templates='{{ templated_fields }}'
:labels='{{ labels | json_encode }}'
:existing-fields='{{ existing_fields }}'
:templates='{{ templated_fields }}'
:labels='{{ labels | json_encode }}'
:limit='{{ limit | json_encode }}'
></editor-collection>

{% endblock %}