Add DocumentLink

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

@ -6,25 +6,26 @@ import (
) )
type DashboardItem struct { type DashboardItem struct {
UID string UID string
Created string Created string
LastName string LastName string
FirstName string FirstName string
Title string Title string
Description string Description string
Hyperlink string Hyperlink string
ItemType string DocumentLink string
ItemType string
} }
func GetReportedItems(conn *sql.Conn) ([]DashboardItem, error) { func GetReportedItems(conn *sql.Conn) ([]DashboardItem, error) {
rows, err := conn.QueryContext(context.Background(), ` 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' FROM scholarship s JOIN users u ON u.Username = s.Username WHERE s.Status = 'reported'
UNION ALL 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' FROM activities a JOIN users u ON u.Username = a.Username WHERE a.Status = 'reported'
UNION ALL 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' FROM appearances ap JOIN users u ON u.Username = ap.Username WHERE ap.Status = 'reported'
ORDER BY Created DESC ORDER BY Created DESC
`) `)
@ -36,7 +37,7 @@ func GetReportedItems(conn *sql.Conn) ([]DashboardItem, error) {
var items []DashboardItem var items []DashboardItem
for rows.Next() { for rows.Next() {
var item DashboardItem 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 return nil, err
} }
items = append(items, item) items = append(items, item)

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

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

@ -6,10 +6,11 @@ import (
func genScholarship(username string) Scholarship { func genScholarship(username string) Scholarship {
return Scholarship{ return Scholarship{
Citation: randString(40), Citation: randString(40),
Hyperlink: "https://" + randString(12) + ".example.com", Hyperlink: "https://" + randString(12) + ".example.com",
Status: "reported", DocumentLink: "https://" + randString(12) + ".example.com/doc.pdf",
Username: username, Status: "reported",
Username: username,
} }
} }
@ -112,6 +113,7 @@ func TestUpdateScholarship(t *testing.T) {
originalCreated := s.Created originalCreated := s.Created
s.Citation = randString(40) s.Citation = randString(40)
s.Hyperlink = "https://" + randString(12) + ".example.com" s.Hyperlink = "https://" + randString(12) + ".example.com"
s.DocumentLink = "https://" + randString(12) + ".example.com/updated.pdf"
s.Status = "posted" s.Status = "posted"
if err := UpdateScholarship(conn, &s); err != nil { if err := UpdateScholarship(conn, &s); err != nil {
@ -131,6 +133,9 @@ func TestUpdateScholarship(t *testing.T) {
if got.Citation != s.Citation { if got.Citation != s.Citation {
t.Errorf("Citation not updated: got %q, want %q", 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" { if got.Status != "posted" {
t.Errorf("Status not updated: got %q", got.Status) 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">Title</th>
<th scope="col">Description</th> <th scope="col">Description</th>
<th scope="col">Hyperlink</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> <th scope="col"></th>
</tr> </tr>
</thead> </thead>
@ -75,7 +76,8 @@ var dashboardTmpl = template.Must(template.New("dashboard").Parse(`<!DOCTYPE htm
<td>{{.LastName}}, {{.FirstName}}</td> <td>{{.LastName}}, {{.FirstName}}</td>
<td>{{.Title}}</td> <td>{{.Title}}</td>
<td>{{.Description}}</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>{{.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> <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> </tr>
@ -176,15 +178,15 @@ var dashboardTmpl = template.Must(template.New("dashboard").Parse(`<!DOCTYPE htm
} }
var lines = ['sep=|']; 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) { Array.prototype.forEach.call(table.querySelectorAll('tbody tr'), function(row) {
var cells = row.querySelectorAll('td'); var cells = row.querySelectorAll('td');
var fields = []; var fields = [];
Array.prototype.forEach.call(cells, function(cell, i) { Array.prototype.forEach.call(cells, function(cell, i) {
if (i === 4) { if (i === 4 || i === 5) {
var a = cell.querySelector('a'); var a = cell.querySelector('a');
fields.push(esc(a ? a.href : '')); fields.push(esc(a ? a.href : ''));
} else if (i < 6) { } else if (i < 7) {
fields.push(esc(cell.textContent.trim())); 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"> <input class="rvt-input" type="url" id="scholarship-hyperlink" name="scholarship_hyperlink">
</div> </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"> <div class="section-save-btn" style="display:none">
<button class="rvt-button rvt-button--secondary" type="button">Save Item</button> <button class="rvt-button rvt-button--secondary" type="button">Save Item</button>
</div> </div>
@ -308,7 +313,7 @@ func MainFormPage(jwtToken string) string {
Array.prototype.forEach.call(summaryArea.children, function(itemDiv) { Array.prototype.forEach.call(summaryArea.children, function(itemDiv) {
var data = JSON.parse(itemDiv.dataset.reportData || '{}'); var data = JSON.parse(itemDiv.dataset.reportData || '{}');
if (legendText === 'Scholarship') { 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') { } else if (legendText === 'Talks and Activities') {
params.activities.push({title: data['talks-title'] || '', description: data['talks-description'] || '', hyperlink: data['talks-hyperlink'] || ''}); params.activities.push({title: data['talks-title'] || '', description: data['talks-description'] || '', hyperlink: data['talks-hyperlink'] || ''});
} else if (legendText === 'Media Appearances') { } else if (legendText === 'Media Appearances') {

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

Loading…
Cancel
Save