Skip to content
Snippets Groups Projects
Commit 0c419783 authored by \nrlucke's avatar \nrlucke Committed by Jan-Hendrik Willms
Browse files

fixes #120

parent aa650590
No related branches found
No related tags found
No related merge requests found
...@@ -38,7 +38,7 @@ class Block extends SchemaProvider ...@@ -38,7 +38,7 @@ class Block extends SchemaProvider
{ {
return [ return [
'position' => (int) $resource['position'], 'position' => (int) $resource['position'],
'block-type' => (string) $resource['block_type'], 'block-type' => (string) $resource->getBlockType(),
'title' => (string) $resource->type->getTitle(), 'title' => (string) $resource->type->getTitle(),
'visible' => (bool) $resource['visible'], 'visible' => (bool) $resource['visible'],
'payload' => $resource->type->getPayload(), 'payload' => $resource->type->getPayload(),
......
...@@ -191,4 +191,16 @@ class Block extends \SimpleORMap ...@@ -191,4 +191,16 @@ class Block extends \SimpleORMap
return $block; return $block;
} }
public function getBlockType(): ?string
{
if ($this->type->findBlockType($this->block_type)) {
return $this->block_type;
} else {
$this->payload = json_encode(array(
'original_block_type' => $this->block_type
));
return 'error';
}
}
} }
...@@ -160,7 +160,8 @@ abstract class BlockType ...@@ -160,7 +160,8 @@ abstract class BlockType
{ {
if (!($class = self::findBlockType($block['block_type']))) { if (!($class = self::findBlockType($block['block_type']))) {
// TODO: Hier müsste es eine weniger allgemeine Exception geben. // TODO: Hier müsste es eine weniger allgemeine Exception geben.
throw new \RuntimeException('Invalid `block_type` attribute in database.'); // throw new \RuntimeException('Invalid `block_type` attribute in database.');
return new \Courseware\BlockTypes\Error($block);
} }
return new $class($block); return new $class($block);
......
{
"title": "Payload schema of Courseware\\BlockType\\Error",
"type": "object",
"properties": {},
"required": [],
"additionalProperties": false
}
<?php
namespace Courseware\BlockTypes;
use Opis\JsonSchema\Schema;
/**
* This class represents the content of a Courseware error block.
*
* @author Ron Lucke <lucke@elan-ev.de>
* @license GPL2 or any later version
*
* @since Stud.IP 5.0
*/
class Error extends BlockType
{
public static function getType(): string
{
return 'error';
}
public static function getTitle(): string
{
return _('Fehler');
}
public static function getDescription(): string
{
return _('Zeigt eine Fehlemeldung an.');
}
public function initialPayload(): array
{
return [];
}
public static function getJsonSchema(): Schema
{
$schemaFile = __DIR__.'/Error.json';
return Schema::fromJsonString(file_get_contents($schemaFile));
}
public static function getCategories(): array
{
return [];
}
public static function getContentTypes(): array
{
return [];
}
public static function getFileTypes(): array
{
return [];
}
}
...@@ -23,6 +23,10 @@ export default { ...@@ -23,6 +23,10 @@ export default {
}, },
props: { props: {
canEdit: Boolean, canEdit: Boolean,
deleteOnly: {
type: Boolean,
default: false
},
block: Object, block: Object,
}, },
data() { data() {
...@@ -44,29 +48,34 @@ export default { ...@@ -44,29 +48,34 @@ export default {
}, },
}, },
mounted() { mounted() {
if (this.deleteOnly) {
this.menuItems = [];
}
if (this.canEdit) { if (this.canEdit) {
this.menuItems.push({ id: 1, label: this.$gettext('Block bearbeiten'), icon: 'edit', emit: 'editBlock' }); if (!this.deleteOnly) {
this.menuItems.push({ this.menuItems.push({ id: 1, label: this.$gettext('Block bearbeiten'), icon: 'edit', emit: 'editBlock' });
id: 2, this.menuItems.push({
label: this.block.attributes.visible id: 2,
? this.$gettext('unsichtbar setzen') label: this.block.attributes.visible
: this.$gettext('sichtbar setzen'), ? this.$gettext('unsichtbar setzen')
icon: this.block.attributes.visible ? 'visibility-visible' : 'visibility-invisible', // do we change the icons ? : this.$gettext('sichtbar setzen'),
emit: 'setVisibility', icon: this.block.attributes.visible ? 'visibility-visible' : 'visibility-invisible', // do we change the icons ?
}); emit: 'setVisibility',
this.menuItems.push({ });
id: 5, this.menuItems.push({
label: this.$gettext('Feedback anzeigen'), id: 5,
icon: 'comment', label: this.$gettext('Feedback anzeigen'),
emit: 'showFeedback', icon: 'comment',
}); emit: 'showFeedback',
});
this.menuItems.push({
id: 7,
label: this.$gettext('Informationen zum Block'),
icon: 'info',
emit: 'showInfo',
});
}
this.menuItems.push({ this.menuItems.push({
id: 7,
label: this.$gettext('Informationen zum Block'),
icon: 'info',
emit: 'showInfo',
});
this.menuItems.push({
id: 9, id: 9,
label: this.$gettext('Block löschen'), label: this.$gettext('Block löschen'),
icon: 'trash', icon: 'trash',
......
<template> <template>
<div class="cw-companion-box" :class="[mood]"> <div class="cw-companion-box" :class="[mood]">
<div> <div>
<p>{{ msgCompanion }}</p> <p v-html="msgCompanion"></p>
<slot name="companionActions"></slot> <slot name="companionActions"></slot>
</div> </div>
</div> </div>
...@@ -21,4 +21,4 @@ export default { ...@@ -21,4 +21,4 @@ export default {
} }
}, },
}; };
</script> </script>
\ No newline at end of file
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
<courseware-block-actions <courseware-block-actions
:block="block" :block="block"
:canEdit="canEdit" :canEdit="canEdit"
:deleteOnly="deleteOnly"
@editBlock="displayFeature('Edit')" @editBlock="displayFeature('Edit')"
@showFeedback="displayFeature('Feedback')" @showFeedback="displayFeature('Feedback')"
@showComments="displayFeature('Comments')" @showComments="displayFeature('Comments')"
...@@ -101,9 +102,14 @@ export default { ...@@ -101,9 +102,14 @@ export default {
props: { props: {
block: Object, block: Object,
canEdit: Boolean, canEdit: Boolean,
deleteOnly: {
type: Boolean,
default: false
},
isTeacher: Boolean, isTeacher: Boolean,
preview: Boolean, preview: Boolean,
defaultGrade: { defaultGrade: {
type: Boolean,
default: true, default: true,
}, },
}, },
...@@ -152,7 +158,7 @@ export default { ...@@ -152,7 +158,7 @@ export default {
blockTitle() { blockTitle() {
const type = this.block.attributes['block-type']; const type = this.block.attributes['block-type'];
return this.blockTypes.find((blockType) => blockType.type === type)?.title || ''; return this.blockTypes.find((blockType) => blockType.type === type)?.title || this.$gettext('Fehler');
}, },
}, },
mounted() { mounted() {
......
<template>
<div class="cw-block cw-block-error">
<courseware-default-block
:block="block"
:canEdit="canEdit"
:deleteOnly="true"
:isTeacher="isTeacher"
:preview="false"
:defaultGrade="false"
>
<template #content>
<div class="cw-block-error-content">
<courseware-companion-box
mood="sad"
:msgCompanion="errorMessage"
>
</courseware-companion-box>
</div>
</template>
</courseware-default-block>
</div>
</template>
<script>
import CoursewareDefaultBlock from './CoursewareDefaultBlock.vue';
import { blockMixin } from './block-mixin.js';
import CoursewareCompanionBox from './CoursewareCompanionBox.vue';
export default {
name: 'courseware-error-block',
mixins: [blockMixin],
components: {
CoursewareDefaultBlock,
CoursewareCompanionBox,
},
props: {
block: Object,
canEdit: Boolean,
isTeacher: Boolean,
},
computed: {
originalBlockType() {
return this.block?.attributes?.payload?.original_block_type;
},
errorMessage() {
let message = '<b>'
message += this.$gettext('Es ist ein Fehler aufgetretten! Der Block-Typ dieses Blocks ist nicht verfügbar.');
message += '</b><br>'
message += 'block_type: ' + this.originalBlockType + ' not found';
return message;
}
},
};
</script>
...@@ -13,6 +13,7 @@ import CoursewareDialogCardsBlock from './CoursewareDialogCardsBlock.vue'; ...@@ -13,6 +13,7 @@ import CoursewareDialogCardsBlock from './CoursewareDialogCardsBlock.vue';
import CoursewareDocumentBlock from './CoursewareDocumentBlock.vue'; import CoursewareDocumentBlock from './CoursewareDocumentBlock.vue';
import CoursewareDownloadBlock from './CoursewareDownloadBlock.vue'; import CoursewareDownloadBlock from './CoursewareDownloadBlock.vue';
import CoursewareEmbedBlock from './CoursewareEmbedBlock.vue'; import CoursewareEmbedBlock from './CoursewareEmbedBlock.vue';
import CoursewareErrorBlock from './CoursewareErrorBlock.vue';
import CoursewareFolderBlock from './CoursewareFolderBlock.vue'; import CoursewareFolderBlock from './CoursewareFolderBlock.vue';
import CoursewareGalleryBlock from './CoursewareGalleryBlock.vue'; import CoursewareGalleryBlock from './CoursewareGalleryBlock.vue';
import CoursewareHeadlineBlock from './CoursewareHeadlineBlock.vue'; import CoursewareHeadlineBlock from './CoursewareHeadlineBlock.vue';
...@@ -41,6 +42,7 @@ const ContainerComponents = { ...@@ -41,6 +42,7 @@ const ContainerComponents = {
CoursewareDocumentBlock, CoursewareDocumentBlock,
CoursewareDownloadBlock, CoursewareDownloadBlock,
CoursewareEmbedBlock, CoursewareEmbedBlock,
CoursewareErrorBlock,
CoursewareFolderBlock, CoursewareFolderBlock,
CoursewareGalleryBlock, CoursewareGalleryBlock,
CoursewareHeadlineBlock, CoursewareHeadlineBlock,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment