Skip to content

Commit 9b43823

Browse files
Add dynamic render title and name info
1 parent 38b8fbf commit 9b43823

File tree

3 files changed

+64
-17
lines changed

3 files changed

+64
-17
lines changed

datasheet.json

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,57 @@
11
{
2-
"CMS001": "Q01TLURhby1UaGFuaC1Mb25nLnBkZg==",
3-
"CMS002": "Q01TLUh1eW5oLVRoaS1OZ29jLUhhbi5wZGY=",
4-
"CMS003": "Q01TLU5nby1UaGFvLU5ndXllbi5wZGY=",
5-
"CMS004": "Q01TLVRyYW4tTWFuLU1hbi5wZGY=",
6-
"CMS005": "Q01TLVZ1LUFuaC1UdWFuLnBkZg==",
7-
"DBS001": "REJTLUhvYW5nLVllbi1OaGkucGRm",
8-
"DBS002": "REJTLUx1b25nLVR1YW4tQW5oLnBkZg==",
9-
"DBS003": "REJTLU5ndXllbi1WYW4tTGluaC5wZGY=",
10-
"DBS004": "REJTLVRyYW4tTWFuLU1hbi5wZGY=",
11-
"DBS005": "REJTLVRyYW4tTmhhdC1QaGkucGRm",
12-
"DBS006": "REJTLVZ1LUFuaC1UdWFuLnBkZg=="
2+
"CMS001": {
3+
"courseTitle": "CMS - Content Management System",
4+
"certifiedName": "Đào Thanh Long",
5+
"certData": "Q01TLURhby1UaGFuaC1Mb25nLnBkZg=="
6+
},
7+
"CMS002": {
8+
"courseTitle": "CMS - Content Management System",
9+
"certifiedName": "Huỳnh Thị Ngọc Hân",
10+
"certData": "Q01TLUh1eW5oLVRoaS1OZ29jLUhhbi5wZGY="
11+
},
12+
"CMS003": {
13+
"courseTitle": "CMS - Content Management System",
14+
"certifiedName": "Ngô Thảo Nguyên",
15+
"certData": "Q01TLU5nby1UaGFvLU5ndXllbi5wZGY="
16+
},
17+
"CMS004": {
18+
"courseTitle": "CMS - Content Management System",
19+
"certifiedName": "Trần Mẫn Mẫn",
20+
"certData": "Q01TLVRyYW4tTWFuLU1hbi5wZGY="
21+
},
22+
"CMS005": {
23+
"courseTitle": "CMS - Content Management System",
24+
"certifiedName": "Vũ Anh Tuấn",
25+
"certData": "Q01TLVZ1LUFuaC1UdWFuLnBkZg=="
26+
},
27+
"DBS001": {
28+
"courseTitle": "DBS - Database System",
29+
"certifiedName": "Hoàng Yến Nhi",
30+
"certData": "REJTLUhvYW5nLVllbi1OaGkucGRm"
31+
},
32+
"DBS002": {
33+
"courseTitle": "DBS - Database System",
34+
"certifiedName": "Lương Tuấn Anh",
35+
"certData": "REJTLUx1b25nLVR1YW4tQW5oLnBkZg=="
36+
},
37+
"DBS003": {
38+
"courseTitle": "DBS - Database System",
39+
"certifiedName": "Nguyễn Văn Linh",
40+
"certData": "REJTLU5ndXllbi1WYW4tTGluaC5wZGY="
41+
},
42+
"DBS004": {
43+
"courseTitle": "DBS - Database System",
44+
"certifiedName": "Trần Mẫn Mẫn",
45+
"certData": "REJTLVRyYW4tTWFuLU1hbi5wZGY="
46+
},
47+
"DBS005": {
48+
"courseTitle": "DBS - Database System",
49+
"certifiedName": "Trần Nhật Phi",
50+
"certData": "REJTLVRyYW4tTmhhdC1QaGkucGRm"
51+
},
52+
"DBS006": {
53+
"courseTitle": "DBS - Database System",
54+
"certifiedName": "Vũ Anh Tuấn",
55+
"certData": "REJTLVZ1LUFuaC1UdWFuLnBkZg=="
56+
}
1357
}

render.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class CertData {
3636
async renderPDF(url) {
3737
// Đặt workerSrc để tránh lỗi "Deprecated API usage"
3838
pdfjsLib.GlobalWorkerOptions.workerSrc = "https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.16.105/pdf.worker.min.js";
39-
39+
4040
const loadingTask = pdfjsLib.getDocument(url);
4141
loadingTask.promise.then(pdf => {
4242
pdf.getPage(1).then(page => {
@@ -70,12 +70,15 @@ class CertData {
7070
async renderData() {
7171
// Check if the ID is valid
7272
if (this.validIds.includes(this.codeId) && this.verifyData()) {
73-
// Extract the image data from the data source file
73+
// Extract the cert data and other info from the data source file
7474
const renderData = this.data[this.codeId];
75+
// Cập nhật thông tin tiêu đề và mô tả chứng chỉ
76+
document.getElementById("courseTitle").textContent = renderData.courseTitle;
77+
document.getElementById("certifiedName").textContent = renderData.certifiedName;
7578
// Get final data string from course and id
76-
const finalData = `${this.course.toUpperCase()}/Certificates/${atob(renderData)}`; // /CMS/Certificates/CMS-Dao-Thanh-Long.pdf
79+
const finalData = `${this.course.toUpperCase()}/Certificates/${atob(renderData.certData)}`; // /<course>/Certificates/<cert-path>.pdf
7780
// Add the data parameter to the URL if it is not already present
78-
const checkData = renderData.slice(-20, -5);
81+
const checkData = renderData.certData.slice(-20, -5); // ?id=<uuid>&data=<encoded>
7982
if (this.urlParams.get('data') != checkData) {
8083
this.urlParams.set("data", checkData)
8184
window.location.search = this.urlParams;

verify.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
</section>
5757
<section class="details">
5858
<h1>Certificate Title</h1>
59-
<p>Student Name</p>
60-
<p>Teacher Comments and Grade</p>
59+
<p id="courseTitle"></p>
60+
<p>Certify for: <span id="certifiedName"></span></p>
6161
</section>
6262
<section class="description">
6363
<h2>Certificate Description</h2>

0 commit comments

Comments
 (0)