Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Findspot display #404

Merged
merged 43 commits into from
Nov 8, 2023
Merged
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
9386b38
add DateRange interface
fsimonjetz Nov 2, 2023
7fb575a
implement Findspot interface
fsimonjetz Nov 2, 2023
8473576
use lodash capitalize
fsimonjetz Nov 2, 2023
8c89069
prepare findspot class display
fsimonjetz Nov 2, 2023
9aa9dc7
update schema with findspot id
fsimonjetz Nov 2, 2023
5f4ba5c
Merge branch 'master' into findspot-display
fsimonjetz Nov 3, 2023
02f6a82
pass findspotService through app
fsimonjetz Nov 3, 2023
541cbf9
add FindspotService
fsimonjetz Nov 3, 2023
ea65719
refactor findspot from dto
fsimonjetz Nov 3, 2023
edcca30
add findspot route
fsimonjetz Nov 3, 2023
114219b
remove debug log
fsimonjetz Nov 3, 2023
88fb0ea
wrap ArchaeologyEditor in withData
fsimonjetz Nov 3, 2023
03945a2
add updateFindspot and renderFindspot
fsimonjetz Nov 3, 2023
8c6e44d
add findspotServiceMock
fsimonjetz Nov 3, 2023
ea9c1c4
add findspotFactory
fsimonjetz Nov 3, 2023
8cfa98f
update object dto conversions
fsimonjetz Nov 6, 2023
1346f57
update tests
fsimonjetz Nov 6, 2023
3f75e18
extend dto transformation functions
fsimonjetz Nov 6, 2023
3bedff3
extend findspot factories
fsimonjetz Nov 6, 2023
9fccb15
add tests for dto functions
fsimonjetz Nov 6, 2023
3b0f68b
change date datatype
fsimonjetz Nov 6, 2023
e98d2b0
new date display logic
fsimonjetz Nov 6, 2023
23a6f61
refactoring, bug fixes
fsimonjetz Nov 7, 2023
a7516c4
add findspot display tests
fsimonjetz Nov 7, 2023
64302a4
add helper functions, refactor
fsimonjetz Nov 7, 2023
2241ac5
better levelLayer mock
fsimonjetz Nov 7, 2023
52e3874
better levelLayer mock
fsimonjetz Nov 7, 2023
5b70f2b
Merge branch 'findspot-display' of https://github.com/ElectronicBabyl…
fsimonjetz Nov 7, 2023
8084c44
add findspotService mocks
fsimonjetz Nov 7, 2023
e97aee9
refactor JsonApiClient
fsimonjetz Nov 7, 2023
5dff10a
refactor type
fsimonjetz Nov 7, 2023
7ff4780
make site optional
fsimonjetz Nov 7, 2023
ec71fef
add FindspotService test
fsimonjetz Nov 7, 2023
3f9d53e
extract FindspotRepository
fsimonjetz Nov 7, 2023
5cce710
fix typo
fsimonjetz Nov 7, 2023
e7095ca
add FindspotRepository test
fsimonjetz Nov 7, 2023
a5365bd
refactoring
fsimonjetz Nov 7, 2023
42799fa
fix findspot update
fsimonjetz Nov 7, 2023
a6e3b76
add findspots selection test
fsimonjetz Nov 7, 2023
6db3785
shorter test values
fsimonjetz Nov 7, 2023
841bb4a
fix missing key
fsimonjetz Nov 7, 2023
ea8a5f3
longer test list
fsimonjetz Nov 8, 2023
00e332f
prevent double whitespace
fsimonjetz Nov 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update object dto conversions
  • Loading branch information
fsimonjetz committed Nov 6, 2023
commit 8cfa98f346a349cf322bd5e15c519333964f7d45
82 changes: 75 additions & 7 deletions src/fragmentarium/domain/archaeology.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import Reference from 'bibliography/domain/Reference'
import MuseumNumber, { museumNumberToString } from './MuseumNumber'
import { Provenances } from 'corpus/domain/provenance'
import _ from 'lodash'
import { DateRange } from './Date'
import { immerable } from 'immer'
import { ReferenceDto } from 'bibliography/domain/referenceDto'
import createReference from 'bibliography/application/createReference'

