Skip to content

Commit a4d0bf6

Browse files
committed
feat(messagelist): Implement paging and improve styling for nativemessagelist
1 parent aa6266d commit a4d0bf6

File tree

2 files changed

+59
-26
lines changed

2 files changed

+59
-26
lines changed

src/app/messagelist/nativemessagelist.component.html

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
1-
<style>
2-
.messageButton {
3-
text-align: left;
4-
width: 100%;
5-
}
6-
7-
.firstRow {
8-
display: flex;
9-
justify-content: space-between;
10-
}
11-
</style>
12-
<div>
1+
<div id="nativemessagelist">
2+
<div *ngIf="rowsDisplayed < rowCount">
3+
Showing messages {{ offset + 1 }}..{{ upto }} out of {{ rowCount }}
4+
</div>
5+
<button mat-stroked-button class="pagingButton" *ngIf="offset > 0" (click)="scrollUp()">
6+
Show previous {{ rowsDisplayed }} messages
7+
</button>
138
<button mat-stroked-button
149
*ngFor="let row of shownRows; index as i"
15-
[ngClass]="{ 'messageButton': true, 'selectedFolder': rows.openedRowIndex == i }"
16-
(click)="openMessage(i)"
10+
[ngClass]="{ 'messageButton': true, 'selectedFolder': rows.openedRowIndex == row.rowid }"
11+
(click)="openMessage(row.rowid)"
1712
>
1813
<div class="firstRow">
1914
<div>
20-
{{ row[columnsByName["From"]] }}
15+
{{ row.from }}
2116
</div>
2217
<div>
23-
{{ row[columnsByName["Date"]] }}
18+
{{ row.date }}
2419
</div>
2520
</div>
26-
<strong> {{ row[columnsByName["Subject"]] }} </strong>
21+
<div class="subjectRow">
22+
<div class="subject"> {{ row.subject }} </div>
23+
<div *ngIf="row.unread"> <em>UNREAD</em> </div>
24+
</div>
25+
</button>
26+
<button mat-stroked-button class="pagingButton" *ngIf="remaining > 0" (click)="scrollDown()">
27+
Show next {{ rowsDisplayed }} messages
2728
</button>
2829
</div>
2930
<!--

src/app/messagelist/nativemessagelist.ts

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,18 @@ import { AppComponent } from '../app.component';
2525
import { Subject } from 'rxjs';
2626
import { CanvasTableColumn } from '../canvastable/canvastablecolumn';
2727

28+
interface Message {
29+
rowid: number;
30+
from: string;
31+
date: string;
32+
subject: string;
33+
unread: boolean;
34+
}
35+
2836
@Component({
2937
selector: 'app-nativemessagelist',
3038
templateUrl: 'nativemessagelist.component.html',
39+
styleUrls: ['nativemessagelist.component.scss'],
3140
})
3241
export class NativeMessageListComponent implements MessageListComponent {
3342
sortColumn = 2;
@@ -38,7 +47,13 @@ export class NativeMessageListComponent implements MessageListComponent {
3847
visibleRowsChanged: Subject<number[]> = new Subject();
3948
rowSelected: EventEmitter<RowSelection> = new EventEmitter();
4049
rows: MessageDisplay;
41-
shownRows: any[] = [];
50+
shownRows: Message[] = [];
51+
52+
offset = 0;
53+
rowsDisplayed = 10;
54+
upto: number;
55+
rowCount: number;
56+
remaining: number;
4257

4358
columns: CanvasTableColumn[];
4459
columnNames: string[];
@@ -49,20 +64,28 @@ export class NativeMessageListComponent implements MessageListComponent {
4964
return;
5065
}
5166
this.shownRows = [];
52-
let limit = 25;
53-
if (this.rows.rowCount() < 25) {
54-
limit = this.rows.rowCount();
67+
this.upto = this.offset + this.rowsDisplayed;
68+
this.rowCount = this.rows.rowCount();
69+
if (this.rowCount < this.upto) {
70+
this.upto = this.rowCount;
5571
}
56-
for (let i = 0; i < limit; i++) {
72+
for (let i = this.offset; i < this.upto; i++) {
5773
const row = this.columns.map(c => {
5874
let value = c.getValue(i);
5975
if (c.getFormattedValue) {
6076
value = c.getFormattedValue(value);
6177
}
6278
return value;
6379
});
64-
this.shownRows.push(row);
80+
this.shownRows.push({
81+
rowid: i,
82+
from: row[this.columnsByName['From']],
83+
subject: row[this.columnsByName['Subject']],
84+
date: row[this.columnsByName['Date']],
85+
unread: this.rows.getRowSeen(i),
86+
});
6587
}
88+
this.remaining = this.rowCount - this.upto;
6689
}
6790

6891
resetColumns(app: AppComponent): void {
@@ -89,7 +112,16 @@ export class NativeMessageListComponent implements MessageListComponent {
89112
});
90113
}
91114

92-
scrollDown(): void {}
93-
scrollUp(): void {}
94-
scrollTop(): void {}
115+
scrollDown(): void {
116+
this.offset += this.rowsDisplayed;
117+
this.detectChanges();
118+
}
119+
scrollUp(): void {
120+
this.offset -= this.rowsDisplayed;
121+
this.detectChanges();
122+
}
123+
scrollTop(): void {
124+
this.offset = 0;
125+
this.detectChanges();
126+
}
95127
}

0 commit comments

Comments
 (0)