Skip to content

Commit

Permalink
fix: ensure we display enough test suites
Browse files Browse the repository at this point in the history
  • Loading branch information
lynzrand committed Nov 29, 2021
1 parent 86f746c commit 9e6f6dd
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
9 changes: 7 additions & 2 deletions web/src/services/api_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,14 @@ export class ApiService {
};

dashboard = {
get: () => {
get: (limit: number = 10, startId?: string) => {
let params: any = { limit };
if (startId) {
params.startId = startId;
}
return this.httpClient.get<DashboardItem[]>(
endpointBase + endpoints.dashboard.get
endpointBase + endpoints.dashboard.get,
{ params }
);
},
};
Expand Down
3 changes: 2 additions & 1 deletion web/src/views/admin/dashboard/dashboard.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export class DashboardComponent implements OnInit {
}

fetchTestSuites() {
this.api.testSuite.query({ take: 20 }).subscribe({
// TODO: add LoadMore button. We just make this value large enough for now.
this.api.testSuite.query({ take: 100 }).subscribe({
next: (v) => (this.suite = v),
});
}
Expand Down
7 changes: 7 additions & 0 deletions web/src/views/default/dash-board/dash-board.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ <h1>作业</h1>
[item]="i"
(click)="gotoJudgeSuite(i.suite.id)"
></app-dashboard-item-component>
<button
class="btn info"
(click)="loadmore()"
*ngIf="!error && !isLoading && hasMore"
>
加载更多
</button>
</ng-template>
</div>
</div>
Expand Down
31 changes: 30 additions & 1 deletion web/src/views/default/dash-board/dash-board.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
NAVBAR_DEFAULT_STYLE,
} from 'src/services/navbar_service';

const DEFAULT_NUM_ITEMS = 20;

@Component({
selector: 'app-dash-board',
templateUrl: './dash-board.component.html',
Expand All @@ -37,6 +39,8 @@ export class DashBoardComponent implements OnInit, OnDestroy {
}
loading = true;
items: DashboardItem[] | undefined = undefined;
itemsCount: number = 0;
hasMore = true;

announcements: Announcement[] | undefined = undefined;

Expand Down Expand Up @@ -64,14 +68,39 @@ export class DashBoardComponent implements OnInit, OnDestroy {

intervalId: any;

loadmore(): void {
this.loading = true;
this.api.dashboard
.get(DEFAULT_NUM_ITEMS, this.items[this.items.length - 1].job.id)
.subscribe({
next: (items) => {
this.items.push(...items);
this.loading = false;
if (items.length < DEFAULT_NUM_ITEMS) this.hasMore = false;
},
error: (e) => {
if (e instanceof HttpErrorResponse) {
this.errorMessage = e.message;
} else {
this.errorMessage = JSON.stringify(e);
}
console.warn(e);
this.error = true;
this.loading = false;
this.hasMore = false;
},
});
}

ngOnInit(): void {
this.title.setTitle('Rurikawa', 'dashboard');
this.error = false;
this.errorMessage = undefined;
this.api.dashboard.get().subscribe({
this.api.dashboard.get(DEFAULT_NUM_ITEMS).subscribe({
next: (items) => {
this.items = items;
this.loading = false;
if (items.length < DEFAULT_NUM_ITEMS) this.hasMore = false;
},
error: (e) => {
if (e instanceof HttpErrorResponse) {
Expand Down

0 comments on commit 9e6f6dd

Please sign in to comment.