-
Notifications
You must be signed in to change notification settings - Fork 63
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
8 changed files
with
110 additions
and
5 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
29 changes: 29 additions & 0 deletions
29
papermerge/core/alembic/versions/cea868700f4e_add_value_yearmonth_and_value_year_.py
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,29 @@ | ||
"""add value_yearmonth and value_year columns to custom_field_values | ||
Revision ID: cea868700f4e | ||
Revises: 85fda75f19f1 | ||
Create Date: 2024-11-27 07:30:19.631965 | ||
""" | ||
|
||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "cea868700f4e" | ||
down_revision: Union[str, None] = "85fda75f19f1" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
op.add_column( | ||
"custom_field_values", sa.Column("value_yearmonth", sa.Float(), nullable=True) | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
op.drop_column("custom_field_values", "value_yearmonth") |
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
57 changes: 57 additions & 0 deletions
57
ui2/src/features/document/components/customFields/YearMonth.tsx
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,57 @@ | ||
import {rem} from "@mantine/core" | ||
import {DateValue, MonthPickerInput} from "@mantine/dates" | ||
import {IconCalendar} from "@tabler/icons-react" | ||
import dayjs from "dayjs" | ||
import {useEffect, useState} from "react" | ||
import {CustomFieldArgs} from "./types" | ||
|
||
export default function CustomFieldYearMonth({ | ||
customField, | ||
onChange | ||
}: CustomFieldArgs) { | ||
const [value, setValue] = useState<Date | null>(null) | ||
const icon = ( | ||
<IconCalendar style={{width: rem(18), height: rem(18)}} stroke={1.5} /> | ||
) | ||
|
||
useEffect(() => { | ||
if (customField.value && customField.value.toString().length > 0) { | ||
const parts = customField.value.toString().split("-") | ||
if (parts.length < 2) { | ||
setValue(null) | ||
} else { | ||
const year = Number(parts[0]) | ||
const month = Number(parts[1]) - 1 | ||
|
||
const date = new Date(year, month, 1) | ||
setValue(date) | ||
} | ||
} | ||
}, [customField.value]) | ||
|
||
const onLocalChange = (value: DateValue) => { | ||
if (value) { | ||
const d = dayjs(value) | ||
const DATE_FORMAT = "YYYY-MM" | ||
const strValue = d.format(DATE_FORMAT) | ||
onChange({customField, value: strValue}) | ||
} else { | ||
onChange({customField, value: ""}) | ||
} | ||
setValue(value) | ||
} | ||
|
||
return ( | ||
<MonthPickerInput | ||
leftSection={icon} | ||
leftSectionPointerEvents="none" | ||
clearable | ||
// `valueFormat` will be retrieved from user preferences | ||
valueFormat="YYYY.MM" | ||
label={customField.name} | ||
placeholder="Pick date" | ||
value={value} | ||
onChange={onLocalChange} | ||
/> | ||
) | ||
} |
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,4 +1,5 @@ | ||
import CustomFieldDate from "./Date" | ||
import CustomFieldMonetary from "./Monetary" | ||
import CustomFieldYearMonth from "./YearMonth" | ||
|
||
export {CustomFieldDate, CustomFieldMonetary} | ||
export {CustomFieldDate, CustomFieldMonetary, CustomFieldYearMonth} |
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