Hide single objectives instead of whole groups
This commit is contained in:
parent
3ae39cefce
commit
76b3f70a87
|
|
@ -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>
|
||||||
|
|
@ -1,20 +1,12 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="objective-group">
|
<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>
|
<h4>{{group.displayTitle}}</h4>
|
||||||
|
|
||||||
<ul class="objective-group__objective-list">
|
<ul class="objective-group__objective-list">
|
||||||
<li class="objective-group__objective" v-for="objective in group.objectives" :key="objective.id">
|
<objective class="objective-group__objective" v-for="objective in group.objectives" :key="objective.id"
|
||||||
{{objective.text}}
|
:objective="objective">
|
||||||
</li>
|
</objective>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -22,6 +14,7 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import VisibilityAction from '@/components/visibility/VisibilityAction';
|
import VisibilityAction from '@/components/visibility/VisibilityAction';
|
||||||
|
import Objective from '@/components/objective-groups/Objective';
|
||||||
import EyeIcon from '@/components/icons/EyeIcon';
|
import EyeIcon from '@/components/icons/EyeIcon';
|
||||||
import PenIcon from '@/components/icons/PenIcon';
|
import PenIcon from '@/components/icons/PenIcon';
|
||||||
|
|
||||||
|
|
@ -37,6 +30,7 @@
|
||||||
|
|
||||||
components: {
|
components: {
|
||||||
VisibilityAction,
|
VisibilityAction,
|
||||||
|
Objective,
|
||||||
EyeIcon,
|
EyeIcon,
|
||||||
PenIcon
|
PenIcon
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
import ME_QUERY from '@/graphql/gql/meQuery.gql';
|
import ME_QUERY from '@/graphql/gql/meQuery.gql';
|
||||||
import CHANGE_CONTENT_BLOCK_MUTATION from '@/graphql/gql/mutations/mutateContentBlock.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 {
|
export default {
|
||||||
props: ['block'],
|
props: ['block'],
|
||||||
|
|
@ -68,15 +68,15 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// todo: refactor for single objectives when concept is clear
|
// todo: refactor for single objectives when concept is clear
|
||||||
// else {
|
else {
|
||||||
// mutation = UPDATE_OBJECTIVE_GROUP_VISIBILITY_MUTATION;
|
mutation = UPDATE_OBJECTIVE_VISIBILITY_MUTATION;
|
||||||
// variables = {
|
variables = {
|
||||||
// input: {
|
input: {
|
||||||
// id,
|
id,
|
||||||
// visibility
|
visibility
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
this.$apollo.mutate({
|
this.$apollo.mutate({
|
||||||
mutation,
|
mutation,
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#import "./fragments/chapterParts.gql"
|
#import "./fragments/chapterParts.gql"
|
||||||
#import "./fragments/assignmentParts.gql"
|
#import "./fragments/assignmentParts.gql"
|
||||||
#import "./fragments/objectiveGroupParts.gql"
|
#import "./fragments/objectiveGroupParts.gql"
|
||||||
|
#import "./fragments/objectiveParts.gql"
|
||||||
#import "./fragments/moduleParts.gql"
|
#import "./fragments/moduleParts.gql"
|
||||||
query ModulesQuery($slug: String!) {
|
query ModulesQuery($slug: String!) {
|
||||||
module(slug: $slug) {
|
module(slug: $slug) {
|
||||||
|
|
@ -19,16 +20,7 @@ query ModulesQuery($slug: String!) {
|
||||||
objectives {
|
objectives {
|
||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
id
|
...ObjectiveParts
|
||||||
text
|
|
||||||
objectiveProgress {
|
|
||||||
edges {
|
|
||||||
node {
|
|
||||||
id
|
|
||||||
done
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
#import "../fragments/objectiveGroupParts.gql"
|
|
||||||
mutation UpdateObjectiveGroupVisibility($input: UpdateObjectiveGroupVisibilityInput!) {
|
|
||||||
updateObjectiveGroupVisibility(input: $input) {
|
|
||||||
objectiveGroup {
|
|
||||||
...ObjectiveGroupParts
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
#import "../fragments/objectiveParts.gql"
|
||||||
|
mutation UpdateObjectiveVisibility($input: UpdateObjectiveVisibilityInput!) {
|
||||||
|
updateObjectiveVisibility(input: $input) {
|
||||||
|
objective {
|
||||||
|
...ObjectiveParts
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -122,22 +122,6 @@ class ModuleNode(DjangoObjectType):
|
||||||
def resolve_solutions_enabled(self, info, **kwargs):
|
def resolve_solutions_enabled(self, info, **kwargs):
|
||||||
return self.solutions_enabled_by.filter(pk=info.context.user.pk).exists()
|
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):
|
class TopicNode(DjangoObjectType):
|
||||||
pk = graphene.Int()
|
pk = graphene.Int()
|
||||||
|
|
@ -146,7 +130,7 @@ class TopicNode(DjangoObjectType):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Topic
|
model = Topic
|
||||||
only_fields = [
|
only_fields = [
|
||||||
'slug', 'title', 'meta_title', 'teaser', 'description', 'vimeo_id', 'order'
|
'slug', 'title', 'meta_title', 'teaser', 'description', 'vimeo_id', 'order'
|
||||||
]
|
]
|
||||||
filter_fields = {
|
filter_fields = {
|
||||||
'slug': ['exact', 'icontains', 'in'],
|
'slug': ['exact', 'icontains', 'in'],
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,8 @@ class ObjectiveGroupAdmin(admin.ModelAdmin):
|
||||||
|
|
||||||
@admin.register(Objective)
|
@admin.register(Objective)
|
||||||
class ObjectiveAdmin(admin.ModelAdmin):
|
class ObjectiveAdmin(admin.ModelAdmin):
|
||||||
list_display = ('text', 'group')
|
list_display = ('text', 'group', 'owner')
|
||||||
list_filter = ('group',)
|
list_filter = ('group', 'owner')
|
||||||
|
|
||||||
|
|
||||||
@admin.register(ObjectiveProgressStatus)
|
@admin.register(ObjectiveProgressStatus)
|
||||||
|
|
|
||||||
|
|
@ -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'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -38,6 +38,9 @@ class Objective(models.Model):
|
||||||
text = models.CharField('text', blank=True, null=False, max_length=255)
|
text = models.CharField('text', blank=True, null=False, max_length=255)
|
||||||
group = models.ForeignKey(ObjectiveGroup, blank=False, null=False, on_delete=models.CASCADE,
|
group = models.ForeignKey(ObjectiveGroup, blank=False, null=False, on_delete=models.CASCADE,
|
||||||
related_name='objectives')
|
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):
|
def __str__(self):
|
||||||
return 'Objective {}-{}'.format(self.id, self.text)
|
return 'Objective {}-{}'.format(self.id, self.text)
|
||||||
|
|
|
||||||
|
|
@ -36,28 +36,28 @@ class UpdateObjectiveProgress(relay.ClientIDMutation):
|
||||||
return cls(objective=objective)
|
return cls(objective=objective)
|
||||||
|
|
||||||
|
|
||||||
class UpdateObjectiveGroupVisibility(relay.ClientIDMutation):
|
class UpdateObjectiveVisibility(relay.ClientIDMutation):
|
||||||
class Input:
|
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)
|
visibility = graphene.List(UserGroupBlockVisibility)
|
||||||
|
|
||||||
objective_group = graphene.Field(ObjectiveGroupNode)
|
objective = graphene.Field(ObjectiveNode)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def mutate_and_get_payload(cls, root, info, **kwargs):
|
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')
|
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 visibility_list is not None:
|
||||||
if objective_group.owner is not None:
|
if objective.owner is not None:
|
||||||
set_visible_for(objective_group, visibility_list)
|
set_visible_for(objective, visibility_list)
|
||||||
else:
|
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):
|
class AddObjectiveGroup(relay.ClientIDMutation):
|
||||||
|
|
@ -126,6 +126,6 @@ class UpdateObjectiveGroup(relay.ClientIDMutation):
|
||||||
|
|
||||||
class ObjectiveMutations:
|
class ObjectiveMutations:
|
||||||
update_objective_progress = UpdateObjectiveProgress.Field()
|
update_objective_progress = UpdateObjectiveProgress.Field()
|
||||||
update_objective_group_visibility = UpdateObjectiveGroupVisibility.Field()
|
update_objective_visibility = UpdateObjectiveVisibility.Field()
|
||||||
add_objective_group = AddObjectiveGroup.Field()
|
add_objective_group = AddObjectiveGroup.Field()
|
||||||
update_objective_group = UpdateObjectiveGroup.Field()
|
update_objective_group = UpdateObjectiveGroup.Field()
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,22 @@ class ObjectiveGroupNode(DjangoObjectType):
|
||||||
def resolve_mine(self, info, **kwargs):
|
def resolve_mine(self, info, **kwargs):
|
||||||
return self.owner is not None and self.owner.pk == info.context.user.pk
|
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):
|
class ObjectiveNode(DjangoObjectType):
|
||||||
pk = graphene.Int()
|
pk = graphene.Int()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue