Skip to content

Commit 0455b4a

Browse files
authored
Merge pull request #104 from hackclub/review-refinement
Review refinement
2 parents 9d949fe + f887443 commit 0455b4a

File tree

6 files changed

+141
-58
lines changed

6 files changed

+141
-58
lines changed

src/routes/dashboard/admin/print/+page.server.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { db } from '$lib/server/db/index.js';
2-
import { project, user, devlog } from '$lib/server/db/schema.js';
2+
import { project, user, devlog, legionReview } from '$lib/server/db/schema.js';
33
import { error } from '@sveltejs/kit';
4-
import { eq, and, sql, ne, inArray } from 'drizzle-orm';
4+
import { eq, and, sql, ne, inArray, desc, gt } from 'drizzle-orm';
55
import type { Actions } from './$types';
66
import { getCurrentlyPrinting } from './utils.server';
77

@@ -31,13 +31,34 @@ export async function load({ locals }) {
3131
.from(user)
3232
.where(and(ne(user.trust, 'red'), ne(user.hackatimeTrust, 'red'))); // hide banned users
3333

34+
const legionAgg = db
35+
.$with('legionAgg')
36+
.as(
37+
db
38+
.select({ userId: legionReview.userId, legionCnt: sql<number>`COUNT(*)`.as('legionCnt') })
39+
.from(legionReview)
40+
.where(eq(legionReview.action, 'print'))
41+
.groupBy(legionReview.userId)
42+
);
43+
44+
const totalExpr = sql<number>`COALESCE(${legionAgg.legionCnt}, 0)`;
45+
46+
const leaderboard = await db
47+
.with(legionAgg)
48+
.select({ id: user.id, name: user.name, review_count: totalExpr })
49+
.from(user)
50+
.leftJoin(legionAgg, eq(legionAgg.userId, user.id))
51+
.where(and(ne(user.trust, 'red'), ne(user.hackatimeTrust, 'red'), gt(totalExpr, 0)))
52+
.orderBy(desc(totalExpr));
53+
3454
const currentlyPrinting = await getCurrentlyPrinting(locals.user);
3555

3656
return {
3757
allProjects,
3858
projects,
3959
users,
40-
currentlyPrinting
60+
currentlyPrinting,
61+
leaderboard
4162
};
4263
}
4364

