Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow first day of week to be Sunday or Monday #3093

Merged
merged 8 commits into from Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions asset/assets_vfsdata.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions ui/app/index.html
Expand Up @@ -20,6 +20,7 @@
var app = Elm.Main.init({
flags: {
production: true,
firstDayOfWeek: JSON.parse(localStorage.getItem('firstDayOfWeek')),
defaultCreator: localStorage.getItem('defaultCreator'),
groupExpandAll: JSON.parse(localStorage.getItem('groupExpandAll'))
}
Expand All @@ -30,6 +31,9 @@
app.ports.persistGroupExpandAll.subscribe(function(expanded) {
localStorage.setItem('groupExpandAll', JSON.stringify(expanded));
});
app.ports.persistFirstDayOfWeek.subscribe(function(firstDayOfWeek) {
localStorage.setItem('firstDayOfWeek', JSON.stringify(firstDayOfWeek));
});
</script>
</body>
</html>
21 changes: 20 additions & 1 deletion ui/app/src/Main.elm
Expand Up @@ -8,6 +8,7 @@ import Types exposing (Model, Msg(..), Route(..))
import Updates exposing (update)
import Url exposing (Url)
import Utils.Api as Api
import Utils.DateTimePicker.Utils exposing (FirstDayOfWeek(..))
import Utils.Filter exposing (nullFilter)
import Utils.Types exposing (ApiData(..))
import Views
Expand Down Expand Up @@ -86,12 +87,25 @@ init flags url key =

else
"/"

firstDayOfWeek =
flags
|> Json.decodeValue (Json.field "firstDayOfWeek" Json.string)
|> Result.withDefault "Monday"
Git-Jiro marked this conversation as resolved.
Show resolved Hide resolved
|> (\d ->
case d of
"Sunday" ->
Sunday

_ ->
Monday
)
in
update (urlUpdate url)
(Model
(initSilenceList key)
(initSilenceView key)
(initSilenceForm key)
(initSilenceForm key firstDayOfWeek)
(initAlertList key groupExpandAll)
route
filter
Expand All @@ -105,6 +119,8 @@ init flags url key =
defaultCreator
groupExpandAll
key
{ firstDayOfWeek = firstDayOfWeek
}
)


Expand Down Expand Up @@ -133,6 +149,9 @@ urlUpdate url =
StatusRoute ->
NavigateToStatus

SettingsRoute ->
NavigateToSettings

TopLevelRoute ->
RedirectAlerts

Expand Down
2 changes: 2 additions & 0 deletions ui/app/src/Parsing.elm
Expand Up @@ -5,6 +5,7 @@ import Types exposing (Route(..))
import Url exposing (Url)
import Url.Parser exposing (Parser, map, oneOf, parse, top)
import Views.AlertList.Parsing exposing (alertsParser)
import Views.Settings.Parsing exposing (settingsViewParser)
import Views.SilenceForm.Parsing exposing (silenceFormEditParser, silenceFormNewParser)
import Views.SilenceList.Parsing exposing (silenceListParser)
import Views.SilenceView.Parsing exposing (silenceViewParser)
Expand Down Expand Up @@ -46,6 +47,7 @@ routeParser =
oneOf
[ map SilenceListRoute silenceListParser
, map StatusRoute statusParser
, map SettingsRoute settingsViewParser
, map SilenceFormNewRoute silenceFormNewParser
, map SilenceViewRoute silenceViewParser
, map SilenceFormEditRoute silenceFormEditParser
Expand Down
5 changes: 5 additions & 0 deletions ui/app/src/Types.elm
Expand Up @@ -4,6 +4,7 @@ import Browser.Navigation exposing (Key)
import Utils.Filter exposing (Filter, SilenceFormGetParams)
import Utils.Types exposing (ApiData)
import Views.AlertList.Types as AlertList exposing (AlertListMsg)
import Views.Settings.Types as SettingsView exposing (SettingsMsg)
import Views.SilenceForm.Types as SilenceForm exposing (SilenceFormMsg)
import Views.SilenceList.Types as SilenceList exposing (SilenceListMsg)
import Views.SilenceView.Types as SilenceView exposing (SilenceViewMsg)
Expand All @@ -27,6 +28,7 @@ type alias Model =
, defaultCreator : String
, expandAll : Bool
, key : Key
, settings : SettingsView.Model
}


Expand All @@ -36,13 +38,15 @@ type Msg
| MsgForSilenceForm SilenceFormMsg
| MsgForSilenceList SilenceListMsg
| MsgForStatus StatusMsg
| MsgForSettings SettingsMsg
| NavigateToAlerts Filter
| NavigateToNotFound
| NavigateToSilenceView String
| NavigateToSilenceFormEdit String
| NavigateToSilenceFormNew SilenceFormGetParams
| NavigateToSilenceList Filter
| NavigateToStatus
| NavigateToSettings
| NavigateToInternalUrl String
| NavigateToExternalUrl String
| RedirectAlerts
Expand All @@ -62,3 +66,4 @@ type Route
| SilenceViewRoute String
| StatusRoute
| TopLevelRoute
| SettingsRoute
11 changes: 11 additions & 0 deletions ui/app/src/Updates.elm
Expand Up @@ -5,6 +5,7 @@ import Task
import Types exposing (Model, Msg(..), Route(..))
import Views.AlertList.Types exposing (AlertListMsg(..))
import Views.AlertList.Updates
import Views.Settings.Updates
import Views.SilenceForm.Types exposing (SilenceFormMsg(..))
import Views.SilenceForm.Updates
import Views.SilenceList.Types exposing (SilenceListMsg(..))
Expand Down Expand Up @@ -66,6 +67,9 @@ update msg ({ basePath, apiUrl } as model) =
RedirectAlerts ->
( model, Navigation.pushUrl model.key (basePath ++ "#/alerts") )

NavigateToSettings ->
( { model | route = SettingsRoute }, Cmd.none )

MsgForStatus subMsg ->
Views.Status.Updates.update subMsg model

Expand All @@ -83,6 +87,13 @@ update msg ({ basePath, apiUrl } as model) =
in
( { model | silenceList = silenceList }, Cmd.map MsgForSilenceList cmd )

MsgForSettings subMsg ->
let
( settingsView, cmd ) =
Views.Settings.Updates.update subMsg model.settings
in
( { model | settings = settingsView }, cmd )

MsgForSilenceView subMsg ->
let
( silenceView, cmd ) =
Expand Down
13 changes: 8 additions & 5 deletions ui/app/src/Utils/DateTimePicker/Types.elm
Expand Up @@ -8,7 +8,7 @@ module Utils.DateTimePicker.Types exposing
)

import Time exposing (Posix)
import Utils.DateTimePicker.Utils exposing (floorMinute)
import Utils.DateTimePicker.Utils exposing (FirstDayOfWeek, floorMinute)


type alias DateTimePicker =
Expand All @@ -18,6 +18,7 @@ type alias DateTimePicker =
, endDate : Maybe Posix
, startTime : Maybe Posix
, endTime : Maybe Posix
, firstDayOfWeek : FirstDayOfWeek
}


