Merged in feature/instrument-overview (pull request #25)

Feature/instrument overview

Approved-by: Christian Cueni <christian.cueni@iterativ.ch>
This commit is contained in:
Ramon Wenger 2019-07-17 11:10:24 +00:00 committed by Christian Cueni
commit ba6b80dfdc
13 changed files with 117 additions and 50 deletions

View File

@ -1,14 +1,23 @@
<template> <template>
<div class="instrument-teaser"> <router-link tag="div" :to="{name: 'instrument', params: {slug: slug}}" class="instrument-teaser">
<h3 class="instrument-teaser__title">Instrument: Diskussionsregeln</h3> <h3 class="instrument-teaser__title">{{title}}</h3>
<p class="instrument-teaser__text"> <p class="instrument-teaser__text" v-html="teaser">
Für eine konstruktive Diskussion braucht es gewisse Regeln.
</p> </p>
</div> </router-link>
</template> </template>
<script> <script>
export default {} import teaser from '@/helpers/teaser';
export default {
props: ['title', 'contents', 'slug'],
computed: {
teaser() {
return teaser(this.contents);
}
}
}
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
@ -20,6 +29,8 @@
box-sizing: border-box; box-sizing: border-box;
padding: $medium-spacing; padding: $medium-spacing;
@include widget-shadow; @include widget-shadow;
width: 100%;
cursor: pointer;
&__title { &__title {
@include heading-3; @include heading-3;

View File

@ -4,8 +4,8 @@
<book-topic-navigation></book-topic-navigation> <book-topic-navigation></book-topic-navigation>
</sub-navigation-item> </sub-navigation-item>
<sub-navigation-item title="Instrument"> <sub-navigation-item title="Instrument">
<router-link tag="div" class="book-subnavigation__item" to="/basic-knowledge">Sprache und Kommunikation</router-link> <router-link tag="div" class="book-subnavigation__item" to="/instruments/sprache-kommunikation">Sprache und Kommunikation</router-link>
<router-link tag="div" class="book-subnavigation__item" to="/basic-knowledge">Gesellschaft</router-link> <router-link tag="div" class="book-subnavigation__item" to="/instruments/gesellschaft">Gesellschaft</router-link>
</sub-navigation-item> </sub-navigation-item>
<sub-navigation-item title="News"> <sub-navigation-item title="News">
<template slot="title"> <template slot="title">

View File

@ -29,6 +29,12 @@
} }
}, },
watch: {
$route(to, from) {
this.show = false;
}
},
methods: { methods: {
close() { close() {
this.show = false; this.show = false;

View File

@ -27,6 +27,7 @@
import UserWidget from '@/components/UserWidget'; import UserWidget from '@/components/UserWidget';
import MoreOptionsWidget from '@/components/MoreOptionsWidget'; import MoreOptionsWidget from '@/components/MoreOptionsWidget';
import teaser from '@/helpers/teaser';
export default { export default {
props: ['title', 'author', 'contents', 'slug', 'id'], props: ['title', 'author', 'contents', 'slug', 'id'],
@ -72,24 +73,7 @@
return ''; return '';
}, },
teaser() { teaser() {
if (this.contents && this.contents.length) { return teaser(this.contents);
let first = this.contents.find(content => content.type !== 'image_url_block');
if (first && first.type) {
switch (first.type) {
case 'text_block':
return first.value.text.replace(/<p>/g, '').replace(/<\/p>/g, '<br>').slice(0, 75) + '...';
// return first.value.text;
case 'link_block':
return first.value.url;
case 'document_block':
const parts = first.value.url.split('/');
return parts[parts.length - 1];
default:
return ''
}
}
}
return '';
}, },
myEntry() { myEntry() {
return this.author.id === this.me.id; return this.author.id === this.me.id;

View File

@ -1,9 +0,0 @@
query BasicKnowledgeQuery($slug: String!){
basicKnowledge(slug: $slug) {
id
title
slug
type
contents
}
}

View File

@ -0,0 +1,9 @@
query InstrumentQuery($slug: String!){
instrument(slug: $slug) {
id
title
slug
type
contents
}
}

View File

@ -0,0 +1,12 @@
query InstrumentQuery($type: String!){
instruments(type: $type) {
edges {
node {
id
title
contents
slug
}
}
}
}

View File

@ -0,0 +1,20 @@
export default (contents) => {
if (contents && contents.length) {
let first = contents.find(content => content.type !== 'image_url_block');
if (first && first.type) {
switch (first.type) {
case 'text_block':
return first.value.text.replace(/<p>/g, '').replace(/<\/p>/g, '<br>').slice(0, 75) + '...';
// return first.value.text;
case 'link_block':
return first.value.url;
case 'document_block':
const parts = first.value.url.split('/');
return parts[parts.length - 1];
default:
return ''
}
}
}
return '';
}

View File

@ -1,8 +1,8 @@
<template> <template>
<div class="instrument"> <div class="instrument">
<h1 class="instrument__title">{{basicKnowledge.title}}</h1> <h1 class="instrument__title">{{instrument.title}}</h1>
<component v-for="component in basicKnowledge.contents" <component v-for="component in instrument.contents"
:key="component.id" :key="component.id"
:is="component.type" :is="component.type"
v-bind="component"> v-bind="component">
@ -12,7 +12,7 @@
</template> </template>
<script> <script>
import BASIC_KNOWLEDGE_QUERY from '@/graphql/gql/basicKnowledgeQuery.gql'; import INSTRUMENT_QUERY from '@/graphql/gql/instrumentQuery.gql';
import TextBlock from '@/components/content-blocks/TextBlock'; import TextBlock from '@/components/content-blocks/TextBlock';
import InstrumentWidget from '@/components/content-blocks/InstrumentWidget'; import InstrumentWidget from '@/components/content-blocks/InstrumentWidget';
@ -25,9 +25,9 @@
export default { export default {
apollo: { apollo: {
basicKnowledge() { instrument() {
return { return {
query: BASIC_KNOWLEDGE_QUERY, query: INSTRUMENT_QUERY,
variables: { variables: {
slug: this.$route.params.slug slug: this.$route.params.slug
} }
@ -49,7 +49,7 @@
data() { data() {
return { return {
basicKnowledge: {} instrument: {}
} }
} }
} }

View File

@ -2,23 +2,55 @@
<div class="instrument-overview"> <div class="instrument-overview">
<div class="instrument-overview__heading"> <div class="instrument-overview__heading">
<h1 class="instrument-overview__title"> <h1 class="instrument-overview__title">
Instrument:<br> Sprache und Kommunikation Instrument:<br> {{instrumentType}}
</h1> </h1>
</div> </div>
<div class="instrument-overview__list"> <div class="instrument-overview__list">
<instrument-teaser></instrument-teaser> <instrument-teaser
<instrument-teaser></instrument-teaser> v-bind="instrument"
<instrument-teaser></instrument-teaser> v-for="instrument in instruments"
:key="instrument.id"
></instrument-teaser>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import InstrumentTeaser from '@/components/InstrumentTeaser'; import InstrumentTeaser from '@/components/InstrumentTeaser';
import INSTRUMENTS_QUERY from '@/graphql/gql/instrumentsByTypeQuery.gql';
export default { export default {
components: { components: {
InstrumentTeaser InstrumentTeaser
},
computed: {
instrumentType () {
return this.$route.params.slug === 'gesellschaft' ? 'Gesellschaft' : 'Sprache und Kommunikation';
}
},
apollo: {
instruments: {
query: INSTRUMENTS_QUERY,
variables() {
return {
type: this.$route.params.slug === 'gesellschaft' ? 'society' : 'language_communication'
}
},
manual: true,
result({data, loading, networkStatus}) {
if (!loading) {
this.instruments = this.$getRidOfEdges(data).instruments;
}
}
}
},
data() {
return {
instruments: []
}
} }
} }
</script> </script>
@ -49,6 +81,7 @@
&__list { &__list {
padding: $large-spacing 0; padding: $large-spacing 0;
max-width: 1200px; max-width: 1200px;
width: 100%;
display: grid; display: grid;
grid-template-columns: repeat(3, 1fr); grid-template-columns: repeat(3, 1fr);
grid-auto-rows: auto; grid-auto-rows: auto;

View File

@ -55,7 +55,7 @@ const routes = [
{path: '/room/:slug', name: 'room', component: room, props: true}, {path: '/room/:slug', name: 'room', component: room, props: true},
{path: '/article/:slug', name: 'article', component: article, meta: {layout: 'simple'}}, {path: '/article/:slug', name: 'article', component: article, meta: {layout: 'simple'}},
{ {
path: '/instrument/', path: '/instruments/:slug',
name: 'instrument-overview', name: 'instrument-overview',
component: instrumentOverview, component: instrumentOverview,
meta: {subnavigation: true} meta: {subnavigation: true}

View File

@ -57,6 +57,7 @@
padding: $large-spacing; padding: $large-spacing;
width: 100%; width: 100%;
box-sizing: border-box; box-sizing: border-box;
margin-top: 17px;
&:empty { &:empty {
display: none; display: none;

View File

@ -10,7 +10,7 @@ from .models import BasicKnowledge
class BasicKnowledgeNode(DjangoObjectType): class BasicKnowledgeNode(DjangoObjectType):
class Meta: class Meta:
model = BasicKnowledge model = BasicKnowledge
filter_fields = ['slug'] filter_fields = ['slug', 'type']
interfaces = (relay.Node,) interfaces = (relay.Node,)
only_fields = [ only_fields = [
'slug', 'title', 'type', 'contents', 'slug', 'title', 'type', 'contents',
@ -18,10 +18,10 @@ class BasicKnowledgeNode(DjangoObjectType):
class BasicKnowledgeQuery(object): class BasicKnowledgeQuery(object):
basic_knowledge = graphene.Field(BasicKnowledgeNode, slug=graphene.String(), id=graphene.ID()) instrument = graphene.Field(BasicKnowledgeNode, slug=graphene.String(), id=graphene.ID())
basic_knowledge_pages = DjangoFilterConnectionField(BasicKnowledgeNode) instruments = DjangoFilterConnectionField(BasicKnowledgeNode)
def resolve_basic_knowledge(self, info, **kwargs): def resolve_instrument(self, info, **kwargs):
slug = kwargs.get('slug') slug = kwargs.get('slug')
room_id = kwargs.get('id') room_id = kwargs.get('id')