Hide single objectives instead of whole groups

This commit is contained in:
Ramon Wenger 2019-08-21 16:26:51 +02:00
parent 3ae39cefce
commit 76b3f70a87
13 changed files with 140 additions and 70 deletions

View File

@ -0,0 +1,21 @@
<template>
<li class="objective">
<div class="objective__actions">
<visibility-action
:block="objective"></visibility-action>
</div>
{{objective.text}}
</li>
</template>
<script>
import VisibilityAction from '@/components/visibility/VisibilityAction';
export default {
props: ['objective'],
components: {
VisibilityAction
}
}
</script>

View File

@ -1,20 +1,12 @@
<template>
<div class="objective-group">
<div class="objective-group__actions">
<!--visibility-action :block="group">
</visibility-action-->
<a @click="editObjectiveGroup()" v-if="group.mine" class="objective-group__action-button">
<pen-icon class="objective-group__action-icon action-icon"></pen-icon>
</a>
</div>
<h4>{{group.displayTitle}}</h4>
<ul class="objective-group__objective-list">
<li class="objective-group__objective" v-for="objective in group.objectives" :key="objective.id">
{{objective.text}}
</li>
<objective class="objective-group__objective" v-for="objective in group.objectives" :key="objective.id"
:objective="objective">
</objective>
</ul>
</div>
@ -22,6 +14,7 @@
<script>
import VisibilityAction from '@/components/visibility/VisibilityAction';
import Objective from '@/components/objective-groups/Objective';
import EyeIcon from '@/components/icons/EyeIcon';
import PenIcon from '@/components/icons/PenIcon';
@ -37,6 +30,7 @@
components: {
VisibilityAction,
Objective,
EyeIcon,
PenIcon
},

View File

