diff --git a/src/app/dashboard/table/table.component.html b/src/app/dashboard/table/table.component.html index 45a256b..dc98d4b 100644 --- a/src/app/dashboard/table/table.component.html +++ b/src/app/dashboard/table/table.component.html @@ -1,6 +1,7 @@
-

All Partners ({{ userData.length }})

+

All Partners ({{ userData.length }}) +

@@ -11,7 +12,8 @@
- - +
+
+
Filters:
+ + + + + + + + + + +
+
Select Data Type
-
+
Profile Data -
+
Implementation Data -
+
Both -
+
- +
Export as
-
- - +
+ +
- +
-
Select
+
+ Select
Name
Primary Disctrict & State
Type
@@ -68,14 +96,15 @@
-
+
{{ partner.organizationBasicInfo.name }}
{{ partner.detailedProfile.district }}, {{ partner.detailedProfile.state }}
-
+
{{ partner.organizationBasicInfo.type }}
+
-
+
diff --git a/src/app/dashboard/table/table.component.scss b/src/app/dashboard/table/table.component.scss index 1e4ddcf..aedb9e4 100644 --- a/src/app/dashboard/table/table.component.scss +++ b/src/app/dashboard/table/table.component.scss @@ -27,6 +27,23 @@ } } +.filter-row { + padding: 5px 15px; + display: flex; + align-items: center; + + .explainer { + flex-basis: 150px; + font-style: italic; + color: silver; + } + + ng-select { + flex-grow: 1; + margin: 0 5px; + } +} + .card { position: relative; @@ -71,7 +88,7 @@ .sub-options { - div{ + div { margin: 3px 0; display: flex; align-items: center; @@ -81,12 +98,12 @@ color: var(--input-border); - span{ + span { width: 85%; } } - - .radioButton{ + + .radioButton { border: 2px solid var(--input-border); width: 15px; height: 15px; @@ -94,7 +111,7 @@ display: flex; align-items: center; justify-content: center; - + &::before { content: ''; display: block; @@ -103,18 +120,18 @@ border-radius: inherit; background-color: white; } - + &.active { border-color: var(--input-border); - + &::before { background-color: var(--input-border); } } } } - - + + button { border: 2px solid var(--input-border); @@ -126,7 +143,7 @@ font-weight: 500; } - + } .table { @@ -135,13 +152,14 @@ line-height: 1.8; letter-spacing: 0.5px; - header, .row { + header, + .row { display: flex; flex-wrap: nowrap; align-items: center; padding: 0 10px; - .col { + .col { width: calc(100% / 7); font-size: 14px; @@ -149,7 +167,9 @@ margin-right: 5px; } - p, a, &>div { + p, + a, + &>div { display: block; white-space: nowrap; overflow: hidden; @@ -175,7 +195,7 @@ &:nth-child(5) { width: 100px; - } + } } } diff --git a/src/app/dashboard/table/table.component.ts b/src/app/dashboard/table/table.component.ts index 7cb2d08..7d4aedf 100644 --- a/src/app/dashboard/table/table.component.ts +++ b/src/app/dashboard/table/table.component.ts @@ -3,6 +3,9 @@ import { PartnerProfileService } from '../../services/partner-profile.service'; import { Router } from '@angular/router'; import * as Papa from 'papaparse'; import * as XLSX from 'xlsx' +import { UserData, UserDataOption } from 'src/shared/structure/user'; +import { COUNTRIES, STATES, COMMUNITIES } from 'src/shared/data/form-options'; +import { PartnerType, PARTNER_MAPPING } from 'src/shared/data/partner-mapping'; type exportType = "CSV" | "XLSX"; @@ -13,16 +16,28 @@ type exportType = "CSV" | "XLSX"; }) export class TableComponent implements OnInit { - userData: Array = []; - tempUserData: Array = []; + userData: Array = []; + tempUserData: Array = []; showExportOptions: boolean = false; shouldHaveImplementationData: boolean = false; searchText: string = ''; - selectedPartnerList: Array = []; + selectedPartnerList: Array = []; isProfileData: boolean = true; isImplementationData: boolean = false; isBothData: boolean = false; + communities = COMMUNITIES; + countries = COUNTRIES; + states = STATES; + districts: Array = []; + partnerTypes = [PartnerType.ENABLER, PartnerType.IMPLEMENTER, PartnerType.PROVIDER]; + + filteredCommunities: Array = []; + filteredCountries: Array = []; + filteredStates: Array = []; + filteredDistricts: Array = []; + filteredPartnerTypes: Array = []; + exportData: Array = []; exportSurveyCtoData: Array = []; @@ -35,33 +50,100 @@ export class TableComponent implements OnInit { this.getFilteredData(); } + updateDistricts(states: Array<{ districts: Array }>) { + console.log(states); + this.districts = states.map(state => state.districts).flat(); + this.getFilteredData(); + } + getFilteredData() { - this.partnerProfileService.getPartnersData().then((data: any) => { + this.partnerProfileService.getPartnersData().then((data) => { this.userData = data; - if (this.shouldHaveImplementationData) { - this.userData = this.userData.filter(user => { - return (user.surveyCtoData.hiiData && user.surveyCtoData.hiiData.length > 0) || + const searchText = this.searchText.toLowerCase().trim(); + + const filteredCommunitySet = new Set(this.filteredCommunities); + const filteredCountrySet = new Set(this.filteredCountries); + const filteredStateSet = new Set(this.filteredStates); + const filteredDistrictSet = new Set(this.filteredDistricts); + const filteredPartnerTypeSet = new Set(this.filteredPartnerTypes); + + this.userData = this.userData.filter(user => { + + if (this.shouldHaveImplementationData) { + const hasImplementationData = (user.surveyCtoData.hiiData && user.surveyCtoData.hiiData.length > 0) || (user.surveyCtoData.spData && user.surveyCtoData.spData.length > 0) || (user.surveyCtoData.spSchemeData && user.surveyCtoData.spSchemeData.length > 0) - }); - } - if (this.searchText) { - this.userData = this.userData.filter(user => { - return user.organizationBasicInfo.name && user.organizationBasicInfo.name.toLowerCase().trim().includes(this.searchText.toLowerCase().trim()); - }) - } + if (!hasImplementationData) { + return false; + } + } + + if (filteredCommunitySet.size > 0) { + const communitiesForUser = user.detailedProfile.communities.map(community => community.name); + const hasCommunities = communitiesForUser.some(community => filteredCommunitySet.has(community)); + + if (!hasCommunities) { + return false; + } + } + + if (filteredCountrySet.size > 0) { + const countriesForUser = user.detailedProfile.branchLocationCountries.map(country => country.name).concat(user.detailedProfile.partnerLocation); + const hasCountries = countriesForUser.some(country => filteredCountrySet.has(country)); + + if (!hasCountries) { + return false; + } + } + + if (filteredStateSet.size > 0) { + const statesForUser = user.detailedProfile.states.map(state => state.name).concat(user.detailedProfile.state); + const hasStates = statesForUser.some(state => filteredStateSet.has(state)); + + if (!hasStates) { + return false; + } + } + + if (filteredDistrictSet.size > 0) { + const districtsForUser = user.detailedProfile.districts.map(district => district.name).concat(user.detailedProfile.district); + const hasDistricts = districtsForUser.some(district => filteredDistrictSet.has(district)); + + if (!hasDistricts) { + return false; + } + } + + if (filteredPartnerTypeSet.size > 0) { + const partnerTypeOfUser = PARTNER_MAPPING.find(mapping => mapping.portalId === user.portalId)?.type; + const hasPartnerType = partnerTypeOfUser && filteredPartnerTypeSet.has(partnerTypeOfUser); + + if (!hasPartnerType) { + return false; + } + } + + + if (this.searchText) { + const hasSearchText = (!!user.organizationBasicInfo.name && user.organizationBasicInfo.name.toLowerCase().trim().includes(searchText)); + + if (!hasSearchText) { + return false; + } + } + + return true; + }); this.partialLoad(this.userData.slice(0, 100)) - console.log(this.userData); }, (e) => console.log(e)); } - partialLoad(data: Array) { + partialLoad(data: Array) { this.tempUserData = data; - console.log(this.tempUserData); } loadMore() { @@ -174,9 +256,9 @@ export class TableComponent implements OnInit { "SP Name": spData.name, "SP Status": spData.status, 'SP Reason Name': spData.reasonName, - "SP Female Number" : spData.femaleNo ? spData.femaleNo : '' , - "SP Male Number" : spData.maleNo ? spData.maleNo : '', - "Tg Number" : spData.tgNo ? spData.tgNo : '', + "SP Female Number": spData.femaleNo ? spData.femaleNo : '', + "SP Male Number": spData.maleNo ? spData.maleNo : '', + "Tg Number": spData.tgNo ? spData.tgNo : '', "SP TotalAggregation": spData.totalAggregation, "SP OtherRemarks": spData.otherRemarks, "SP RelevantDocuments": spData.relevantDocuments, diff --git a/src/app/services/partner-profile.service.ts b/src/app/services/partner-profile.service.ts index c6b84ce..0da2556 100644 --- a/src/app/services/partner-profile.service.ts +++ b/src/app/services/partner-profile.service.ts @@ -17,7 +17,7 @@ export class PartnerProfileService { ) { } async getPartnersData() { - return lastValueFrom(this.http.get(BASE_URL + '/user-data/?token=' + localStorage.getItem('token'))); + return lastValueFrom(this.http.get>(BASE_URL + '/user-data/?token=' + localStorage.getItem('token'))); } async updatePartnerData(userData: UserData) { diff --git a/src/shared b/src/shared index 98e1875..6e14e2b 160000 --- a/src/shared +++ b/src/shared @@ -1 +1 @@ -Subproject commit 98e1875b53e2b1612bd350141f86bf38866a5221 +Subproject commit 6e14e2b89a7d2191840dc6a74d1322288e75af30