95 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			Elm
		
	
	
	
	
	
			
		
		
	
	
			95 lines
		
	
	
		
			2.9 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, 544)
 | 
						|
      , name = "Operating Systems II"
 | 
						|
      , instructors = ["Yeongjin Jang"]
 | 
						|
      , times = onDays [Tuesday, Thursday] <| oneHour <| nAm 8
 | 
						|
      }
 | 
						|
    , { crn = (ComputerScience, 480)
 | 
						|
      , name = "Translators"
 | 
						|
      , instructors = ["Rob Hess"]
 | 
						|
      ,  times = onDays [Tuesday, Thursday] <| oneHour <| nAm 10
 | 
						|
      }
 | 
						|
    , { crn = (ComputerScience, 583)
 | 
						|
      , name = "Advanced Functional Programming"
 | 
						|
      , instructors = ["Eric Walkingshaw"]
 | 
						|
      , times = onDays [Monday, Wednesday] <| oneHour <| nAm 10
 | 
						|
      }
 | 
						|
    , { crn = (ComputerScience, 583)
 | 
						|
      , name = "Advanced Functional Programming"
 | 
						|
      , instructors = ["Eric Walkingshaw"]
 | 
						|
      , times = onDays [Monday, Wednesday] <| oneHour <| nAm 11
 | 
						|
      }
 | 
						|
    , { crn = (ComputerScience, 583)
 | 
						|
      , name = "Advanced Functional Programming"
 | 
						|
      , instructors = ["Eric Walkingshaw"]
 | 
						|
      , times = onDays [Monday, Wednesday] <| twoHours <| nAm 10
 | 
						|
      }
 | 
						|
    , { crn = (ComputerScience, 582)
 | 
						|
      , name = "Programming Languages II"
 | 
						|
      , instructors = ["Martin Erwig"]
 | 
						|
      , times = onDays [Monday, Wednesday] <| oneHour <| 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)
 | 
						|
        _ -> (m, Cmd.none)
 | 
						|
 | 
						|
subscriptions : Model -> Sub Msg
 | 
						|
subscriptions m = Sub.none
 | 
						|
 | 
						|
main = document
 | 
						|
    { init = init
 | 
						|
    , view = view
 | 
						|
    , update = update
 | 
						|
    , subscriptions = subscriptions
 | 
						|
    }
 |