Prevent students from adding new rooms, Verify room form
This commit is contained in:
parent
aa85c152dd
commit
1591095553
|
|
@ -1,8 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="room-form">
|
<form class="room-form" @submit.prevent="$emit('save', localRoom)">
|
||||||
<div class="room-form__content">
|
<div class="room-form__content">
|
||||||
<h1 class="room-form__heading">Neues Board</h1>
|
<h1 class="room-form__heading">Neues Board</h1>
|
||||||
|
|
||||||
<label class="room-form__property-heading" for="room-title">Titel</label>
|
<label class="room-form__property-heading" for="room-title">Titel</label>
|
||||||
<input class="skillbox-input room-form__input" v-model="localRoom.title" id="room-title">
|
<input class="skillbox-input room-form__input" v-model="localRoom.title" id="room-title">
|
||||||
<label class="room-form__property-heading" for="room-description">Beschreibung</label>
|
<label class="room-form__property-heading" for="room-description">Beschreibung</label>
|
||||||
|
|
@ -13,6 +12,7 @@
|
||||||
class="skillbox-input room-form__input"
|
class="skillbox-input room-form__input"
|
||||||
id="room-class"
|
id="room-class"
|
||||||
v-model="localRoom.schoolClass"
|
v-model="localRoom.schoolClass"
|
||||||
|
@change="classSelectionChanged"
|
||||||
>
|
>
|
||||||
<option disabled value="">-</option>
|
<option disabled value="">-</option>
|
||||||
<option
|
<option
|
||||||
|
|
@ -30,13 +30,15 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="room-form__footer">
|
<div class="room-form__footer">
|
||||||
<button
|
<button
|
||||||
|
type="submit"
|
||||||
class="button button--primary room-form__save-button"
|
class="button button--primary room-form__save-button"
|
||||||
@click="$emit('save', localRoom)"
|
:class="{'button--disabled': noClassSelected}"
|
||||||
|
:disabled="noClassSelected"
|
||||||
>Speichern
|
>Speichern
|
||||||
</button>
|
</button>
|
||||||
<router-link to="/rooms" tag="button" class="button">Abbrechen</router-link>
|
<router-link to="/rooms" tag="button" class="button">Abbrechen</router-link>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</form>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
@ -54,7 +56,8 @@
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
localRoom: Object.assign({}, this.room),
|
localRoom: Object.assign({}, this.room),
|
||||||
me: {}
|
me: {},
|
||||||
|
noClassSelected: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -68,6 +71,9 @@
|
||||||
updateColor(newColor) {
|
updateColor(newColor) {
|
||||||
this.localRoom.appearance = newColor;
|
this.localRoom.appearance = newColor;
|
||||||
this.$store.dispatch('setSpecialContainerClass', newColor);
|
this.$store.dispatch('setSpecialContainerClass', newColor);
|
||||||
|
},
|
||||||
|
classSelectionChanged() {
|
||||||
|
this.noClassSelected = this.localRoom.schoolClass.id === undefined;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="rooms-page">
|
<div class="rooms-page">
|
||||||
<room-widget v-for="room in filteredRooms" v-bind="room" :key="room.name"></room-widget>
|
<room-widget v-for="room in filteredRooms" v-bind="room" :key="room.name"></room-widget>
|
||||||
<add-room></add-room>
|
<add-room v-if="me.role === 'teacher'"></add-room>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import ROOMS_QUERY from '@/graphql/gql/roomsQuery.gql';
|
import ROOMS_QUERY from '@/graphql/gql/roomsQuery.gql';
|
||||||
|
import ME_QUERY from '@/graphql/gql/meQuery.gql'
|
||||||
|
|
||||||
import RoomWidget from '@/components/rooms/RoomWidget.vue';
|
import RoomWidget from '@/components/rooms/RoomWidget.vue';
|
||||||
import AddRoom from '@/components/rooms/AddRoom.vue';
|
import AddRoom from '@/components/rooms/AddRoom.vue';
|
||||||
|
|
@ -38,12 +39,16 @@
|
||||||
update(data) {
|
update(data) {
|
||||||
return this.$getRidOfEdges(data).rooms
|
return this.$getRidOfEdges(data).rooms
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
me: {
|
||||||
|
query: ME_QUERY,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
rooms: []
|
rooms: [],
|
||||||
|
me: {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,4 +19,8 @@
|
||||||
&--white-bg {
|
&--white-bg {
|
||||||
background-color: $color-white;
|
background-color: $color-white;
|
||||||
}
|
}
|
||||||
|
&--disabled {
|
||||||
|
border: 2px solid $color-lightgrey-2;
|
||||||
|
background-color: $color-lightgrey;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,21 @@ class AddRoom(MutateRoom):
|
||||||
class Input:
|
class Input:
|
||||||
room = graphene.Argument(AddRoomArgument) # NB: can't be named AddRoomInput, otherwise graphene complains
|
room = graphene.Argument(AddRoomArgument) # NB: can't be named AddRoomInput, otherwise graphene complains
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def mutate_and_get_payload(cls, root, info, **kwargs):
|
||||||
|
|
||||||
|
if info.context.user.user_roles.first().role.key != 'teacher':
|
||||||
|
return cls(room=None, errors=['not allowed'])
|
||||||
|
|
||||||
|
room_data = kwargs.get('room')
|
||||||
|
room_data['school_class'] = get_object(SchoolClass, room_data.get('school_class').id).id
|
||||||
|
serializer = RoomSerializer(data=room_data)
|
||||||
|
if serializer.is_valid():
|
||||||
|
serializer.save()
|
||||||
|
return cls(room=serializer.instance)
|
||||||
|
|
||||||
|
return cls(room=None, errors=['{}: {}'.format(key, value) for key, value in serializer.errors.items()])
|
||||||
|
|
||||||
|
|
||||||
class UpdateRoom(MutateRoom):
|
class UpdateRoom(MutateRoom):
|
||||||
class Input:
|
class Input:
|
||||||
|
|
@ -65,7 +80,6 @@ class AddRoomEntry(relay.ClientIDMutation):
|
||||||
@classmethod
|
@classmethod
|
||||||
def mutate_and_get_payload(cls, *args, **kwargs):
|
def mutate_and_get_payload(cls, *args, **kwargs):
|
||||||
room_entry_data = kwargs.get('room_entry')
|
room_entry_data = kwargs.get('room_entry')
|
||||||
|
|
||||||
room_entry_data['room'] = get_object(Room, room_entry_data.get('room')).id
|
room_entry_data['room'] = get_object(Room, room_entry_data.get('room')).id
|
||||||
|
|
||||||
serializer = RoomEntrySerializer(data=room_entry_data)
|
serializer = RoomEntrySerializer(data=room_entry_data)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue