Add action to configure category time warnings

This commit is contained in:
Jonas L
2019-06-03 00:00:00 +00:00
parent 46af33f2cd
commit 7cfed5ed4f
7 changed files with 151 additions and 1 deletions
+1
View File
@@ -53,6 +53,7 @@ export { UpdateAppActivitiesAction } from './updateappactivities'
export { UpdateCategoryBlockAllNotificationsAction } from './updatecategoryblockallnotifications'
export { UpdateCategoryBlockedTimesAction } from './updatecategoryblockedtimes'
export { UpdateCategoryTemporarilyBlockedAction } from './updatecategorytemporarilyblocked'
export { UpdateCategoryTimeWarningsAction } from './updatecategorytimewarnings'
export { UpdateCategoryTitleAction } from './updatecategorytitle'
export { UpdateDeviceNameAction } from './updatedevicename'
export { UpdateDeviceStatusAction } from './updatedevicestatus'
+4
View File
@@ -44,6 +44,7 @@ import { SerializedSetUserTimezoneAction, SetUserTimezoneAction } from '../setus
import { SerializedUpdateCategoryBlockAllNotificationsAction, UpdateCategoryBlockAllNotificationsAction } from '../updatecategoryblockallnotifications'
import { SerializedUpdateCategoryBlockedTimesAction, UpdateCategoryBlockedTimesAction } from '../updatecategoryblockedtimes'
import { SerializedUpdateCategoryTemporarilyBlockedAction, UpdateCategoryTemporarilyBlockedAction } from '../updatecategorytemporarilyblocked'
import { SerializedUpdateCategoryTimeWarningsAction, UpdateCategoryTimeWarningsAction } from '../updatecategorytimewarnings'
import { SerializedUpdateCategoryTitleAction, UpdateCategoryTitleAction } from '../updatecategorytitle'
import { SerializedUpdateDeviceNameAction, UpdateDeviceNameAction } from '../updatedevicename'
import { SerializedUpdateEnableActivityLevelBlockingAction, UpdateEnableActivityLevelBlockingAction } from '../updateenableactivitylevelblocking'
@@ -80,6 +81,7 @@ export type SerializedParentAction =
SerializedUpdateCategoryBlockAllNotificationsAction |
SerializedUpdateCategoryBlockedTimesAction |
SerializedUpdateCategoryTemporarilyBlockedAction |
SerializedUpdateCategoryTimeWarningsAction |
SerializedUpdateCategoryTitleAction |
SerializedUpdateDeviceNameAction |
SerializedUpdateEnableActivityLevelBlockingAction |
@@ -142,6 +144,8 @@ export const parseParentAction = (action: SerializedParentAction): ParentAction
return UpdateCategoryBlockAllNotificationsAction.parse(action)
} else if (action.type === 'UPDATE_CATEGORY_BLOCKED_TIMES') {
return UpdateCategoryBlockedTimesAction.parse(action)
} else if (action.type === 'UPDATE_CATEGORY_TIME_WARNINGS') {
return UpdateCategoryTimeWarningsAction.parse(action)
} else if (action.type === 'UPDATE_CATEGORY_TITLE') {
return UpdateCategoryTitleAction.parse(action)
} else if (action.type === 'UPDATE_CATEGORY_TEMPORARILY_BLOCKED') {
+62
View File
@@ -0,0 +1,62 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { allowedTimeWarningFlags } from '../database/category'
import { assertIdWithinFamily } from '../util/token'
import { ParentAction } from './basetypes'
export class UpdateCategoryTimeWarningsAction extends ParentAction {
readonly categoryId: string
readonly enable: boolean
readonly flags: number
constructor ({ categoryId, enable, flags }: {
categoryId: string
enable: boolean
flags: number
}) {
super()
assertIdWithinFamily(categoryId)
if ((flags & allowedTimeWarningFlags) !== flags) {
throw new Error('illegal flags')
}
this.categoryId = categoryId
this.enable = enable
this.flags = flags
}
serialize = (): SerializedUpdateCategoryTimeWarningsAction => ({
type: 'UPDATE_CATEGORY_TIME_WARNINGS',
categoryId: this.categoryId,
enable: this.enable,
flags: this.flags
})
static parse = ({ categoryId, enable, flags }: SerializedUpdateCategoryTimeWarningsAction) => (
new UpdateCategoryTimeWarningsAction({ categoryId, enable, flags })
)
}
export interface SerializedUpdateCategoryTimeWarningsAction {
type: 'UPDATE_CATEGORY_TIME_WARNINGS'
categoryId: string
enable: boolean
flags: number
}