@ -7,6 +7,11 @@ import (
"faculty_media_report/dbi"
)
type dashboardData struct {
JWT string
Items [ ] dbi . DashboardItem
}
var dashboardTmpl = template . Must ( template . New ( "dashboard" ) . Parse ( ` < ! DOCTYPE html >
< html lang = "en" >
< head >
@ -14,6 +19,7 @@ var dashboardTmpl = template.Must(template.New("dashboard").Parse(`<!DOCTYPE htm
< meta name = "viewport" content = "width=device-width, initial-scale=1.0" >
< title > Dashboard — Maurer School of Law < / title >
< link rel = "stylesheet" href = "https://unpkg.com/rivet-core@2/css/rivet.min.css" >
< script > var JWT = "{{.JWT}}" ; < / script >
< / head >
< body >
< header class = "rvt-header-wrapper" >
@ -41,7 +47,7 @@ var dashboardTmpl = template.Must(template.New("dashboard").Parse(`<!DOCTYPE htm
< main id = "main-content" class = "rvt-container-xl rvt-p-top-xxl rvt-p-bottom-xxl" >
< h1 class = "rvt-ts-xxl rvt-m-bottom-xxl" > Activity Report Dashboard < / h1 >
{ { if . } }
{ { if . Items } }
< div class = "rvt-m-bottom-lg" >
< button class = "rvt-button rvt-button--secondary" type = "button" id = "download-csv" > Download CSV Report < / button >
< / div >
@ -59,17 +65,19 @@ var dashboardTmpl = template.Must(template.New("dashboard").Parse(`<!DOCTYPE htm
< 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" > < / th >
< / tr >
< / thead >
< tbody >
{ { range . } }
< tr >
{ { range . Items } }
< tr data - uid = "{{.UID}}" >
< td > { { . Created } } < / td >
< 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 > { { . 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 >
{ { end } }
< / tbody >
@ -79,6 +87,7 @@ var dashboardTmpl = template.Must(template.New("dashboard").Parse(`<!DOCTYPE htm
< p class = "rvt-ts-lg" > No reported items . < / p >
{ { end } }
< / main >
< script type = "module" src = "https://unpkg.com/rivet-icons@3/dist/rivet-icons.js" > < / script >
< script >
( function ( ) {
var table = document . getElementById ( ' report - table ' ) ;
@ -124,6 +133,31 @@ var dashboardTmpl = template.Must(template.New("dashboard").Parse(`<!DOCTYPE htm
apply ( ) ;
} ) ;
} ) ;
table . addEventListener ( ' click ' , function ( e ) {
var btn = e . target . closest ( ' . mark - posted - btn ' ) ;
if ( ! btn ) return ;
var row = btn . closest ( ' tr ' ) ;
var uid = row ? row . getAttribute ( ' data - uid ' ) : null ;
if ( ! uid ) return ;
btn . disabled = true ;
fetch ( ' / faculty / activity / api ' , {
method : ' POST ' ,
headers : { ' Content - Type ' : ' application / json ' , ' Authorization ' : ' Bearer ' + JWT } ,
body : JSON . stringify ( { jsonrpc : ' 2.0 ' , method : ' mark_posted ' , params : { uid : uid } , id : 1 } )
} )
. then ( function ( resp ) { return resp . json ( ) ; } )
. then ( function ( data ) {
if ( data . error ) {
btn . disabled = false ;
return ;
}
allRows = allRows . filter ( function ( r ) { return r != = row ; } ) ;
row . remove ( ) ;
} )
. catch ( function ( ) { btn . disabled = false ; } ) ;
} ) ;
}
var dlBtn = document . getElementById ( ' download - csv ' ) ;
@ -150,7 +184,7 @@ var dashboardTmpl = template.Must(template.New("dashboard").Parse(`<!DOCTYPE htm
if ( i == = 4 ) {
var a = cell . querySelector ( 'a' ) ;
fields . push ( esc ( a ? a . href : ' ' ) ) ;
} else {
} else if ( i < 6 ) {
fields . push ( esc ( cell . textContent . trim ( ) ) ) ;
}
} ) ;
@ -174,9 +208,9 @@ var dashboardTmpl = template.Must(template.New("dashboard").Parse(`<!DOCTYPE htm
< / body >
< / html > ` ) )
func DashboardPage ( items [ ] dbi . DashboardItem ) ( string , error ) {
func DashboardPage ( jwtToken string , items [ ] dbi . DashboardItem ) ( string , error ) {
var buf bytes . Buffer
if err := dashboardTmpl . Execute ( & buf , items) ; err != nil {
if err := dashboardTmpl . Execute ( & buf , dashboardData{ JWT : jwtToken , Items : items} ) ; err != nil {
return "" , err
}
return buf . String ( ) , nil