Wire up portfolio frontend to backend
This commit is contained in:
parent
485a6ca4eb
commit
474110126d
|
|
@ -14,12 +14,23 @@
|
||||||
import ProjectWidget from '@/components/portfolio/ProjectWidget';
|
import ProjectWidget from '@/components/portfolio/ProjectWidget';
|
||||||
import AddProject from '@/components/portfolio/AddProject';
|
import AddProject from '@/components/portfolio/AddProject';
|
||||||
|
|
||||||
|
import PROJECTS_QUERY from '@/graphql/gql/allProjects.gql';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
ProjectWidget,
|
ProjectWidget,
|
||||||
AddProject
|
AddProject
|
||||||
},
|
},
|
||||||
|
|
||||||
|
apollo: {
|
||||||
|
projects: {
|
||||||
|
query: PROJECTS_QUERY,
|
||||||
|
update(data) {
|
||||||
|
return this.$getRidOfEdges(data).projects
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
projects: [
|
projects: [
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<page-form title="Neues Projekt">
|
<page-form @save="$emit('save', localProject)" title="Neues Projekt">
|
||||||
<page-form-input label="Titel" v-model="localProject.title"></page-form-input>
|
<page-form-input label="Titel" v-model="localProject.title"></page-form-input>
|
||||||
<page-form-input label="Beschreibung" type="textarea" v-model="localProject.description"></page-form-input>
|
<page-form-input label="Beschreibung" type="textarea" v-model="localProject.description"></page-form-input>
|
||||||
<page-form-input label="Ziele" type="textarea" v-model="localProject.objectives"></page-form-input>
|
<page-form-input label="Ziele" type="textarea" v-model="localProject.objectives"></page-form-input>
|
||||||
|
|
@ -11,8 +11,9 @@
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
class="button button--primary"
|
class="button button--primary"
|
||||||
:class="{'button--disabled': true}"
|
data-cy="save-project-button"
|
||||||
:disabled="true"
|
:class="{'button--disabled': !formValid}"
|
||||||
|
:disabled="!formValid"
|
||||||
>Speichern
|
>Speichern
|
||||||
</button>
|
</button>
|
||||||
<router-link to="/portfolio" tag="button" class="button">Abbrechen</router-link>
|
<router-link to="/portfolio" tag="button" class="button">Abbrechen</router-link>
|
||||||
|
|
@ -34,6 +35,12 @@
|
||||||
ColorChooser
|
ColorChooser
|
||||||
},
|
},
|
||||||
|
|
||||||
|
computed: {
|
||||||
|
formValid() {
|
||||||
|
return this.localProject.title && this.localProject.description && this.localProject.objectives;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
localProject: Object.assign({}, this.project),
|
localProject: Object.assign({}, this.project),
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
#import "./fragments/projectParts.gql"
|
||||||
|
query ProjectsQuery {
|
||||||
|
projects {
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
...ProjectParts
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
fragment ProjectParts on ProjectNode {
|
||||||
|
id
|
||||||
|
title
|
||||||
|
appearance
|
||||||
|
description
|
||||||
|
slug
|
||||||
|
objectives
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
#import "../fragments/projectParts.gql"
|
||||||
|
mutation AddProjectMutation($input: AddProjectInput!){
|
||||||
|
addProject(input: $input){
|
||||||
|
project {
|
||||||
|
...ProjectParts
|
||||||
|
}
|
||||||
|
errors
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
#import "../fragments/projectParts.gql"
|
||||||
|
mutation UpdateProjectMutation($input: UpdateProjectInput!){
|
||||||
|
updateProject(input: $input) {
|
||||||
|
project {
|
||||||
|
...ProjectParts
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
#import "./fragments/projectParts.gql"
|
||||||
|
query ProjectQuery($id: ID, $slug: String){
|
||||||
|
project(slug: $slug, id: $id) {
|
||||||
|
...ProjectParts
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,10 +1,16 @@
|
||||||
<template>
|
<template>
|
||||||
<project-form :project="project"></project-form>
|
<project-form
|
||||||
|
@save="saveProject"
|
||||||
|
:project="project"
|
||||||
|
></project-form>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import ProjectForm from '@/components/portfolio/ProjectForm';
|
import ProjectForm from '@/components/portfolio/ProjectForm';
|
||||||
|
|
||||||
|
import ADD_PROJECT_MUTATION from '@/graphql/gql/mutations/addProject.gql';
|
||||||
|
import PROJECTS_QUERY from '@/graphql/gql/allProjects.gql';
|
||||||
|
|
||||||
const defaultAppearance = 'blue';
|
const defaultAppearance = 'blue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
@ -15,12 +21,41 @@
|
||||||
computed: {
|
computed: {
|
||||||
project() {
|
project() {
|
||||||
return {
|
return {
|
||||||
title: 'title',
|
title: '',
|
||||||
description: 'description',
|
description: '',
|
||||||
objectives: 'objectives',
|
objectives: '',
|
||||||
appearance: defaultAppearance
|
appearance: defaultAppearance
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
saveProject(project) {
|
||||||
|
this.$apollo.mutate({
|
||||||
|
mutation: ADD_PROJECT_MUTATION,
|
||||||
|
variables: {
|
||||||
|
input: {
|
||||||
|
project: project
|
||||||
|
}
|
||||||
|
},
|
||||||
|
update: (store, {data: {addProject: {project}}}) => {
|
||||||
|
try {
|
||||||
|
const data = store.readQuery({query: PROJECTS_QUERY});
|
||||||
|
if (data.projects) {
|
||||||
|
data.projects.edges.push({
|
||||||
|
node: project,
|
||||||
|
__typename: 'ProjectNode'
|
||||||
|
});
|
||||||
|
store.writeQuery({query: PROJECTS_QUERY, data});
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// Query did not exist in the cache, and apollo throws a generic Error. Do nothing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).then(() => {
|
||||||
|
this.$router.push('/portfolio');
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,14 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="project">
|
<div class="project">
|
||||||
<div class="project__header">
|
<div class="project__header">
|
||||||
<h1 class="project__title">Quartalsarbeit: Mein Lehrbetrieb</h1>
|
<h1 class="project__title">{{project.title}}</h1>
|
||||||
<p class="project__description">
|
<p class="project__description">
|
||||||
Das ist eine Beschreibung und kann maximal 200 Zeichen enthalten. Das ist eine Beschreibung und kann maximal 200
|
{{project.description}}
|
||||||
Zeichen enthalten. Das ist eine Beschreibung und kann maximal 200 Zeichen enthalten.
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<h2 class="project__objectives-title">Ziele</h2>
|
<h2 class="project__objectives-title">Ziele</h2>
|
||||||
<ul class="project__objectives">
|
<ul class="project__objectives">
|
||||||
<li class="project__objective">Ich kann ein Interview mit geeigneten Fragen vorbereiten.</li>
|
<li class="project__objective" :key="index" v-for="(objective, index) in objectives">{{objective}}</li>
|
||||||
<li class="project__objective">Ich kann ein Interview führen und auf interessante oder ausweichende
|
|
||||||
Antworten näher eingehen.
|
|
||||||
</li>
|
|
||||||
<li class="project__objective">Ich kann ein mündlich geführtes Interview in Standardsprache
|
|
||||||
aufzeichnen.
|
|
||||||
</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -31,13 +24,39 @@
|
||||||
import ProjectEntry from '@/components/portfolio/ProjectEntry';
|
import ProjectEntry from '@/components/portfolio/ProjectEntry';
|
||||||
import AddProjectEntry from '@/components/portfolio/AddProjectEntry';
|
import AddProjectEntry from '@/components/portfolio/AddProjectEntry';
|
||||||
|
|
||||||
|
import PROJECT_QUERY from '@/graphql/gql/projectQuery.gql';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
props: ['slug'],
|
||||||
|
|
||||||
components: {
|
components: {
|
||||||
AddProjectEntry,
|
AddProjectEntry,
|
||||||
ProjectEntry
|
ProjectEntry
|
||||||
},
|
},
|
||||||
|
|
||||||
|
computed: {
|
||||||
|
objectives() {
|
||||||
|
return this.project.objectives ? this.project.objectives.split('\n') : [];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
apollo: {
|
||||||
|
project: {
|
||||||
|
query: PROJECT_QUERY,
|
||||||
|
variables() {
|
||||||
|
return {
|
||||||
|
slug: this.slug
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
project: {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
created() {
|
created() {
|
||||||
this.$store.dispatch('setSpecialContainerClass', 'red');
|
this.$store.dispatch('setSpecialContainerClass', 'red');
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ const routes = [
|
||||||
{path: '/basic-knowledge/:slug', name: 'basic-knowledge', component: basicknowledge, meta: {layout: 'simple'}},
|
{path: '/basic-knowledge/:slug', name: 'basic-knowledge', component: basicknowledge, meta: {layout: 'simple'}},
|
||||||
{path: '/submission/:id', name: 'submission', component: submission, meta: {layout: 'simple'}},
|
{path: '/submission/:id', name: 'submission', component: submission, meta: {layout: 'simple'}},
|
||||||
{path: '/portfolio', name: 'portfolio', component: portfolio},
|
{path: '/portfolio', name: 'portfolio', component: portfolio},
|
||||||
{path: '/portfolio/:slug', name: 'project', component: project},
|
{path: '/portfolio/:slug', name: 'project', component: project, props: true},
|
||||||
{path: '/new-project/', name: 'new-project', component: newProject},
|
{path: '/new-project/', name: 'new-project', component: newProject},
|
||||||
{
|
{
|
||||||
path: '/book',
|
path: '/book',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue