Skip to content

Commit

Permalink
Merge pull request #306 from pandutibil/development
Browse files Browse the repository at this point in the history
Dependency removed from the filters, no they'll be individual
  • Loading branch information
tibil-it authored Aug 1, 2022
2 parents ce0716e + 85eee0b commit 078d78d
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 51 deletions.
84 changes: 52 additions & 32 deletions development/ui/back-end/controller/common/CommonController.js
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,11 @@ async function getMultiBarChartData(reqBody, reportConfig, rawData) {
return;
}

if (col.key) {
data[col.name] = record[col.property];
return;
}

if (col.tooltipDesc) {
data[col.name] = col.tooltipDesc + ' ' + record[col.property];
return;
Expand Down Expand Up @@ -1150,6 +1155,13 @@ async function getBarChartData(reqBody, reportConfig, rawData) {
}

function compare(a, b, sortDirection) {
if (a && typeof a === 'string') {
return a.localeCompare(b, undefined, {
numeric: true,
sensitivity: 'base'
});
}

return (a < b ? -1 : 1) * (sortDirection === 'asc' ? 1 : -1);
}

Expand Down Expand Up @@ -1186,25 +1198,23 @@ async function convertRawDataToJSONAndUploadToS3(fileContent, filePath) {

function applyFilters(filters, rawData, groupByColumn, level = undefined) {
filters.map((filter, index) => {
let filterOptionMap = new Map();
let filterProperty = filter.optionValueColumn ? filter.optionValueColumn : filter.column;

if (index === 0 || filters[index - 1].includeAll || filters[index - 1].defaultValue || (filters[index - 1].value && filters[index - 1].value !== '')) {
if (filter.options.length === 0) {
filter.options = [];
rawData.forEach(record => {
if (!filterOptionMap.has(record[filterProperty])) {
filter.options.push({
label: record[filter.column],
value: record[filterProperty]
});

filterOptionMap.set(record[filterProperty], true);
}
});
}
if (filter && filter.options.length === 0) {
let filterOptionMap = new Map();
let filterProperty = filter.optionValueColumn ? filter.optionValueColumn : filter.column;

filter.options = [];
rawData.forEach(record => {
if (!filterOptionMap.has(record[filterProperty])) {
filter.options.push({
label: record[filter.column],
value: record[filterProperty]
});

if (filter && filter.value === null) {
filterOptionMap.set(record[filterProperty], true);
}
});

if (filter.value === null) {
if (filter.options.length > 1) {
filter.options.sort((a, b) => compare(a.label, b.label, 'asc'));
}
Expand All @@ -1221,27 +1231,37 @@ function applyFilters(filters, rawData, groupByColumn, level = undefined) {

filter.value = 'overall';
}
}

if (filter && filter.value !== null) {
let filterProperty = filter.optionValueColumn ? filter.optionValueColumn : filter.column;

if (filter.value && filter.value !== '' && filter.value !== 'overall') {
rawData = rawData.filter(record => {
return record[filterProperty] === filter.value;
});

if (filter.level) {
groupByColumn = filter.level.property;
level = filter.level.value;
}
}
} else if (filter && filter.options.length > 0) {
if (filter.value === null) {
if (filter.defaultValue && filter.options.length > 0) {
filter.value = filter.options[0].value;
}

if (filter.includeAll) {
filter.value = 'overall';
}
}
}

return filter;
});

filters.forEach((filter, index) => {
if (filter && filter.value && filter.value !== null && filter.value !== '' && filter.value !== 'overall') {
let filterProperty = filter.optionValueColumn ? filter.optionValueColumn : filter.column;

rawData = rawData.filter(record => {
return record[filterProperty] === filter.value;
});

if (filter.level) {
groupByColumn = filter.level.property;
level = filter.level.value;
}
}
});

return {
filters,
rawData,
Expand Down
3 changes: 2 additions & 1 deletion development/ui/back-end/core/config/nvsk/nishtha_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ const dataSourceInfo = {
columns: [
{
name: "Location",
key: true
property: "State Name",
isLocationName: true
},
{
name: "Total Enrollments",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
<div class="wrapper" *ngIf="filters && filters.length > 0">
<div class="grid grid-cols-12 filter-panel-wrapper">
<ng-container *ngFor="let filter of filters; let i = index">
<div class="filter-wrapper" [ngClass]="colSize">
<ng-select class="mx-2" dropdownPosition="bottom" placeholder="Select {{filter.name}}" [clearable]="resetOthers" [(ngModel)]="filter.value" (change)="onSelectOption($event, i)">
<!-- <ng-option disabled="true">Select {{filter.name}}</ng-option> -->
<ng-option *ngFor="let option of filter.options" [value]="option.value">{{ option.label }}</ng-option>
</ng-select>
<div class="grid grid-cols-12 filter-panel-wrapper align-items-center">
<div class="col-span-full xmd:col-span-full">
<div class="grid grid-cols-12">
<ng-container *ngFor="let filter of filters; let i = index">
<div class="filter-wrapper" [ngClass]="colSize">
<ng-select class="mx-2" dropdownPosition="bottom" placeholder="Select {{filter.name}}" [clearable]="resetOthers" [(ngModel)]="filter.value" (change)="onSelectOption($event, i)">
<!-- <ng-option disabled="true">Select {{filter.name}}</ng-option> -->
<ng-option *ngFor="let option of filter.options" [value]="option.value">{{ option.label }}</ng-option>
</ng-select>
</div>
</ng-container>
</div>
</ng-container>
</div>
<!-- <div class="col-span-full xmd:col-span-2 text-right ">
<button mat-raised-button color="primary" (click)="clearFilters()">Clear Filters</button>
</div> -->
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,25 @@ export class FilterPanelComponent implements OnInit, OnChanges {
}

onSelectOption(event: any, ind: number): void {
if (this.resetOthers) {
this.filters = this.filters.map((filter: any, filterInd: number) => {
if (filterInd > ind) {
filter.options = [];
filter.value = null;
}

return filter;
});
}
// if (this.resetOthers) {
// this.filters = this.filters.map((filter: any, filterInd: number) => {
// if (filterInd > ind) {
// filter.options = [];
// filter.value = null;
// }

// return filter;
// });
// }

this.filtersUpdated.emit(this.filters);
}

clearFilters(): void {
this.filters = this.filters.map((filter: any) => {
filter.value = null;
return filter;
});

this.filtersUpdated.emit(this.filters);
}
Expand Down

0 comments on commit 078d78d

Please sign in to comment.