Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Last active January 2, 2019 15:34
Show Gist options
  • Select an option

  • Save trikitrok/201a88170cd2807d71ed339473fc48ab to your computer and use it in GitHub Desktop.

Select an option

Save trikitrok/201a88170cd2807d71ed339473fc48ab to your computer and use it in GitHub Desktop.
(ns horizon.desktop.reports.dialogs.edit.settings.scheduling-section
(:require
[greenpowermonitor.re-om :as re-om]
[horizon.common.i18n.core :refer [i18n]]
[horizon.common.state.lens :as l]
[horizon.common.utils.collections :as utils.collections]
[horizon.common.utils.time.core :as utils.time]
[horizon.controls.utils.css-transitions-group :as css-transitions-group]
;; ...
[horizon.domain.reports.core :as domain.reports.core]
[horizon.domain.reports.dialogs.edit :as domain.reports.dialogs.edit]
[om.core :as om :include-macros true]
[sablono.core :refer-macros [html]]))
(defn- delay->interval
[{:keys [number unit]}]
(let [date-modes (l/view domain.reports.core/reports-options-date-selection-modes-data-lens)
{kw :Keyword} (utils.collections/find-by-kv-pair date-modes :Value unit)]
(get {"hour" {:hour number}
"day" {:day number}}
kw)))
(defn- get-next-generation [start-at delay-unit delay-number]
(when (and start-at delay-number delay-unit)
(let [interval (delay->interval {:number delay-number
:unit delay-unit})
next-date (utils.time/offset start-at interval)]
(utils.time/strftime next-date (i18n ::next-generation-date-format :format-vals [])))))
(defn main-view [_ owner]
(om/component
(html
(let [scheduling? (re-om/subscribe
[::domain.reports.dialogs.edit/field
::scheduling?]
owner)]
[:div.form-dialog__section.form-dialog__section--centered
[:div.form-dialog__switch
;; ...
]
[:div.form-dialog__title
[:strong (i18n ::scheduling-title)]]
(css-transitions-group/with-transition
:collapsible-card
(when scheduling?
(html
[:div
[:div.form-dialog__subtitle
;; ...
]
[:table.form-dialog__field-group
;; ...
]
(let [delay-unit (re-om/subscribe
[::domain.reports.dialogs.edit/field
::delay-generation-unit]
owner)
start-at (re-om/subscribe
[::domain.reports.dialogs.edit/field
::start-at]
owner)
delay-number (re-om/subscribe
[::domain.reports.dialogs.edit/field
::delay-generation-number]
owner)]
(when-let [next-generation (get-next-generation
start-at
delay-unit
delay-number)]
[:div.reports-edition-dialog__next-generation
[:p
(i18n ::next-generation) " "
[:strong next-generation] " (UTC)"]]))])))]))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment