Skip to content

Commit

Permalink
Merge pull request #357 from UniversityRadioYork/ash/new-schedule
Browse files Browse the repository at this point in the history
new schedule
  • Loading branch information
alyxbb authored Jun 10, 2024
2 parents 9f44c1a + 7d5c1c9 commit fca0575
Show file tree
Hide file tree
Showing 13 changed files with 171 additions and 41 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ public/css/*.scss.css
config.toml
public/css/*.scss.css.map


.direnv/

1 change: 1 addition & 0 deletions config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,4 @@
[schedule.sustainer]
name = "Overnight Owen"
desc = "Non-stop tunes from the URY jukebox."
image = "//ury.org.uk/media/image_meta/ShowImageMetadata/22.png"
5 changes: 5 additions & 0 deletions controllers/schedule_week.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ func (sc *ScheduleWeekController) makeAndRenderWeek(w http.ResponseWriter, year,
return
}

if err != nil {
log.Println(err)
return
}

data := struct {
Schedule *models.WeekSchedule
PrevURL, CurrURL, NextURL *url.URL
Expand Down
34 changes: 21 additions & 13 deletions models/schedule_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ type ScheduleItem struct {
// PageURL is the root-relative URL to this schedule item's page,
// or "" if there is no URL.
PageURL string

// ShowArtURL is the URL to the show art image of this show.
ShowArtURL string

ShowWeekDay bool
}

// IsSustainer checks whether this schedule item is the URY sustainer.
Expand All @@ -41,12 +46,14 @@ func (s *ScheduleItem) IsSustainer() bool {
// It takes a sustainer config, c, to work out the sustainer name.
func NewSustainerItem(c structs.SustainerConfig, start, finish time.Time) *ScheduleItem {
return &ScheduleItem{
Name: c.Name,
Desc: c.Desc,
Start: start,
Finish: finish,
Block: "sustainer",
PageURL: "",
Name: c.Name,
Desc: c.Desc,
Start: start,
Finish: finish,
Block: "sustainer",
PageURL: "",
ShowArtURL: c.Image,
ShowWeekDay: false,
}
}

Expand All @@ -62,12 +69,14 @@ func NewTimeslotItem(t *myradio.Timeslot, finish time.Time, u func(*myradio.Time
return nil, err
}
return &ScheduleItem{
Name: t.Title,
Desc: t.Description,
Start: t.StartTime,
Finish: finish,
Block: t.Subtype.Class,
PageURL: url.Path,
Name: t.Title,
Desc: t.Description,
Start: t.StartTime,
Finish: finish,
Block: t.Subtype.Class,
PageURL: url.Path,
ShowArtURL: t.Photo,
ShowWeekDay: false,
}, nil
}

Expand Down Expand Up @@ -175,7 +184,6 @@ func MakeScheduleSlice(c structs.SustainerConfig, start, finish time.Time, slots

s := newScheduleBuilder(c, tbuilder, nslots)
s.fill(start, slots[0].StartTime)

// Now, if possible, start filling between.
var show, nextShow *myradio.Timeslot
for i := range slots {
Expand Down
56 changes: 54 additions & 2 deletions models/schedule_tabulate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import (

// WeekScheduleCell represents one cell in the week schedule.
type WeekScheduleCell struct {
// Number of rows this cell spans.
// If 0, this is a continuation from a cell further up.
RowSpan uint

// Pointer to the timeslot in this cell, if any.
Expand Down Expand Up @@ -276,6 +274,9 @@ type WeekSchedule struct {
// Table is the actual week table.
// If there is no schedule for the given week, this will be nil.
Table []WeekScheduleCol
// The week's schedule but in list form not table form
// If there is no schedule for the given week, this will be nil.
List []WeekScheduleList
}

// hasShows asks whether a schedule slice contains any non-sustainer shows.
Expand Down Expand Up @@ -311,6 +312,12 @@ func (c *WeekScheduleCol) addCell(s uint, i *ScheduleItem, h int, m int) {
c.Cells = append(c.Cells, WeekScheduleCell{RowSpan: s, Item: i, Hour: h, Minute: m})
}

type WeekScheduleList struct {
Day time.Time
Current bool
Shows []ScheduleItem
}

// tableFilp flips the schedule table such that it becomes a list of days which have a list
// of shows on that day.
func tableFilp(rows []WeekScheduleRow, dates []time.Time) []WeekScheduleCol {
Expand All @@ -326,6 +333,48 @@ func tableFilp(rows []WeekScheduleRow, dates []time.Time) []WeekScheduleCol {
return days
}

func buildList(schedule []*ScheduleItem, dates []time.Time) []WeekScheduleList {
thisYear, thisMonth, thisDay := time.Now().Date()
days := make([]WeekScheduleList, 7)
thisWeek := false
for i := range days {
days[i].Day = dates[i]
year, month, day := dates[i].Date()
if year == thisYear && month == thisMonth && day == thisDay {
days[i].Current = true
thisWeek = true
}
}
if !thisWeek {
days[0].Current = true
}
for _, item := range schedule {
dayIndex := (item.Start.Weekday() + 6) % 7
if straddlesDay(item) {
item.ShowWeekDay = true
EnddayIndex := (item.Finish.Weekday() + 6) % 7
for i := dayIndex; i<=EnddayIndex; i++ {
days[i].Shows = append(days[i].Shows, *item);
}
} else {
days[dayIndex].Shows = append(days[dayIndex].Shows, *item)
}
}
for day := range days {
// Where does the come from, nobody knows; here's a fix to get rid of it though -ash (2024)
// TODO: actually fix this
// it comes from makescheduleslice see the s.fill line. needed otherwise the first show on monday will start at 6am on table view
// or not, theres jukeboxes coming from elsewhere aswell
if days[day].Shows[len(days[day].Shows)-1].IsSustainer(){
days[day].Shows = days[day].Shows[:len(days[day].Shows) - 1]
}
if days[day].Shows[0].IsSustainer(){
days[day].Shows = days[day].Shows[1:]
}
}
return days
}

// tabulateWeekSchedule creates a schedule table from the given schedule slice.
func tabulateWeekSchedule(start, finish time.Time, schedule []*ScheduleItem) (*WeekSchedule, error) {
days := []time.Time{}
Expand All @@ -337,6 +386,7 @@ func tabulateWeekSchedule(start, finish time.Time, schedule []*ScheduleItem) (*W
return &WeekSchedule{
Dates: days,
Table: nil,
List: nil,
}, nil
}

Expand All @@ -349,10 +399,12 @@ func tabulateWeekSchedule(start, finish time.Time, schedule []*ScheduleItem) (*W
populateRows(days, rows, schedule)

table := tableFilp(rows, days)
list := buildList(schedule, days)

sch := WeekSchedule{
Dates: days,
Table: table,
List: list,
}

return &sch, nil
Expand Down
3 changes: 2 additions & 1 deletion sass/elements/_elements.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@import "schedule";
@import "seasonTables";
@import "snow";
@import "timeslot";
@import "aprilFools";
@import "show";
@import "faq";
@import "faq";
9 changes: 9 additions & 0 deletions sass/elements/_schedule.scss
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@ $sustainer-color: tint($primary-color, 40%);
@include schedule-block($collab, $off-white-color);
}

.schedule-card {
display: flex;
flex-direction: row;
}

.card-details {
padding: 1rem;
}

.schedule-keys .key-row {
* {
display: inline-block;
Expand Down
3 changes: 3 additions & 0 deletions sass/elements/_timeslot.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.tracklist {
color: white;
}
5 changes: 3 additions & 2 deletions structs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ type ScheduleConfig struct {

// SustainerConfig is a structure describing the sustainer show.
type SustainerConfig struct {
Name string `toml:"name"`
Desc string `toml:"desc"`
Name string `toml:"name"`
Desc string `toml:"desc"`
Image string `toml:"image"`
}

type IndexCountdownBackgroundType string
Expand Down
2 changes: 1 addition & 1 deletion utils/date.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
//

// StartHour is the hour of the day (local time) at which the scheduled day begins.
var StartHour = 16
var StartHour = 6

// StartOfDayOn gets the schedule start-of-day on a given date.
// This is in terms of StartHour.
Expand Down
4 changes: 2 additions & 2 deletions views/partials/base.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha256-4+XzXVhsDmqanXGHaHvgh1gMQKX40OUvDEBTu8JcmNs=" crossorigin="anonymous"></script>
<!-- bootstrap -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct" crossorigin="anonymous"></script>
<!-- bootstrap end -->

<link rel="stylesheet" href='{{url "/css/main.scss.css"}}?ver={{ .PageContext.CacheBuster }}' type="text/css">
Expand Down
86 changes: 67 additions & 19 deletions views/schedule_week.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,6 @@
<h1 class="display-4 mobile-hide">Schedule <a class="fa fa-key schedule-key-icon" href="#key"></a></h1>
<h2 class="text-muted mobile-hide">{{week (index .Schedule.Dates 0)}}</h2>
</div>
<div class="col-12">
<div class="row justify-content-center">
{{with $weekName := week (index .Schedule.Dates 0)}}
{{if eq $weekName "this week"}}
<button class="btn btn-secondary mobile-only inline" id="jumpToNow" type="button" onclick="jumpToNow()">Jump to the current show</button>
{{end}}
{{end}}
<h1 class="mobile-only inline"><a class="fa fa-key schedule-key-icon" data-toggle="collapse" data-target=".schedule-keys" aria-expanded="false" aria-controls="schedule-keys"></a></h1>
</div>
<div class="schedule-keys collapse">
<div class="key-row">
{{ range .Subtypes }}
<span class="schedule-block-{{.Class}}">{{.Name}}</span>
{{end}}
</div>
</div>
</div>
</div>

<nav aria-label="Related Schedules" class="row nav justify-content-between">
Expand All @@ -59,8 +42,8 @@
</div>

<!-- schedule body -->
<div class="container-fluid bg-off-white container-padded">
<div class="container">
<div class="container-fluid bg-off-white container-padded mobile-hide">
<div class="container">
{{with .Schedule}}
{{if .Table}}
<div class="tables-container table">
Expand Down Expand Up @@ -124,6 +107,71 @@
</div>
</div>
</div>
</div>






<div class="bg-off-white mobile-only">
{{with .Schedule}}
{{if .List}}
<div class="container-fluid container">
<ul class="nav nav-tabs" id="schedule-tab" role="tablist">
{{range .List}}
<li class="nav-item" role="presentation">
{{if .Current}}
<button class="nav-link active" id="{{.Day.Weekday}}-tab" data-toggle="pill" data-target="#{{.Day.Weekday}}" type="button" role="tab" aria-controls="{{.Day.Weekday}}" aria-selected="true">
{{else}}
<button class="nav-link" id="{{.Day.Weekday}}-tab" data-toggle="pill" data-target="#{{.Day.Weekday}}" type="button" role="tab" aria-controls="{{.Day.Weekday}}" aria-selected="false">
{{end}}
{{.Day.Weekday}}&nbsp;{{.Day.Format "02"}}
</button>
</li>
{{end}}
</ul>
</div>
<div class="tab-content mt-2" id="schedule-tabContent">
{{range .List}}
{{if .Current}}
<div class="tab-pane show active" id="{{.Day.Weekday}}" role="tabpanel" aria-labelledby="{{.Day.Weekday}}-tab">
{{else}}
<div class="tab-pane" id="{{.Day.Weekday}}" role="tabpanel" aria-labelledby="{{.Day.Weekday}}-tab">
{{end}}
<ul class="p-0">
{{range .Shows}}
<li class="schedule-card">
<img src="https://ury.org.uk{{.ShowArtURL}}" width="128" height="128">
<div class="card-details pb-0">
<h3>
{{if .PageURL}}
<a href="{{.PageURL}}">{{.Name}}</a>
{{else}}
{{.Name}}
{{end}}
</h3>
{{if .ShowWeekDay}}
<h4>{{.Start.Format "Monday 15:04"}} - {{.Finish.Format "Monday 15:04"}}</h4>
{{else}}
<h4>{{.Start.Format "15:04"}} - {{.Finish.Format "15:04"}}</h4>
{{end}}
</div>
</li>
{{end}}
</ul>
</div>
{{end}}
</div>
{{else}}
<div class="row justify-content-center p-5">
<div class="col-12 col-lg-8 p-5 text-center schedule-block-regular disabled">
<h3>There's nothing on for this week.</h3>
<h4>We're most likely off air, or we haven't scheduled it yet!</h4>
</div>
</div>
{{end}}
{{end}}
</div>
{{end}}
{{end}}
Expand Down
2 changes: 1 addition & 1 deletion views/timeslot.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
<div class="container p-3">
<h2>Tracklist</h2>
{{if .Tracklist}}
<table class="table">
<table class="table tracklist">
<thead>
<tr>
<th>Track</th>
Expand Down

0 comments on commit fca0575

Please sign in to comment.