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