Builds edit section form and functionality

This commit is contained in:
Alicia Sykes 2021-10-24 13:26:49 +01:00
parent 0a00c9beb2
commit fecd1c6493
3 changed files with 160 additions and 12 deletions

View File

@ -1,23 +1,119 @@
<template> <template>
<span>Item Editor</span> <modal
:name="modalName"
:resizable="true"
width="50%"
height="80%"
classes="dashy-modal edit-section"
@closed="modalClosed"
>
<div class="edit-section-inner">
<h3>Edit Section</h3>
<FormSchema
:schema="customSchema"
v-model="sectionData"
name="editSectionForm"
class="edit-section-form"
/>
<!-- Save to state button -->
<Button class="edit-section-save-btn" :click="saveSection">Save</Button>
</div>
</modal>
</template> </template>
<script> <script>
import FormSchema from '@formschema/native';
import StoreKeys from '@/utils/StoreMutations';
import DashySchema from '@/utils/ConfigSchema';
import Button from '@/components/FormElements/Button';
import { modalNames } from '@/utils/defaults';
export default { export default {
name: 'EditSection', name: 'EditSection',
data() { props: {
return {}; sectionIndex: Number,
},
components: {
Button,
FormSchema,
},
data() {
return {
modalName: modalNames.EDIT_SECTION,
schema: DashySchema.properties.sections.items.properties,
sectionData: {},
};
},
computed: {
customSchema() {
const sectionSchema = this.schema;
const displayDataSchema = this.schema.displayData.properties;
return {
type: 'object',
properties: {
name: sectionSchema.name,
icon: sectionSchema.icon,
displayData: {
title: '',
description: '',
type: 'object',
properties: {
sortBy: displayDataSchema.sortBy,
rows: displayDataSchema.rows,
cols: displayDataSchema.cols,
collapsed: displayDataSchema.collapsed,
hideForGuests: displayDataSchema.hideForGuests,
},
},
},
};
},
},
mounted() {
this.sectionData = this.$store.getters.getSectionByIndex(this.sectionIndex);
this.$modal.show(modalNames.EDIT_SECTION);
},
methods: {
getSectionFromState(index) {
return this.$store.getters.getSectionByIndex(index);
},
/* Clean up work, triggered when modal closed */
modalClosed() {
this.$store.commit(StoreKeys.SET_MODAL_OPEN, false);
this.$emit('closeEditSection');
},
saveSection() {
const { sectionIndex, sectionData } = this;
this.$store.commit(StoreKeys.UPDATE_SECTION, { sectionIndex, sectionData });
this.$store.commit(StoreKeys.SET_EDIT_MODE, true);
this.$emit('closeEditSection');
},
}, },
props: {},
computed: {},
components: {},
methods: {},
}; };
</script> </script>
<style scoped lang="scss"> <style lang="scss">
@import '@/styles/style-helpers.scss'; @import '@/styles/style-helpers.scss';
@import '@/styles/media-queries.scss'; @import '@/styles/media-queries.scss';
@import '@/styles/schema-editor.scss';
.edit-section-inner {
padding: 1rem;
background: var(--interactive-editor-background);
color: var(--interactive-editor-color);
height: 100%;
overflow-y: auto;
@extend .scroll-bar;
h3 {
font-size: 1.4rem;
margin: 0.5rem;
}
.edit-section-form {
@extend .schema-form;
margin-bottom: 2.5rem;
}
.edit-section-save-btn {
margin-bottom: 2rem;
}
}
</style> </style>

View File

