From 06bf97e6ed2979aab0e8a90b37443e6fab0b9c89 Mon Sep 17 00:00:00 2001 From: Tang Date: Thu, 19 Oct 2023 14:13:02 -0700 Subject: [PATCH] added the district contact download --- frontend/src/utils/common.ts | 22 ++++++++++++ frontend/src/views/DistrictView.vue | 55 +++++++++++++++++++++-------- frontend/src/views/SchoolView.vue | 28 +++------------ 3 files changed, 67 insertions(+), 38 deletions(-) diff --git a/frontend/src/utils/common.ts b/frontend/src/utils/common.ts index a3459726..e9f4f642 100644 --- a/frontend/src/utils/common.ts +++ b/frontend/src/utils/common.ts @@ -13,3 +13,25 @@ export function useSanitizeURL(input: string | String): String { input = input.toLowerCase().replace(/^a-zA-Z0-9 ]/g, '') return input } +export function transformContactForDownload (inputData: any): {} { + return inputData.map((item: any) => ({ + districtNumber: item.districtNumber, + mincode: item.mincode, + displayName: item.displayName, + addressLine1: item.addressLine1, + city: item.city, + provinceCode: item.provinceCode, + postal: item.postal, + jobTitle: item.jobTitle, + firstName: item.firstName, + lastName: item.lastName, + facilityTypeCode: item.facilityTypeCode, + schoolCategoryCode: item.schoolCategoryCode, + phoneNumber: item.phoneNumber, + phoneExtension: item.phoneExtension, + alternatePhoneNumber: item.alternatePhoneNumber, + alternatePhoneExtension: item.alternatePhoneExtension, + email: item.email, + grades: item.grades + })) +} \ No newline at end of file diff --git a/frontend/src/views/DistrictView.vue b/frontend/src/views/DistrictView.vue index 4e4cbc59..924f88a1 100644 --- a/frontend/src/views/DistrictView.vue +++ b/frontend/src/views/DistrictView.vue @@ -4,23 +4,22 @@ import { ref, reactive, onMounted, computed, toValue } from 'vue' import { useAppStore } from '@/stores/app' import { useRoute } from 'vue-router' import { formatPhoneNumber } from '@/utils/common' - import type { District } from '@/types/types.d.ts' - +import * as jsonexport from 'jsonexport/dist' // import common components import DisplayAddress from '@/components/common/DisplayAddress.vue' const appStore = useAppStore() const districtId = ref(null) // Initialize with null initially - const district = reactive({ value: {} as District }) - +const contacts = ref([]) +const filteredContacts = ref([]) +// const downloadContacts = ref([]) const tabOptions = { contacts: 1, schools: 2 } const tab = ref(tabOptions.contacts) // Default to contacts tab - const contactHeaders = [ { title: 'Contact Type', key: 'districtContactTypeCode' }, { title: 'Name', key: 'firstName' }, @@ -28,7 +27,6 @@ const contactHeaders = [ { title: 'Phone', key: 'phoneNumber' }, { title: 'Email', key: 'email' } ] - const schoolHeaders = [ { title: 'School Name', key: 'displayName' }, { title: 'Mincode', key: 'mincode' }, @@ -43,6 +41,16 @@ const schoolHeaders = [ const schoolSearch = ref('') const contactSearch = ref('') +// functions +function downloadDistrictContacts() { + jsonexport(filteredContacts.value, function (err: any, csv: any) { + if (err) return console.error(err) + appStore.exportCSV(csv) + }) +} +function downloadDistrictSchools() { + alert("TODO - Implement CSV download for a district's schools") +} onMounted(async () => { const route = useRoute() @@ -52,7 +60,32 @@ onMounted(async () => { // get district data try { const response = await InstituteService.getDistrictView(districtId.value as string) - district.value = response.data + if (response.data?.districtData?.contacts) { + district.value = response.data + contacts.value = response.data.districtData.contacts + filteredContacts.value = contacts.value.map((item: any) => { + return { + districtNumber: response.data.districtData.districtNumber, + displayName: response.data.districtData.displayName, + jobTitle: item.jobTitle, + firstName: item.firstName, + lastName: item.lastName, + phoneNumber: item.phoneNumber, + phoneExtension: item.phoneExtension, + alternatePhoneNumber: item.alternatePhoneNumber, + alternatePhoneExtension: item.alternatePhoneExtension, + email: item.email, + mailingAddress: response.data.districtData.addresses[0].addressLine1, + mailingCity: response.data.districtData.addresses[0].city, + mailingProvince: response.data.districtData.addresses[0].provinceCode, + mailingPostalCode: response.data.districtData.addresses[0].postal, + districtPhone: response.data.districtData.phoneNumber, + districtFax: response.data.districtData.faxNumber, + website: response.data.districtData.website + } + }) + console.log(filteredContacts.value) + } } catch (error) { console.error(error) } @@ -64,14 +97,6 @@ onMounted(async () => { // console.error(error) // } }) - -function downloadDistrictContacts() { - alert("TODO - Implement CSV download for a district's contacts") -} - -function downloadDistrictSchools() { - alert("TODO - Implement CSV download for a district's schools") -}