Renamed slideshow -> slide.

This commit is contained in:
Patrick Fairbank
2014-08-25 20:18:37 -07:00
parent 903a45030b
commit 450cd6766b
11 changed files with 174 additions and 172 deletions

4
api.go
View File

@@ -55,8 +55,8 @@ func MatchesApiHandler(w http.ResponseWriter, r *http.Request) {
}
}
func SponsorsApiHandler(w http.ResponseWriter, r *http.Request) {
sponsors, err := db.GetAllSponsorSlideshows()
func SponsorSlidesApiHandler(w http.ResponseWriter, r *http.Request) {
sponsors, err := db.GetAllSponsorSlides()
if err != nil {
handleWebErr(w, err)
return

View File

@@ -15,16 +15,16 @@ import (
const migrationsDir = "db/migrations"
type Database struct {
path string
db *sql.DB
eventSettingsMap *modl.DbMap
matchMap *modl.DbMap
matchResultMap *modl.DbMap
rankingMap *modl.DbMap
teamMap *modl.DbMap
allianceTeamMap *modl.DbMap
lowerThirdMap *modl.DbMap
sponsorSlideshowMap *modl.DbMap
path string
db *sql.DB
eventSettingsMap *modl.DbMap
matchMap *modl.DbMap
matchResultMap *modl.DbMap
rankingMap *modl.DbMap
teamMap *modl.DbMap
allianceTeamMap *modl.DbMap
lowerThirdMap *modl.DbMap
sponsorSlideMap *modl.DbMap
}
// Opens the SQLite database at the given path, creating it if it doesn't exist, and runs any pending
@@ -81,6 +81,6 @@ func (database *Database) mapTables() {
database.lowerThirdMap = modl.NewDbMap(database.db, dialect)
database.lowerThirdMap.AddTableWithName(LowerThird{}, "lower_thirds").SetKeys(true, "Id")
database.sponsorSlideshowMap = modl.NewDbMap(database.db, dialect)
database.sponsorSlideshowMap.AddTableWithName(SponsorSlideshow{}, "sponsor_slideshow").SetKeys(true, "Id")
database.sponsorSlideMap = modl.NewDbMap(database.db, dialect)
database.sponsorSlideMap.AddTableWithName(SponsorSlide{}, "sponsor_slides").SetKeys(true, "Id")
}

View File

@@ -1,5 +1,5 @@
-- +goose Up
CREATE TABLE sponsor_slideshow (
CREATE TABLE sponsor_slides (
id INTEGER PRIMARY KEY,
subtitle VARCHAR(255),
line1 VARCHAR(255),
@@ -9,4 +9,4 @@ CREATE TABLE sponsor_slideshow (
);
-- +goose Down
DROP TABLE sponsor_slideshow;
DROP TABLE sponsor_slides;

72
setup_sponsor_slides.go Normal file
View File

@@ -0,0 +1,72 @@
// Copyright 2014 Team 254. All Rights Reserved.
// Author: nick@team254.com (Nick Eyre)
//
// Web routes for managing sponsor slides.
package main
import (
"html/template"
"net/http"
"strconv"
)
// Shows the sponsor slides configuration page.
func SponsorSlidesGetHandler(w http.ResponseWriter, r *http.Request) {
template, err := template.ParseFiles("templates/sponsor_slides.html", "templates/base.html")
if err != nil {
handleWebErr(w, err)
return
}
sponsorSlides, err := db.GetAllSponsorSlides()
if err != nil {
handleWebErr(w, err)
return
}
data := struct {
*EventSettings
SponsorSlides []SponsorSlide
}{eventSettings, sponsorSlides}
err = template.ExecuteTemplate(w, "base", data)
if err != nil {
handleWebErr(w, err)
return
}
}
// Saves the new or modified sponsor slides to the database.
func SponsorSlidesPostHandler(w http.ResponseWriter, r *http.Request) {
sponsorSlideId, _ := strconv.Atoi(r.PostFormValue("id"))
sponsorSlide, err := db.GetSponsorSlideById(sponsorSlideId)
if err != nil {
handleWebErr(w, err)
return
}
if r.PostFormValue("action") == "delete" {
err := db.DeleteSponsorSlide(sponsorSlide)
if err != nil {
handleWebErr(w, err)
return
}
} else {
if sponsorSlide == nil {
sponsorSlide = &SponsorSlide{Subtitle: r.PostFormValue("subtitle"),
Line1: r.PostFormValue("line1"), Line2: r.PostFormValue("line2"),
Image: r.PostFormValue("image"), Priority: r.PostFormValue("priority")}
err = db.CreateSponsorSlide(sponsorSlide)
} else {
sponsorSlide.Subtitle = r.PostFormValue("subtitle")
sponsorSlide.Line1 = r.PostFormValue("line1")
sponsorSlide.Line2 = r.PostFormValue("line2")
sponsorSlide.Image = r.PostFormValue("image")
sponsorSlide.Priority = r.PostFormValue("priority")
err = db.SaveSponsorSlide(sponsorSlide)
}
if err != nil {
handleWebErr(w, err)
return
}
}
http.Redirect(w, r, "/setup/sponsor_slides", 302)
}

View File

@@ -1,74 +0,0 @@
// Copyright 2014 Team 254. All Rights Reserved.
// Author: nick@team254.com (Nick Eyre)
//
// Web routes for managing sponsor slideshow.
package main
import (
"html/template"
"net/http"
"strconv"
)
// Shows the lower third configuration page.
func SponsorSlideshowGetHandler(w http.ResponseWriter, r *http.Request) {
template, err := template.ParseFiles("templates/sponsor_slideshow.html", "templates/base.html")
if err != nil {
handleWebErr(w, err)
return
}
sponsorSlideshow, err := db.GetAllSponsorSlideshows()
if err != nil {
handleWebErr(w, err)
return
}
data := struct {
*EventSettings
SponsorSlideshow []SponsorSlideshow
}{eventSettings, sponsorSlideshow}
err = template.ExecuteTemplate(w, "base", data)
if err != nil {
handleWebErr(w, err)
return
}
}
// Saves the new or modified lower third to the database and triggers showing it on the audience display.
func SponsorSlideshowPostHandler(w http.ResponseWriter, r *http.Request) {
sponsorSlideshowId, _ := strconv.Atoi(r.PostFormValue("id"))
sponsorSlideshow, err := db.GetSponsorSlideshowById(sponsorSlideshowId)
if err != nil {
handleWebErr(w, err)
return
}
if r.PostFormValue("action") == "delete" {
err := db.DeleteSponsorSlideshow(sponsorSlideshow)
if err != nil {
handleWebErr(w, err)
return
}
} else {
if sponsorSlideshow == nil {
sponsorSlideshow = &SponsorSlideshow{Subtitle: r.PostFormValue("subtitle"),
Line1: r.PostFormValue("line1"),
Line2: r.PostFormValue("line2"),
Image: r.PostFormValue("image"),
Priority: r.PostFormValue("priority")}
err = db.CreateSponsorSlideshow(sponsorSlideshow)
} else {
sponsorSlideshow.Subtitle = r.PostFormValue("subtitle")
sponsorSlideshow.Line1 = r.PostFormValue("line1")
sponsorSlideshow.Line2 = r.PostFormValue("line2")
sponsorSlideshow.Image = r.PostFormValue("image")
sponsorSlideshow.Priority = r.PostFormValue("priority")
err = db.SaveSponsorSlideshow(sponsorSlideshow)
}
if err != nil {
handleWebErr(w, err)
return
}
}
http.Redirect(w, r, "/setup/sponsor_slideshow", 302)
}

49
sponsor_slide.go Normal file
View File

@@ -0,0 +1,49 @@
// Copyright 2014 Team 254. All Rights Reserved.
// Author: nick@team254.com (Nick Eyre)
//
// Model and datastore CRUD methods for the sponsor slideshow.
package main
type SponsorSlide struct {
Id int
Subtitle string
Line1 string
Line2 string
Image string
Priority string
}
func (database *Database) CreateSponsorSlide(sponsorSlide *SponsorSlide) error {
return database.sponsorSlideMap.Insert(sponsorSlide)
}
func (database *Database) GetSponsorSlideById(id int) (*SponsorSlide, error) {
sponsorSlide := new(SponsorSlide)
err := database.sponsorSlideMap.Get(sponsorSlide, id)
if err != nil && err.Error() == "sql: no rows in result set" {
sponsorSlide = nil
err = nil
}
return sponsorSlide, err
}
func (database *Database) SaveSponsorSlide(sponsorSlide *SponsorSlide) error {
_, err := database.sponsorSlideMap.Update(sponsorSlide)
return err
}
func (database *Database) DeleteSponsorSlide(sponsorSlide *SponsorSlide) error {
_, err := database.sponsorSlideMap.Delete(sponsorSlide)
return err
}
func (database *Database) TruncateSponsorSlides() error {
return database.sponsorSlideMap.TruncateTables()
}
func (database *Database) GetAllSponsorSlides() ([]SponsorSlide, error) {
var sponsorSlides []SponsorSlide
err := database.teamMap.Select(&sponsorSlides, "SELECT * FROM sponsor_slides ORDER BY id")
return sponsorSlides, err
}

View File

@@ -1,49 +0,0 @@
// Copyright 2014 Team 254. All Rights Reserved.
// Author: nick@team254.com (Nick Eyre)
//
// Model and datastore CRUD methods for the sponsor slideshow.
package main
type SponsorSlideshow struct {
Id int
Subtitle string
Line1 string
Line2 string
Image string
Priority string
}
func (database *Database) CreateSponsorSlideshow(sponsorSlideshow *SponsorSlideshow) error {
return database.sponsorSlideshowMap.Insert(sponsorSlideshow)
}
func (database *Database) GetSponsorSlideshowById(id int) (*SponsorSlideshow, error) {
sponsorSlideshow := new(SponsorSlideshow)
err := database.sponsorSlideshowMap.Get(sponsorSlideshow, id)
if err != nil && err.Error() == "sql: no rows in result set" {
sponsorSlideshow = nil
err = nil
}
return sponsorSlideshow, err
}
func (database *Database) SaveSponsorSlideshow(sponsorSlideshow *SponsorSlideshow) error {
_, err := database.sponsorSlideshowMap.Update(sponsorSlideshow)
return err
}
func (database *Database) DeleteSponsorSlideshow(sponsorSlideshow *SponsorSlideshow) error {
_, err := database.sponsorSlideshowMap.Delete(sponsorSlideshow)
return err
}
func (database *Database) TruncateSponsorSlideshows() error {
return database.sponsorSlideshowMap.TruncateTables()
}
func (database *Database) GetAllSponsorSlideshows() ([]SponsorSlideshow, error) {
var sponsorSlideshows []SponsorSlideshow
err := database.teamMap.Select(&sponsorSlideshows, "SELECT * FROM sponsor_slideshow ORDER BY id")
return sponsorSlideshows, err
}

View File

@@ -317,13 +317,15 @@ var transitionSponsorToScore = function(callback) {
// Load and Prioritize Sponsor Data
var sponsors;
var sponsorIndex = [];
var lastSponsor;
var initializeSponsorDisplay = function() {
$.getJSON("/api/sponsors", function(data) {
$.getJSON("/api/sponsor_slides", function(data) {
sponsors = data;
// Invert Priorities
$.each(sponsors, function(index){
var priorityCount = 10 / sponsors[index]['Priority'];
var priorityCount = 10 / sponsors[index]["Priority"];
for(i=0; i<priorityCount; i++){
sponsorIndex.push(index);
}
@@ -333,32 +335,34 @@ var initializeSponsorDisplay = function() {
loadNextSponsor(true);
if(sponsors.length > 1)
loadNextSponsor();
$('.carousel#sponsor').on('slid.bs.carousel', function(){
$(".carousel#sponsor").on("slid.bs.carousel", function(){
loadNextSponsor();
$('#sponsorContainer').children()[0].remove();
$("#sponsorContainer").children()[0].remove();
});
});
}
var lastSponsor;
};
var loadNextSponsor = function(active) {
// Don't load same sponsor twice in a row
var currentSponsor = sponsorIndex[Math.round(Math.random()*sponsorIndex.length)];
while(currentSponsor == lastSponsor){
currentSponsor = sponsorIndex[Math.round(Math.random()*sponsorIndex.length)];
var currentSponsor = sponsorIndex[Math.round(Math.random() * sponsorIndex.length)];
while(currentSponsor == lastSponsor) {
currentSponsor = sponsorIndex[Math.round(Math.random() * sponsorIndex.length)];
}
lastSponsor = currentSponsor;
currentSponsor = sponsors[currentSponsor];
if(active == true)
active = 'active'
else
active = '';
if(currentSponsor['Image'].length)
$('#sponsorContainer').append('<div class="item '+active+'"><img src="/static/img/sponsors/'+currentSponsor['Image']+'" /><h1>'+currentSponsor['Subtitle']+'</h1></div>');
else
$('#sponsorContainer').append('<div class="item '+active+'"><h2>'+currentSponsor['Line1']+'<br />'+currentSponsor['Line2']+'</h2><h1>'+currentSponsor['Subtitle']+'</h1></div>');
}
if (active == true) {
active = "active"
} else {
active = "";
}
if (currentSponsor["Image"].length) {
$("#sponsorContainer").append('<div class="item '+active+'"><img src="/static/img/sponsors/'+currentSponsor['Image']+'" /><h1>'+currentSponsor['Subtitle']+'</h1></div>');
} else {
$("#sponsorContainer").append('<div class="item '+active+'"><h2>'+currentSponsor['Line1']+'<br />'+currentSponsor['Line2']+'</h2><h1>'+currentSponsor['Subtitle']+'</h1></div>');
}
};
$(function() {

View File

@@ -26,7 +26,7 @@
<li><a href="/setup/schedule">Match Scheduling</a></li>
<li><a href="/setup/alliance_selection">Alliance Selection</a></li>
<li><a href="/setup/lower_thirds">Lower Thirds</a></li>
<li><a href="/setup/sponsor_slideshow">Sponsor Slideshow</a></li>
<li><a href="/setup/sponsor_slides">Sponsor Slides</a></li>
</ul>
</li>
<li class="dropdown">

View File

@@ -1,21 +1,21 @@
{{define "title"}}Sponsor Slideshow Configuration{{end}}
{{define "title"}}Sponsor Slides Configuration{{end}}
{{define "body"}}
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<div class="well">
<legend>Sponsor Slideshow Configuration</legend>
<legend>Sponsor Slides Configuration</legend>
<p>Place images in /static/img/sponsors/</p>
{{range $sponsorSlideshow := .SponsorSlideshow}}
<form class="form-horizontal existing" action="/setup/sponsor_slideshow" method="POST" data-priority="{{$sponsorSlideshow.Priority}}">
{{range $sponsorSlide := .SponsorSlides}}
<form class="form-horizontal existing" action="/setup/sponsor_slides" method="POST" data-priority="{{$sponsorSlide.Priority}}">
<div class="form-group">
<div class="col-lg-7">
<input type="hidden" name="id" value="{{$sponsorSlideshow.Id}}" />
<input type="text" class="form-control" name="image" value="{{$sponsorSlideshow.Image}}" placeholder="Image File Name" />
<input type="hidden" name="id" value="{{$sponsorSlide.Id}}" />
<input type="text" class="form-control" name="image" value="{{$sponsorSlide.Image}}" placeholder="Image File Name" />
<div class='form-inline'>
<input type="text" class="form-control" name="line1" value="{{$sponsorSlideshow.Line1}}" placeholder="Line 1 Text" />
<input type="text" class="form-control" name="line2" value="{{$sponsorSlideshow.Line2}}" placeholder="Line 2 Text" />
<input type="text" class="form-control" name="line1" value="{{$sponsorSlide.Line1}}" placeholder="Line 1 Text" />
<input type="text" class="form-control" name="line2" value="{{$sponsorSlide.Line2}}" placeholder="Line 2 Text" />
</div>
<input type="text" class="form-control" name="subtitle" value="{{$sponsorSlideshow.Subtitle}}" placeholder="Subtitle Text" />
<input type="text" class="form-control" name="subtitle" value="{{$sponsorSlide.Subtitle}}" placeholder="Subtitle Text" />
<label class="radio-inline">
<input type="radio" name="priority" value="1"> 1 (Show Often)
</label>
@@ -40,7 +40,7 @@
</div>
</form>
{{end}}
<form class="form-horizontal" action="/setup/sponsor_slideshow" method="POST">
<form class="form-horizontal" action="/setup/sponsor_slides" method="POST">
<div class="form-group">
<div class="col-lg-7">
<input type="text" class="form-control" name="image" placeholder="Image File Name" />

6
web.go
View File

@@ -126,9 +126,9 @@ func newHandler() http.Handler {
router.HandleFunc("/setup/field/reload_displays", FieldReloadDisplaysHandler).Methods("GET")
router.HandleFunc("/setup/lower_thirds", LowerThirdsGetHandler).Methods("GET")
router.HandleFunc("/setup/lower_thirds", LowerThirdsPostHandler).Methods("POST")
router.HandleFunc("/setup/sponsor_slideshow", SponsorSlideshowGetHandler).Methods("GET")
router.HandleFunc("/setup/sponsor_slideshow", SponsorSlideshowPostHandler).Methods("POST")
router.HandleFunc("/api/sponsors", SponsorsApiHandler).Methods("GET")
router.HandleFunc("/setup/sponsor_slides", SponsorSlidesGetHandler).Methods("GET")
router.HandleFunc("/setup/sponsor_slides", SponsorSlidesPostHandler).Methods("POST")
router.HandleFunc("/api/sponsor_slides", SponsorSlidesApiHandler).Methods("GET")
router.HandleFunc("/match_play", MatchPlayHandler).Methods("GET")
router.HandleFunc("/match_play/{matchId}/load", MatchPlayLoadHandler).Methods("GET")
router.HandleFunc("/match_play/{matchId}/show_result", MatchPlayShowResultHandler).Methods("GET")