Created
March 28, 2020 19:13
-
-
Save currentoor/9e9e6bc07f32ac5a9a1a73def0083a36 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmutation fill-schedule-cells | |
"Mutation: For every employee in the global list of all employees: create a row on the work schedule whose cells | |
reflect the currently-scheduled shifts, or placeholder nodes if nothing is scheduled in that cell. | |
params can include: | |
`:gc` - A list of old schedule IDs to GC before filling out the current schedule." | |
[params] | |
(action [{:keys [state]}] | |
(let [query [{:ucv.models.employee/all-employees | |
[:employee/id :employee/first-name :employee/last-name :employee/hourly-wage]}] | |
all-employees (-> (fdn/db->tree query @state @state) | |
:ucv.models.employee/all-employees) | |
schedule-id (ns/get-in-graph @state [:component/id ::work-schedule-editor :work-schedule/current-week :schedule/id])] | |
(swap!-> state | |
(fill-schedule-cells* {:employees all-employees | |
:schedule/id schedule-id}) | |
(add-materialized-metrics* {:schedule/id schedule-id}))))) | |
(defmutation goto-schedule | |
"Mutation: Load the schedule for the week that contains the inst `of`, GC old schedules, and fill in the cells for the | |
work schedule editor." | |
[{:keys [of]}] | |
(action [{:keys [app state]}] | |
(let [old-schedule-ids (-> state deref :schedule/id keys)] | |
(swap!-> state | |
(cond-> (seq old-schedule-ids) (gc-schedules* old-schedule-ids))) | |
(df/load! app :ucv.models.schedule/for-week WorkScheduleEditor | |
{:target [:component/id ::work-schedule-editor :work-schedule/current-week] | |
:marker ::schedule | |
:params {:of of} | |
:post-mutation `fill-schedule-cells})))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment