Skip to content

Commit

Permalink
Hide panel change warnings when no changes made
Browse files Browse the repository at this point in the history
  • Loading branch information
gordlin committed Aug 30, 2024
1 parent 4ae4c85 commit d986015
Showing 1 changed file with 80 additions and 2 deletions.
82 changes: 80 additions & 2 deletions src/components/slide-editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@
class="editor-input rounded-none cursor-pointer w-4 h-4"
v-model="rightOnly"
:disabled="rightOnly && determineEditorType(currentSlide.panel[panelIndex]) === 'dynamic'"
@change.stop="$vfm.open(`right-only-${slideIndex}`)"
@change.stop="
if (currentSlide.panel.length > 1 && panelModified(currentSlide.panel[0])) {
$vfm.open(`right-only-${slideIndex}`);
} else {
toggleRightOnly();
}
"
/>
<span class="mx-2 font-bold">{{ $t('editor.slides.centerSlide') }}</span>
<input
Expand Down Expand Up @@ -236,8 +242,14 @@
<select
ref="typeSelector"
@input="
$vfm.open(`change-slide-${slideIndex}`);
newType = ($event.target as HTMLInputElement).value;
if (panelModified(currentSlide.panel[panelIndex])) {
$vfm.open(`change-slide-${slideIndex}`);
} else {
changePanelType(determineEditorType(currentSlide.panel[panelIndex]), newType);
toggleCenterPanel();
toggleCenterSlide();
}
"
:value="determineEditorType(currentSlide.panel[panelIndex])"
>
Expand Down Expand Up @@ -334,6 +346,7 @@ import SlideshowEditorV from './slideshow-editor.vue';
import LoadingPageV from './helpers/loading-page.vue';
import DynamicEditorV from './dynamic-editor.vue';
import ConfirmationModalV from './helpers/confirmation-modal.vue';
import { toRaw } from 'vue';
@Options({
components: {
Expand Down Expand Up @@ -383,6 +396,63 @@ export default class SlideEditorV extends Vue {
this.currentSlide ? (this.rightOnly = this.currentSlide.panel.length === 1) : false;
}
panelModified(panel: BasePanel): boolean {
const prevType = this.currentSlide.panel[this.panelIndex].type;
const startingConfig: DefaultConfigs = {
text: {
type: PanelType.Text,
title: '',
content: ''
},
dynamic: {
type: PanelType.Dynamic,
title:
this.currentSlide.panel[0] && prevType === 'text'
? (this.currentSlide.panel[0] as TextPanel).title
: '',
titleTag: '',
content:
this.currentSlide.panel[0] && prevType === 'text'
? (this.currentSlide.panel[0] as TextPanel).content
: '',
children: []
},
slideshow: {
type: PanelType.Slideshow,
items: [],
userCreated: true
},
image: {
type: PanelType.Image,
src: ''
},
chart: {
type: PanelType.Chart,
src: ''
},
map: {
type: PanelType.Map,
config: `${this.configFileStructure.uuid}/ramp-config/${
this.configFileStructure.uuid
}-map-${this.getNumberOfMaps()}.json`,
title: '',
scrollguard: false
},
video: {
type: PanelType.Video,
title: '',
videoType: '',
src: ''
}
};
const oldStartingConfig = JSON.parse(JSON.stringify(startingConfig[panel.type as keyof DefaultConfigs]));
let newConfig = Object.assign({}, toRaw(panel));
newConfig.customStyles = newConfig.customStyles || undefined;
return JSON.stringify(oldStartingConfig) !== JSON.stringify(newConfig);
}
changePanelType(prevType: string, newType: string): void {
const startingConfig: DefaultConfigs = {
text: {
Expand Down Expand Up @@ -628,6 +698,14 @@ export default class SlideEditorV extends Vue {
}
}
}
getNumberOfMaps(): number {
let n = 0;
this.configFileStructure.rampConfig.forEach((f) => {
n += 1;
});
return n;
}
}
</script>

Expand Down

0 comments on commit d986015

Please sign in to comment.