Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/hotwax/facilities into #162
Browse files Browse the repository at this point in the history
  • Loading branch information
amansinghbais committed Mar 28, 2024
2 parents 8421113 + 9dc1fef commit 9d6e457
Show file tree
Hide file tree
Showing 38 changed files with 3,074 additions and 18,497 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ VUE_APP_PERMISSION_ID="FACILITIES_APP_VIEW"
VUE_APP_LOCALES={"en-US": "English"}
VUE_APP_DEFAULT_LOG_LEVEL="error"
VUE_APP_LOGIN_URL="http://launchpad.hotwax.io/login"
VUE_APP_USERS_APPLICATION_URL="http://users.hotwax.io"
VUE_APP_USERS_LOGIN_URL="http://users.hotwax.io/login"
19,833 changes: 1,792 additions & 18,041 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 5 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
{
"name": "facilities",
"version": "1.1.0",
"version": "1.5.0",
"private": true,
"description": "App to manage facilities",
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"test:unit": "vue-cli-service test:unit",
"test:e2e": "vue-cli-service test:e2e",
"lint": "vue-cli-service lint",
"i18n:report": "vue-cli-service i18n:report --src \"./src/**/*.?(js|vue)\" --locales \"./src/locales/**/*.json\""
"lint": "vue-cli-service lint"
},
"dependencies": {
"@capacitor/android": "^2.4.7",
"@capacitor/core": "^2.4.7",
"@casl/ability": "^6.0.0",
"@hotwax/app-version-info": "^1.0.0",
"@hotwax/apps-theme": "^1.2.6",
"@hotwax/dxp-components": "^1.11.0",
"@hotwax/oms-api": "^1.11.0",
"@hotwax/dxp-components": "^1.12.2",
"@hotwax/oms-api": "^1.13.0",
"@ionic/core": "^7.6.0",
"@ionic/vue": "^7.6.0",
"@ionic/vue-router": "^7.6.0",
Expand All @@ -31,15 +30,13 @@
"mitt": "^2.1.0",
"register-service-worker": "^1.7.1",
"vue": "^3.3.8",
"vue-i18n": "~9.1.6",
"vue-logger-plugin": "^2.2.3",
"vue-router": "^4.2.5",
"vuex": "^4.0.1",
"vuex-persistedstate": "^4.0.0-beta.3"
},
"devDependencies": {
"@capacitor/cli": "^2.4.7",
"@intlify/vue-i18n-loader": "^2.1.0",
"@types/luxon": "^2.0.9",
"@typescript-eslint/eslint-plugin": "~5.26.0",
"@typescript-eslint/parser": "~5.26.0",
Expand All @@ -57,7 +54,6 @@
"eslint": "^7.32.0",
"eslint-plugin-vue": "^8.0.3",
"papaparse": "^5.3.1",
"typescript": "~4.7.4",
"vue-cli-plugin-i18n": "^1.0.1"
"typescript": "~4.7.4"
}
}
3 changes: 2 additions & 1 deletion src/adapter/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { api, client, getConfig, getUserFacilities, hasError, initialise, logout, resetConfig, setUserLocale, updateInstanceUrl, updateToken } from '@hotwax/oms-api'
import { api, client, getConfig, getTelecomCountryCode, getUserFacilities, hasError, initialise, logout, resetConfig, setUserLocale, updateInstanceUrl, updateToken } from '@hotwax/oms-api'

