Skip to content

Commit

Permalink
Improved: Fetched groups detail on save from manage facilities page. …
Browse files Browse the repository at this point in the history
…Also added loader on manage facilities page. (#293)
  • Loading branch information
ravilodhi committed Aug 13, 2024
1 parent 447ecee commit 6582426
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/views/FindGroups.vue
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ export default defineComponent({
},
async mounted() {
await this.store.dispatch('util/fetchFacilityGroupTypes')
await this.fetchGroups();
},
async ionViewWillEnter() {
await this.fetchGroups();
this.isScrollingEnabled = false;
},
methods: {
Expand Down
24 changes: 20 additions & 4 deletions src/views/ManageFacilities.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
</ion-list>
</section>

<main>
<main v-if="selectedFacilities.length">
<h3 class="ion-margin-start">{{ translate('Total facilities selected for group', {total: selectedFacilities.length, facilityGroupName: currentFacilityGroup.facilityGroupName ? currentFacilityGroup.facilityGroupName : facilityGroupId}) }}</h3>
<ion-list v-if="selectedFacilities.length">
<ion-list>
<ion-list-header>
<ion-label>{{ translate('Manage sequence') }}</ion-label>
</ion-list-header>
Expand Down Expand Up @@ -96,6 +96,7 @@
import { hasError } from '@/adapter';
import logger from '@/logger';
import { DateTime } from "luxon";
import emitter from "@/event-bus";
export default defineComponent({
name: 'FindGroups',
Expand Down Expand Up @@ -127,16 +128,21 @@
selectedFacilities: [] as any,
toast: null as any,
currentFacilityGroup: {} as any,
isFacilityMembersModified: false
isFacilityMembersModified: false,
isSavingDetail: false
}
},
props: ['facilityGroupId'],
async mounted() {
emitter.emit('presentLoader')
await Promise.all([this.fetchFacilities(), this.fetchFacilityGroup()])
await this.fetchMemberFacilities();
await this.getFilteredFacilities();
emitter.emit('dismissLoader')
},
async beforeRouteLeave() {
if (this.isSavingDetail) return;
let canLeave = false;
const alert = await alertController.create({
header: translate("Leave page"),
Expand Down Expand Up @@ -195,6 +201,15 @@
logger.error('Failed to fetch facility group', err)
}
},
async fetchGroups(vSize?: any, vIndex?: any) {
const viewSize = vSize ? vSize : process.env.VUE_APP_VIEW_SIZE;
const viewIndex = vIndex ? vIndex : 0;
const payload = {
viewSize,
viewIndex
};
await this.store.dispatch('facility/fetchFacilityGroups', payload)
},
async fetchFacilities() {
this.facilities = []
let viewIndex = 0, resp
Expand Down Expand Up @@ -299,6 +314,7 @@
this.isFacilityMembersModified = true;
},
async save () {
this.isSavingDetail = true
const facilitiesToAdd = this.selectedFacilities.filter((facility: any) => !facility.fromDate)
const selectedFacilityIds = this.selectedFacilities ? new Set(this.selectedFacilities.map((facility:any) => facility.facilityId)) as any : [];
const facilitiesToRemove = this.memberFacilities.filter((facility: any) => !selectedFacilityIds.has(facility.facilityId))
Expand Down Expand Up @@ -338,8 +354,8 @@
} else {
showToast(translate("Member facilities updated successfully."))
}
this.fetchMemberFacilities();
this.isFacilityMembersModified = false;
await this.fetchGroups();
this.router.push({ path: `/tabs/find-groups` })
},
async doReorder(event: CustomEvent) {
Expand Down

0 comments on commit 6582426

Please sign in to comment.