@ -13,7 +13,7 @@
import ME_QUERY from '@/graphql/gql/meQuery.gql';
import CHANGE_CONTENT_BLOCK_MUTATION from '@/graphql/gql/mutations/mutateContentBlock.gql';
// import UPDATE_OBJECTIVE_GROUP_VISIBILITY_MUTATION from '@/graphql/gql/mutations/updateObjectiveGroupVisibility.gql';
import UPDATE_OBJECTIVE_VISIBILITY_MUTATION from '@/graphql/gql/mutations/updateObjectiveVisibility.gql';
export default {
props: ['block'],
@ -68,15 +68,15 @@
}
}
// todo: refactor for single objectives when concept is clear
// else {
// mutation = UPDATE_OBJECTIVE_GROUP_VISIBILITY_MUTATION;
// variables = {
// input: {
// id,
// visibility
// }
// }
// }
else {
mutation = UPDATE_OBJECTIVE_VISIBILITY_MUTATION;
variables = {
input: {
id,
visibility
}
}
}
this.$apollo.mutate({
mutation,

View File

@ -0,0 +1,28 @@
fragment ObjectiveParts on ObjectiveNode {
id
text
hiddenFor {
edges {
node {
id
name
}
}
}
visibleFor {
edges {
node {
id
name
}
}
}
objectiveProgress {
edges {
node {
id
done
}
}
}
}

View File

@ -1,6 +1,7 @@
#import "./fragments/chapterParts.gql"
#import "./fragments/assignmentParts.gql"
#import "./fragments/objectiveGroupParts.gql"
#import "./fragments/objectiveParts.gql"
#import "./fragments/moduleParts.gql"
query ModulesQuery($slug: String!) {
module(slug: $slug) {
@ -19,16 +20,7 @@ query ModulesQuery($slug: String!) {
objectives {
edges {
node {
id
text
objectiveProgress {
edges {
node {
id
done
}
}
}
...ObjectiveParts
}
}
}

View File

@ -1,9 +0,0 @@
#import "../fragments/objectiveGroupParts.gql"
mutation UpdateObjectiveGroupVisibility($input: UpdateObjectiveGroupVisibilityInput!) {
updateObjectiveGroupVisibility(input: $input) {
objectiveGroup {
...ObjectiveGroupParts
}
}
}

View File

@ -0,0 +1,9 @@
#import "../fragments/objectiveParts.gql"
mutation UpdateObjectiveVisibility($input: UpdateObjectiveVisibilityInput!) {
updateObjectiveVisibility(input: $input) {
objective {
...ObjectiveParts
}
}
}

View File

@ -122,22 +122,6 @@ class ModuleNode(DjangoObjectType):
def resolve_solutions_enabled(self, info, **kwargs):
return self.solutions_enabled_by.filter(pk=info.context.user.pk).exists()
def resolve_objective_groups(self, info, **kwargs):
user = info.context.user
school_classes = user.school_classes.values_list('pk')
if user.has_perm('users.can_manage_school_class_content'): # teacher
publisher_objective_groups = self.objective_groups.filter(owner=None)
user_created_objective_groups = self.objective_groups.filter(owner=user)
else: # student
publisher_objective_groups = self.objective_groups.filter(owner=None).exclude(
hidden_for__in=school_classes)
user_created_objective_groups = self.objective_groups.filter(owner__isnull=False,
visible_for__in=school_classes)
return publisher_objective_groups.union(user_created_objective_groups)
class TopicNode(DjangoObjectType):
pk = graphene.Int()
@ -146,7 +130,7 @@ class TopicNode(DjangoObjectType):
class Meta:
model = Topic
only_fields = [
'slug', 'title', 'meta_title', 'teaser', 'description', 'vimeo_id', 'order'
'slug', 'title', 'meta_title', 'teaser', 'description', 'vimeo_id', 'order'
]
filter_fields = {
'slug': ['exact', 'icontains', 'in'],

View File

@ -11,8 +11,8 @@ class ObjectiveGroupAdmin(admin.ModelAdmin):
@admin.register(Objective)
class ObjectiveAdmin(admin.ModelAdmin):
list_display = ('text', 'group')
list_filter = ('group',)
list_display = ('text', 'group', 'owner')
list_filter = ('group', 'owner')
@admin.register(ObjectiveProgressStatus)

View File

@ -0,0 +1,32 @@
# Generated by Django 2.0.6 on 2019-08-21 12:52
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('users', '0007_usersetting'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('objectives', '0007_auto_20181031_1347'),
]
operations = [
migrations.AddField(
model_name='objective',
name='hidden_for',
field=models.ManyToManyField(blank=True, related_name='hidden_objectives', to='users.SchoolClass'),
),
migrations.AddField(
model_name='objective',
name='owner',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='objective',
name='visible_for',
field=models.ManyToManyField(blank=True, related_name='visible_objectives', to='users.SchoolClass'),
),
]

View File

@ -38,6 +38,9 @@ class Objective(models.Model):
text = models.CharField('text', blank=True, null=False, max_length=255)
group = models.ForeignKey(ObjectiveGroup, blank=False, null=False, on_delete=models.CASCADE,
related_name='objectives')
owner = models.ForeignKey(get_user_model(), blank=True, null=True, on_delete=models.CASCADE)
hidden_for = models.ManyToManyField(SchoolClass, related_name='hidden_objectives', blank=True)
visible_for = models.ManyToManyField(SchoolClass, related_name='visible_objectives', blank=True)
def __str__(self):
return 'Objective {}-{}'.format(self.id, self.text)

View File

@ -36,28 +36,28 @@ class UpdateObjectiveProgress(relay.ClientIDMutation):
return cls(objective=objective)
class UpdateObjectiveGroupVisibility(relay.ClientIDMutation):
class UpdateObjectiveVisibility(relay.ClientIDMutation):
class Input:
id = graphene.ID(required=True, description='The ID of the objective group')
id = graphene.ID(required=True, description='The ID of the objective')
visibility = graphene.List(UserGroupBlockVisibility)
objective_group = graphene.Field(ObjectiveGroupNode)
objective = graphene.Field(ObjectiveNode)
@classmethod
def mutate_and_get_payload(cls, root, info, **kwargs):
objective_group_id = kwargs.get('id')
objective_id = kwargs.get('id')
visibility_list = kwargs.get('visibility')
objective_group = get_object(ObjectiveGroup, objective_group_id) # info.context.user = django user
objective = get_object(Objective, objective_id) # info.context.user = django user
if visibility_list is not None:
if objective_group.owner is not None:
set_visible_for(objective_group, visibility_list)
if objective.owner is not None:
set_visible_for(objective, visibility_list)
else:
set_hidden_for(objective_group, visibility_list)
set_hidden_for(objective, visibility_list)
objective_group.save()
objective.save()
return cls(objective_group=objective_group)
return cls(objective=objective)
class AddObjectiveGroup(relay.ClientIDMutation):
@ -126,6 +126,6 @@ class UpdateObjectiveGroup(relay.ClientIDMutation):
class ObjectiveMutations:
update_objective_progress = UpdateObjectiveProgress.Field()
update_objective_group_visibility = UpdateObjectiveGroupVisibility.Field()
update_objective_visibility = UpdateObjectiveVisibility.Field()
add_objective_group = AddObjectiveGroup.Field()
update_objective_group = UpdateObjectiveGroup.Field()

View File

@ -25,6 +25,22 @@ class ObjectiveGroupNode(DjangoObjectType):
def resolve_mine(self, info, **kwargs):
return self.owner is not None and self.owner.pk == info.context.user.pk
def resolve_objectives(self, info, **kwargs):
user = info.context.user
school_classes = user.school_classes.values_list('pk')
if user.has_perm('users.can_manage_school_class_content'): # teacher
publisher_objectives = self.objectives.filter(owner=None)
user_created_objectives = self.objectives.filter(owner=user)
else: # student
publisher_objectives = self.objectives.filter(owner=None).exclude(
hidden_for__in=school_classes)
user_created_objectives = self.objectives.filter(owner__isnull=False,
visible_for__in=school_classes)
return publisher_objectives.union(user_created_objectives)
class ObjectiveNode(DjangoObjectType):
pk = graphene.Int()