-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1090 from digitalfabrik/1080-add-start-date
1080: Add start day
- Loading branch information
Showing
27 changed files
with
375 additions
and
49 deletions.
There are no files selected for viewing
10 changes: 5 additions & 5 deletions
10
administration/resources/cards/sample-bulk-import-nuernberg.csv
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,5 +1,5 @@ | ||
Name,Ablaufdatum,Geburtsdatum,Passnummer,Adresszeile 1,Adresszeile 2,PLZ,Ort,Pass-ID | ||
Thea Test,03.3.2026,05.04.1992,12345678,Wertachstraße 29,,86153,Augsburg,35252 | ||
Tilo Torvitz,03.3.2026,13.03.1988,76543210,Teststraße 2,,85353,Augsburg,87456424 | ||
Torben Trost,03.3.2026,15.03.2010,54216782,2. Tür rechts,Ringstraße 16,81375,München,4234 | ||
Torben Trost,03.3.2026,15.03.2010,54216782,,,,,74532 | ||
Name,Ablaufdatum,Startdatum,Geburtsdatum,Passnummer,Adresszeile 1,Adresszeile 2,PLZ,Ort,Pass-ID | ||
Thea Test,03.3.2026,03.3.2024,05.04.1992,12345678,Wertachstraße 29,,86153,Augsburg,35252 | ||
Tilo Torvitz,03.3.2026,03.5.2024,13.03.1988,76543210,Teststraße 2,,85353,Augsburg,87456424 | ||
Torben Trost,03.3.2026,07.3.2026,15.03.2010,54216782,2. Tür rechts,Ringstraße 16,81375,München,4234 | ||
Torben Trost,03.3.2026,03.9.2024,15.03.2010,54216782,,,,,74532 |
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 |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { FormGroup } from '@blueprintjs/core' | ||
import { PartialMessage } from '@bufbuild/protobuf' | ||
import { TextField } from '@mui/material' | ||
|
||
import { CardExtensions } from '../../generated/card_pb' | ||
import PlainDate from '../../util/PlainDate' | ||
import { Extension } from './extensions' | ||
|
||
type StartDayState = { startDay: number } | ||
|
||
class StartDayExtension extends Extension<StartDayState, null> { | ||
public readonly name = StartDayExtension.name | ||
|
||
setInitialState() { | ||
const today = PlainDate.fromLocalDate(new Date()) | ||
this.state = { startDay: today.toDaysSinceEpoch() } | ||
} | ||
|
||
createForm(onUpdate: () => void) { | ||
const startDayDate = | ||
this.state?.startDay !== undefined | ||
? PlainDate.fromDaysSinceEpoch(this.state.startDay) | ||
: PlainDate.fromLocalDate(new Date()) | ||
|
||
return ( | ||
<FormGroup label='Startdatum'> | ||
<TextField | ||
fullWidth | ||
type='date' | ||
required | ||
size='small' | ||
error={!this.isValid()} | ||
value={startDayDate.toString()} | ||
sx={{ '& input[value=""]:not(:focus)': { color: 'transparent' }, '& fieldset': { borderRadius: 0 } }} | ||
inputProps={{ | ||
style: { fontSize: 14, padding: '6px 10px' }, | ||
}} | ||
onChange={e => { | ||
if (e.target.value !== null) { | ||
try { | ||
const date = PlainDate.from(e.target.value) | ||
this.state = { startDay: date.toDaysSinceEpoch() } | ||
onUpdate() | ||
} catch (error) { | ||
console.error("Could not parse date from string '" + e.target.value + "'.", error) | ||
} | ||
} | ||
}} | ||
/> | ||
</FormGroup> | ||
) | ||
} | ||
|
||
causesInfiniteLifetime() { | ||
return false | ||
} | ||
|
||
setProtobufData(message: PartialMessage<CardExtensions>) { | ||
message.extensionStartDay = { | ||
startDay: this.state?.startDay, | ||
} | ||
} | ||
|
||
isValid() { | ||
return this.state !== null | ||
} | ||
|
||
/** | ||
* fromString is only used for the CSV import. | ||
* The expected format is dd.MM.yyyy | ||
* @param value The date formatted using dd.MM.yyyy | ||
*/ | ||
fromString(value: string) { | ||
try { | ||
const startDay = PlainDate.fromCustomFormat(value, 'dd.MM.yyyy') | ||
this.state = { startDay: startDay.toDaysSinceEpoch() } | ||
} catch (e) { | ||
this.state = null | ||
} | ||
} | ||
|
||
toString() { | ||
return this.state ? PlainDate.fromDaysSinceEpoch(this.state.startDay).format('dd.MM.yyyy') : '' | ||
} | ||
} | ||
|
||
export default StartDayExtension |
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
18 changes: 18 additions & 0 deletions
18
backend/src/main/kotlin/app/ehrenamtskarte/backend/migration/migrations/V0007_AddStartDay.kt
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,18 @@ | ||
package app.ehrenamtskarte.backend.migration.migrations | ||
|
||
import app.ehrenamtskarte.backend.migration.Migration | ||
import app.ehrenamtskarte.backend.migration.Statement | ||
|
||
/** | ||
* Add startDay column to cards. startDay can be null. | ||
*/ | ||
@Suppress("ClassName") | ||
internal class V0007_AddStartDay() : Migration() { | ||
override val migrate: Statement = { | ||
exec( | ||
""" | ||
ALTER TABLE cards ADD "startDay" BIGINT NULL; | ||
""".trimIndent() | ||
) | ||
} | ||
} |
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
Oops, something went wrong.