Clean up code
This commit is contained in:
parent
a00206499b
commit
7c9d425a5e
|
|
@ -143,4 +143,17 @@ describe('Class Management', () => {
|
|||
cy.get('[data-cy=old-class-item]').should('have.length', 1);
|
||||
|
||||
});
|
||||
|
||||
it.only('changes class name', () => {
|
||||
cy.visit('/me/my-class');
|
||||
|
||||
let className = 'Gotta have class';
|
||||
|
||||
cy.get('[data-cy=edit-class-name-link]').click();
|
||||
cy.get('[data-cy=edit-class-name-input]').type('{selectall}{backspace}').type(className);
|
||||
cy.get('[data-cy=save-button]').click();
|
||||
cy.get('[data-cy=class-name-heading]').should('equal', className);
|
||||
|
||||
|
||||
})
|
||||
});
|
||||
|
|
@ -18,8 +18,6 @@
|
|||
import EditContentBlockWizard from '@/components/content-block-form/EditContentBlockWizard';
|
||||
import NewRoomEntryWizard from '@/components/rooms/room-entries/NewRoomEntryWizard';
|
||||
import EditRoomEntryWizard from '@/components/rooms/room-entries/EditRoomEntryWizard';
|
||||
import NewObjectiveGroupWizard from '@/components/objective-groups/NewObjectiveGroupWizard';
|
||||
import EditObjectiveGroupWizard from '@/components/objective-groups/EditObjectiveGroupWizard';
|
||||
import NewProjectEntryWizard from '@/components/portfolio/NewProjectEntryWizard';
|
||||
import EditProjectEntryWizard from '@/components/portfolio/EditProjectEntryWizard';
|
||||
import NewObjectiveWizard from '@/components/objective-groups/NewObjectiveWizard';
|
||||
|
|
@ -46,9 +44,6 @@
|
|||
EditContentBlockWizard,
|
||||
NewRoomEntryWizard,
|
||||
EditRoomEntryWizard,
|
||||
// todo: remove
|
||||
NewObjectiveGroupWizard,
|
||||
EditObjectiveGroupWizard,
|
||||
NewProjectEntryWizard,
|
||||
EditProjectEntryWizard,
|
||||
NewObjectiveWizard,
|
||||
|
|
|
|||
|
|
@ -1,65 +0,0 @@
|
|||
<template>
|
||||
<div class="add-objective-group-button" @click="addObjectiveGroup()">
|
||||
<add-icon class="add-objective-group-button__icon"></add-icon>
|
||||
<div class="add-objective-group-button__text">Zusätzlich Lernziele für «{{typeDescription}}» erfassen</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import AddIcon from '@/components/icons/AddIcon';
|
||||
|
||||
export default {
|
||||
props: ['type', 'module'],
|
||||
|
||||
components: {
|
||||
AddIcon
|
||||
},
|
||||
|
||||
computed: {
|
||||
typeDescription() {
|
||||
if (this.type === 'society') {
|
||||
return 'Gesellschaft'
|
||||
}
|
||||
return 'Sprache & Kommunikation';
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
addObjectiveGroup() {
|
||||
this.$store.dispatch('addObjectiveGroup', {
|
||||
module: this.module,
|
||||
type: this.type
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@import "@/styles/_variables.scss";
|
||||
@import "@/styles/_mixins.scss";
|
||||
|
||||
.add-objective-group-button {
|
||||
display: none;
|
||||
grid-template-columns: 45px auto;
|
||||
align-items: center;
|
||||
margin-top: -20px;
|
||||
margin-bottom: 35px;
|
||||
cursor: pointer;
|
||||
|
||||
@include desktop {
|
||||
display: grid;
|
||||
}
|
||||
|
||||
&__icon {
|
||||
width: 25px;
|
||||
height: 25px;
|
||||
fill: $color-silver-dark;
|
||||
}
|
||||
|
||||
&__text {
|
||||
color: $color-silver-dark;
|
||||
font-family: $sans-serif-font-family;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
@ -1,107 +0,0 @@
|
|||
<template>
|
||||
<objective-group-form
|
||||
:title="title"
|
||||
:objectives="objectives"
|
||||
@save="saveObjectiveGroup"
|
||||
@hide="hideModal"
|
||||
></objective-group-form>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Modal from '@/components/Modal';
|
||||
import ObjectiveGroupForm from '@/components/objective-groups/ObjectiveGroupForm';
|
||||
import AddContentElement from '@/components/AddContentElement';
|
||||
|
||||
import UPDATE_OBJECTIVE_GROUP_MUTATION from '@/graphql/gql/mutations/updateObjectiveGroup.gql';
|
||||
import MODULE_DETAILS_QUERY from '@/graphql/gql/moduleDetailsQuery.gql';
|
||||
import OBJECTIVE_GROUP_QUERY from '@/graphql/gql/objectiveGroupQuery.gql';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
AddContentElement,
|
||||
Modal,
|
||||
ObjectiveGroupForm
|
||||
},
|
||||
|
||||
computed: {
|
||||
title() {
|
||||
if (this.$store.state.objectiveGroupType === 'society') {
|
||||
return 'Gesellschaft';
|
||||
}
|
||||
return 'Sprache & Kommunikation';
|
||||
},
|
||||
objectives() {
|
||||
return this.objectiveGroup.objectives.edges.map(edge => edge.node)
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
saveObjectiveGroup(objectives) {
|
||||
const objectiveGroup = {
|
||||
id: this.$store.state.currentObjectiveGroup,
|
||||
objectives,
|
||||
};
|
||||
this.$apollo.mutate({
|
||||
mutation: UPDATE_OBJECTIVE_GROUP_MUTATION,
|
||||
variables: {
|
||||
input: {
|
||||
objectiveGroup
|
||||
}
|
||||
},
|
||||
// todo: make update work
|
||||
// update: (store, {data: {addObjectiveGroup: {objectiveGroup}}}) => {
|
||||
// const query = MODULE_DETAILS_QUERY;
|
||||
// const variables = {slug: this.$route.params.slug};
|
||||
// const data = store.readQuery({query, variables});
|
||||
// debugger;
|
||||
// if (data.module && data.module.objectiveGroups) {
|
||||
// data.module.objectiveGroups.edges.push({
|
||||
// node: objectiveGroup,
|
||||
// __typename: 'ObjectiveGroupNode'
|
||||
// });
|
||||
// store.writeQuery({query, variables, data});
|
||||
// }
|
||||
//
|
||||
// }
|
||||
refetchQueries: [{
|
||||
query: MODULE_DETAILS_QUERY,
|
||||
variables: {
|
||||
slug: this.$route.params.slug
|
||||
}
|
||||
}]
|
||||
|
||||
}).then(() => {
|
||||
this.hideModal();
|
||||
});
|
||||
},
|
||||
hideModal() {
|
||||
this.$store.dispatch('hideModal');
|
||||
},
|
||||
},
|
||||
|
||||
apollo: {
|
||||
objectiveGroup() {
|
||||
return {
|
||||
query: OBJECTIVE_GROUP_QUERY,
|
||||
variables: {
|
||||
id: this.$store.state.currentObjectiveGroup
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
objectiveGroup: {
|
||||
objectives: {
|
||||
edges: []
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
</style>
|
||||
|
|
@ -1,91 +0,0 @@
|
|||
<template>
|
||||
<objective-group-form
|
||||
:title="title"
|
||||
:objectives="objectives"
|
||||
@save="saveObjectiveGroup"
|
||||
@hide="hideModal"
|
||||
></objective-group-form>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Modal from '@/components/Modal';
|
||||
import ObjectiveGroupForm from '@/components/objective-groups/ObjectiveGroupForm';
|
||||
import AddContentElement from '@/components/AddContentElement';
|
||||
|
||||
import NEW_OBJECTIVE_GROUP_MUTATION from '@/graphql/gql/mutations/addObjectiveGroup.gql';
|
||||
import MODULE_DETAILS_QUERY from '@/graphql/gql/moduleDetailsQuery.gql';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
AddContentElement,
|
||||
Modal,
|
||||
ObjectiveGroupForm
|
||||
},
|
||||
|
||||
computed: {
|
||||
title() {
|
||||
if (this.$store.state.objectiveGroupType === 'society') {
|
||||
return 'Gesellschaft';
|
||||
}
|
||||
return 'Sprache & Kommunikation';
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
saveObjectiveGroup(objectives) {
|
||||
const objectiveGroup = {
|
||||
title: this.$store.state.objectiveGroupType,
|
||||
module: this.$store.state.parentModule,
|
||||
objectives,
|
||||
};
|
||||
this.$apollo.mutate({
|
||||
mutation: NEW_OBJECTIVE_GROUP_MUTATION,
|
||||
variables: {
|
||||
input: {
|
||||
objectiveGroup
|
||||
}
|
||||
},
|
||||
// todo: make update work
|
||||
// update: (store, {data: {addObjectiveGroup: {objectiveGroup}}}) => {
|
||||
// const query = MODULE_DETAILS_QUERY;
|
||||
// const variables = {slug: this.$route.params.slug};
|
||||
// const data = store.readQuery({query, variables});
|
||||
// debugger;
|
||||
// if (data.module && data.module.objectiveGroups) {
|
||||
// data.module.objectiveGroups.edges.push({
|
||||
// node: objectiveGroup,
|
||||
// __typename: 'ObjectiveGroupNode'
|
||||
// });
|
||||
// store.writeQuery({query, variables, data});
|
||||
// }
|
||||
//
|
||||
// }
|
||||
refetchQueries: [{
|
||||
query: MODULE_DETAILS_QUERY,
|
||||
variables: {
|
||||
slug: this.$route.params.slug
|
||||
}
|
||||
}]
|
||||
|
||||
}).then(() => {
|
||||
this.hideModal();
|
||||
});
|
||||
},
|
||||
hideModal() {
|
||||
this.$store.dispatch('hideModal');
|
||||
},
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
objectives: [
|
||||
{},
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
</style>
|
||||
|
|
@ -56,12 +56,6 @@
|
|||
return this.me.selectedClass;
|
||||
},
|
||||
},
|
||||
|
||||
methods: {
|
||||
editObjectiveGroup() {
|
||||
this.$store.dispatch('editObjectiveGroup', this.group.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,64 +0,0 @@
|
|||
<template>
|
||||
<modal class="objective-group-form">
|
||||
<template slot="header">
|
||||
<h4 class="objective-group-form__heading">Lernziele: {{title}}</h4>
|
||||
</template>
|
||||
|
||||
<objective-form
|
||||
:objective="objective"
|
||||
v-for="(objective, index) in initialObjectives"
|
||||
@input="updateObjective($event, index)"
|
||||
@delete="removeObjective(index)"
|
||||
:key="index"></objective-form>
|
||||
<add-content-element @add-element="addObjective"></add-content-element>
|
||||
|
||||
<div slot="footer">
|
||||
<a class="button button--primary" data-cy="modal-save-button"
|
||||
@click="$emit('save', initialObjectives)">Speichern</a>
|
||||
<a class="button" @click="$emit('hide')">Abbrechen</a>
|
||||
</div>
|
||||
|
||||
</modal>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Modal from '@/components/Modal';
|
||||
import ObjectiveForm from '@/components/objective-groups/ObjectiveForm';
|
||||
import AddContentElement from '@/components/AddContentElement';
|
||||
|
||||
export default {
|
||||
props: ['title', 'objectives'],
|
||||
|
||||
components: {
|
||||
AddContentElement,
|
||||
Modal,
|
||||
ObjectiveForm
|
||||
},
|
||||
|
||||
methods: {
|
||||
addObjective() {
|
||||
this.initialObjectives.push({});
|
||||
},
|
||||
updateObjective(text, index) {
|
||||
this.initialObjectives.splice(index, 1, {text});
|
||||
},
|
||||
removeObjective(index) {
|
||||
this.initialObjectives.splice(index, 1);
|
||||
}
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
initialObjectives: this.objectives
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.objective-group-form {
|
||||
&__heading {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
#import "../fragments/objectiveGroupParts.gql"
|
||||
mutation AddObjectiveGroup($input: AddObjectiveGroupInput!) {
|
||||
addObjectiveGroup(input: $input) {
|
||||
objectiveGroup {
|
||||
...ObjectiveGroupParts
|
||||
objectives {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
text
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
#import "../fragments/objectiveGroupParts.gql"
|
||||
mutation UpdateObjectiveGroup($input: UpdateObjectiveGroupInput!) {
|
||||
updateObjectiveGroup(input: $input) {
|
||||
objectiveGroup {
|
||||
...ObjectiveGroupParts
|
||||
objectives {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
text
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -19,7 +19,6 @@ export default new Vuex.Store({
|
|||
currentRoomEntry: '',
|
||||
parentRoom: null,
|
||||
parentModule: '',
|
||||
objectiveGroupType: '',
|
||||
currentObjectiveGroup: '',
|
||||
parentProject: null,
|
||||
currentNote: null,
|
||||
|
|
@ -70,8 +69,6 @@ export default new Vuex.Store({
|
|||
commit('setContentBlockPosition', {});
|
||||
commit('setParentRoom', null);
|
||||
commit('setParentModule', '');
|
||||
// todo: remove
|
||||
commit('setObjectiveGroupType', '');
|
||||
commit('setCurrentObjectiveGroup', '');
|
||||
commit('setParentProject', null);
|
||||
commit('setCurrentProjectEntry', null);
|
||||
|
|
@ -110,16 +107,6 @@ export default new Vuex.Store({
|
|||
commit('setCurrentRoomEntry', payload);
|
||||
dispatch('showModal', 'edit-room-entry-wizard');
|
||||
},
|
||||
// todo: remove
|
||||
addObjectiveGroup({commit, dispatch}, {module, type}) {
|
||||
commit('setParentModule', module);
|
||||
commit('setObjectiveGroupType', type);
|
||||
dispatch('showModal', 'new-objective-group-wizard');
|
||||
},
|
||||
editObjectiveGroup({commit, dispatch}, payload) {
|
||||
commit('setCurrentObjectiveGroup', payload);
|
||||
dispatch('showModal', 'edit-objective-group-wizard');
|
||||
},
|
||||
showModal({commit}, payload) {
|
||||
document.body.classList.add('no-scroll'); // won't get at the body any other way
|
||||
commit('setModal', payload);
|
||||
|
|
@ -216,10 +203,6 @@ export default new Vuex.Store({
|
|||
setParentModule(state, payload) {
|
||||
state.parentModule = payload;
|
||||
},
|
||||
// todo: remove
|
||||
setObjectiveGroupType(state, payload) {
|
||||
state.objectiveGroupType = payload;
|
||||
},
|
||||
setCurrentObjectiveGroup(state, payload) {
|
||||
state.currentObjectiveGroup = payload;
|
||||
},
|
||||
|
|
|
|||
|
|
@ -10,13 +10,3 @@ class ObjectiveInput(InputObjectType):
|
|||
class AddObjectiveArgument(InputObjectType):
|
||||
text = graphene.String(required=True)
|
||||
objective_group = graphene.ID(reuired=True)
|
||||
|
||||
class AddObjectiveGroupArgument(InputObjectType):
|
||||
title = graphene.String(required=True)
|
||||
module = graphene.ID(required=True)
|
||||
objectives = graphene.List(ObjectiveInput)
|
||||
|
||||
|
||||
class UpdateObjectiveGroupArgument(InputObjectType):
|
||||
id = graphene.ID(required=True)
|
||||
objectives = graphene.List(ObjectiveInput)
|
||||
|
|
|
|||
|
|
@ -1,13 +1,11 @@
|
|||
import graphene
|
||||
from graphene import relay, InputObjectType
|
||||
from graphql_relay import from_global_id
|
||||
from graphene import relay
|
||||
from rest_framework.exceptions import PermissionDenied
|
||||
|
||||
from api.utils import get_object
|
||||
from books.models import Module
|
||||
from books.schema.inputs import UserGroupBlockVisibility
|
||||
from core.utils import set_visible_for, set_hidden_for
|
||||
from objectives.inputs import AddObjectiveGroupArgument, UpdateObjectiveGroupArgument, AddObjectiveArgument
|
||||
from objectives.inputs import AddObjectiveArgument
|
||||
from objectives.models import ObjectiveProgressStatus, Objective, ObjectiveGroup
|
||||
from objectives.schema import ObjectiveNode, ObjectiveGroupNode
|
||||
|
||||
|
|
@ -105,75 +103,8 @@ class DeleteObjective(relay.ClientIDMutation):
|
|||
return cls(success=True)
|
||||
|
||||
|
||||
|
||||
class AddObjectiveGroup(relay.ClientIDMutation):
|
||||
class Input:
|
||||
objective_group = graphene.Argument(AddObjectiveGroupArgument)
|
||||
|
||||
objective_group = graphene.Field(ObjectiveGroupNode)
|
||||
|
||||
@classmethod
|
||||
def mutate_and_get_payload(cls, root, info, **kwargs):
|
||||
|
||||
owner = info.context.user
|
||||
if not owner.has_perm('users.can_manage_school_class_content'):
|
||||
raise PermissionDenied('Missing permissions')
|
||||
|
||||
objective_group_data = kwargs.get('objective_group')
|
||||
title = objective_group_data.get('title')
|
||||
if title != 'society':
|
||||
title = 'language_communication'
|
||||
module_id = objective_group_data.get('module')
|
||||
module = get_object(Module, module_id)
|
||||
|
||||
new_objective_group = ObjectiveGroup.objects.create(title=title, module=module, owner=owner)
|
||||
objectives = objective_group_data.get('objectives')
|
||||
for objective in objectives:
|
||||
Objective.objects.create(text=objective.get('text'), group=new_objective_group)
|
||||
return cls(objective_group=new_objective_group)
|
||||
|
||||
|
||||
class UpdateObjectiveGroup(relay.ClientIDMutation):
|
||||
class Input:
|
||||
objective_group = graphene.Argument(UpdateObjectiveGroupArgument)
|
||||
|
||||
objective_group = graphene.Field(ObjectiveGroupNode)
|
||||
|
||||
@classmethod
|
||||
def mutate_and_get_payload(cls, root, info, **kwargs):
|
||||
|
||||
user = info.context.user
|
||||
if not user.has_perm('users.can_manage_school_class_content'):
|
||||
raise PermissionDenied('Missing permissions')
|
||||
|
||||
objective_group_data = kwargs.get('objective_group')
|
||||
id = objective_group_data.get('id')
|
||||
objective_group = get_object(ObjectiveGroup, id)
|
||||
|
||||
objectives = objective_group_data.get('objectives')
|
||||
existing_objective_ids = list(objective_group.objectives.values_list('id', flat=True))
|
||||
for objective in objectives:
|
||||
if objective.get('id') is not None:
|
||||
objective_id = objective.get('id')
|
||||
updated_objective = get_object(Objective, objective_id)
|
||||
updated_objective.text = objective.get('text')
|
||||
updated_objective.save()
|
||||
existing_objective_ids.remove(int(from_global_id(objective_id)[1]))
|
||||
else:
|
||||
Objective.objects.create(text=objective.get('text'), group=objective_group)
|
||||
|
||||
# remove existing items that are not in payload
|
||||
for objective_id in existing_objective_ids:
|
||||
objective = Objective.objects.get(pk=objective_id)
|
||||
objective.delete()
|
||||
|
||||
return cls(objective_group=objective_group)
|
||||
|
||||
|
||||
class ObjectiveMutations:
|
||||
update_objective_progress = UpdateObjectiveProgress.Field()
|
||||
update_objective_visibility = UpdateObjectiveVisibility.Field()
|
||||
add_objective = AddObjective.Field()
|
||||
delete_objective = DeleteObjective.Field()
|
||||
add_objective_group = AddObjectiveGroup.Field()
|
||||
update_objective_group = UpdateObjectiveGroup.Field()
|
||||
|
|
|
|||
Loading…
Reference in New Issue