@ -4,16 +4,17 @@
:style="`${color ? 'background: '+color : ''}; ${sanitizeCustomStyles(customStyles)};`" :style="`${color ? 'background: '+color : ''}; ${sanitizeCustomStyles(customStyles)};`"
> >
<input <input
:id="`collapsible-${uniqueKey}`" :id="sectionKey"
class="toggle" class="toggle"
type="checkbox" type="checkbox"
:checked="getCollapseState()" :checked="getCollapseState()"
@change="collapseChanged" @change="collapseChanged"
tabIndex="-1" tabIndex="-1"
> >
<label :for="`collapsible-${uniqueKey}`" class="lbl-toggle" tabindex="-1"> <label :for="sectionKey" class="lbl-toggle" tabindex="-1">
<Icon v-if="icon" :icon="icon" size="small" :url="title" class="section-icon" /> <Icon v-if="icon" :icon="icon" size="small" :url="title" class="section-icon" />
<h3>{{ title }}</h3> <h3>{{ title }}</h3>
<EditModeIcon v-if="isEditMode" class="edit-mode-item" @click="openEditModal" />
</label> </label>
<div class="collapsible-content"> <div class="collapsible-content">
<div class="content-inner"> <div class="content-inner">
@ -27,6 +28,7 @@
import { localStorageKeys } from '@/utils/defaults'; import { localStorageKeys } from '@/utils/defaults';
import Icon from '@/components/LinkItems/ItemIcon.vue'; import Icon from '@/components/LinkItems/ItemIcon.vue';
import EditModeIcon from '@/assets/interface-icons/interactive-editor-edit-mode.svg';
export default { export default {
name: 'CollapsableContainer', name: 'CollapsableContainer',
@ -42,6 +44,16 @@ export default {
}, },
components: { components: {
Icon, Icon,
EditModeIcon,
},
computed: {
isEditMode() {
return this.$store.state.editMode;
},
sectionKey() {
if (this.isEditMode) return undefined;
return `collapsible-${this.uniqueKey}`;
},
}, },
methods: { methods: {
/* Check that row & column span is valid, and not over the max */ /* Check that row & column span is valid, and not over the max */
@ -95,6 +107,9 @@ export default {
this.setCollapseState(this.uniqueKey.toString(), whatChanged.srcElement.checked); this.setCollapseState(this.uniqueKey.toString(), whatChanged.srcElement.checked);
} }
}, },
openEditModal() {
this.$emit('openEditSection');
},
}, },
}; };
</script> </script>
@ -207,5 +222,13 @@ export default {
.collapsible-content .content-inner { .collapsible-content .content-inner {
padding: 0.5rem; padding: 0.5rem;
} }
.edit-mode-item {
width: 1rem;
height: 1rem;
float: right;
right: 0.5rem;
top: 0.5rem;
}
} }
</style> </style>

View File

@ -8,6 +8,7 @@
:rows="displayData.rows" :rows="displayData.rows"
:color="displayData.color" :color="displayData.color"
:customStyles="displayData.customStyles" :customStyles="displayData.customStyles"
@openEditSection="openEditSection"
> >
<div v-if="!items || items.length < 1" class="no-items"> <div v-if="!items || items.length < 1" class="no-items">
No Items to Show Yet No Items to Show Yet
@ -45,15 +46,22 @@
:name="`iframeModal-${groupId}`" :name="`iframeModal-${groupId}`"
@closed="$emit('itemClicked')" @closed="$emit('itemClicked')"
/> />
<EditSection
v-if="editMenuOpen"
@closeEditSection="closeEditSection"
:sectionIndex="index"
/>
</Collapsable> </Collapsable>
</template> </template>
<script> <script>
import { sortOrder as defaultSortOrder, localStorageKeys } from '@/utils/defaults';
import ErrorHandler from '@/utils/ErrorHandler';
import Item from '@/components/LinkItems/Item.vue'; import Item from '@/components/LinkItems/Item.vue';
import Collapsable from '@/components/LinkItems/Collapsable.vue'; import Collapsable from '@/components/LinkItems/Collapsable.vue';
import IframeModal from '@/components/LinkItems/IframeModal.vue'; import IframeModal from '@/components/LinkItems/IframeModal.vue';
import EditSection from '@/components/InteractiveEditor/EditSection.vue';
import ErrorHandler from '@/utils/ErrorHandler';
import StoreKeys from '@/utils/StoreMutations';
import { sortOrder as defaultSortOrder, localStorageKeys, modalNames } from '@/utils/defaults';
export default { export default {
name: 'Section', name: 'Section',
@ -64,11 +72,18 @@ export default {
displayData: Object, displayData: Object,
items: Array, items: Array,
itemSize: String, itemSize: String,
index: Number,
}, },
components: { components: {
Collapsable, Collapsable,
Item, Item,
IframeModal, IframeModal,
EditSection,
},
data() {
return {
editMenuOpen: false,
};
}, },
computed: { computed: {
appConfig() { appConfig() {
@ -113,6 +128,9 @@ export default {
} }
return styles; return styles;
}, },
isEditMode() {
return this.$store.state.editMode;
},
}, },
methods: { methods: {
/* Opens the iframe modal */ /* Opens the iframe modal */
@ -157,6 +175,17 @@ export default {
.sort((a, b) => a.sort - b.sort) .sort((a, b) => a.sort - b.sort)
.map(({ value }) => value); .map(({ value }) => value);
}, },
/* Open the Section Edit Menu */
openEditSection() {
this.editMenuOpen = true;
this.$modal.show(modalNames.EDIT_SECTION);
this.$store.commit(StoreKeys.SET_MODAL_OPEN, true);
},
closeEditSection() {
this.editMenuOpen = false;
this.$modal.hide(modalNames.EDIT_SECTION);
this.$store.commit(StoreKeys.SET_MODAL_OPEN, false);
},
}, },
}; };
</script> </script>