-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
306 additions
and
166 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
fixtures/grafik.xlsx |
Binary file not shown.
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
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
Empty file.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,30 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
import { WorkersInfoModel } from "../../../common-models/worker-info.model"; | ||
import { scheduleDataInitialState } from "./schedule-data/schedule-data-initial-state"; | ||
import { ScheduleActionModel } from "./schedule-data/schedule-data.action-creator"; | ||
import { TemporaryScheduleActionType } from "./schedule-data/temporary-schedule.reducer"; | ||
import { | ||
ScheduleActionModel, | ||
createActionName, | ||
ScheduleActionType, | ||
} from "./schedule-data/schedule.actions"; | ||
|
||
/* eslint-disable @typescript-eslint/camelcase */ | ||
export function employeeInfoReducer( | ||
state: WorkersInfoModel = scheduleDataInitialState.employee_info, | ||
action: ScheduleActionModel | ||
): WorkersInfoModel { | ||
const data = action.payload?.employee_info; | ||
if (!data) return state; | ||
switch (action.type) { | ||
case TemporaryScheduleActionType.ADD_NEW: | ||
return { ...data }; | ||
case TemporaryScheduleActionType.UPDATE: | ||
return { ...state, ...data }; | ||
default: | ||
return state; | ||
} | ||
export function employeeInfoReducerF(name: string) { | ||
return ( | ||
state: WorkersInfoModel = scheduleDataInitialState.employee_info, | ||
action: ScheduleActionModel | ||
): WorkersInfoModel => { | ||
const data = action.payload?.employee_info; | ||
if (!data) return state; | ||
switch (action.type) { | ||
case createActionName(name, ScheduleActionType.ADD_NEW): | ||
return { ...data }; | ||
case createActionName(name, ScheduleActionType.UPDATE): | ||
return { ...state, ...data }; | ||
default: | ||
return state; | ||
} | ||
}; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,40 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
import { ScheduleKey } from "../../../api/persistance-store.model"; | ||
import { MonthInfoModel } from "../../../common-models/month-info.model"; | ||
import { ActionModel } from "../../models/action.model"; | ||
import { copyMonthInfo } from "./schedule-data/common-reducers"; | ||
import { scheduleDataInitialState } from "./schedule-data/schedule-data-initial-state"; | ||
import { ScheduleActionModel } from "./schedule-data/schedule-data.action-creator"; | ||
import { TemporaryScheduleActionType } from "./schedule-data/temporary-schedule.reducer"; | ||
import { | ||
ScheduleActionModel, | ||
createActionName, | ||
ScheduleActionType, | ||
isScheduleAction, | ||
} from "./schedule-data/schedule.actions"; | ||
|
||
/* eslint-disable @typescript-eslint/camelcase */ | ||
export function monthInfoReducer( | ||
state: MonthInfoModel = scheduleDataInitialState.month_info, | ||
action: ScheduleActionModel | ||
): MonthInfoModel { | ||
const data = action.payload?.month_info; | ||
if (!data) { | ||
return state; | ||
} | ||
switch (action.type) { | ||
case TemporaryScheduleActionType.ADD_NEW: | ||
return { ...data }; | ||
case TemporaryScheduleActionType.UPDATE: | ||
return { ...state, ...data }; | ||
default: | ||
return state; | ||
} | ||
export function monthInfoReducerF(name: string) { | ||
return ( | ||
state: MonthInfoModel = scheduleDataInitialState.month_info, | ||
action: ScheduleActionModel | ActionModel<ScheduleKey> | ||
): MonthInfoModel => { | ||
switch (action.type) { | ||
case createActionName(name, ScheduleActionType.ADD_NEW): | ||
case createActionName(name, ScheduleActionType.UPDATE): | ||
if (!isScheduleAction(action)) { | ||
return state; | ||
} | ||
const data = action.payload?.month_info; | ||
if (!data) { | ||
return state; | ||
} | ||
return { ...data }; | ||
case createActionName(name, ScheduleActionType.COPY_TO_MONTH): | ||
const { month, year } = action.payload as ScheduleKey; | ||
return copyMonthInfo(month, year, state); | ||
default: | ||
return state; | ||
} | ||
}; | ||
} | ||
/* eslint-enable @typescript-eslint/camelcase */ |
46 changes: 46 additions & 0 deletions
46
src/state/reducers/month-state/schedule-data/common-reducers.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* eslint-disable @typescript-eslint/camelcase */ | ||
import _ from "lodash"; | ||
import { MonthInfoModel } from "../../../../common-models/month-info.model"; | ||
import { ShiftCode, ShiftInfoModel } from "../../../../common-models/shift-info.model"; | ||
|
||
export function daysInMonth(month = 0, year = 0): number[] { | ||
let day = 1; | ||
const result = [day]; | ||
let date = new Date(year, month, day); | ||
while (month === date.getMonth()) { | ||
day++; | ||
date = new Date(year, month, day); | ||
result.push(day); | ||
} | ||
return result; | ||
} | ||
export function copyShiftstoMonth( | ||
month: number, | ||
year: number, | ||
shifts: ShiftInfoModel | ||
): ShiftInfoModel { | ||
const days = daysInMonth(month, year).length; | ||
const copiedShifts = _.cloneDeep(shifts); | ||
Object.keys(copiedShifts).forEach((key) => { | ||
const values = copiedShifts[key].slice(0, days); | ||
copiedShifts[key] = values.map((shift) => | ||
[ShiftCode.L4, ShiftCode.U, ShiftCode.K].includes(shift) ? ShiftCode.W : shift | ||
); | ||
}); | ||
return copiedShifts; | ||
} | ||
|
||
export function copyMonthInfo( | ||
month: number, | ||
year: number, | ||
monthInfo: MonthInfoModel | ||
): MonthInfoModel { | ||
const days = daysInMonth(month, year); | ||
const copiedInfo: MonthInfoModel = { | ||
children_number: monthInfo.children_number?.slice(0, days.length), | ||
extra_workers: monthInfo.extra_workers?.slice(0, days.length), | ||
dates: days, | ||
frozen_shifts: [], | ||
}; | ||
return copiedInfo; | ||
} |
Oops, something went wrong.