1
0
mirror of https://github.com/ohwgiles/laminar.git synced 2026-11-02 08:34:44 +00:00

resolves #38: implement pagination for the job page

This commit is contained in:
Oliver Giles
2018-06-01 14:51:34 +03:00
parent d1ca6392a4
commit a0f586581d
5 changed files with 41 additions and 9 deletions

View File

@@ -195,9 +195,10 @@ void Laminar::sendStatus(LaminarClient* client) {
populateArtifacts(j, client->scope.job, client->scope.num);
j.EndArray();
} else if(client->scope.type == MonitorScope::JOB) {
const uint runsPerPage = 10;
j.startArray("recent");
db->stmt("SELECT number,startedAt,completedAt,result,reason FROM builds WHERE name = ? ORDER BY completedAt DESC LIMIT 25")
.bind(client->scope.job)
db->stmt("SELECT number,startedAt,completedAt,result,reason FROM builds WHERE name = ? ORDER BY completedAt DESC LIMIT ?,?")
.bind(client->scope.job, client->scope.page * runsPerPage, runsPerPage)
.fetch<uint,time_t,time_t,int,str>([&](uint build,time_t started,time_t completed,int result,str reason){
j.StartObject();
j.set("number", build)
@@ -208,6 +209,11 @@ void Laminar::sendStatus(LaminarClient* client) {
.EndObject();
});
j.EndArray();
db->stmt("SELECT COUNT(*) FROM builds WHERE name = ?")
.bind(client->scope.job)
.fetch<uint>([&](uint nRuns){
j.set("pages", (nRuns-1) / runsPerPage + 1);
});
j.startArray("running");
auto p = activeJobs.byJobName().equal_range(client->scope.job);
for(auto it = p.first; it != p.second; ++it) {