96 lines
3.0 KiB
Elm
96 lines
3.0 KiB
Elm
module Main exposing (..)
|
|
import ClassSchedule.Model exposing (..)
|
|
import ClassSchedule.View exposing (..)
|
|
import Browser exposing (Document, document)
|
|
import Dict exposing (..)
|
|
import Tuple exposing (..)
|
|
|
|
oneHour : Time -> (Time, Time)
|
|
oneHour t = (t, addMinutes 50 t)
|
|
|
|
twoHours : Time -> (Time, Time)
|
|
twoHours t = (t, addMinutes 110 t)
|
|
|
|
nAm : Int -> Time
|
|
nAm i = (i, 0, AM)
|
|
|
|
nPm : Int -> Time
|
|
nPm i = (i, 0, PM)
|
|
|
|
onDays : List DayOfWeek -> (Time, Time) -> List (DayOfWeek, Time, Time)
|
|
onDays dds (t1, t2) = List.map (\d -> (d, t1, t2)) dds
|
|
|
|
classes : List Course
|
|
classes =
|
|
[ { crn = (ComputerScience, 517)
|
|
, name = "Theory of Comp"
|
|
, instructors = ["Mike Rosulek"]
|
|
, times = onDays [Monday, Wednesday, Friday] <| oneHour <| nPm 2
|
|
}
|
|
, { crn = (ComputerScience, 531)
|
|
, name = "Artificial Intelligence"
|
|
, instructors = ["John Doe"]
|
|
, times = onDays [Monday, Wednesday, Friday] <| oneHour <| nPm 0
|
|
}
|
|
, { crn = (ComputerScience, 533)
|
|
, name = "Intelligent Somethings"
|
|
, instructors = ["Alan Fern"]
|
|
, times = onDays [Monday, Wednesday] <| twoHours <| nAm 10
|
|
}
|
|
, { crn = (ComputerScience, 535)
|
|
, name = "Deep Learning"
|
|
, instructors = ["F. Li"]
|
|
, times = onDays [Tuesday, Thursday] <| twoHours <| nPm 2
|
|
}
|
|
, { crn = (ComputerScience, 551)
|
|
, name = "Computer Graphics"
|
|
, instructors = ["Mike Bailey"]
|
|
, times = onDays [Monday, Wednesday] <| twoHours <| nPm 0
|
|
}
|
|
, { crn = (ComputerScience, 565)
|
|
, name = "Human-Computer Interaction"
|
|
, instructors = ["Minsuk Kahng"]
|
|
, times = onDays [Tuesday, Thursday] <| twoHours <| nPm 4
|
|
}
|
|
]
|
|
|
|
terms : Dict String (List (CourseStatus, Course))
|
|
terms = Dict.singleton "Spring 2021"
|
|
<| List.map (pair NotAdded) classes
|
|
|
|
init : Flags -> (Model, Cmd Msg)
|
|
init () = ({ terms = terms, term = "Spring 2021", searchInput = "", selected = Nothing }, Cmd.none)
|
|
|
|
view : Model -> Document Msg
|
|
view m =
|
|
{ title = "Course Scheduler"
|
|
, body = [ viewModel m ]
|
|
}
|
|
|
|
modifyCurrent : (List (CourseStatus, Course) -> List (CourseStatus, Course)) -> Model -> Model
|
|
modifyCurrent f m = { m | terms = Dict.update (m.term) (Maybe.map f) (m.terms) }
|
|
|
|
changeCourse : Int -> CourseStatus -> List (CourseStatus, Course) -> List (CourseStatus, Course)
|
|
changeCourse i ncs =
|
|
let updateCourses j (cs, c) = if i == j then (ncs, c) else (cs, c)
|
|
in List.indexedMap updateCourses
|
|
|
|
update : Msg -> Model -> (Model, Cmd Msg)
|
|
update msg m =
|
|
case msg of
|
|
SelectCourse i -> ({ m | selected = Just i}, Cmd.none)
|
|
AddCourse i -> (modifyCurrent (changeCourse i Added) m, Cmd.none)
|
|
RemoveCourse i -> (modifyCurrent (changeCourse i NotAdded) m, Cmd.none)
|
|
SearchInput s -> ({ m | searchInput = s }, Cmd.none)
|
|
_ -> (m, Cmd.none)
|
|
|
|
subscriptions : Model -> Sub Msg
|
|
subscriptions m = Sub.none
|
|
|
|
main = document
|
|
{ init = init
|
|
, view = view
|
|
, update = update
|
|
, subscriptions = subscriptions
|
|
}
|