Refactor some code

This commit is contained in:
Ramon Wenger 2021-02-18 18:15:19 +01:00
parent d97ad231cc
commit 16baba9423
7 changed files with 28 additions and 58 deletions

View File

@ -60,11 +60,11 @@
import CHAPTER_QUERY from '@/graphql/gql/chapterQuery.gql';
import DELETE_CONTENT_BLOCK_MUTATION from '@/graphql/gql/mutations/deleteContentBlock.gql';
import {meQuery} from '@/graphql/queries';
import {mapState} from 'vuex';
import {isHidden} from '@/helpers/content-block';
import me from '@/mixins/me';
import {hidden} from '@/helpers/visibility';
import {CONTENT_TYPE} from '@/consts/types';
const instruments = {
base_communication: 'Sprache & Kommunikation',
@ -77,6 +77,8 @@
name: 'ContentBlock',
props: ['contentBlock', 'parent'],
mixins: [me],
components: {
ContentComponent,
AddContentButton,
@ -85,13 +87,6 @@
UserWidget
},
data() {
return {
showVisibility: false,
me: {}
};
},
computed: {
...mapState(['editModule']),
canEditModule() {
@ -164,11 +159,12 @@
contents: this.removeSingleContentListItem(newContent, startingIndex)
});
},
schoolClass() {
return this.me.selectedClass;
},
hidden() {
return isHidden(this.contentBlock, this.schoolClass);
return hidden({
block: this.contentBlock,
schoolClass: this.schoolClass,
type: CONTENT_TYPE
});
},
root() {
// we need the root content block id, not the generated content block if inside a content list block
@ -235,10 +231,6 @@
}
return [...content.slice(0, listIndex), ...content[listIndex].contents[0].value, ...content.slice(listIndex + 1)];
}
},
apollo: {
me: meQuery
}
};
</script>

View File

@ -59,21 +59,20 @@
<script>
import {moduleQuery} from '@/graphql/queries';
import ME_QUERY from '@/graphql/gql/meQuery.gql';
import SubNavigationItem from '@/components/book-navigation/SubNavigationItem';
import ToggleSolutionsForModule from '@/components/toggle-menu/ToggleSolutionsForModule';
import ToggleEditing from '@/components/toggle-menu/ToggleEditing';
import ChevronLeft from '@/components/icons/ChevronLeft';
import me from '@/mixins/me';
export default {
apollo: {
module: moduleQuery,
me: {
query: ME_QUERY
}
},
mixins: [me],
components: {
SubNavigationItem,
ToggleSolutionsForModule,
@ -87,9 +86,6 @@
assignments: [],
topic: {}
},
me: {
permissions: []
}
};
},
@ -103,9 +99,6 @@
showResults() {
return this.me.permissions.includes('users.can_manage_school_class_content');
},
canManageContent() {
return this.me.permissions.includes('users.can_manage_school_class_content');
},
assignments() {
if (!this.module.chapters) {
return [];

View File

@ -29,10 +29,11 @@
import MoreOptionsWidget from '@/components/MoreOptionsWidget';
import {mapState} from 'vuex';
import {isHidden} from '@/helpers/content-block';
import {meQuery} from '@/graphql/queries';
import DELETE_OBJECTIVE_MUTATION from '@/graphql/gql/mutations/deleteObjective.gql';
import MODULE_DETAILS_QUERY from '@/graphql/gql/moduleDetailsQuery.gql';
import {hidden} from '@/helpers/visibility';
import {OBJECTIVE_TYPE} from '@/consts/types';
export default {
props: ['objective', 'schoolClass'],
@ -52,7 +53,11 @@
computed: {
...mapState(['editModule']),
hidden() {
return isHidden(this.objective, this.schoolClass);
return hidden({
block: this.objective,
schoolClass: this.schoolClass,
type: OBJECTIVE_TYPE
});
},
canEdit() {
return this.objective.mine;

View File

@ -21,11 +21,12 @@
<script>
import Objective from '@/components/objective-groups/Objective';
import ME_QUERY from '@/graphql/gql/meQuery.gql';
import AddContentButton from '@/components/AddContentButton';
import {mapState} from 'vuex';
import me from '@/mixins/me';
export default {
props: {
group: {
@ -34,22 +35,15 @@
}
},
mixins: [me],
components: {
AddContentButton,
Objective
},
apollo: {
me: {
query: ME_QUERY,
},
},
computed: {
...mapState(['editModule']),
canManageContent() {
return this.me.permissions.includes('users.can_manage_school_class_content');
},
currentFilter() {
return this.me.selectedClass;
},

View File

@ -8,7 +8,7 @@
<script>
import Checkbox from '@/components/Checkbox';
import {mapGetters, mapActions} from 'vuex';
import {mapState, mapActions} from 'vuex';
export default {
components: {
@ -16,7 +16,7 @@
},
computed: {
...mapGetters({
...mapState({
checked: 'editModule',
})
},

View File

@ -1,17 +1,3 @@
export function setUserBlockType(isAssignment) {
return isAssignment ? 'TASK' : 'NORMAL';
}
export const isHidden = (contentBlock, schoolClass) => {
if (!contentBlock.id || !contentBlock.visibleFor || !contentBlock.hiddenFor) {
return false;
}
if (contentBlock.userCreated) {
if (schoolClass.id === '') {
return false;
}
return !contentBlock.visibleFor.map(entry => entry.id).includes(schoolClass.id);
} else {
return contentBlock.hiddenFor.map(entry => entry.id).includes(schoolClass.id);
}
};

View File

@ -6,7 +6,7 @@
</template>
<script>
import {mapGetters, mapActions} from 'vuex';
import {mapState, mapActions} from 'vuex';
import MODULE_DETAILS_QUERY from '@/graphql/gql/moduleDetailsQuery.gql';
import SCROLL_POSITION from '@/graphql/gql/local/scrollPosition.gql';
@ -26,7 +26,7 @@
},
computed: {
...mapGetters({
...mapState({
editModule: 'editModule'
}),
},