mirror of https://github.com/Lissy93/dashy.git
✨ Add new section functionality
This commit is contained in:
parent
229e67aca8
commit
beb532b967
|
@ -0,0 +1,66 @@
|
||||||
|
<!-- Main homepage for default view -->
|
||||||
|
<template>
|
||||||
|
<div class="add-section">
|
||||||
|
<!-- When in edit mode, show Add New Section button -->
|
||||||
|
<div v-if="isEditMode" @click="openAddNewSectionMenu()" class="add-new-section">
|
||||||
|
<p>➕ {{ $t('interactive-editor.edit-section.add-section-title') }}</p>
|
||||||
|
</div>
|
||||||
|
<!-- Add new section form -->
|
||||||
|
<EditSectionMenu
|
||||||
|
v-if="isEditMode && addNewSectionOpen"
|
||||||
|
:isAddNew="true"
|
||||||
|
@closeEditSection="closeEditSection"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
import EditSectionMenu from '@/components/InteractiveEditor/EditSection.vue';
|
||||||
|
import StoreKeys from '@/utils/StoreMutations';
|
||||||
|
import { modalNames } from '@/utils/defaults';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'add-section-container',
|
||||||
|
components: {
|
||||||
|
EditSectionMenu,
|
||||||
|
},
|
||||||
|
data: () => ({
|
||||||
|
addNewSectionOpen: false,
|
||||||
|
}),
|
||||||
|
computed: {
|
||||||
|
isEditMode() {
|
||||||
|
return this.$store.state.editMode;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
openAddNewSectionMenu() {
|
||||||
|
this.addNewSectionOpen = true;
|
||||||
|
this.$modal.show(modalNames.EDIT_SECTION);
|
||||||
|
this.$store.commit(StoreKeys.SET_MODAL_OPEN, true);
|
||||||
|
},
|
||||||
|
closeEditSection() {
|
||||||
|
this.addNewSectionOpen = false;
|
||||||
|
this.$modal.hide(modalNames.EDIT_SECTION);
|
||||||
|
this.$store.commit(StoreKeys.SET_MODAL_OPEN, false);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
|
||||||
|
.add-new-section {
|
||||||
|
border: 2px dashed var(--primary);
|
||||||
|
border-radius: var(--curve-factor);
|
||||||
|
padding: var(--item-group-padding);
|
||||||
|
background: var(--item-group-background);
|
||||||
|
color: var(--primary);
|
||||||
|
font-size: 1.2rem;
|
||||||
|
cursor: pointer;
|
||||||
|
text-align: center;
|
||||||
|
height: fit-content;
|
||||||
|
margin: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
|
@ -1,14 +1,13 @@
|
||||||
<template>
|
<template>
|
||||||
<modal
|
<modal
|
||||||
:name="modalName"
|
:name="modalName" @closed="modalClosed"
|
||||||
:resizable="true"
|
:resizable="true" width="50%" height="80%"
|
||||||
width="50%"
|
|
||||||
height="80%"
|
|
||||||
classes="dashy-modal edit-section"
|
classes="dashy-modal edit-section"
|
||||||
@closed="modalClosed"
|
|
||||||
>
|
>
|
||||||
<div class="edit-section-inner">
|
<div class="edit-section-inner">
|
||||||
<h3>{{ $t('interactive-editor.edit-section.edit-section-title') }}</h3>
|
<h3>
|
||||||
|
{{ $t(`interactive-editor.edit-section.${isAddNew ? 'add' : 'edit'}-section-title`) }}
|
||||||
|
</h3>
|
||||||
<FormSchema
|
<FormSchema
|
||||||
:schema="customSchema"
|
:schema="customSchema"
|
||||||
v-model="sectionData"
|
v-model="sectionData"
|
||||||
|
@ -34,6 +33,7 @@ export default {
|
||||||
name: 'EditSection',
|
name: 'EditSection',
|
||||||
props: {
|
props: {
|
||||||
sectionIndex: Number,
|
sectionIndex: Number,
|
||||||
|
isAddNew: Boolean,
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
SaveCancelButtons,
|
SaveCancelButtons,
|
||||||
|
@ -47,6 +47,7 @@ export default {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
/* Make a custom schema object, using fields from ConfigSchema */
|
||||||
customSchema() {
|
customSchema() {
|
||||||
const sectionSchema = this.schema;
|
const sectionSchema = this.schema;
|
||||||
const displayDataSchema = this.schema.displayData.properties;
|
const displayDataSchema = this.schema.displayData.properties;
|
||||||
|
@ -76,7 +77,9 @@ export default {
|
||||||
this.$modal.show(modalNames.EDIT_SECTION);
|
this.$modal.show(modalNames.EDIT_SECTION);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
/* From the current index, return section data */
|
||||||
getSectionFromState(index) {
|
getSectionFromState(index) {
|
||||||
|
if (this.isAddNew) return {};
|
||||||
return this.$store.getters.getSectionByIndex(index);
|
return this.$store.getters.getSectionByIndex(index);
|
||||||
},
|
},
|
||||||
/* Clean up work, triggered when modal closed */
|
/* Clean up work, triggered when modal closed */
|
||||||
|
@ -84,9 +87,14 @@ export default {
|
||||||
this.$store.commit(StoreKeys.SET_MODAL_OPEN, false);
|
this.$store.commit(StoreKeys.SET_MODAL_OPEN, false);
|
||||||
this.$emit('closeEditSection');
|
this.$emit('closeEditSection');
|
||||||
},
|
},
|
||||||
|
/* Either update existing section, or insert new one, then close modal */
|
||||||
saveSection() {
|
saveSection() {
|
||||||
const { sectionIndex, sectionData } = this;
|
const { sectionIndex, sectionData } = this;
|
||||||
|
if (this.isAddNew) {
|
||||||
|
this.$store.commit(StoreKeys.INSERT_SECTION, sectionData);
|
||||||
|
} else {
|
||||||
this.$store.commit(StoreKeys.UPDATE_SECTION, { sectionIndex, sectionData });
|
this.$store.commit(StoreKeys.UPDATE_SECTION, { sectionIndex, sectionData });
|
||||||
|
}
|
||||||
this.$store.commit(StoreKeys.SET_EDIT_MODE, true);
|
this.$store.commit(StoreKeys.SET_EDIT_MODE, true);
|
||||||
this.$emit('closeEditSection');
|
this.$emit('closeEditSection');
|
||||||
},
|
},
|
||||||
|
|
|
@ -44,6 +44,8 @@
|
||||||
:class="
|
:class="
|
||||||
(searchValue && filterTiles(section.items, searchValue).length === 0) ? 'no-results' : ''"
|
(searchValue && filterTiles(section.items, searchValue).length === 0) ? 'no-results' : ''"
|
||||||
/>
|
/>
|
||||||
|
<!-- Show add new section button, in edit mode -->
|
||||||
|
<AddNewSection v-if="isEditMode" />
|
||||||
</div>
|
</div>
|
||||||
<!-- Show message when there's no data to show -->
|
<!-- Show message when there's no data to show -->
|
||||||
<div v-if="checkIfResults()" class="no-data">
|
<div v-if="checkIfResults()" class="no-data">
|
||||||
|
@ -62,8 +64,10 @@ import SettingsContainer from '@/components/Settings/SettingsContainer.vue';
|
||||||
import Section from '@/components/LinkItems/Section.vue';
|
import Section from '@/components/LinkItems/Section.vue';
|
||||||
import EditModeSaveMenu from '@/components/InteractiveEditor/EditModeSaveMenu.vue';
|
import EditModeSaveMenu from '@/components/InteractiveEditor/EditModeSaveMenu.vue';
|
||||||
import ExportConfigMenu from '@/components/InteractiveEditor/ExportConfigMenu.vue';
|
import ExportConfigMenu from '@/components/InteractiveEditor/ExportConfigMenu.vue';
|
||||||
|
import AddNewSection from '@/components/InteractiveEditor/AddNewSectionLauncher.vue';
|
||||||
import { searchTiles } from '@/utils/Search';
|
import { searchTiles } from '@/utils/Search';
|
||||||
import Defaults, { localStorageKeys, iconCdns } from '@/utils/defaults';
|
import StoreKeys from '@/utils/StoreMutations';
|
||||||
|
import Defaults, { localStorageKeys, iconCdns, modalNames } from '@/utils/defaults';
|
||||||
import ErrorHandler from '@/utils/ErrorHandler';
|
import ErrorHandler from '@/utils/ErrorHandler';
|
||||||
import BackIcon from '@/assets/interface-icons/back-arrow.svg';
|
import BackIcon from '@/assets/interface-icons/back-arrow.svg';
|
||||||
|
|
||||||
|
@ -73,6 +77,7 @@ export default {
|
||||||
SettingsContainer,
|
SettingsContainer,
|
||||||
EditModeSaveMenu,
|
EditModeSaveMenu,
|
||||||
ExportConfigMenu,
|
ExportConfigMenu,
|
||||||
|
AddNewSection,
|
||||||
Section,
|
Section,
|
||||||
BackIcon,
|
BackIcon,
|
||||||
},
|
},
|
||||||
|
@ -80,6 +85,7 @@ export default {
|
||||||
searchValue: '',
|
searchValue: '',
|
||||||
layout: '',
|
layout: '',
|
||||||
itemSizeBound: '',
|
itemSizeBound: '',
|
||||||
|
addNewSectionOpen: false,
|
||||||
}),
|
}),
|
||||||
computed: {
|
computed: {
|
||||||
sections() {
|
sections() {
|
||||||
|
@ -164,6 +170,16 @@ export default {
|
||||||
updateModalVisibility(modalState) {
|
updateModalVisibility(modalState) {
|
||||||
this.$store.commit('SET_MODAL_OPEN', modalState);
|
this.$store.commit('SET_MODAL_OPEN', modalState);
|
||||||
},
|
},
|
||||||
|
openAddNewSectionMenu() {
|
||||||
|
this.addNewSectionOpen = true;
|
||||||
|
this.$modal.show(modalNames.EDIT_SECTION);
|
||||||
|
this.$store.commit(StoreKeys.SET_MODAL_OPEN, true);
|
||||||
|
},
|
||||||
|
closeEditSection() {
|
||||||
|
this.addNewSectionOpen = false;
|
||||||
|
this.$modal.hide(modalNames.EDIT_SECTION);
|
||||||
|
this.$store.commit(StoreKeys.SET_MODAL_OPEN, false);
|
||||||
|
},
|
||||||
/* If on sub-route, and section exists, then return only that section */
|
/* If on sub-route, and section exists, then return only that section */
|
||||||
findSingleSection: (allSections, sectionTitle) => {
|
findSingleSection: (allSections, sectionTitle) => {
|
||||||
if (!sectionTitle) return undefined;
|
if (!sectionTitle) return undefined;
|
||||||
|
@ -346,6 +362,18 @@ export default {
|
||||||
&.single-section-view {
|
&.single-section-view {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
.add-new-section {
|
||||||
|
border: 2px dashed var(--primary);
|
||||||
|
border-radius: var(--curve-factor);
|
||||||
|
padding: var(--item-group-padding);
|
||||||
|
background: var(--item-group-background);
|
||||||
|
color: var(--primary);
|
||||||
|
font-size: 1.2rem;
|
||||||
|
cursor: pointer;
|
||||||
|
text-align: center;
|
||||||
|
height: fit-content;
|
||||||
|
margin: 10px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Custom styles only applied when there is no sections in config */
|
/* Custom styles only applied when there is no sections in config */
|
||||||
|
|
Loading…
Reference in New Issue