ldc-showroom/app.vue

135 lines
3.7 KiB
Vue

<template>
<div class="app-component">
<NuxtLink to="/">
Home
</NuxtLink>
<NuxtLink to="/ranges">
Ranges
</NuxtLink>
<NuxtPage :page-key="(route: RouteLocation) => route.fullPath" />
<!-- <RangesShow :data-json="data" @selected="itemClicked($event.item)" />
<ProductModal
v-if="selectedItem"
:id="modalId"
:item="selectedItem"
:settings="data.modalSettings"
@saved="SaveContact"
/>
<AdministrativeModal :id="adminModalId" :contacts="contacts" /> -->
</div>
</template>
<script lang="ts">
import Modal from "bootstrap/js/dist/modal";
import KonamiCode from "konami-code-js";
import Swal from "sweetalert2";
import { defineComponent } from "vue";
import dataJson from "public/assets/data.json";
import data from "data/test.json";
export default defineComponent({
name: "IndexPage",
data(): {
modalId: string;
adminModalId: string;
modal: Modal;
adminModal: Modal;
data: typeof data;
dataJson: TypeApp;
selectedItem: Item | null;
konami: KonamiCode;
contacts: Array<Contact>;
} {
return {
modalId: "productModal",
adminModalId: "adminModal",
data,
dataJson,
selectedItem: null,
modal: {} as Modal,
adminModal: {} as Modal,
konami: {} as KonamiCode,
contacts: []
};
},
computed: {
},
watch :{
selectedItem() {
this.$nextTick(() => {
if (!Object.entries(this.modal).length) {
const el = document.getElementById(this.modalId);
if (!el) {
throw new Error(`Missing element ${this.modalId}`);
}
this.modal = new Modal(el);
}
this.modal.show();
});
}
},
mounted() {
// * Make sure array does not start using 0 index
const items: typeof data.items = [];
this.data.items.forEach((item, itemIndex) => {
items[itemIndex +1] = item;
});
this.data.items = items;
// * Init contacts (Fetch form local storage or new)
const serializedContacts = window.localStorage.getItem("contacts");
this.contacts = !serializedContacts ? new Array<Contact>() : JSON.parse(serializedContacts);
// * Hidden action and modal show
this.konami = new KonamiCode(() => {
this.$nextTick(() => {
if (!Object.entries(this.modal).length) {
const el = document.getElementById(this.adminModalId);
if (!el) {
throw new Error(`Missing element ${this.adminModalId}`);
}
this.adminModal = new Modal(el);
}
this.adminModal.show();
});
});
},
methods: {
itemClicked(item: Item): void {
this.selectedItem = item;
},
isMultOf(numerator:number, divider: number):boolean {
return numerator % divider === 0;
},
SaveContact(contact: Contact) {
this.contacts.push(contact);
window.localStorage.setItem("contacts", JSON.stringify(this.contacts));
this.modal.hide();
this.$nextTick(() => this.ShowConfirmedInscription());
},
ShowConfirmedInscription(): void {
Swal.fire({
// timer: 10000,
timerProgressBar: true,
// position: "top",
title: "Votre inscription est validée",
text: "Nous avons bien enregistré votre inscription",
color: getComputedStyle(document.body).getPropertyValue("--bs-body-color"),
icon: "success",
confirmButtonText: "OK",
reverseButtons: true,
// * Bootstrap Styling
customClass: {
confirmButton: "btn btn-primary mx-1",
cancelButton: "btn btn-danger mx-1",
},
buttonsStyling: false,
background: getComputedStyle(document.body).getPropertyValue("--bs-body-bg")
});
},
},
});
</script>