export {
api,
client,
getConfig,
getTelecomCountryCode,
getUserFacilities,
hasError,
initialise,
Expand Down
242 changes: 242 additions & 0 deletions src/components/AddFacilityToGroupModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
<template>
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-button @click="closeModal">
<ion-icon slot="icon-only" :icon="close" />
</ion-button>
</ion-buttons>
<ion-title>{{ translate("Select facilities") }}</ion-title>
</ion-toolbar>
</ion-header>

<ion-content class="ion-padding">
<ion-searchbar v-model="queryString" @keyup.enter="queryString = $event.target.value; fetchFacilities()" />
<ion-chip outline>
{{ translate("Facilities:", { count: selectedFacilityValues.length }) }}
</ion-chip>

<ion-list>
<div class="ion-padding" v-if="!facilities.length">
{{ translate("No facility found") }}
</div>
<div v-else>
<ion-item v-for="(facility, index) in facilities" :key="index" @click="updateSelectedFacilities(facility.facilityId)" lines="none">
<ion-label>
{{ facility.facilityName }}
<p>{{ facility.facilityId }}</p>
</ion-label>
<ion-checkbox :checked="isFacilitySelected(facility.facilityId)" />
</ion-item>
</div>
</ion-list>
<ion-fab vertical="bottom" horizontal="end" slot="fixed">
<ion-fab-button :disabled="!areFacilitiesUpdated()" @click="confirmSave()">
<ion-icon :icon="saveOutline" />
</ion-fab-button>
</ion-fab>
</ion-content>
</template>

<script lang="ts">
import {
IonButton,
IonButtons,
IonCheckbox,
IonChip,
IonContent,
IonFab,
IonFabButton,
IonHeader,
IonIcon,
IonItem,
IonLabel,
IonList,
IonSearchbar,
IonTitle,
IonToolbar,
modalController
} from "@ionic/vue";
import { defineComponent } from "vue";
import { close, closeCircle, saveOutline } from "ionicons/icons";
import { useStore } from "vuex";
import { hasError } from "@/adapter";
import logger from "@/logger"
import { translate } from '@hotwax/dxp-components'
import { FacilityService } from "@/services/FacilityService";
import { DateTime } from "luxon";
import { showToast } from "@/utils";
export default defineComponent({
name: "AddFacilityToGroupModal",
components: {
IonButtons,
IonButton,
IonCheckbox,
IonChip,
IonContent,
IonFab,
IonFabButton,
IonHeader,
IonIcon,
IonItem,
IonLabel,
IonList,
IonSearchbar,
IonTitle,
IonToolbar,
},
data() {
return {
queryString: '',
facilities: [] as any,
selectedFacilities: [] as any,
selectedFacilityValues: [] as any
}
},
props: ['facilityGroupId'],
mounted() {
Promise.all([this.fetchFacilities(), this.fetchAssociatedFacilities()])
},
methods: {
closeModal() {
modalController.dismiss()
},
async fetchFacilities() {
this.facilities = []
let filters = {} as any;
if(this.queryString) {
filters["facilityId_value"] = this.queryString
filters["facilityId_op"] = "contains"
filters["facilityId_ic"] = "Y"
filters["facilityId_grp"] = "1"
filters["facilityName_value"] = this.queryString
filters["facilityName_op"] = "contains"
filters["facilityName_ic"] = "Y"
filters["facilityName_grp"] = "1"
filters["grp_op_1"] = "OR"
}
const params = {
"inputFields": {
...filters
},
"entityName": "Facility",
"noConditionFind": "Y",
"distinct": "Y",
"fieldList": ["facilityId", "facilityName"],
// By default we show only 20 facilities, others get rendered on search query.
"viewSize": 20
}
try {
const resp = await FacilityService.fetchFacilities(params)
if (!hasError(resp) && resp.data.count) {
this.facilities = resp.data.docs
} else {
throw resp.data
}
} catch (error) {
logger.error(error)
}
},
async fetchAssociatedFacilities() {
try {
const resp = await FacilityService.fetchAssociatedFacilitiesToGroup({
"inputFields": {
"facilityGroupId": this.facilityGroupId
},
"viewSize": 250, // maximum view size
"entityName": 'FacilityGroupAndMember',
"noConditionFind": "Y",
"filterByDate": 'Y',
"fieldList": ['facilityId', 'fromDate']
})
if(!hasError(resp)) {
this.selectedFacilities = resp.data.docs
this.selectedFacilityValues = JSON.parse(JSON.stringify(resp.data.docs))
} else {
throw resp.data
}
} catch(err) {
logger.error(err)
}
},
updateSelectedFacilities(id: string) {
const facility = this.isFacilitySelected(id)
if (facility) {
// if facility is already selected then removing that facility from the list on click
this.selectedFacilityValues = this.selectedFacilityValues.filter((facility: any) => facility.facilityId !== id)
} else {
this.selectedFacilityValues.push(this.facilities.find((facility: any) => facility.facilityId == id))
}
},
isFacilitySelected(facilityId: any) {
return this.selectedFacilityValues.some((facility: any) => facility.facilityId === facilityId)
},
async confirmSave() {
const facilitiesToAdd = this.selectedFacilityValues.filter((selectedFacility: any) => !this.selectedFacilities.some((facility: any) => facility.facilityId === selectedFacility.facilityId))
const facilitiesToRemove = this.selectedFacilities.filter((facility: any) => !this.selectedFacilityValues.some((selectedFacility: any) => facility.facilityId === selectedFacility.facilityId))
const removeResponses = await Promise.allSettled(facilitiesToRemove
.map(async (facility: any) => await FacilityService.updateFacilityToGroup({
"facilityId": facility.facilityId,
"facilityGroupId": this.facilityGroupId,
"fromDate": facility.fromDate,
"thruDate": DateTime.now().toMillis()
}))
)
const addResponses = await Promise.allSettled(facilitiesToAdd
.map(async (facility: any) => await FacilityService.addFacilityToGroup({
"facilityId": facility.facilityId,
"facilityGroupId": this.facilityGroupId
}))
)
const hasFailedResponse = [...removeResponses, ...addResponses].some((response: any) => response.status === 'rejected')
if (hasFailedResponse) {
showToast(translate("Failed to associate some facilites to group."))
} else {
showToast(translate("Facilities associated to group successfully."))
}
this.fetchGroups()
modalController.dismiss()
},
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)
},
areFacilitiesUpdated() {
if(this.selectedFacilities.length !== this.selectedFacilityValues.length) return true;
return this.selectedFacilityValues.some((selectedFacility: any) => !this.selectedFacilities.find((facility: any) => facility.facilityId === selectedFacility.facilityId))
}
},
setup() {
const store = useStore();
return {
close,
saveOutline,
closeCircle,
store,
translate
};
}
});
</script>

<style scoped>
ion-content {
--padding-bottom: 80px;
}
</style>
Loading

0 comments on commit 9d6e457

Please sign in to comment.