Skip to content

Commit bbe3e50

Browse files
authored
Merge pull request #5645 from mohamalnadi/boac-6370
BOAC-6370 - Peer Notes - add topic total count to PAM dashboard
2 parents a65fe40 + 63e1fb6 commit bbe3e50

5 files changed

Lines changed: 105 additions & 0 deletions

File tree

boac/api/peer_advising_reports_controller.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
get_peer_advising_note_author_count,
3939
get_peer_advising_note_count_since,
4040
get_peer_advising_note_template_usage,
41+
get_peer_advising_note_topic_usage,
4142
get_total_peer_advising_notes,
4243
)
4344
from boac.models.peer_advising_department import PeerAdvisingDepartment
@@ -98,6 +99,7 @@ def peer_advising_notes_report(peer_advising_department_id):
9899
},
99100
'distinctPeerAdvisorAuthors': get_peer_advising_note_author_count(peer_advising_department.id),
100101
'noteTemplates': get_peer_advising_note_template_usage(peer_advising_department.id),
102+
'noteTopics': get_peer_advising_note_topic_usage(peer_advising_department.id),
101103
'peerAdvisingDepartment': peer_advising_department.to_api_json(),
102104
'totalPeerAdvisingNoteCount': get_total_peer_advising_notes(peer_advising_department.id),
103105
})

boac/merged/peer_advising_notes_reports.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,36 @@ def _to_api_json(row):
236236
return [_to_api_json(row) for row in db.session.execute(text(sql), params).mappings()]
237237

238238

239+
def get_peer_advising_note_topic_usage(peer_advising_department_id):
240+
sql = """
241+
SELECT
242+
pat.id AS id,
243+
pat.topic AS topic,
244+
COALESCE(COUNT(n.id), 0) AS usage_count
245+
FROM peer_advising_topics pat
246+
LEFT JOIN note_topics nt
247+
ON nt.topic = pat.topic
248+
AND nt.deleted_at IS NULL
249+
LEFT JOIN notes n
250+
ON n.id = nt.note_id
251+
AND n.deleted_at IS NULL
252+
AND n.parent_note_id IS NULL
253+
AND n.peer_advising_department_id = :peer_advising_department_id
254+
WHERE pat.deleted_at IS NULL
255+
GROUP BY pat.id, pat.topic
256+
ORDER BY usage_count DESC, pat.topic
257+
"""
258+
259+
def _to_api_json(row):
260+
return {
261+
'id': row['id'],
262+
'topic': row['topic'],
263+
'usageCount': row['usage_count'],
264+
}
265+
266+
params = {'peer_advising_department_id': peer_advising_department_id}
267+
return [_to_api_json(row) for row in db.session.execute(text(sql), params).mappings()]
268+
239269

240270
def get_total_peer_advising_notes(peer_advising_department_id=None):
241271
params = {}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<template>
2+
<div>
3+
<h3 class="font-size-16">Topics Used</h3>
4+
<div v-if="noteTopics.length">
5+
<table class="mt-2 w-100">
6+
<thead class="sr-only">
7+
<tr>
8+
<th>Note Topic</th>
9+
<th>Note Topic Usage Count</th>
10+
</tr>
11+
</thead>
12+
<tbody>
13+
<tr
14+
v-for="(noteTopic, index) in noteTopics"
15+
:id="`tr-note-topic-${noteTopic.id}`"
16+
:key="noteTopic.id"
17+
:class="{
18+
'bg-surface-light': index % 2 !== 0,
19+
'border-t-md': index === 0
20+
}"
21+
>
22+
<td :class="{'pt-2': index === 0}" class="pl-3">
23+
<span :id="`peer-advising-note-topic-${noteTopic.id}-title`">{{ noteTopic.topic }}</span>
24+
</td>
25+
<td class="font-weight-550 pr-3 text-right">
26+
<span :id="`peer-advising-note-topic-${noteTopic.id}-usage-count`">{{ numFormat(noteTopic.usageCount) }}</span>
27+
</td>
28+
</tr>
29+
</tbody>
30+
</table>
31+
</div>
32+
<div v-if="!noteTopics.length" class="pa-3 text-medium-emphasis">
33+
No peer advising topics are configured.
34+
</div>
35+
</div>
36+
</template>
37+
38+
<script setup lang="ts">
39+
import {get} from 'lodash'
40+
import type {PropType} from 'vue'
41+
import {numFormat} from '@/lib/utils'
42+
import type {PeerAdvisingManagerReport} from '@/lib/types-peer-advising'
43+
44+
const props = defineProps({
45+
notesReport: {
46+
required: true,
47+
type: Object as PropType<PeerAdvisingManagerReport>
48+
}
49+
})
50+
51+
const noteTopics = get(props.notesReport, 'noteTopics', [])
52+
</script>
53+
54+
<style scoped>
55+
table {
56+
border-collapse: collapse;
57+
}
58+
td {
59+
padding: 4px 0 4px 0;
60+
}
61+
td:first-child {
62+
padding-left: 8px;
63+
}
64+
</style>

src/components/peer/reports/PeerAdvisorManagerReports.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
<div v-if="notesReport" class="mt-8 pr-2">
3636
<PeerAdvisingTemplatesUsed :notes-report="notesReport" />
3737
</div>
38+
<div v-if="notesReport" class="mt-8 pr-2">
39+
<PeerAdvisingTopicsUsed :notes-report="notesReport" />
40+
</div>
3841
</v-col>
3942
<v-col class="pl-7" cols="12" md="6">
4043
<div v-if="notesReport">
@@ -67,6 +70,7 @@ import type {PeerAdvisingManagerReport} from '@/lib/types-peer-advising'
6770
import PeerAdvisingCurrentMonthReport from '@/components/peer/reports/PeerAdvisingCurrentMonthReport.vue'
6871
import PeerAdvisingHistoricalReport from '@/components/peer/reports/PeerAdvisingHistoricalReport.vue'
6972
import PeerAdvisingTemplatesUsed from '@/components/peer/reports/PeerAdvisingTemplatesUsed.vue'
73+
import PeerAdvisingTopicsUsed from '@/components/peer/reports/PeerAdvisingTopicsUsed.vue'
7074
import {downloadPeerAdvisingNotes, getPeerAdvisingNotesReport} from '@/api/peer-advising-reports'
7175
7276
const props = defineProps({

src/lib/types-peer-advising.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ export type PeerAdvisingManagerReport = {
2424
title: string,
2525
usageCount: number
2626
}[],
27+
noteTopics: {
28+
id: number,
29+
topic: string,
30+
usageCount: number
31+
}[],
2732
peerAdvisingDepartment: PeerAdvisingDepartment,
2833
totalPeerAdvisingNoteCount: number
2934
}

0 commit comments

Comments
 (0)