diff options
-rw-r--r-- | index.go | 49 | ||||
-rw-r--r-- | state.go | 6 | ||||
-rw-r--r-- | tmpl/student_disabled.html | 60 |
3 files changed, 98 insertions, 17 deletions
@@ -25,6 +25,7 @@ import ( "fmt" "log" "net/http" + "sync/atomic" "github.com/jackc/pgx/v5" ) @@ -125,6 +126,24 @@ func handleIndex(w http.ResponseWriter, req *http.Request) { return } + if atomic.LoadUint32(&state) == 0 { + err := tmpl.ExecuteTemplate( + w, + "student_disabled", + struct { + Name string + Department string + }{ + userName, + userDepartment, + }, + ) + if err != nil { + log.Println(err) + } + return + } + /* TODO: The below should be completed on-update. */ type groupT struct { Handle courseGroupT @@ -153,23 +172,19 @@ func handleIndex(w http.ResponseWriter, req *http.Request) { return true }) - err = func() error { - return tmpl.ExecuteTemplate( - w, - "student", - struct { - Open bool - Name string - Department string - Groups *map[courseGroupT]groupT - }{ - true, - userName, - userDepartment, - &_groups, - }, - ) - }() + err = tmpl.ExecuteTemplate( + w, + "student", + struct { + Name string + Department string + Groups *map[courseGroupT]groupT + }{ + userName, + userDepartment, + &_groups, + }, + ) if err != nil { log.Println(err) return @@ -84,6 +84,12 @@ func setState(ctx context.Context, newState uint32) error { return err } atomic.StoreUint32(&state, newState) + /* + * TODO: Various actions about connections during state changes: + * If set to 0, kill all connections. If set to 2, send all channels + * a message that selections are open. If set to 1, send all channels + * a message saying that selections are closed. + */ return nil } diff --git a/tmpl/student_disabled.html b/tmpl/student_disabled.html new file mode 100644 index 0000000..e451169 --- /dev/null +++ b/tmpl/student_disabled.html @@ -0,0 +1,60 @@ +{{- define "student_disabled" -}} +<!DOCTYPE html> +<html lang="en"> + <head> + <title> + {{ .Name }} – CCA Selection System + </title> + <link rel="stylesheet" href="/static/style.css" /> + <meta charset="utf-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1" /> + <meta name="description" content="YK Pao School CCA Selection System" /> + </head> + <body> + <div style="font-size: 150%; color: red; font-weight: bold;" class="broken-styling-warning"> + The fact that you see this message means that the CSS styling information for this site is not loading correctly, and usability would be severely impacted. Check your network connection, and if this issue persists, you should contact the system administrator. + </div> + <header> + <div class="header-content"> + <div class="header-left"> + <h1><a id="site-title" href="./">CCA Selection System</a></h1> + </div> + <div class="header-middle"> + <nav> + <ul> + <li> + <a href="./">Home</a> + </li> + <li> + <a href="./docs/">Docs</a> + </li> + <li> + <a href="./iadocs/">IA Docs</a> + </li> + <li> + <a href="./src/">Source</a> + </li> + </ul> + </nav> + </div> + <div class="header-right"> + <p>{{- .Name }} ({{ .Department -}})</p> + </div> + </div> + </header> + <div class="reading-width" id="wip-notice"> + <p> + This site is still a work in progress and may contain bugs! Please contact <a href="mailto:s22537@stu.ykpaoschool.cn">Runxi Yu</a> for any issues. + </p> + </div> + <div class="reading-width"> + <p> + Student access is currently disabled. + </p> + <p> + Please check back later. + </p> + </div> + </body> +</html> +{{- end -}} |