Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export only displayed data #2059

Merged
merged 13 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ export interface TableRow<T extends Entity> {
})
export class EntitySubrecordComponent<T extends Entity> implements OnChanges {
@Input() isLoading: boolean;

@Input() clickMode: "popup" | "navigate" | "none" = "popup";

@Input() showInactive = false;
Expand All @@ -115,6 +114,9 @@ export class EntitySubrecordComponent<T extends Entity> implements OnChanges {
/** data to be displayed, can also be used as two-way-binding */
@Input() records: T[] = [];

/** output the currently displayed records, whenever filters for the user change */
@Output() filteredRecordsChange = new EventEmitter<T[]>();

/**
* factory method to create a new instance of the displayed Entity type
* used when the user adds a new entity to the list.
Expand Down Expand Up @@ -266,6 +268,9 @@ export class EntitySubrecordComponent<T extends Entity> implements OnChanges {
this.sortDefault();
}

this.filteredRecordsChange.emit(
this.recordsDataSource.filteredData.map((item) => item.record),
);
this.listenToEntityUpdates();
}

Expand Down
21 changes: 20 additions & 1 deletion src/app/core/entity-list/entity-list/entity-list.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ <h2>{{ listName }}</h2>
[filter]="filterObj"
[defaultSort]="listConfig?.defaultSort"
[showInactive]="showInactive"
(filteredRecordsChange)="filteredData = $event"
></app-entity-subrecord>
</ng-template>

Expand Down Expand Up @@ -183,7 +184,25 @@ <h2>{{ listName }}</h2>
aria-label="download csv"
icon="download"
></fa-icon>
<span i18n="Download list contents as CSV"> Download CSV </span>
<span i18n="Download list contents as CSV"> Download all data (.csv) </span>
</button>

<button
mat-menu-item
[appExportData]="filteredData"
format="csv"
[exportConfig]="listConfig?.exportConfig"
[filename]="listName.replace(' ', '')"
angulartics2On="click"
[angularticsCategory]="entityConstructor?.ENTITY_TYPE"
angularticsAction="list_csv_export"
>
<fa-icon
class="color-accent standard-icon-with-text"
aria-label="download csv"
icon="download"
></fa-icon>
<span i18n="Download list contents as CSV"> Download current (.csv) </span>
</button>

<button
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
AfterViewInit,
ChangeDetectionStrategy,
Component,
EventEmitter,
Input,
Expand Down Expand Up @@ -55,6 +56,7 @@ import { DisableEntityOperationDirective } from "../../permissions/permission-di
*/
@RouteTarget("EntityList")
@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
selector: "app-entity-list",
templateUrl: "./entity-list.component.html",
styleUrls: ["./entity-list.component.scss"],
Expand Down Expand Up @@ -114,6 +116,7 @@ export class EntityListComponent<T extends Entity>

filterObj: DataFilter<T>;
filterString = "";
filteredData = [];

get selectedColumnGroupIndex(): number {
return this.selectedColumnGroupIndex_;
Expand Down Expand Up @@ -259,10 +262,13 @@ export class EntityListComponent<T extends Entity>
}

applyFilter(filterValue: string) {
// TODO: turn this into one of our filter types, so that all filtering happens the same way (and we avoid accessing internal datasource of sub-component here)
filterValue = filterValue.trim();
filterValue = filterValue.toLowerCase(); // MatTableDataSource defaults to lowercase matches
this.entityTable.recordsDataSource.filter = filterValue;

this.filteredData = this.entityTable.recordsDataSource.filteredData.map(
(x) => x.record,
);
this.analyticsService.eventTrack("list_filter_freetext", {
category: this.entityConstructor?.ENTITY_TYPE,
});
Expand Down
Loading