Skip to content

Commit

Permalink
Reformat and redesign admin page (#1377)
Browse files Browse the repository at this point in the history
* Moved statistics to own tab instead of button in settings

* Refactored Admin data

* Fixed golangci

* Removed break from switch
  • Loading branch information
SebiWrn authored Sep 11, 2024
1 parent 9fc27cc commit 7252e64
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 51 deletions.
105 changes: 56 additions & 49 deletions web/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,61 +44,32 @@ func (r mainRoutes) AdminPage(c *gin.Context) {
lectureHalls := r.LectureHallsDao.GetAllLectureHalls()
indexData := NewIndexData()
indexData.TUMLiveContext = tumLiveContext
page := "schedule"
if c.Request.URL.Path == "/admin/users" {
page = "users"
}
if c.Request.URL.Path == "/admin/lectureHalls" {
page = "lectureHalls"
}
if c.Request.URL.Path == "/admin/lectureHalls/new" {
page = "createLectureHalls"
}
if c.Request.URL.Path == "/admin/workers" {
page = "workers"
}
if c.Request.URL.Path == "/admin/create-course" {
page = "createCourse"
}
if c.Request.URL.Path == "/admin/course-import" {
page = "courseImport"
}
if c.Request.URL.Path == "/admin/audits" {
page = "audits"
}
if c.Request.URL.Path == "/admin/maintenance" {
page = "maintenance"
}
page := GetPageString(c.Request.URL.Path)
var notifications []model.Notification
if c.Request.URL.Path == "/admin/notifications" {
page = "notifications"
var tokens []dao.AllTokensDto
var infopages []model.InfoPage
var serverNotifications []model.ServerNotification
switch page {
case "notifications":
found, err := r.NotificationsDao.GetAllNotifications()
if err != nil {
logger.Error("couldn't query notifications", "err", err)
} else {
notifications = found
}
}
var tokens []dao.AllTokensDto
if c.Request.URL.Path == "/admin/token" {
page = "token"
case "token":
tokens, err = r.TokenDao.GetAllTokens()
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
logger.Error("couldn't query tokens", "err", err)
c.AbortWithStatus(http.StatusInternalServerError)
}
}
var infopages []model.InfoPage
if c.Request.URL.Path == "/admin/infopages" {
page = "info-pages"
case "info-pages":
infopages, err = r.InfoPageDao.GetAll()
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
logger.Error("couldn't query texts", "err", err)
c.AbortWithStatus(http.StatusInternalServerError)
}
}
if c.Request.URL.Path == "/admin/server-stats" {
page = "serverStats"
case "serverStats":
streams, err := r.StreamsDao.GetAllStreams()
if err != nil {
logger.Error("Can't get all streams", "err", err)
Expand All @@ -109,10 +80,7 @@ func (r mainRoutes) AdminPage(c *gin.Context) {
Model: gorm.Model{ID: 0},
Streams: streams,
}
}
var serverNotifications []model.ServerNotification
if c.Request.URL.Path == "/admin/server-notifications" {
page = "serverNotifications"
case "serverNotifications":
if res, err := r.ServerNotificationDao.GetAllServerNotifications(); err == nil {
serverNotifications = res
} else {
Expand Down Expand Up @@ -142,6 +110,41 @@ func (r mainRoutes) AdminPage(c *gin.Context) {
}
}

func GetPageString(s string) string {
switch s {
case "":
return "schedule"
case "/admin/users":
return "users"
case "/admin/lectureHalls":
return "lectureHalls"
case "/admin/lectureHalls/new":
return "createLectureHalls"
case "/admin/workers":
return "workers"
case "/admin/create-course":
return "createCourse"
case "/admin/course-import":
return "courseImport"
case "/admin/audits":
return "audits"
case "/admin/maintenance":
return "maintenance"
case "/admin/notifications":
return "notifications"
case "/admin/token":
return "token"
case "/admin/infopages":
return "info-pages"
case "/admin/server-stats":
return "serverStats"
case "/admin/server-notifications":
return "serverNotifications"
default:
return "schedule"
}
}

type WorkersData struct {
Workers []model.Worker
Token string
Expand Down Expand Up @@ -236,13 +239,17 @@ func (r mainRoutes) EditCoursePage(c *gin.Context) {
}
}
err = templateExecutor.ExecuteTemplate(c.Writer, "admin.gohtml", AdminPageData{
IndexData: indexData,
Courses: courses,
Page: "course",
Semesters: semesters,
CurY: tumLiveContext.Course.Year,
CurT: tumLiveContext.Course.TeachingTerm,
EditCourseData: EditCourseData{IndexData: indexData, IngestBase: tools.Cfg.IngestBase, LectureHalls: lectureHalls},
IndexData: indexData,
Courses: courses,
Page: "course",
Semesters: semesters,
CurY: tumLiveContext.Course.Year,
CurT: tumLiveContext.Course.TeachingTerm,
EditCourseData: EditCourseData{
IndexData: indexData,
IngestBase: tools.Cfg.IngestBase,
LectureHalls: lectureHalls,
},
})
if err != nil {
logger.Error("Error executing template admin.gohtml", "err", err)
Expand Down
13 changes: 13 additions & 0 deletions web/template/admin/admin_tabs/edit-course.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@
: 'inline-block p-4 border-b-2 border-transparent rounded-t-lg hover:text-gray-600 hover:border-gray-300 dark:hover:text-gray-300'"
>Settings</button>
</li>
<li class="mr-2">
<button
@click="selectedTab = $el.dataset.tab"
data-tab="statistics"
:class="selectedTab == $el.dataset.tab ?
'inline-block p-4 border-b-2 rounded-t-lg'
: 'inline-block p-4 border-b-2 border-transparent rounded-t-lg hover:text-gray-600 hover:border-gray-300 dark:hover:text-gray-300'"
>Statistics</button>
</li>
<li class="mr-2">
<button
@click="selectedTab = $el.dataset.tab"
Expand Down Expand Up @@ -91,6 +100,10 @@
</div>
</div>

<div data-tab="statistics" x-show="selectedTab === $el.dataset.tab">
{{template "stats" .IndexData}}
</div>

<div data-tab="external-participants" x-show="selectedTab === $el.dataset.tab">
<div class="form-container">
<h2 class="form-container-title">External Participants</h2>
Expand Down
1 change: 0 additions & 1 deletion web/template/admin/admin_tabs/stats.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<label class="hidden" for="courseID">CourseID<input id="courseID" type="text" class="hidden"
value="{{.TUMLiveContext.Course.Model.ID}}"></label>

<h1 class="text-2xl text-1 my-4">Server Statistics</h1>
<div class="form-container">

<h2 class="form-container-title">Quick stats</h2>
Expand Down
1 change: 0 additions & 1 deletion web/template/partial/course/manage/course_settings.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
<input name="submit" class="btn" type="submit" value="Reload Enrollments">
<!-- <input name="submit" class="btn border-0" type="submit" value="Reload Lectures From TUMOnline"> -->
{{end}}
<a class="btn" href="{{.Model.ID}}/stats">Statistics</a>
</div>
</form>
{{template "course-settings-modal" .}}
Expand Down

0 comments on commit 7252e64

Please sign in to comment.