Skip to content

Commit

Permalink
Made Major Updates to Leath's List, Added Browsing
Browse files Browse the repository at this point in the history
  • Loading branch information
jhleath committed Apr 13, 2014
1 parent ab56292 commit ade941d
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 16 deletions.
74 changes: 66 additions & 8 deletions app/controllers/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (
"github.com/huntaub/list/app/routes"
"github.com/huntaub/list/schedule"
"github.com/robfig/revel"
"labix.org/v2/mgo"
"net/http"
"regexp"
"sort"
"strconv"
"strings"
"time"
Expand All @@ -17,7 +19,14 @@ var classList schedule.ClassList
var lastUpdate time.Time
var classRegex, sectionRegex *regexp.Regexp

var collection *mgo.Collection
var users *mgo.Collection

func init() {
session, _ := mgo.Dial("mongodb://leath:hunter0813@oceanic.mongohq.com:10000/list")
collection = session.DB("list").C("classes")
users = session.DB("list").C("users")

f := func(now time.Time) {
fmt.Println("Updating Lou's List at", now)
// fi, err := os.Open("/Users/hunter/Documents/Developer/golang/src/list/app/cache/complete_schedule.html")
Expand All @@ -35,6 +44,7 @@ func init() {
if err != nil {
panic(err)
}
classList.SaveToDB(collection)
lastUpdate = now
}
go func() {
Expand Down Expand Up @@ -73,36 +83,82 @@ func init() {
revel.TemplateFuncs["lastUpdated"] = func() string {
return lastUpdate.Format("January 2, 3:04PM")
}

revel.TemplateFuncs["classPanel"] = func(c *schedule.Class) string {
totalCapacity := 0.0
totalEnrollment := 0.0
for _, v := range c.Sections {
totalCapacity += float64(v.Capacity)
totalEnrollment += float64(v.Enrollment)
}
if totalEnrollment/totalCapacity >= 0.75 {
return "panel-danger"
} else if totalEnrollment/totalCapacity >= 0.5 {
return "panel-warning"
}
return "panel-default"
}

revel.TemplateFuncs["sectionBorder"] = func(v *schedule.Section) string {
totalEnrollment := float64(v.Enrollment)
totalCapacity := float64(v.Capacity)
if totalEnrollment/totalCapacity >= 0.75 {
return "border-danger"
} else if totalEnrollment/totalCapacity >= 0.5 {
return "border-warning"
}
return "border-default"
}
}

type App struct {
*revel.Controller
}

func (c App) Index() revel.Result {
return c.Render()
var result []string
err := collection.Find(nil).Distinct("department", &result)
if err != nil {
panic(err)
}

sort.Sort(sort.StringSlice(result))

return c.Render(result)
}

func (c App) NotFound() revel.Result {
return c.Render()
}

func (c App) Class(dept string, num string) revel.Result {
cl, ok := classList[dept+" "+num]
//"sections":{"$elemMatch":{"sisnumber":10120}}

if !ok {
func (c App) Class(dept string, num int) revel.Result {
var class *schedule.Class
err := collection.Find(map[string]interface{}{"department": dept, "number": num}).One(&class)
if err != nil {
fmt.Println(err)
return c.Redirect(routes.App.NotFound())
}

c.RenderArgs = map[string]interface{}{
"class": cl,
"ok": ok,
"class": class,
"lastUpdated": lastUpdate,
}

return c.Render()
}

func (c App) Department(dept string) revel.Result {
var classes []schedule.Class
err := collection.Find(map[string]string{"department": dept}).Sort("number").All(&classes)
if err != nil {
panic(err)
}

return c.Render(classes, dept)
}

func (c App) Search(class string) revel.Result {
revel.INFO.Printf("Searching %s", class)

Expand All @@ -118,7 +174,8 @@ func (c App) Search(class string) revel.Result {
return c.Redirect(routes.App.NotFound())
} else {
comp := strings.Split(lookup, " ")
return c.Redirect(routes.App.Class(comp[0], comp[1]))
number, _ := strconv.Atoi(comp[1])
return c.Redirect(routes.App.Class(comp[0], number))
}
}

Expand All @@ -127,7 +184,8 @@ func (c App) SchedulesFromList(list string, stop chan bool) ([]*schedule.Schedul
if len(matches) < 0 {
return nil, c.Redirect(routes.App.NotFound())
} else if len(matches) == 1 {
return nil, c.Redirect(routes.App.Class(strings.ToUpper(matches[0][1]), matches[0][2]))
number, _ := strconv.Atoi(matches[0][2])
return nil, c.Redirect(routes.App.Class(strings.ToUpper(matches[0][1]), number))
}
schedulizer := schedule.CreateSchedulizer()

Expand Down
5 changes: 1 addition & 4 deletions app/views/App/Class.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ <h5>{{ len .class.ValidClassTimes }} Valid Classes - {{ len .class.Sections }} S

<div class="actions">
<a href="http://www.hoosbooks.com/#!{{ .class.Department }}-{{ .class.Number }}-55" class="btn btn-success">Purchase Textbooks</a>
<a href="https://evals.itc.virginia.edu/course-selectionguide/pages/SGMain.jsp?cmp={{ .class.Department }},{{ .class.Number }}," class="btn btn-primary">Course Evals</a>
</div>

<div class="row">
Expand Down Expand Up @@ -40,10 +41,6 @@ <h5>{{ len .class.ValidClassTimes }} Valid Classes - {{ len .class.Sections }} S
</div>
{{ end }}
</div>
<!-- <h3>Valid Class Times</h3>
{{ range .class.ValidClassTimes }}
<p>{{ . }}</p>
{{ end }} -->
<p>Last Updated - {{ .lastUpdated.Format "January 2, 3:04PM" }}</p>
</div>
</div>
Expand Down
72 changes: 72 additions & 0 deletions app/views/App/Department.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{{set . "title" .dept }}
{{template "header.html" .}}

<div class="container" id="main">
<br/>
{{ range .classes }}
<div class="panel panel-default">
<div class="panel-heading">
<h4><a href="/class/{{ .Department }}/{{ .Number }}">{{ .Department }} {{ .Number }}</a> - <strong>{{ .Name }}</strong> <a href="#" class="pull-right slider"><i class="fa {{ if or (eq .Name "Independent Study") (eq .Name "Capstone Research") }}fa-plus-square{{ else }}fa-minus-square{{ end }}"></i></a></h4>
</div>
<div class="list-group" {{ if or (eq .Name "Independent Study") (eq .Name "Capstone Research") }}style="display:none;"{{ end }}>
{{ range .Sections }}
<div class="list-group-item {{ sectionBorder . }}">
<div class="row">
<div class="col-xs-1">
<strong>{{ .SISNumber }}</strong>
</div>
<div class="col-xs-5">
<p>
{{ .Number }} - <i>{{.Type}}</i> <br/>
{{ .Topic }}
</p>
</div>
<div class="col-xs-6">
{{ range .Meetings }}
<p style="margin: 0;">
{{ if .Days.ContainsString "M" }}M{{ else }}_{{ end }}
{{ if .Days.ContainsString "T" }}T{{ else }}_{{ end }}
{{ if .Days.ContainsString "W" }}W{{ else }}_{{ end }}
{{ if .Days.ContainsString "R" }}R{{ else }}_{{ end }}
{{ if .Days.ContainsString "F" }}F{{ else }}_{{ end }}
{{ if .Days.ContainsString "S" }}S{{ else }}{{ end }}
- {{ .StartTime.Format "3:04PM" }} to {{ .EndTime.Format "3:04PM" }}
<a href="http://www.ratemyprofessors.com/SelectTeacher.jsp?searchName={{ lastName .Instructor }}&search_submit1=Search&sid=1277">{{ .Instructor }}</a> <span class="text-muted">{{ .Location }}</span>
</p>
{{ end }}
</div>
</div>
{{ .Enrollment }} <span class="text-muted">students</span> / {{ .Capacity }} <span class="text-muted">seats</span>
</div>
{{ end }}
</div>

<div class="panel-footer">
<a href="http://www.hoosbooks.com/#!{{ .Department }}-{{ .Number }}-55" class="btn btn-link btn-xs">Purchase Textbooks</a>
<a href="https://evals.itc.virginia.edu/course-selectionguide/pages/SGMain.jsp?cmp={{ .Department }},{{ .Number }}," class="btn btn-link btn-xs">Course Evals</a>
<!-- <a href="https://evals.itc.virginia.edu/course-selectionguide/pages/SGMain.jsp?cmp={{ .Department }},{{ .Number }}," class="btn btn-success btn-xs pull-right">+ Add to My Class List</a> -->
</div>
</div>
{{ else }}
<h1>Sorry, couldn't find any classes for that department.</h1>
{{ end }}
</div>

<script>
$(document).ready(function() {
$(".slider").click(function() {
if ($(this).children("i").hasClass("fa-plus-square")) {
$(this).parent().parent().parent().children(".list-group").slideDown();
$(this).children("i").removeClass("fa-plus-square");
$(this).children("i").addClass("fa-minus-square");
} else {
$(this).parent().parent().parent().children(".list-group").slideUp();
$(this).children("i").removeClass("fa-minus-square");
$(this).children("i").addClass("fa-plus-square");
}
return false;
});
});
</script>

{{template "footer.html" .}}
43 changes: 40 additions & 3 deletions app/views/App/Index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
{{set . "title" "Leath's List"}}
{{template "header.html" .}}

<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="/public/js/triangles.js"></script>
<script>
$(document).ready(function() {
var t = new Trianglify({
x_gradient: colorbrewer.PuOr[9],
});
var pattern = t.generate(document.body.clientWidth, 500);
$(".hero-unit")[0].setAttribute('style', 'background-image: '+pattern.dataUrl + '; background-repeat: none; background-size: 100%;');
});
</script>
<style>
@media(max-width: 960px;) {
.hero-unit {
background-width: 960px;
}
}
</style>

<div class="hero-unit" id="main">
<div class="container">
<!-- <h1>Find information on classes.</h1> -->
Expand Down Expand Up @@ -37,9 +56,6 @@

<div class="container">
<br/>
<div class="alert alert-warning">
<strong>NEW</strong> You may select specific sections of classes like this `STS 2500:{1}`, and classes on the schedule now have borders that reflect how full they are.
</div>
<div class="row">
<div class="col-md-4">
<h3>Why?</h3>
Expand All @@ -54,6 +70,27 @@ <h3>Contribute</h3>
<p>Help make class registration and scheduling the best at UVa by building applications on top of our Class API (to be released soon).</p>
</div>
</div>

<hr/>

<h2>Browse</h2>

<!-- <div class="input-group">
<input type="text" class="form-control input-lg" placeholder="ECON" name="userList">
<span class="input-group-btn">
<input class="btn btn-primary btn-lg" id="go" type="submit" value="Go"/>
</span>
</div>
<br/> -->

<div class="row">
{{ range .result }}
<div class="col-xs-3 col-sm-1">
<a href="/department/{{ . }}" style="margin-bottom: 15px;">{{ . }}</a>
</div>
{{ end }}
</div>

<br/>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Leath's List -->
Expand Down
1 change: 1 addition & 0 deletions app/views/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<link rel="stylesheet" type="text/css" href="/public/css/main.css">
<link rel="shortcut icon" type="image/png" href="/public/img/favicon.png">
<script src="http://code.jquery.com/jquery-1.9.1.min.js" type="text/javascript" charset="utf-8"></script>
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
{{range .moreStyles}}
<link rel="stylesheet" type="text/css" href="/public/{{.}}">
Expand Down
2 changes: 2 additions & 0 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ GET / App.Index
GET /class/none App.NotFound
GET /class/:dept/:num App.Class

GET /department/:dept App.Department

GET /schedule/:perm/:num App.Schedule

POST /search App.Search
Expand Down
12 changes: 12 additions & 0 deletions public/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,16 @@ form#classSearch {
.text-small {
font-size: 90%;
color: #535353;
}

.border-danger {
border-left: solid 7px #e62426 !important;
}

.border-warning {
border-left: solid 5px #e0d916 !important;
}

.border-default {
border-left: solid 3px #23a020 !important;
}
1 change: 1 addition & 0 deletions public/js/triangles.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion schedule/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Class struct {
Department string
Number int
Sections SectionList
SectionMap map[int]*Section
SectionMap map[int]*Section `bson:"-,omitempty"`
}

type Section struct {
Expand Down
10 changes: 10 additions & 0 deletions schedule/db.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package schedule

import "labix.org/v2/mgo"

func (c ClassList) SaveToDB(collection *mgo.Collection) {
// collection.RemoveAll(nil)
// for _, v := range c {
// collection.Insert(v)
// }
}

0 comments on commit ade941d

Please sign in to comment.