Add DocumentLink

master
Joshua Herring 3 weeks ago
parent 8e0565293f
commit 06096009f0

@ -13,18 +13,19 @@ type DashboardItem struct {
Title string
Description string
Hyperlink string
DocumentLink string
ItemType string
}
func GetReportedItems(conn *sql.Conn) ([]DashboardItem, error) {
rows, err := conn.QueryContext(context.Background(), `
SELECT s.UID, s.Created, u.LastName, u.FirstName, '' AS Title, s.Citation AS Description, s.Hyperlink, 'Scholarship'
SELECT s.UID, s.Created, u.LastName, u.FirstName, '' AS Title, s.Citation AS Description, s.Hyperlink, s.DocumentLink, 'Scholarship'
FROM scholarship s JOIN users u ON u.Username = s.Username WHERE s.Status = 'reported'
UNION ALL
SELECT a.UID, a.Created, u.LastName, u.FirstName, a.Title, a.Description, a.Hyperlink, 'Activity'
SELECT a.UID, a.Created, u.LastName, u.FirstName, a.Title, a.Description, a.Hyperlink, '' AS DocumentLink, 'Activity'
FROM activities a JOIN users u ON u.Username = a.Username WHERE a.Status = 'reported'
UNION ALL
SELECT ap.UID, ap.Created, u.LastName, u.FirstName, ap.Title, ap.Description, ap.Hyperlink, 'Media Appearance'
SELECT ap.UID, ap.Created, u.LastName, u.FirstName, ap.Title, ap.Description, ap.Hyperlink, '' AS DocumentLink, 'Media Appearance'
FROM appearances ap JOIN users u ON u.Username = ap.Username WHERE ap.Status = 'reported'
ORDER BY Created DESC
`)
@ -36,7 +37,7 @@ func GetReportedItems(conn *sql.Conn) ([]DashboardItem, error) {
var items []DashboardItem
for rows.Next() {
var item DashboardItem
if err := rows.Scan(&item.UID, &item.Created, &item.LastName, &item.FirstName, &item.Title, &item.Description, &item.Hyperlink, &item.ItemType); err != nil {
if err := rows.Scan(&item.UID, &item.Created, &item.LastName, &item.FirstName, &item.Title, &item.Description, &item.Hyperlink, &item.DocumentLink, &item.ItemType); err != nil {
return nil, err
}
items = append(items, item)

@ -13,6 +13,7 @@ CREATE TABLE scholarship (
UID text PRIMARY KEY,
Citation text,
Hyperlink text,
DocumentLink text,
Status text not null CHECK (Status in ('reported','posted')),
Created text,
Modified text,

@ -11,6 +11,7 @@ type Scholarship struct {
UID string `json:"uid"`
Citation string `json:"citation"`
Hyperlink string `json:"hyperlink"`
DocumentLink string `json:"document_link"`
Status string `json:"status"`
Created string `json:"created"`
Modified string `json:"modified"`
@ -25,21 +26,21 @@ func CreateScholarship(conn *sql.Conn, s *Scholarship) error {
s.Created = now
s.Modified = now
_, err := conn.ExecContext(context.Background(),
`INSERT INTO scholarship (UID, Citation, Hyperlink, Status, Created, Modified, Username)
VALUES (?, ?, ?, ?, ?, ?, ?)`,
s.UID, s.Citation, s.Hyperlink, s.Status, s.Created, s.Modified, s.Username,
`INSERT INTO scholarship (UID, Citation, Hyperlink, DocumentLink, Status, Created, Modified, Username)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
s.UID, s.Citation, s.Hyperlink, s.DocumentLink, s.Status, s.Created, s.Modified, s.Username,
)
return err
}
func GetScholarship(conn *sql.Conn, uid string) (Scholarship, error) {
row := conn.QueryRowContext(context.Background(),
`SELECT UID, Citation, Hyperlink, Status, Created, Modified, Username
`SELECT UID, Citation, Hyperlink, DocumentLink, Status, Created, Modified, Username
FROM scholarship WHERE UID = ?`,
uid,
)
var s Scholarship
err := row.Scan(&s.UID, &s.Citation, &s.Hyperlink, &s.Status, &s.Created, &s.Modified, &s.Username)
err := row.Scan(&s.UID, &s.Citation, &s.Hyperlink, &s.DocumentLink, &s.Status, &s.Created, &s.Modified, &s.Username)
if err == sql.ErrNoRows {
return Scholarship{}, fmt.Errorf("scholarship %q not found", uid)
}
@ -49,9 +50,9 @@ func GetScholarship(conn *sql.Conn, uid string) (Scholarship, error) {
func UpdateScholarship(conn *sql.Conn, s *Scholarship) error {
s.Modified = GetNow()
_, err := conn.ExecContext(context.Background(),
`UPDATE scholarship SET Citation = ?, Hyperlink = ?, Status = ?, Modified = ?, Username = ?
`UPDATE scholarship SET Citation = ?, Hyperlink = ?, DocumentLink = ?, Status = ?, Modified = ?, Username = ?
WHERE UID = ?`,
s.Citation, s.Hyperlink, s.Status, s.Modified, s.Username, s.UID,
s.Citation, s.Hyperlink, s.DocumentLink, s.Status, s.Modified, s.Username, s.UID,
)
return err
}
@ -66,7 +67,7 @@ func DeleteScholarship(conn *sql.Conn, uid string) error {
func GetScholarshipsForUsername(conn *sql.Conn, username string) ([]Scholarship, error) {
rows, err := conn.QueryContext(context.Background(),
`SELECT UID, Citation, Hyperlink, Status, Created, Modified, Username
`SELECT UID, Citation, Hyperlink, DocumentLink, Status, Created, Modified, Username
FROM scholarship WHERE Username = ?`,
username,
)
@ -78,7 +79,7 @@ func GetScholarshipsForUsername(conn *sql.Conn, username string) ([]Scholarship,
var results []Scholarship
for rows.Next() {
var s Scholarship
if err := rows.Scan(&s.UID, &s.Citation, &s.Hyperlink, &s.Status, &s.Created, &s.Modified, &s.Username); err != nil {
if err := rows.Scan(&s.UID, &s.Citation, &s.Hyperlink, &s.DocumentLink, &s.Status, &s.Created, &s.Modified, &s.Username); err != nil {
return nil, err
}
results = append(results, s)

@ -8,6 +8,7 @@ func genScholarship(username string) Scholarship {
return Scholarship{
Citation: randString(40),
Hyperlink: "https://" + randString(12) + ".example.com",
DocumentLink: "https://" + randString(12) + ".example.com/doc.pdf",
Status: "reported",
Username: username,
}
@ -112,6 +113,7 @@ func TestUpdateScholarship(t *testing.T) {
originalCreated := s.Created
s.Citation = randString(40)
s.Hyperlink = "https://" + randString(12) + ".example.com"
s.DocumentLink = "https://" + randString(12) + ".example.com/updated.pdf"
s.Status = "posted"
if err := UpdateScholarship(conn, &s); err != nil {
@ -131,6 +133,9 @@ func TestUpdateScholarship(t *testing.T) {
if got.Citation != s.Citation {
t.Errorf("Citation not updated: got %q, want %q", got.Citation, s.Citation)
}
if got.DocumentLink != s.DocumentLink {
t.Errorf("DocumentLink not updated: got %q, want %q", got.DocumentLink, s.DocumentLink)
}
if got.Status != "posted" {
t.Errorf("Status not updated: got %q", got.Status)
}

@ -64,7 +64,8 @@ var dashboardTmpl = template.Must(template.New("dashboard").Parse(`<!DOCTYPE htm
<th scope="col">Title</th>
<th scope="col">Description</th>
<th scope="col">Hyperlink</th>
<th scope="col" data-col="5" style="cursor:pointer;white-space:nowrap;">Type <span class="sort-ind">&#8597;</span></th>
<th scope="col">Document Link</th>
<th scope="col" data-col="6" style="cursor:pointer;white-space:nowrap;">Type <span class="sort-ind">&#8597;</span></th>
<th scope="col"></th>
</tr>
</thead>
@ -75,7 +76,8 @@ var dashboardTmpl = template.Must(template.New("dashboard").Parse(`<!DOCTYPE htm
<td>{{.LastName}}, {{.FirstName}}</td>
<td>{{.Title}}</td>
<td>{{.Description}}</td>
<td>{{if .Hyperlink}}<a href="{{.Hyperlink}}" target="_blank" rel="noopener">Link</a>{{end}}</td>
<td>{{if .Hyperlink}}<a href="{{.Hyperlink}}" target="_blank" rel="noopener"><rvt-icon name="link"></rvt-icon></a>{{end}}</td>
<td>{{if .DocumentLink}}<a href="{{.DocumentLink}}" target="_blank" rel="noopener"><rvt-icon name="link-external"></rvt-icon></a>{{end}}</td>
<td>{{.ItemType}}</td>
<td><button type="button" class="mark-posted-btn" aria-label="Mark as posted" style="background:none;border:none;cursor:pointer;color:#006633;padding:0;"><rvt-icon name="check"></rvt-icon></button></td>
</tr>
@ -176,15 +178,15 @@ var dashboardTmpl = template.Must(template.New("dashboard").Parse(`<!DOCTYPE htm
}
var lines = ['sep=|'];
lines.push(['Date Submitted', 'Name', 'Title', 'Description', 'Hyperlink', 'Type'].map(esc).join('|'));
lines.push(['Date Submitted', 'Name', 'Title', 'Description', 'Hyperlink', 'Document Link', 'Type'].map(esc).join('|'));
Array.prototype.forEach.call(table.querySelectorAll('tbody tr'), function(row) {
var cells = row.querySelectorAll('td');
var fields = [];
Array.prototype.forEach.call(cells, function(cell, i) {
if (i === 4) {
if (i === 4 || i === 5) {
var a = cell.querySelector('a');
fields.push(esc(a ? a.href : ''));
} else if (i < 6) {
} else if (i < 7) {
fields.push(esc(cell.textContent.trim()));
}
});

@ -62,6 +62,11 @@ func MainFormPage(jwtToken string) string {
<input class="rvt-input" type="url" id="scholarship-hyperlink" name="scholarship_hyperlink">
</div>
<div class="rvt-m-bottom-lg">
<label class="rvt-label" for="scholarship-document-link">If you would like your scholarship added to the Institutional Repository and/or SSRN, please include a link to a downloadable copy of the document (e.g. from OneDrive, SecureShare, Amazon S3, etc.)</label>
<input class="rvt-input" type="url" id="scholarship-document-link" name="scholarship_document_link">
</div>
<div class="section-save-btn" style="display:none">
<button class="rvt-button rvt-button--secondary" type="button">Save Item</button>
</div>
@ -308,7 +313,7 @@ func MainFormPage(jwtToken string) string {
Array.prototype.forEach.call(summaryArea.children, function(itemDiv) {
var data = JSON.parse(itemDiv.dataset.reportData || '{}');
if (legendText === 'Scholarship') {
params.scholarship.push({citation: data['scholarship-citation'] || '', hyperlink: data['scholarship-hyperlink'] || ''});
params.scholarship.push({citation: data['scholarship-citation'] || '', hyperlink: data['scholarship-hyperlink'] || '', document_link: data['scholarship-document-link'] || ''});
} else if (legendText === 'Talks and Activities') {
params.activities.push({title: data['talks-title'] || '', description: data['talks-description'] || '', hyperlink: data['talks-hyperlink'] || ''});
} else if (legendText === 'Media Appearances') {

@ -148,6 +148,7 @@ func seedScholarship(conn *sql.Conn) error {
UID: row["UID"],
Citation: row["Citation"],
Hyperlink: row["Hyperlink"],
DocumentLink: row["DocumentLink"],
Status: row["Status"],
Username: row["Username"],
}

Loading…
Cancel
Save