Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented: Ionic Date Time Picker inplace of Default Browser Date Time Picker #191

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
32 changes: 32 additions & 0 deletions src/components/DateSelectionModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<template>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improve indentation, use 2 spaces

<ion-content>
<ion-datetime
@ionChange="onDateChange($event)"
showDefaultButtons
presentation="date"
/>
</ion-content>
</template>

<script lang="ts">
import {
IonContent,
IonDatetime,
modalController,
} from "@ionic/vue";
import { defineComponent } from "vue";

export default defineComponent({
name: "DateSelectionModal",
components: {
IonContent,
IonDatetime
},
methods: {
onDateChange(event: any) {
modalController.dismiss(event.target.value);
}
}
});
</script>

6 changes: 6 additions & 0 deletions src/theme/variables.css
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,12 @@ hr {
text-transform: capitalize;
}

.date-selection-modal {
--width: 290px;
--height: 400px;
--border-radius: 8px;
}

@media (min-width: 700px) {
.list-item {
--col-calc: var(--columns-tablet);
Expand Down
58 changes: 37 additions & 21 deletions src/views/orders.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,34 @@
<div class="filters">
<ion-item>
<ion-label>{{ $t("Ordered after") }}</ion-label>
<ion-chip slot="end">
<!--
TODO Need to fix this
:value is a recommended way for vuex state but value is not working for date when resetting with close button used v-model instead of :value
https://vuex.vuejs.org/guide/forms.html#two-way-computed-property
-->
<ion-input v-model="query.orderedAfter" @ionChange="updateQuery()" type="date" />
<ion-icon @click='query.orderedAfter = ""' v-if="query.orderedAfter" :icon="close"/>
<ion-chip class="ion-padding-horizontal" slot="end">
<ion-label @click="openDateSelectionModal('orderedAfter')">{{ query.orderedAfter ? $filters.formatDate(query.orderedAfter,'yyyy-mm-dd', 'dd/mm/yyyy') : 'dd/mm/yyyy' }}</ion-label>
<ion-icon @click="openDateSelectionModal('orderedAfter')" class="ion-padding-start" :icon="calendarClearOutline"/>
<ion-icon @click='query.orderedAfter = ""; updateQuery()' v-if="query.orderedAfter" :icon="close"/>
</ion-chip>
</ion-item>
<ion-item>
<ion-label>{{ $t("Ordered before") }}</ion-label>
<ion-chip slot="end">
<ion-input v-model="query.orderedBefore" @ionChange="query.orderedBefore = $event.target.value; updateQuery()" type="date" />
<ion-icon @click='query.orderedBefore = ""' v-if="query.orderedBefore" :icon="close"/>
<ion-chip class="ion-padding-horizontal" slot="end">
<ion-label @click="openDateSelectionModal('orderedBefore')">{{ query.orderedBefore ? $filters.formatDate(query.orderedBefore,'yyyy-mm-dd', 'dd/mm/yyyy') : 'dd/mm/yyyy' }}</ion-label>
<ion-icon @click="openDateSelectionModal('orderedBefore')" class="ion-padding-start" :icon="calendarClearOutline"/>
<ion-icon @click='query.orderedBefore = ""; updateQuery()' v-if="query.orderedBefore" :icon="close"/>
</ion-chip>
</ion-item>
<ion-item>
<ion-label>{{ $t("Promised after") }}</ion-label>
<ion-chip slot="end">
<ion-input v-model="query.promisedAfter" @ionChange="query.promisedAfter = $event.target.value; updateQuery()" type="date" />
<ion-icon @click='query.promisedAfter = ""' v-if="query.promisedAfter" :icon="close"/>
<ion-chip class="ion-padding-horizontal" slot="end">
<ion-label @click="openDateSelectionModal('promisedAfter')">{{ query.promisedAfter ? $filters.formatDate(query.promisedAfter,'yyyy-mm-dd', 'dd/mm/yyyy') : 'dd/mm/yyyy' }}</ion-label>
<ion-icon @click="openDateSelectionModal('promisedAfter')" class="ion-padding-start" :icon="calendarClearOutline"/>
<ion-icon @click='query.promisedAfter = ""; updateQuery()' v-if="query.promisedAfter" :icon="close"/>
</ion-chip>
</ion-item>
<ion-item>
<ion-label>{{ $t("Promised before") }}</ion-label>
<ion-chip slot="end">
<ion-input v-model="query.promisedBefore" @ionChange="query.promisedBefore = $event.target.value; updateQuery()" type="date" />
<ion-icon @click='query.promisedBefore = ""' v-if="query.promisedBefore" :icon="close"/>
<ion-chip class="ion-padding-horizontal" slot="end">
<ion-label @click="openDateSelectionModal('promisedBefore')">{{ query.promisedBefore ? $filters.formatDate(query.promisedBefore,'yyyy-mm-dd', 'dd/mm/yyyy') : 'dd/mm/yyyy' }}</ion-label>
<ion-icon @click="openDateSelectionModal('promisedBefore')" class="ion-padding-start" :icon="calendarClearOutline"/>
<ion-icon @click='query.promisedBefore = ""; updateQuery()' v-if="query.promisedBefore" :icon="close"/>
</ion-chip>
</ion-item>
<ion-item>
Expand Down Expand Up @@ -186,7 +185,6 @@ import {
IonItem,
IonLabel,
IonMenuButton,
IonInput,
IonNote,
IonPage,
IonSelect,
Expand Down Expand Up @@ -216,14 +214,16 @@ import {
calendar,
closeCircle,
hourglass,
close
close,
calendarClearOutline
} from "ionicons/icons";
import { useStore } from "@/store";
import { mapGetters } from "vuex";
import { showToast } from '@/utils'
import { Plugins } from '@capacitor/core';
import Image from '@/components/Image.vue';
import emitter from "@/event-bus";
import DateSelectionModal from '@/components/DateSelectionModal.vue';

const { Clipboard } = Plugins;

Expand All @@ -239,7 +239,6 @@ export default defineComponent({
IonContent,
IonFooter,
IonHeader,
IonInput,
IonItem,
IonIcon,
IonLabel,
Expand Down Expand Up @@ -281,7 +280,23 @@ export default defineComponent({
}),
},
methods: {
updateQuery() {
async openDateSelectionModal(dateFilter: string) {
const dateSelectionModal = await modalController.create({
component: DateSelectionModal,
cssClass: 'date-selection-modal'
});

// Getting selected date from the modal on modal dismiss
dateSelectionModal.onDidDismiss().then((dataFromModal) => {
ymaheshwari1 marked this conversation as resolved.
Show resolved Hide resolved
if(dataFromModal.data){
// Assigning value to dateFilters of this.query (orderedAfter, orderedBefore, promisedAfter, promisedBefore) the selected date from the modal
this.query[dateFilter] = dataFromModal.data.split('T')[0];
this.updateQuery();
}
});
return dateSelectionModal.present();
},
updateQuery() {
this.query.viewSize = parseInt(process.env.VUE_APP_VIEW_SIZE);
this.query.viewIndex = 0;
this.store.dispatch("order/updateQuery", { query: this.query});
Expand Down Expand Up @@ -483,6 +498,7 @@ export default defineComponent({
send,
business,
calendar,
calendarClearOutline,
closeCircle,
hourglass,
close,
Expand Down
47 changes: 35 additions & 12 deletions src/views/product-details.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,34 @@
<div class="filters">
<ion-item>
<ion-label>{{ $t("Ordered after") }} </ion-label>
<ion-chip slot="end">
<ion-input v-model="orderedAfter" @ionChange="getVariantProducts()" type="date" />
<ion-icon @click='orderedAfter = ""' v-if="orderedAfter" :icon="close"/>
<ion-chip class="ion-padding-horizontal" slot="end">
<ion-label @click="openDateSelectionModal('orderedAfter')">{{ orderedAfter ? $filters.formatDate(orderedAfter,'yyyy-mm-dd', 'dd/mm/yyyy') : 'dd/mm/yyyy' }}</ion-label>
<ion-icon @click="openDateSelectionModal('orderedAfter')" class="ion-padding-start" :icon="calendarClearOutline"/>
<ion-icon @click='orderedAfter = ""; getVariantProducts()' v-if="orderedAfter" :icon="close"/>
</ion-chip>
</ion-item>
<ion-item>
<ion-label>{{ $t("Ordered before") }}</ion-label>
<ion-chip slot="end">
<ion-input v-model="orderedBefore" @ionChange="getVariantProducts()" type="date" />
<ion-icon @click='orderedBefore = ""' v-if="orderedBefore" :icon="close"/>
<ion-chip class="ion-padding-horizontal" slot="end">
<ion-label @click="openDateSelectionModal('orderedBefore')">{{ orderedBefore ? $filters.formatDate(orderedBefore,'yyyy-mm-dd', 'dd/mm/yyyy') : 'dd/mm/yyyy' }}</ion-label>
<ion-icon @click="openDateSelectionModal('orderedBefore')" class="ion-padding-start" :icon="calendarClearOutline"/>
<ion-icon @click='orderedBefore = ""; getVariantProducts()' v-if="orderedBefore" :icon="close"/>
</ion-chip>
</ion-item>
<ion-item>
<ion-label>{{ $t("Promised after") }}</ion-label>
<ion-chip slot="end">
<ion-input v-model="promisedAfter" @ionChange="getVariantProducts()" type="date" />
<ion-icon @click='promisedAfter = ""' v-if="promisedAfter" :icon="close"/>
<ion-chip class="ion-padding-horizontal" slot="end">
<ion-label @click="openDateSelectionModal('promisedAfter')">{{ promisedAfter ? $filters.formatDate(promisedAfter,'yyyy-mm-dd', 'dd/mm/yyyy') : 'dd/mm/yyyy' }}</ion-label>
<ion-icon @click="openDateSelectionModal('promisedAfter')" class="ion-padding-start" :icon="calendarClearOutline"/>
<ion-icon @click='promisedAfter = ""; getVariantProducts()' v-if="promisedAfter" :icon="close"/>
</ion-chip>
</ion-item>
<ion-item>
<ion-label>{{ $t("Promised before") }}</ion-label>
<ion-chip slot="end">
<ion-input v-model="promisedBefore" @ionChange="getVariantProducts()" type="date" />
<ion-icon @click='promisedBefore = ""' v-if="promisedBefore" :icon="close"/>
<ion-chip class="ion-padding-horizontal" slot="end">
<ion-label @click="openDateSelectionModal('promisedBefore')">{{ promisedBefore ? $filters.formatDate(promisedBefore,'yyyy-mm-dd', 'dd/mm/yyyy') : 'dd/mm/yyyy' }}</ion-label>
<ion-icon @click="openDateSelectionModal('promisedBefore')" class="ion-padding-start" :icon="calendarClearOutline"/>
<ion-icon @click='promisedBefore = ""; getVariantProducts()' v-if="promisedBefore" :icon="close"/>
</ion-chip>
</ion-item>
<!-- TODO -->
Expand Down Expand Up @@ -203,6 +207,7 @@ import {
closeCircle,
hourglass,
calendar,
calendarClearOutline,
close,
list,
refresh,
Expand All @@ -217,6 +222,7 @@ import Image from '@/components/Image.vue';
import { sizeIndex } from "@/apparel-sorter"
import { DateTime } from 'luxon';
import emitter from "@/event-bus";
import DateSelectionModal from'@/components/DateSelectionModal.vue';

export default defineComponent({
name: "product-details",
Expand Down Expand Up @@ -290,6 +296,22 @@ export default defineComponent({
})
},
methods: {
async openDateSelectionModal(dateFilter: string) {
const dateSelectionModal = await modalController.create({
component: DateSelectionModal,
cssClass: 'date-selection-modal'
});

// Getting selected date from the modal on modal dismiss
dateSelectionModal.onDidDismiss().then((dataFromModal) => {
if(dataFromModal.data){
// Assigning value to dateFilters data properties (orderedAfter, orderedBefore, promisedAfter, promisedBefore) the selected date from the modal
(this as any)[dateFilter] = dataFromModal.data.split('T')[0];
this.getVariantProducts();
}
});
return dateSelectionModal.present();
},
onBackgroundJobsFinished() {
this.refreshProducts();
// Reset quantity when the background job is finished
Expand Down Expand Up @@ -583,6 +605,7 @@ export default defineComponent({
closeCircle,
hourglass,
calendar,
calendarClearOutline,
close,
list,
ribbon,
Expand Down
Loading