Skip to content

Commit

Permalink
Merge pull request #94 from seki-seki/feature/scheduling-easy
Browse files Browse the repository at this point in the history
Feature/scheduling easy
  • Loading branch information
kawasima authored Jan 20, 2017
2 parents af7d361 + 364de2c commit 99f98db
Showing 1 changed file with 116 additions and 12 deletions.
128 changes: 116 additions & 12 deletions src/cljs/job_streamer/console/components/job_detail.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,32 @@
:batch-status/failed "red"
""))

(defn to-cron-expression-daily [hour]
(if (not-empty hour)
(str "0 0 " hour " * * ?")
""))

(defn to-cron-expression-weekly [hour day-of-week]
(if (and (not-empty hour) (not-empty day-of-week))
(str "0 0 " hour " ? * " day-of-week)
""))

(defn to-cron-expression-monthly[hour day]
(if (and (not-empty hour) (not-empty day))
(str "0 0 " hour " " day " * ?")
""))

(defn to-cron-expression[{:keys [schedule scheduling-type scheduling-hour scheduling-date scheduling-day-of-week]}]
(condp = scheduling-type
"Daily"
(to-cron-expression-daily scheduling-hour)
"Weekly"
(to-cron-expression-weekly scheduling-hour scheduling-day-of-week)
"Monthly"
(to-cron-expression-monthly scheduling-hour scheduling-date)
(:schedule/cron-notation schedule)))


;;;
;;; Om view components
;;;
Expand Down Expand Up @@ -182,7 +208,11 @@
(init-state [_]
{:error-ch (chan)
:has-error false
:schedule (:job/schedule job)})
:schedule (:job/schedule job)
:scheduling-type ""
:scheduling-hour ""
:scheduling-date ""
:scheduling-day-of-week "Sun"})

(will-mount [_]
(go
Expand All @@ -192,7 +222,7 @@
{:handler (fn [response]
(om/set-state! owner :calendars response))}))

(render-state [_ {:keys [schedule scheduling-ch calendars refresh-job-ch error-ch has-error]}]
(render-state [_ {:keys [schedule scheduling-ch calendars refresh-job-ch error-ch has-error scheduling-type scheduling-hour scheduling-date scheduling-day-of-week] :as state}]
(html
[:form.ui.form
(merge {:on-submit (fn [e]
Expand All @@ -205,19 +235,93 @@
[:div.ui.error.message
[:p has-error]])
[:div.fields
[:div.field (when has-error {:class "error"})
[:label "Quartz format"]
[:input {:id "cron-notation" :type "text" :placeholder "Quartz format"
:value (:schedule/cron-notation schedule)
:on-change (fn [e]
(let [value (.. js/document (getElementById "cron-notation") -value)]
(om/set-state! owner [:schedule :schedule/cron-notation] value)))}]]
[:div.field (when has-error {:class "error"})
[:label "Easy Scheduling"]
[:select {:id "scheduling-type"
:value (or scheduling-type "")
:on-change (fn [e]
(let [value (.. js/document (getElementById "scheduling-type") -value)]
(om/set-state! owner :scheduling-type value)
(om/set-state! owner [:schedule :schedule/cron-notation] (to-cron-expression (assoc state :scheduling-type value)))))}
[:option {:value ""} ""]
[:option {:value "Daily"} "Daily"]
[:option {:value "Weekly"} "Weekly"]
[:option {:value "Monthly"} "Monthly"]]
(when (= scheduling-type "Daily")
[:div
"Fire at"
[:input
{:type "text"
:id "scheduling-hour"
:value (or scheduling-hour "")
:on-change (fn [e]
(let [hour (.. js/document (getElementById "scheduling-hour") -value)]
(om/set-state! owner :scheduling-hour hour)
(om/set-state! owner [:schedule :schedule/cron-notation] (to-cron-expression-daily hour))))}]
"o'clock every day"])
(when (= scheduling-type "Weekly")
[:div
"Fire at"
[:input
{:type "text"
:id "scheduling-hour"
:value (or scheduling-hour "")
:on-change (fn [e]
(let [hour (.. js/document (getElementById "scheduling-hour") -value)
day-of-week (.. js/document (getElementById "scheduling-day-of-week") -value)]
(om/set-state! owner :scheduling-hour hour)
(om/set-state! owner [:schedule :schedule/cron-notation] (to-cron-expression-weekly hour day-of-week))))}]
"o'clock at every"
[:select
{:id "scheduling-day-of-week"
:value (or scheduling-day-of-week "")
:on-change (fn [e]
(let [hour (.. js/document (getElementById "scheduling-hour") -value)
day-of-week (.. js/document (getElementById "scheduling-day-of-week") -value)]
(om/set-state! owner :scheduling-day-of-week day-of-week)
(om/set-state! owner [:schedule :schedule/cron-notation] (to-cron-expression-weekly hour day-of-week))))}
[:option {:value "Sun"} "Sun"]
[:option {:value "Mon"} "Mon"]
[:option {:value "Tue"} "Tue"]
[:option {:value "Wed"} "Wed"]
[:option {:value "Thu"} "Thu"]
[:option {:value "Fri"} "Fri"]
[:option {:value "Sat"} "Sat"]]])
(when (= scheduling-type "Monthly")
[:div
"Fire at"
[:input
{:type "text"
:id "scheduling-hour"
:value (or scheduling-hour "")
:on-change (fn [e]
(let [hour (.. js/document (getElementById "scheduling-hour") -value)
date (.. js/document (getElementById "scheduling-date") -value)]
(om/set-state! owner :scheduling-hour hour)
(om/set-state! owner [:schedule :schedule/cron-notation] (to-cron-expression-monthly hour date))))}]
"o'clock every"
[:input
{:type "text"
:id "scheduling-date"
:value (or scheduling-date "")
:on-change (fn [e]
(let [hour (.. js/document (getElementById "scheduling-hour") -value)
date (.. js/document (getElementById "scheduling-date") -value)]
(om/set-state! owner :scheduling-date date)
(om/set-state! owner [:schedule :schedule/cron-notation] (to-cron-expression-monthly hour date))))}]])
[:label "Quartz format"]
[:input {:id "cron-notation" :type "text" :placeholder "Quartz format"
:value (or (:schedule/cron-notation schedule) "")
:on-change (fn [e]
(let [value (.. js/document (getElementById "cron-notation") -value)]
(om/set-state! owner [:schedule :schedule/cron-notation] value)))}]]
(when calendars
[:div.field
[:label "Calendar"]
[:select {:value (get-in schedule [:schedule/calendar :calendar/name])
[:select {:value (or (get-in schedule [:schedule/calendar :calendar/name]) "")
:id "scheduling-calendar"
:on-change (fn [_]
(let [value (.. (om/get-node owner) (querySelector "select") -value)]
(let [value (.. js/document (getElementById "scheduling-calendar") -value)]
(om/set-state! owner [:schedule :schedule/calendar :calendar/name] value)))}
[:option {:value ""} ""]
(for [cal calendars]
Expand All @@ -236,7 +340,7 @@
{:scheduling-ch (chan)
:has-error false
:error-ch (chan)
:scheduling? false})
:scheduling? false})

(will-mount [_]
(let [ch (chan)]
Expand Down

0 comments on commit 99f98db

Please sign in to comment.