gamebrary/src/components/Lists/ListTweaks.vue

141 lines
3.5 KiB
Vue
Raw Normal View History

2020-08-11 23:39:11 +00:00
<template lang="html">
<b-dropdown-item-button v-b-modal="modalId">
<b-icon-toggles /> List tweaks
<b-modal
:id="modalId"
title="List tweaks"
2020-08-24 17:22:01 +00:00
@show="getSettings"
2020-08-11 23:39:11 +00:00
>
<form ref="renameListForm" @submit.stop.prevent="save">
<b-form-checkbox v-model="showReleaseDates" name="check-button" switch>
Show release date for unreleased games
</b-form-checkbox>
<b-form-checkbox v-model="showGameRatings" name="check-button" switch>
Show game ratings
</b-form-checkbox>
<b-form-checkbox v-model="showGameProgress" name="check-button" switch>
Show game progress
</b-form-checkbox>
<b-form-checkbox v-model="showGameNotes" name="check-button" switch>
Show game notes
</b-form-checkbox>
<b-form-checkbox v-model="showGameTags" name="check-button" switch>
Show game tags
</b-form-checkbox>
2020-08-15 00:02:17 +00:00
<b-form-checkbox v-model="showGameCount" name="check-button" switch>
Show game count
</b-form-checkbox>
2020-08-11 23:39:11 +00:00
</form>
<template v-slot:modal-footer="{ cancel }">
<b-button @click="cancel">
Cancel
</b-button>
<b-button
variant="primary"
:disabled="saving"
@click="save"
>
<b-spinner small v-if="saving" />
<span v-else>Save</span>
</b-button>
</template>
</b-modal>
</b-dropdown-item-button>
</template>
<script>
import { mapState } from 'vuex';
export default {
props: {
2020-08-21 14:38:03 +00:00
listIndex: Number,
list: Object,
2020-08-11 23:39:11 +00:00
},
data() {
return {
showReleaseDates: false,
showGameRatings: false,
showGameProgress: false,
showGameNotes: false,
showGameTags: false,
2020-08-15 00:02:17 +00:00
showGameCount: false,
2020-08-11 23:39:11 +00:00
saving: false,
};
},
computed: {
...mapState(['gameLists', 'platform']),
modalId() {
return `list-tweaks-${this.listIndex}`;
},
isDuplicate() {
return this.listName && this.existingListNames.includes(this.listName.toLowerCase());
},
},
methods: {
getSettings() {
const {
showReleaseDates,
showGameRatings,
showGameProgress,
showGameNotes,
showGameTags,
2020-08-15 00:02:17 +00:00
showGameCount,
2020-08-21 14:38:03 +00:00
} = this.list.settings;
2020-08-11 23:39:11 +00:00
this.showReleaseDates = showReleaseDates || false;
this.showGameRatings = showGameRatings || false;
this.showGameProgress = showGameProgress || false;
this.showGameNotes = showGameNotes || false;
this.showGameTags = showGameTags || false;
2020-08-15 00:02:17 +00:00
this.showGameCount = showGameCount || false;
2020-08-11 23:39:11 +00:00
},
async save() {
2020-08-21 14:38:03 +00:00
const { listIndex, list: { settings } } = this;
2020-08-11 23:39:11 +00:00
this.saving = true;
2020-08-21 14:38:03 +00:00
settings.showReleaseDates = this.showReleaseDates;
settings.showGameRatings = this.showGameRatings;
settings.showGameProgress = this.showGameProgress;
settings.showGameNotes = this.showGameNotes;
settings.showGameTags = this.showGameTags;
settings.showGameCount = this.showGameCount;
2020-08-11 23:39:11 +00:00
2020-08-21 14:38:03 +00:00
this.$store.commit('SET_LIST_SETTINGS', { listIndex, settings });
2020-08-11 23:39:11 +00:00
2020-08-21 14:38:03 +00:00
await this.$store.dispatch('SAVE_BOARD')
2020-08-11 23:39:11 +00:00
.catch(() => {
this.saving = false;
this.$bvToast.toast('There was an error renaming list', {
title: 'Error',
variant: 'danger',
});
});
this.saving = false;
this.$bvToast.toast('Settings saved', {
title: 'Success',
variant: 'success',
});
this.$bvModal.hide(this.modalId);
},
},
};
</script>