src/routes/dashboard/admin/print/+page.svelte

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -123,22 +123,29 @@
123123
</div>
124124
<div class="themed-box grow p-3 lg:min-w-[30%]">
125125
<h2 class="text-xl font-bold">Leaderboard</h2>
126-
<div class="w-full overflow-scroll">
127-
Coming soon!
128-
<!-- <table class="w-full">
129-
<thead>
130-
<tr>
131-
<th align="left">a</th>
132-
<th align="right">a</th>
133-
</tr>
134-
</thead>
135-
<tbody>
136-
<tr>
137-
<td align="left">a</td>
138-
<td align="right">a</td>
139-
</tr>
140-
</tbody>
141-
</table> -->
126+
<div class="w-full overflow-x-auto">
127+
{#if data.leaderboard?.length > 0}
128+
<table class="w-full text-sm">
129+
<thead>
130+
<tr class="text-primary-300">
131+
<th class="py-1" align="left">Printer</th>
132+
<th class="py-1" align="right">Number of prints</th>
133+
</tr>
134+
</thead>
135+
<tbody>
136+
{#each data.leaderboard as row}
137+
<tr>
138+
<td class="py-1" align="left">
139+
<a class="underline" href={`/dashboard/users/${row.id}`}>{row.name}</a>
140+
</td>
141+
<td class="py-1" align="right">{row.review_count}</td>
142+
</tr>
143+
{/each}
144+
</tbody>
145+
</table>
146+
{:else}
147+
<p class="text-sm text-primary-300">No printing actions yet.</p>
148+
{/if}
142149
</div>
143150
</div>
144151
</div>

src/routes/dashboard/admin/review/+page.server.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { db } from '$lib/server/db/index.js';
2-
import { project, user, devlog } from '$lib/server/db/schema.js';
2+
import { project, user, devlog, t1Review } from '$lib/server/db/schema.js';
33
import { error } from '@sveltejs/kit';
4-
import { eq, and, sql, ne, inArray } from 'drizzle-orm';
4+
import { eq, and, sql, ne, inArray, desc, gt } from 'drizzle-orm';
55
import type { Actions } from './$types';
66

77
export async function load({ locals }) {
@@ -30,10 +30,31 @@ export async function load({ locals }) {
3030
.from(user)
3131
.where(and(ne(user.trust, 'red'), ne(user.hackatimeTrust, 'red'))); // hide banned users
3232

33+
const t1Agg = db
34+
.$with('t1Agg')
35+
.as(
36+
db
37+
.select({ userId: t1Review.userId, t1Cnt: sql<number>`COUNT(*)`.as('t1Cnt') })
38+
.from(t1Review)
39+
.where(ne(t1Review.action, 'add_comment'))
40+
.groupBy(t1Review.userId)
41+
);
42+
43+
const totalExpr = sql<number>`COALESCE(${t1Agg.t1Cnt}, 0)`;
44+
45+
const leaderboard = await db
46+
.with(t1Agg)
47+
.select({ id: user.id, name: user.name, review_count: totalExpr })
48+
.from(user)
49+
.leftJoin(t1Agg, eq(t1Agg.userId, user.id))
50+
.where(and(ne(user.trust, 'red'), ne(user.hackatimeTrust, 'red'), gt(totalExpr, 0)))
51+
.orderBy(desc(totalExpr));
52+
3353
return {
3454
allProjects,
3555
projects,
36-
users
56+
users,
57+
leaderboard
3758
};
3859
}
3960

src/routes/dashboard/admin/review/+page.svelte

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -111,27 +111,34 @@
111111
</div>
112112
<div class="themed-box grow p-3 lg:min-w-[30%]">
113113
<h2 class="text-xl font-bold">Leaderboard</h2>
114-
<div class="w-full overflow-scroll">
115-
Coming soon!
116-
<!-- <table class="w-full">
117-
<thead>
118-
<tr>
119-
<th align="left">a</th>
120-
<th align="right">a</th>
121-
</tr>
122-
</thead>
123-
<tbody>
124-
<tr>
125-
<td align="left">a</td>
126-
<td align="right">a</td>
127-
</tr>
128-
</tbody>
129-
</table> -->
114+
<div class="w-full overflow-x-auto">
115+
{#if data.leaderboard?.length > 0}
116+
<table class="w-full text-sm">
117+
<thead>
118+
<tr class="text-primary-300">
119+
<th class="py-1" align="left">Reviewer</th>
120+
<th class="py-1" align="right">Reviews</th>
121+
</tr>
122+
</thead>
123+
<tbody>
124+
{#each data.leaderboard as row}
125+
<tr>
126+
<td class="py-1" align="left">
127+
<a class="underline" href={`/dashboard/users/${row.id}`}>{row.name}</a>
128+
</td>
129+
<td class="py-1" align="right">{row.review_count}</td>
130+
</tr>
131+
{/each}
132+
</tbody>
133+
</table>
134+
{:else}
135+
<p class="text-sm text-primary-300">No reviews yet.</p>
136+
{/if}
130137
</div>
131138
</div>
132139
</div>
133140

134-
<h2 class="mt-4 mb-2 text-2xl font-bold">Projects</h2>
141+
<h2 class="mt-4 mb-2 text-2xl font-bold">Projects <span class="ml-2 align-middle text-sm font-normal">({projects.length})</span></h2>
135142

136143
{#if projects.length == 0}
137144
<div class="flex grow items-center justify-center">

src/routes/dashboard/admin/ysws-review/+page.server.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { db } from '$lib/server/db/index.js';
2-
import { project, user, devlog } from '$lib/server/db/schema.js';
2+
import { project, user, devlog, t2Review } from '$lib/server/db/schema.js';
33
import { error } from '@sveltejs/kit';
4-
import { eq, and, sql, ne, inArray } from 'drizzle-orm';
4+
import { eq, and, sql, ne, inArray, desc, gt } from 'drizzle-orm';
55
import type { Actions } from './$types';
66

77
export async function load({ locals }) {
@@ -30,10 +30,30 @@ export async function load({ locals }) {
3030
.from(user)
3131
.where(and(ne(user.trust, 'red'), ne(user.hackatimeTrust, 'red'))); // hide banned users
3232

33+
const t2Agg = db
34+
.$with('t2Agg')
35+
.as(
36+
db
37+
.select({ userId: t2Review.userId, t2Cnt: sql<number>`COUNT(*)`.as('t2Cnt') })
38+
.from(t2Review)
39+
.groupBy(t2Review.userId)
40+
);
41+
42+
const totalExpr = sql<number>`COALESCE(${t2Agg.t2Cnt}, 0)`;
43+
44+
const leaderboard = await db
45+
.with(t2Agg)
46+
.select({ id: user.id, name: user.name, review_count: totalExpr })
47+
.from(user)
48+
.leftJoin(t2Agg, eq(t2Agg.userId, user.id))
49+
.where(and(ne(user.trust, 'red'), ne(user.hackatimeTrust, 'red'), gt(totalExpr, 0)))
50+
.orderBy(desc(totalExpr));
51+
3352
return {
3453
allProjects,
3554
projects,
36-
users
55+
users,
56+
leaderboard
3757
};
3858
}
3959

src/routes/dashboard/admin/ysws-review/+page.svelte

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -111,22 +111,29 @@
111111
</div>
112112
<div class="themed-box grow p-3 lg:min-w-[30%]">
113113
<h2 class="text-xl font-bold">Leaderboard</h2>
114-
<div class="w-full overflow-scroll">
115-
Coming soon!
116-
<!-- <table class="w-full">
117-
<thead>
118-
<tr>
119-
<th align="left">a</th>
120-
<th align="right">a</th>
121-
</tr>
122-
</thead>
123-
<tbody>
124-
<tr>
125-
<td align="left">a</td>
126-
<td align="right">a</td>
127-
</tr>
128-
</tbody>
129-
</table> -->
114+
<div class="w-full overflow-x-auto">
115+
{#if data.leaderboard?.length > 0}
116+
<table class="w-full text-sm">
117+
<thead>
118+
<tr class="text-primary-300">
119+
<th class="py-1" align="left">Reviewer</th>
120+
<th class="py-1" align="right">Reviews</th>
121+
</tr>
122+
</thead>
123+
<tbody>
124+
{#each data.leaderboard as row}
125+
<tr>
126+
<td class="py-1" align="left">
127+
<a class="underline" href={`../users/${row.id}`}>{row.name}</a>
128+
</td>
129+
<td class="py-1" align="right">{row.review_count}</td>
130+
</tr>
131+
{/each}
132+
</tbody>
133+
</table>
134+
{:else}
135+
<p class="text-sm text-primary-300">No reviews yet.</p>
136+
{/if}
130137
</div>
131138
</div>
132139
</div>

0 commit comments

Comments
 (0)