Update save method to work on new room entry page
This commit is contained in:
parent
d458790117
commit
14319a0ca8
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
import ContentBlockForm from '@/components/content-block-form/ContentBlockForm';
|
||||
import {ROOMS_FEATURE_SET} from '@/consts/features.consts';
|
||||
import {ROOM_PAGE} from '@/router/room.names';
|
||||
|
||||
export default Vue.extend( {
|
||||
props: {
|
||||
|
|
@ -39,23 +40,31 @@
|
|||
},
|
||||
|
||||
methods: {
|
||||
goBack() {
|
||||
this.$router.push({
|
||||
name: ROOM_PAGE,
|
||||
params: {
|
||||
slug: this.slug
|
||||
}
|
||||
});
|
||||
},
|
||||
save({title, contents}) {
|
||||
const entry = {
|
||||
title,
|
||||
contents,
|
||||
room: this.slug
|
||||
slug: this.slug
|
||||
};
|
||||
this.$apollo.mutate({
|
||||
mutation: NEW_ROOM_ENTRY_MUTATION,
|
||||
variables: {
|
||||
input: {
|
||||
roomEntry: entry
|
||||
roomEntry: entry,
|
||||
}
|
||||
},
|
||||
update: (store, {data: {addRoomEntry: {roomEntry}}}) => {
|
||||
try {
|
||||
const query = ROOM_ENTRIES_QUERY;
|
||||
const variables = {slug: this.room.slug};
|
||||
const variables = {slug: this.slug};
|
||||
const {room} = store.readQuery({query, variables});
|
||||
if (room && room.roomEntries) {
|
||||
const newEdge ={
|
||||
|
|
@ -82,8 +91,7 @@
|
|||
}
|
||||
}
|
||||
}).then(() => {
|
||||
this.saving = false;
|
||||
this.hideModal();
|
||||
this.goBack();
|
||||
});
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
export const NEW_ROOM_PAGE = 'new-room';
|
||||
export const ROOMS_PAGE = 'rooms';
|
||||
export const ROOM_PAGE = 'room';
|
||||
export const ADD_ROOM_ENTRY_PAGE = 'add-room-entry';
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import {NEW_ROOM_PAGE, ROOMS_PAGE, ADD_ROOM_ENTRY_PAGE} from '@/router/room.names';
|
||||
import {NEW_ROOM_PAGE, ROOMS_PAGE, ADD_ROOM_ENTRY_PAGE, ROOM_PAGE} from '@/router/room.names';
|
||||
|
||||
const rooms = () => import(/* webpackChunkName: "rooms" */'@/pages/rooms/rooms');
|
||||
const newRoom = () => import(/* webpackChunkName: "rooms" */'@/pages/rooms/newRoom');
|
||||
|
|
@ -11,7 +11,7 @@ export default [
|
|||
{path: '/rooms', name: ROOMS_PAGE, component: rooms, meta: {filter: true, hideFooter: true}},
|
||||
{path: '/new-room/', name: NEW_ROOM_PAGE, component: newRoom},
|
||||
{path: '/edit-room/:id', name: 'edit-room', component: editRoom, props: true},
|
||||
{path: '/room/:slug', name: 'room', component: room, props: true},
|
||||
{path: '/room/:slug', name: ROOM_PAGE, component: room, props: true},
|
||||
{path: '/room/:slug/add', name: ADD_ROOM_ENTRY_PAGE, component: newRoomEntry, props: true},
|
||||
{
|
||||
path: '/module-room/:slug',
|
||||
|
|
|
|||
|
|
@ -86,9 +86,10 @@ class MutateRoomEntry(relay.ClientIDMutation):
|
|||
def mutate_and_get_payload(cls, root, info, **kwargs):
|
||||
room_entry_data = kwargs.get('room_entry')
|
||||
room = None
|
||||
slug = room_entry_data.get('slug')
|
||||
|
||||
if room_entry_data.get('room') is not None:
|
||||
room = get_object(Room, room_entry_data.get('room'))
|
||||
if slug is not None:
|
||||
room = Room.objects.get(slug=slug)
|
||||
room_entry_data['room'] = room.id
|
||||
|
||||
if room_entry_data.get('id') is not None:
|
||||
|
|
@ -105,19 +106,18 @@ class MutateRoomEntry(relay.ClientIDMutation):
|
|||
|
||||
@classmethod
|
||||
def update_room_entry(cls, info, room_entry_data):
|
||||
instance = get_object(RoomEntry, room_entry_data.get('id'))
|
||||
instance = get_object(RoomEntry, room_entry_data.get('id'))
|
||||
|
||||
if not instance.room.school_class.is_user_in_schoolclass(info.context.user):
|
||||
raise Exception('You are in the wrong class')
|
||||
if not instance.room.school_class.is_user_in_schoolclass(info.context.user):
|
||||
raise Exception('You are in the wrong class')
|
||||
|
||||
if instance.author.pk != info.context.user.pk:
|
||||
raise Exception('You are not the author')
|
||||
if instance.author.pk != info.context.user.pk:
|
||||
raise Exception('You are not the author')
|
||||
|
||||
return RoomEntrySerializer(instance, data=room_entry_data, partial=True)
|
||||
return RoomEntrySerializer(instance, data=room_entry_data, partial=True)
|
||||
|
||||
@classmethod
|
||||
def add_room_entry(cls, info, room_entry_data, room):
|
||||
|
||||
if not room or not room.school_class.is_user_in_schoolclass(info.context.user):
|
||||
raise PermissionDenied('You are in the wrong class')
|
||||
|
||||
|
|
@ -170,7 +170,8 @@ class UpdateRoomVisibility(relay.ClientIDMutation):
|
|||
restricted = kwargs.get('restricted')
|
||||
user = info.context.user
|
||||
room = get_object(Room, id)
|
||||
if not user.is_teacher() or not SchoolClassMember.objects.filter(active=True,user=user,school_class=room.school_class).exists():
|
||||
if not user.is_teacher() or not SchoolClassMember.objects.filter(active=True, user=user,
|
||||
school_class=room.school_class).exists():
|
||||
raise Exception('You are not permitted to do this')
|
||||
room.restricted = restricted
|
||||
room.save()
|
||||
|
|
@ -197,7 +198,6 @@ class AddComment(relay.ClientIDMutation):
|
|||
return cls(success=True, comment=comment)
|
||||
|
||||
|
||||
|
||||
class RoomMutations:
|
||||
update_room = UpdateRoom.Field()
|
||||
add_room = AddRoom.Field()
|
||||
|
|
|
|||
Loading…
Reference in New Issue