export const excavationSites = {
..._.omit(Provenances, 'Standard Text'),
Expand All @@ -28,6 +29,12 @@ export interface ExcavationPlan {
readonly svg: string
readonly references: readonly Reference[]
}
type CommentedDateRange = {
start?: Date | null
end?: Date | null
notes?: string
}
type CommentedDateRangeDto = { start?: string; end?: string; notes?: string }

export class Findspot {
readonly [immerable] = true
Expand All @@ -39,7 +46,7 @@ export class Findspot {
readonly building: string = '',
readonly buildingType: BuildingType = 'UNKNOWN',
readonly levelLayerPhase: string = '',
readonly dateRange: (DateRange & { notes?: string }) | null = null,
readonly dateRange: CommentedDateRange | null = null,
readonly plans: readonly ExcavationPlan[] = [],
readonly room: string = '',
readonly context: string = '',
Expand Down Expand Up @@ -67,31 +74,91 @@ export interface Archaeology {
readonly findspot?: Findspot | null
}

interface PlanDto {
svg: string
references: readonly ReferenceDto[]
}

export type FindspotDto = Pick<
Findspot,
| 'area'
| 'building'
| 'buildingType'
| 'levelLayerPhase'
| 'room'
| 'context'
| 'primaryContext'
| 'notes'
> & {
_id: number
site: SiteKey
dateRange: CommentedDateRangeDto | null
plans: readonly PlanDto[]
}

export interface ArchaeologyDto {
readonly excavationNumber?: string
readonly site?: SiteKey
readonly isRegularExcavation?: boolean
readonly findspotId?: number | null
readonly findspot?: any
readonly findspot?: FindspotDto | null
}

export function fromFindspotDto(dto): Findspot {
function fromDateRangeDto(dto: CommentedDateRangeDto): CommentedDateRange {
return {
start: dto.start ? new Date(dto.start) : null,
end: dto.end ? new Date(dto.end) : null,
notes: dto.notes || '',
}
}
function toDateRangeDto(dateRange: CommentedDateRange): CommentedDateRangeDto {
return {
start: dateRange.start?.toString(),
end: dateRange.end?.toString(),
notes: dateRange.notes,
}
}
function fromPlanDto(dto: PlanDto): ExcavationPlan {
return {
svg: dto.svg,
references: dto.references.map(createReference),
}
}

export function fromFindspotDto(dto: FindspotDto): Findspot {
return new Findspot(
dto._id,
excavationSites[dto.site || ''],
dto.area,
dto.building,
dto.buildingType,
dto.levelLayerPhase,
dto.dateRange,
dto.plans,
dto.dateRange ? fromDateRangeDto(dto.dateRange) : null,
dto.plans.map(fromPlanDto),
dto.room,
dto.context,
dto.primaryContext,
dto.notes
)
}

export function toFindspotDto(findspot: Findspot): FindspotDto {
return {
_id: findspot.id,
area: findspot.area,
building: findspot.building,
buildingType: findspot.buildingType,
levelLayerPhase: findspot.levelLayerPhase,
room: findspot.room,
context: findspot.context,
primaryContext: findspot.primaryContext,
notes: findspot.notes,
site: findspot.site.name as SiteKey,
dateRange: findspot.dateRange ? toDateRangeDto(findspot.dateRange) : null,
plans: findspot.plans,
}
}

export function createArchaeology(
dto: Omit<ArchaeologyDto, 'excavationNumber'> & {
excavationNumber?: MuseumNumber
Expand All @@ -103,13 +170,14 @@ export function createArchaeology(
? museumNumberToString(dto.excavationNumber)
: undefined,
site: excavationSites[dto.site || ''],
findspot: _.isNull(dto.findspot) ? null : fromFindspotDto(dto.findspot),
findspot: dto.findspot ? fromFindspotDto(dto.findspot) : null,
}
}

export function toArchaeologyDto(archaeology: Archaeology): ArchaeologyDto {
return {
...archaeology,
site: (archaeology.site?.name || '') as SiteKey,
findspot: archaeology.findspot ? toFindspotDto(archaeology.findspot) : null,
}
}
Loading