Add validation and filtering to content block creation
This commit is contained in:
parent
b775d857a6
commit
769f87e05d
|
|
@ -68,10 +68,13 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<footer class="create-content-block__footer">
|
<footer class="create-content-block__footer">
|
||||||
<a
|
<button
|
||||||
|
:disabled="!isValid"
|
||||||
class="button button--primary"
|
class="button button--primary"
|
||||||
@click="save(contentBlock)"
|
@click="save(contentBlock)"
|
||||||
>Speichern</a>
|
>
|
||||||
|
Speichern
|
||||||
|
</button>
|
||||||
<a
|
<a
|
||||||
class="button"
|
class="button"
|
||||||
@click="goToModule"
|
@click="goToModule"
|
||||||
|
|
@ -94,6 +97,9 @@
|
||||||
import MODULE_DETAILS_QUERY from '@/graphql/gql/queries/modules/moduleDetailsQuery.gql';
|
import MODULE_DETAILS_QUERY from '@/graphql/gql/queries/modules/moduleDetailsQuery.gql';
|
||||||
import {removeAtIndex, replaceAtIndex} from '@/graphql/immutable-operations';
|
import {removeAtIndex, replaceAtIndex} from '@/graphql/immutable-operations';
|
||||||
|
|
||||||
|
const CHOOSER = 'content-block-element-chooser-widget';
|
||||||
|
const chooserFilter = value => value.type !== CHOOSER;
|
||||||
|
|
||||||
export default Vue.extend({
|
export default Vue.extend({
|
||||||
props: {
|
props: {
|
||||||
parent: {
|
parent: {
|
||||||
|
|
@ -123,6 +129,12 @@
|
||||||
]},
|
]},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
computed: {
|
||||||
|
isValid() {
|
||||||
|
return this.contentBlock.title > '';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
update(index, element, parent) {
|
update(index, element, parent) {
|
||||||
if (parent === undefined) {
|
if (parent === undefined) {
|
||||||
|
|
@ -158,7 +170,7 @@
|
||||||
...block.contents.slice(0, innerIndex + 1),
|
...block.contents.slice(0, innerIndex + 1),
|
||||||
{
|
{
|
||||||
id: -1,
|
id: -1,
|
||||||
type: 'content-block-element-chooser-widget',
|
type: CHOOSER,
|
||||||
},
|
},
|
||||||
...block.contents.slice(innerIndex + 1)
|
...block.contents.slice(innerIndex + 1)
|
||||||
]
|
]
|
||||||
|
|
@ -170,7 +182,7 @@
|
||||||
...this.contentBlock.contents.slice(0, afterOuterIndex+1),
|
...this.contentBlock.contents.slice(0, afterOuterIndex+1),
|
||||||
{
|
{
|
||||||
id: -1,
|
id: -1,
|
||||||
type: 'content-block-element-chooser-widget',
|
type: CHOOSER,
|
||||||
includeListOption: true
|
includeListOption: true
|
||||||
},
|
},
|
||||||
...this.contentBlock.contents.slice(afterOuterIndex+1)
|
...this.contentBlock.contents.slice(afterOuterIndex+1)
|
||||||
|
|
@ -202,9 +214,23 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
save({title, contents, isAssignment}) {
|
save({title, contents, isAssignment}) {
|
||||||
|
let filteredContents = contents
|
||||||
|
.filter(chooserFilter); // only use items that are not chooser elements
|
||||||
|
|
||||||
|
let mappedContents = filteredContents.map(content => {
|
||||||
|
// if the element has a contents property, it's a list of contents, filter them
|
||||||
|
if (content.contents) {
|
||||||
|
return {
|
||||||
|
...content,
|
||||||
|
contents: content.contents.filter(chooserFilter)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// else just return it
|
||||||
|
return content;
|
||||||
|
});
|
||||||
const contentBlock = {
|
const contentBlock = {
|
||||||
title: title,
|
title: title,
|
||||||
contents: contents.filter(value => Object.keys(value).length > 0),
|
contents: mappedContents,
|
||||||
type: setUserBlockType(isAssignment),
|
type: setUserBlockType(isAssignment),
|
||||||
};
|
};
|
||||||
let input;
|
let input;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue