Skip to content

Commit

Permalink
simplify the output interface further
Browse files Browse the repository at this point in the history
  • Loading branch information
sleidig committed Nov 6, 2023
1 parent b223d64 commit 96046bc
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
class="full-width table"
>
<ng-container matColumnDef="select">
<th mat-header-cell *matHeaderCellDef>
Select
</th>
<th mat-header-cell *matHeaderCellDef>Select</th>
<td mat-cell *matCellDef="let row">
<mat-checkbox (change)="selectRow(row)"></mat-checkbox>
<mat-checkbox (change)="selectRow(row, $event)"></mat-checkbox>
</td>
</ng-container>

Expand Down Expand Up @@ -136,7 +134,10 @@
</div>
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="columnsToDisplay.concat('select')"></tr>
<tr
mat-header-row
*matHeaderRowDef="columnsToDisplay.concat('select')"
></tr>
<tr
mat-row
*matRowDef="let row; columns: columnsToDisplay.concat('select')"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ import { FontAwesomeModule } from "@fortawesome/angular-fontawesome";
import { DisableEntityOperationDirective } from "../../../permissions/permission-directive/disable-entity-operation.directive";
import { Angulartics2Module } from "angulartics2";
import { ListPaginatorComponent } from "../list-paginator/list-paginator.component";
import { MatCheckboxModule } from '@angular/material/checkbox';
import {
MatCheckboxChange,
MatCheckboxModule,
} from "@angular/material/checkbox";
import { MatSlideToggleModule } from "@angular/material/slide-toggle";

export interface TableRow<T extends Entity> {
Expand Down Expand Up @@ -98,9 +101,10 @@ export class EntitySubrecordComponent<T extends Entity> implements OnChanges {
@Input() isLoading: boolean;

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

/** outputs an event containing an array of currently selected records (checkmarked by the user) */
@Output() selectedRecords: EventEmitter<T[] > = new EventEmitter<T[]>
@Output() selectedRecordsChange: EventEmitter<T[]> = new EventEmitter<T[]>();
selectedRecords: T[] = [];

@Input() showInactive = false;
@Output() showInactiveChange = new EventEmitter<boolean>();
Expand Down Expand Up @@ -485,8 +489,17 @@ export class EntitySubrecordComponent<T extends Entity> implements OnChanges {
return this.screenWidthObserver.currentScreenSize() >= numericValue;
}

selectRow (row: T[]) {
this.selectedRecords.emit(row);
selectRow(row: TableRow<T>, event: MatCheckboxChange) {
if (event.checked) {
this.selectedRecords.push(row.record);
} else {
const index = this.selectedRecords.indexOf(row.record);
if (index > -1) {
this.selectedRecords.splice(index, 1);
}
}

this.selectedRecordsChange.emit(this.selectedRecords);
}

filterActiveInactive() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ <h2>{{ listName }}</h2>
[isLoading]="isLoading"
[filter]="filterObj"
[defaultSort]="listConfig?.defaultSort"
(selectedRecords)="setSelectedRows($event)"
(selectedRecordsChange)="selectedRows = $event"
[showInactive]="showInactive"
></app-entity-subrecord>
</ng-template>
Expand Down Expand Up @@ -202,12 +202,14 @@ <h2>{{ listName }}</h2>
></fa-icon>
<span i18n> Import from file </span>
</button>

<button
mat-menu-item
(click)="duplicateRecords()"
[disabled]="selectedRows.length === 0"
matTooltip="Please select rows" [matTooltipDisabled]="selectedRows.length > 0" i18n-matTooltip
matTooltip="Please select rows"
[matTooltipDisabled]="selectedRows.length > 0"
i18n-matTooltip
>
<fa-icon
class="color-accent standard-icon-with-text"
Expand Down
15 changes: 3 additions & 12 deletions src/app/core/entity-list/entity-list/entity-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class EntityListComponent<T extends Entity>

@Output() elementClick = new EventEmitter<T>();
@Output() addNewClick = new EventEmitter();
@Input() selectedRows : T[] = [];
selectedRows: T[] = [];

@ViewChild(EntitySubrecordComponent) entityTable: EntitySubrecordComponent<T>;

Expand Down Expand Up @@ -152,7 +152,7 @@ export class EntityListComponent<T extends Entity>
private entityMapperService: EntityMapperService,
private entities: EntityRegistry,
private dialog: MatDialog,
private duplicateRecord: DuplicateRecordService,
private duplicateRecord: DuplicateRecordService,
) {
if (this.activatedRoute.component === EntityListComponent) {
// the component is used for a route and not inside a template
Expand Down Expand Up @@ -308,17 +308,8 @@ export class EntityListComponent<T extends Entity>
this.addNewClick.emit();
}

setSelectedRows(data: any) {
const index = this.selectedRows.findIndex((item) => item === data.record);
if (index > -1) {
this.selectedRows.splice(index, 1);
} else {
this.selectedRows.push(data.record);
}
}

duplicateRecords() {
this.duplicateRecord.duplicateRecord(this.selectedRows);
this.selectedRows = [];
this.selectedRows = [];
}
}

0 comments on commit 96046bc

Please sign in to comment.