Update filtering in client

This commit is contained in:
Ramon Wenger 2022-09-13 16:28:56 +02:00
parent ac972c7196
commit 2b3f9c7ae0
7 changed files with 49 additions and 64 deletions

View File

@ -12,7 +12,6 @@
</template>
<script>
import {INTERDISCIPLINARY, LANGUAGE_COMMUNICATION, SOCIETY} from '@/consts/instrument.consts';
import INSTRUMENT_FILTER_QUERY from 'gql/local/instrumentFilter.gql';
const ChevronRight = () => import(/* webpackChunkName: "icons" */'@/components/icons/ChevronRight');
@ -22,7 +21,7 @@
type: String,
required: true,
},
type: {
id: {
type: String,
default: '',
},
@ -31,8 +30,8 @@
default: false,
},
category: {
type: String,
default: '',
type: Object,
default: () => {},
},
},
@ -65,9 +64,6 @@
},
typeClass() {
return {
'filter-entry--language-communication': this.category === LANGUAGE_COMMUNICATION,
'filter-entry--society': this.category === SOCIETY,
'filter-entry--interdisciplinary': this.category === INTERDISCIPLINARY,
'filter-entry--active': this.isActive,
'filter-entry--category': this.isCategory,
};

View File

@ -3,20 +3,20 @@
<filter-entry
:text="title"
v-bind="$attrs"
:type="category"
:category="category"
:is-category="true"
@click.native="setCategoryFilter(category)"
:id="category.id"
@click.native="setCategoryFilter(category.id)"
/>
<div class="filter-group__children">
<filter-entry
:data-cy="`filter-${type.type}`"
:category="type.category"
:text="type.name"
:type="type.type"
v-for="type in types"
:id="type.id"
:key="type.id"
@click.native="setFilter(`type:${type.type}`)"
@click.native="setFilter(`type:${type.id}`)"
/>
</div>
</div>
@ -39,8 +39,8 @@
default: () => [],
},
category: {
type: String,
default: '',
type: Object,
default: () => ({}),
},
},
components: {

View File

@ -1,15 +1,21 @@
<template>
<div
:class="typeClass"
:style="{
color: instrument.type.category.foreground,
backgroundColor: instrument.type.category.background
}"
class="instrument-entry"
>
<h4
class="instrument-entry__category"
:style="{color: instrument.type.category.foreground}"
data-cy="instrument-subheader"
>
{{ categoryName }}
</h4>
<h3 class="instrument-entry__title">
<h3
class="instrument-entry__title"
>
{{ instrument.title }}
</h3>
</div>

View File

@ -6,72 +6,34 @@
/>
<filter-group
:types="languageCommunicationTypes"
:category="LANGUAGE_COMMUNICATION"
title="Sprache und Kommunikation"
data-cy="filter-language-communication"
class="instrument-filter__group--language"
/>
<filter-group
:types="societyTypes"
:category="SOCIETY"
title="Gesellschaft"
data-cy="filter-society"
/>
<filter-group
:category="INTERDISCIPLINARY"
title="Überfachliche Instrumente"
data-cy="filter-interdisciplinary"
:types="category.types"
:category="category"
:title="category.name"
v-for="category in instrumentCategories"
:key="category.id"
/>
</div>
</template>
<script>
import {INTERDISCIPLINARY, LANGUAGE_COMMUNICATION, SOCIETY} from '@/consts/instrument.consts';
import FilterGroup from '@/components/instruments/FilterGroup';
import INSTRUMENT_TYPES_QUERY from 'gql/queries/instrumentTypesQuery';
import INSTRUMENT_CATEGORIES_QUERY from 'gql/queries/instrumentCategoriesQuery.gql';
export default {
components: {
FilterGroup,
},
data() {
return {
filter: '',
LANGUAGE_COMMUNICATION,
SOCIETY,
INTERDISCIPLINARY,
instrumentTypes: [],
instrumentCategories: [],
};
},
computed: {
languageCommunicationTypes() {
return this.instrumentTypes.filter(t => t.category === 'LANGUAGE_COMMUNICATION');
},
societyTypes() {
return this.instrumentTypes.filter(t => t.category === 'SOCIETY');
},
interdisciplinaryTypes() {
return this.instrumentTypes.filter(t => t.category === 'INTERDISCIPLINARY');
},
},
methods: {
setFilter(filter) {
this.filter = filter;
this.$emit('filter', filter);
}
},
apollo: {
instrumentTypes: {
query: INSTRUMENT_TYPES_QUERY,
instrumentCategories: {
query: INSTRUMENT_CATEGORIES_QUERY,
},
},
};

View File

@ -0,0 +1,17 @@
query InstrumentTypesQuery {
instrumentCategories {
name
id
types {
name
id
type
category {
id
name
foreground
background
}
}
}
}

View File

@ -6,7 +6,7 @@ const instrumentType = (instrument) => {
if (typeof instrument === 'string') {
category = instrument;
} else {
category = instrument.type.category;
return instrument.type.category.name;
}
return typeDictionary[category] || '';
};

View File

@ -48,7 +48,11 @@
const {currentFilter} = instrumentFilter;
if (currentFilter && currentFilter.indexOf(':') > -1) {
const [filterType, identifier] = currentFilter.split(':');
this.filter = i => i.type[filterType] === identifier;
if(filterType === 'type') {
this.filter = i => i.type.id === identifier;
} else {
this.filter = i => i.type.category.id === identifier;
}
} else {
this.filter = i => i; // identity
}