Expand All @@ -41,19 +42,20 @@ type InputHourOrMinute
| InputMinute


initDateTimePicker : DateTimePicker
initDateTimePicker =
initDateTimePicker : FirstDayOfWeek -> DateTimePicker
initDateTimePicker firstDayOfWeek =
{ month = Nothing
, mouseOverDay = Nothing
, startDate = Nothing
, endDate = Nothing
, startTime = Nothing
, endTime = Nothing
, firstDayOfWeek = firstDayOfWeek
}


initFromStartAndEndTime : Maybe Posix -> Maybe Posix -> DateTimePicker
initFromStartAndEndTime start end =
initFromStartAndEndTime : Maybe Posix -> Maybe Posix -> FirstDayOfWeek -> DateTimePicker
initFromStartAndEndTime start end firstDayOfWeek =
let
startTime =
Maybe.map (\s -> floorMinute s) start
Expand All @@ -67,4 +69,5 @@ initFromStartAndEndTime start end =
, endDate = end
, startTime = startTime
, endTime = endTime
, firstDayOfWeek = firstDayOfWeek
}
33 changes: 28 additions & 5 deletions ui/app/src/Utils/DateTimePicker/Utils.elm
@@ -1,5 +1,6 @@
module Utils.DateTimePicker.Utils exposing
( addHour
( FirstDayOfWeek(..)
, addHour
, addMinute
, firstDayOfNextMonth
, firstDayOfPrevMonth
Expand All @@ -21,8 +22,13 @@ import Time exposing (Month(..), Posix, Weekday(..), utc)
import Time.Extra as Time exposing (Interval(..))


listDaysOfMonth : Posix -> List Posix
listDaysOfMonth time =
type FirstDayOfWeek
= Monday
| Sunday


listDaysOfMonth : Posix -> FirstDayOfWeek -> List Posix
listDaysOfMonth time firstDayOfWeek =
let
firstOfMonth =
Time.floor Time.Month utc time
Expand All @@ -33,17 +39,34 @@ listDaysOfMonth time =
padFront =
weekToInt (Time.toWeekday utc firstOfMonth)
|> (\wd ->
if wd == 7 then
if firstDayOfWeek == Sunday then
if wd == 7 then
0

else
wd

else if wd == 1 then
0

else
wd
wd - 1
)
|> (\w -> Time.add Time.Day -w utc firstOfMonth)
|> (\d -> Time.range Time.Day 1 utc d firstOfMonth)

padBack =
weekToInt (Time.toWeekday utc firstOfNextMonth)
|> (\wd ->
if firstDayOfWeek == Sunday then
wd

else if wd == 1 then
7

else
wd - 1
)
|> (\w -> Time.add Time.Day (7 - w) utc firstOfNextMonth)
|> Time.range Time.Day 1 utc firstOfNextMonth
in
Expand Down
12 changes: 9 additions & 3 deletions ui/app/src/Utils/DateTimePicker/Views.elm
Expand Up @@ -9,7 +9,8 @@ import Time exposing (Posix, utc)
import Utils.DateTimePicker.Types exposing (DateTimePicker, InputHourOrMinute(..), Msg(..), StartOrEnd(..))
import Utils.DateTimePicker.Utils
exposing
( floorDate
( FirstDayOfWeek(..)
, floorDate
, floorMonth
, listDaysOfMonth
, monthToString
Expand Down Expand Up @@ -80,14 +81,19 @@ viewMonth : DateTimePicker -> Posix -> Html Msg
viewMonth dateTimePicker justViewTime =
let
days =
listDaysOfMonth justViewTime
listDaysOfMonth justViewTime dateTimePicker.firstDayOfWeek

weeks =
splitWeek days []
in
div [ class "row justify-content-center" ]
[ div [ class "weekheader" ]
(List.map viewWeekHeader [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ])
(if dateTimePicker.firstDayOfWeek == Sunday then
Git-Jiro marked this conversation as resolved.
Show resolved Hide resolved
List.map viewWeekHeader [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ]

else
List.map viewWeekHeader [ "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" ]
)
, div
[ class "date-container"
, onMouseOut ClearMouseOverDay
Expand Down
4 changes: 4 additions & 0 deletions ui/app/src/Views.elm
Expand Up @@ -11,6 +11,7 @@ import Utils.Views
import Views.AlertList.Views as AlertList
import Views.NavBar.Views exposing (navBar)
import Views.NotFound.Views as NotFound
import Views.Settings.Views as SettingsView
import Views.SilenceForm.Views as SilenceForm
import Views.SilenceList.Views as SilenceList
import Views.SilenceView.Views as SilenceView
Expand Down Expand Up @@ -74,6 +75,9 @@ cssNode url msg =
currentView : Model -> Html Msg
currentView model =
case model.route of
SettingsRoute ->
SettingsView.view model.settings |> Html.map MsgForSettings

StatusRoute ->
Status.view model.status

Expand Down
9 changes: 7 additions & 2 deletions ui/app/src/Views/NavBar/Types.elm
@@ -1,4 +1,4 @@
module Views.NavBar.Types exposing (Tab, alertsTab, noneTab, silencesTab, statusTab, tabs)
module Views.NavBar.Types exposing (Tab, alertsTab, noneTab, settingsTab, silencesTab, statusTab, tabs)


type alias Tab =
Expand All @@ -22,6 +22,11 @@ statusTab =
{ link = "#/status", name = "Status" }


settingsTab : Tab
settingsTab =
{ link = "#/settings", name = "Settings" }


helpTab : Tab
helpTab =
{ link = "https://prometheus.io/docs/alerting/alertmanager/", name = "Help" }
Expand All @@ -34,4 +39,4 @@ noneTab =

tabs : List Tab
tabs =
[ alertsTab, silencesTab, statusTab, helpTab ]
[ alertsTab, silencesTab, statusTab, settingsTab, helpTab ]
5 changes: 4 additions & 1 deletion ui/app/src/Views/NavBar/Views.elm
Expand Up @@ -3,7 +3,7 @@ module Views.NavBar.Views exposing (navBar)
import Html exposing (Html, a, div, header, li, nav, text, ul)
import Html.Attributes exposing (class, href, style, title)
import Types exposing (Route(..))
import Views.NavBar.Types exposing (Tab, alertsTab, noneTab, silencesTab, statusTab, tabs)
import Views.NavBar.Types exposing (Tab, alertsTab, noneTab, settingsTab, silencesTab, statusTab, tabs)


navBar : Route -> Html msg
Expand Down Expand Up @@ -82,3 +82,6 @@ routeToTab currentRoute =

TopLevelRoute ->
noneTab

SettingsRoute ->
settingsTab
8 changes: 8 additions & 0 deletions ui/app/src/Views/Settings/Parsing.elm
@@ -0,0 +1,8 @@
module Views.Settings.Parsing exposing (settingsViewParser)

import Url.Parser exposing (Parser, s)


settingsViewParser : Parser a a
settingsViewParser =
s "settings"
12 changes: 12 additions & 0 deletions ui/app/src/Views/Settings/Types.elm
@@ -0,0 +1,12 @@
module Views.Settings.Types exposing (..)

import Utils.DateTimePicker.Utils exposing (FirstDayOfWeek)


type alias Model =
{ firstDayOfWeek : FirstDayOfWeek
}


type SettingsMsg
= UpdateFirstDayOfWeek String