implement share project button

This commit is contained in:
Christian Cueni 2019-03-27 14:09:34 +01:00
parent d9f07c1adb
commit 2b39cc92dd
6 changed files with 73 additions and 38 deletions

View File

@ -1,11 +1,11 @@
<template>
<div class="widget-footer">
<a @click="showMenu = !showMenu" class="widget-footer__more-link">
<a @click="toggleMenu" class="widget-footer__more-link">
<ellipses></ellipses>
</a>
<widget-popover v-if="showMenu"
@hide-me="showMenu = false">
<slot></slot>
<slot :hide="toggleMenu"></slot>
</widget-popover>
</div>
</template>
@ -25,6 +25,12 @@
return {
showMenu: false
}
},
methods: {
toggleMenu: function () {
this.showMenu = !this.showMenu
}
}
}
</script>

View File

@ -8,18 +8,16 @@
</router-link>
<widget-footer>
<li class="popover-links__link"><a @click="deleteProject()">Projekt löschen</a></li>
<li class="popover-links__link"><a @click="editProject()">Projekt bearbeiten</a></li>
<li class="popover-links__link"><a @click="shareProject()">Projekt teilen</a></li>
<template slot-scope="scope">
<li class="popover-links__link"><a @click="$emit('delete', id)">Projekt löschen</a></li>
<li class="popover-links__link"><a @click="$emit('edit', id)">Projekt bearbeiten</a></li>
<li class="popover-links__link"><a @click="share(scope)">Projekt teilen</a></li>
</template>
</widget-footer>
</div>
</template>
<script>
import DELETE_PROJECT_MUTATION from '@/graphql/gql/mutations/deleteProject.gql';
import PROJECTS_QUERY from '@/graphql/gql/allProjects.gql';
import OwnerWidget from '@/components/portfolio/OwnerWidget';
import EntryCountWidget from '@/components/rooms/EntryCountWidget';
import WidgetFooter from '@/components/WidgetFooter';
@ -38,33 +36,11 @@
return `project-widget--${this.appearance}`;
}
},
methods: {
deleteProject() {
const theId = this.id
this.$apollo.mutate({
mutation: DELETE_PROJECT_MUTATION,
variables: {
input: {
id: theId
}
},
update(store, {data: {deleteProject: {success}}}) {
if (success) {
const data = store.readQuery({query: PROJECTS_QUERY});
if (data) {
data.projects.edges.splice(data.projects.edges.findIndex(edge => edge.node.id === theId), 1);
store.writeQuery({query: PROJECTS_QUERY, data});
}
}
}
})
},
editProject() {
this.$router.push({name: 'edit-room', params: {id: this.id}});
},
shareProject() {
share: function (scope) {
scope.hide();
this.$emit('share', this.id);
}
}
}

View File

@ -5,7 +5,11 @@
<project-widget
v-for="project in projects"
v-bind="project" :key="project.id"
v-bind="project"
@delete="deleteProject"
@share="shareProject"
@edit="editProject"
:key="project.id"
class="portfolio__project"
></project-widget>
</div>
@ -18,6 +22,8 @@
import AddProject from '@/components/portfolio/AddProject';
import PROJECTS_QUERY from '@/graphql/gql/allProjects.gql';
import DELETE_PROJECT_MUTATION from '@/graphql/gql/mutations/deleteProject.gql';
import UPDATE_PROJECT_MUTATION from '@/graphql/gql/mutations/updateProject.gql';
export default {
components: {
@ -38,6 +44,49 @@
return {
projects: []
}
},
methods: {
deleteProject(id) {
this.$apollo.mutate({
mutation: DELETE_PROJECT_MUTATION,
variables: {
input: {
id
}
},
update(store, {data: {deleteProject: {success}}}) {
if (success) {
const data = store.readQuery({query: PROJECTS_QUERY});
if (data) {
data.projects.edges.splice(data.projects.edges.findIndex(edge => edge.node.id === id), 1);
store.writeQuery({query: PROJECTS_QUERY, data});
}
}
}
})
},
editProject(id) {
this.$router.push({name: 'edit-project', params: { id }});
},
shareProject(id) {
const project = this.projects.filter(project => project.id === id)[0];
this.$apollo.mutate({
mutation: UPDATE_PROJECT_MUTATION,
variables: {
input: {
project: {
id: project.id,
title: project.title,
description: project.description,
appearance: project.appearance,
objectives: project.objectives,
final: true
}
}
}
})
}
}
}
</script>

View File

@ -15,6 +15,7 @@ class AddProjectArgument(ProjectInput):
class UpdateProjectArgument(ProjectInput):
id = graphene.ID(required=True)
final = graphene.Boolean()
class ProjectEntryInput(InputObjectType):
@ -29,3 +30,4 @@ class AddProjectEntryArgument(ProjectEntryInput):
class UpdateProjectEntryArgument(ProjectEntryInput):
id = graphene.ID(required=True)

View File

@ -41,8 +41,10 @@ class MutateProject(relay.ClientIDMutation):
# serializer_class = ProjectSerializer
@classmethod
def mutate_and_get_payload(cls, *args, **kwargs):
def mutate_and_get_payload(cls, root, info, **kwargs):
data = kwargs.get('project')
data['student'] = info.context.user.id
if data.get('id') is not None:
entity = get_object(Project, data['id'])
serializer = ProjectSerializer(entity, data=data)

View File

@ -6,7 +6,7 @@ from portfolio.models import Project, ProjectEntry
class ProjectSerializer(serializers.ModelSerializer):
class Meta:
model = Project
fields = ('id', 'title', 'description', 'objectives', 'slug', 'appearance', 'student',)
fields = ('id', 'title', 'description', 'objectives', 'slug', 'appearance', 'student', 'final',)
read_only_fields = ('id', 'slug',)