78 lines
1.4 KiB
Elm
78 lines
1.4 KiB
Elm
module ClassSchedule.Model exposing (..)
|
|
import Dict exposing (..)
|
|
|
|
type Department
|
|
= ComputerScience
|
|
| Mathematics
|
|
| Art
|
|
| Biology
|
|
|
|
type alias Crn = (Department, Int)
|
|
|
|
type DayOfWeek
|
|
= Monday
|
|
| Tuesday
|
|
| Wednesday
|
|
| Thursday
|
|
| Friday
|
|
| Saturday
|
|
| Sunday
|
|
|
|
type DayHalf = AM | PM
|
|
|
|
type alias Time = (Int, Int, DayHalf)
|
|
|
|
flipDayHalf : DayHalf -> DayHalf
|
|
flipDayHalf dh =
|
|
case dh of
|
|
AM -> PM
|
|
PM -> AM
|
|
|
|
addHours : Int -> Time -> Time
|
|
addHours hh (h, m, dh) =
|
|
if h + hh >= 12
|
|
then (h + hh - 12, m, flipDayHalf dh)
|
|
else (h + hh, m, dh)
|
|
|
|
addMinutes : Int -> Time -> Time
|
|
addMinutes mm (h, m, dh) =
|
|
let
|
|
remainder = modBy 60 (m + mm)
|
|
hh = (m + mm) // 60
|
|
in
|
|
addHours hh (h, remainder, dh)
|
|
|
|
type alias Course =
|
|
{ crn : Crn
|
|
, name : String
|
|
, instructors : List String
|
|
, times : List (DayOfWeek, Time, Time)
|
|
}
|
|
|
|
type CourseStatus = None | Selected | Added
|
|
|
|
isSelected : CourseStatus -> Bool
|
|
isSelected cs =
|
|
case cs of
|
|
Selected -> True
|
|
_ -> False
|
|
|
|
isAdded : CourseStatus -> Bool
|
|
isAdded cs =
|
|
case cs of
|
|
Added -> True
|
|
_ -> False
|
|
|
|
type alias Flags = ()
|
|
|
|
type Msg
|
|
= SearchInput String
|
|
| SelectTerm String
|
|
| MarkCourse Int CourseStatus
|
|
|
|
type alias Model =
|
|
{ terms : Dict String (List (CourseStatus, Course))
|
|
, term : String
|
|
, searchInput : String
|
|
}
|