Skip to content

Commit

Permalink
Subsection Infopanel (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannaPeanut authored Jan 29, 2024
2 parents 613d61c + e429018 commit 10d041c
Show file tree
Hide file tree
Showing 44 changed files with 1,477 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Subsubsection" ADD COLUMN "planningPeriod" DOUBLE PRECISION;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Subsubsection" ADD COLUMN "constructionPeriod" DOUBLE PRECISION;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Subsubsection" ADD COLUMN "quarterPlannedCompletion" TEXT;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
Warnings:
- Made the column `lengthKm` on table `Subsection` required. This step will fail if there are existing NULL values in that column.
- Made the column `lengthKm` on table `Subsubsection` required. This step will fail if there are existing NULL values in that column.
*/
-- AlterTable
ALTER TABLE "Subsection" ALTER COLUMN "lengthKm" SET NOT NULL;

-- AlterTable
ALTER TABLE "Subsubsection" ALTER COLUMN "lengthKm" SET NOT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
Warnings:
- You are about to drop the column `quarterPlannedCompletion` on the `Subsubsection` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "Subsubsection" DROP COLUMN "quarterPlannedCompletion",
ADD COLUMN "estimatedCompletionDate" TIMESTAMP(3);
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- AlterTable
ALTER TABLE "Subsection" ADD COLUMN "networkHierarchyId" INTEGER;

-- CreateTable
CREATE TABLE "NetworkHierarchy" (
"id" SERIAL NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"slug" TEXT NOT NULL,
"title" TEXT NOT NULL,
"projectId" INTEGER NOT NULL,

CONSTRAINT "NetworkHierarchy_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "NetworkHierarchy_projectId_slug_key" ON "NetworkHierarchy"("projectId", "slug");

-- AddForeignKey
ALTER TABLE "Subsection" ADD CONSTRAINT "Subsection_networkHierarchyId_fkey" FOREIGN KEY ("networkHierarchyId") REFERENCES "NetworkHierarchy"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "NetworkHierarchy" ADD CONSTRAINT "NetworkHierarchy_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "Project"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- CreateEnum
CREATE TYPE "PriorityEnum" AS ENUM ('OPEN', 'TOP', 'HIGH', 'MEDIUM', 'LOW');

-- AlterTable
ALTER TABLE "Subsection" ADD COLUMN "priority" "PriorityEnum" NOT NULL DEFAULT 'OPEN';
76 changes: 55 additions & 21 deletions db/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ model Project {
SubsubsectionTask SubsubsectionTask[]
SubsubsectionInfra SubsubsectionInfra[]
SubsubsectionSpecial SubsubsectionSpecial[]
NetworkHierarchy NetworkHierarchy[]
}

model Membership {
Expand Down Expand Up @@ -199,25 +200,28 @@ model Operator {
}

model Subsection {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
//
slug String // shortTitle and URL Slug
start String
end String
order Int @default(autoincrement())
geometry Json
labelPos LabelPositionEnum @default(top)
description String?
lengthKm Float?
//
project Project @relation(fields: [projectId], references: [id])
projectId Int
manager User? @relation(fields: [managerId], references: [id])
managerId Int?
operator Operator? @relation(fields: [operatorId], references: [id])
operatorId Int?
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
//
slug String // shortTitle and URL Slug
start String
end String
order Int @default(autoincrement())
geometry Json
labelPos LabelPositionEnum @default(top)
description String?
lengthKm Float // Kilometer
priority PriorityEnum @default(OPEN) // Priorität
//
project Project @relation(fields: [projectId], references: [id])
projectId Int
manager User? @relation(fields: [managerId], references: [id])
managerId Int?
operator Operator? @relation(fields: [operatorId], references: [id])
operatorId Int?
networkHierarchy NetworkHierarchy? @relation(fields: [networkHierarchyId], references: [id])
networkHierarchyId Int?
subsubsections Subsubsection[]
stakeholdernotes Stakeholdernote[]
Expand All @@ -227,6 +231,29 @@ model Subsection {
@@unique([projectId, order])
}

enum PriorityEnum {
OPEN
TOP //sehr hoch, hoch, mittel, niedrig
HIGH
MEDIUM
LOW
}

model NetworkHierarchy {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
//
slug String // shortTitle and URL Slug
title String
//
project Project @relation(fields: [projectId], references: [id])
projectId Int
Subsection Subsection[]
@@unique([projectId, slug])
}

model Subsubsection {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
Expand All @@ -238,10 +265,9 @@ model Subsubsection {
geometry Json
labelPos LabelPositionEnum @default(top)
task String? // Maßnahmentyp - UNUSED
lengthKm Float? // Kilometer
lengthKm Float // Kilometer
width Float? // Meter
widthExisting Float? // Meter
costEstimate Float? // Euro
description String? // Anmerkungen
mapillaryKey String?
isExistingInfra Boolean? @default(false) // Bestandsführung
Expand All @@ -250,13 +276,21 @@ model Subsubsection {
trafficLoad Int? // Verkehrsbelastung
trafficLoadDate DateTime? // Datum der Verkehrsbelastung
planningPeriod Float? // Planungsdauer
constructionPeriod Float? // Baudauer
estimatedCompletionDate DateTime? // Jahresquartal der geplanten Fertigstellung als string Form "1-2023"
//
costEstimate Float? // Euro
//
planningCosts Float? // Planungskosten
deliveryCosts Float? // Lieferkosten
constructionCosts Float? // Baukosten
landAcquisitionCosts Float? // Grunderwerbskosten
expensesOfficialOrders Float? // Ausgaben aufgrund behördlicher Anordnungen
expensesTechnicalVerification Float? // Ausgaben für den fachtechnischen Nachweis usw.
//
nonEligibleExpenses Float? // Nicht zuwendungsfähige Ausgaben
//
revenuesEconomicIncome Float? // Erlöse und wirtschafltiche Einnahmen
contributionsThirdParties Float? // Beiträge Dritter
grantsOtherFunding Float? // Zuwendungen aus anderen Förderprogrammen
Expand Down
4 changes: 3 additions & 1 deletion db/seeds/subsection_subsubsections.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Prisma } from "@prisma/client"

// lengthKm is NOT calculated here but arbitrary values to satisfy the schema

export const subsubsections: Omit<Prisma.SubsubsectionUncheckedCreateInput, "subsectionId">[] = [
{
slug: "rf1",
Expand Down Expand Up @@ -110,7 +112,7 @@ export const subsubsections: Omit<Prisma.SubsubsectionUncheckedCreateInput, "sub
geometry: [13.329078172644188, 52.5225862734311],
labelPos: "top",
task: "Fahrbahnmarkierung mit Querung",
lengthKm: null,
lengthKm: 3,
width: 2,
costEstimate: 30_000,
qualityLevelId: 4,
Expand Down
11 changes: 11 additions & 0 deletions db/seeds/subsections.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import db, { Prisma } from "../index"
import { subsubsections } from "./subsection_subsubsections"

// lengthKm is NOT calculated here but arbitrary values to satisfy the schema

const seedSubsections = async () => {
const seedData: Prisma.SubsectionUncheckedCreateInput[] = [
// NORD:
Expand Down Expand Up @@ -31,6 +33,7 @@ const seedSubsections = async () => {
[13.357157800454104, 52.517204842057566],
[13.363361116374904, 52.519430986022115],
],
lengthKm: 56,
managerId: 1,
subsubsections: { create: subsubsections },
},
Expand All @@ -52,6 +55,7 @@ const seedSubsections = async () => {
[13.369246313529857, 52.52252804216468],
[13.36352017575777, 52.519430986022115],
],
lengthKm: 12,
managerId: null,
},
{
Expand All @@ -69,6 +73,7 @@ const seedSubsections = async () => {
[13.399308536836458, 52.521366671697535],
[13.392787102151175, 52.52252804216468],
],
lengthKm: 12,
managerId: null,
},
{
Expand All @@ -86,6 +91,7 @@ const seedSubsections = async () => {
[13.421258731631525, 52.51333301867112],
[13.451639073702552, 52.499875779590525],
],
lengthKm: 12,
managerId: 1,
},
// SÜD:
Expand All @@ -104,6 +110,7 @@ const seedSubsections = async () => {
[13.33697529376991, 52.51115272935999],
[13.35222310471977, 52.5057391067665],
],
lengthKm: 12,
managerId: 2,
},
{
Expand All @@ -124,6 +131,7 @@ const seedSubsections = async () => {
[13.379859762067383, 52.49916452570534],
[13.388754318454033, 52.49800420344744],
],
lengthKm: 12,
managerId: 2,
},
{
Expand All @@ -141,6 +149,7 @@ const seedSubsections = async () => {
[13.41278184895532, 52.4950788842759],
[13.41977042897335, 52.49614258494796],
],
lengthKm: 12,
managerId: 2,
},
{
Expand All @@ -157,6 +166,7 @@ const seedSubsections = async () => {
[13.439306686753582, 52.4902435569129],
[13.451695533149916, 52.49991367999152],
],
lengthKm: 3,
managerId: 2,
},
{
Expand All @@ -173,6 +183,7 @@ const seedSubsections = async () => {
[13.439306686753582, 52.4902435569129],
[13.451695533149916, 52.49991367999152],
],
lengthKm: 8,
managerId: 2,
},
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ import { length, lineString } from "@turf/turf"
export const LabeledFormatNumberFieldCalculateLength: React.FC<LabeledFormatNumberFieldProps> = (
props,
) => {
const { setValue, getValues } = useFormContext()
const { watch, setValue, getValues } = useFormContext()

const isGeometry = watch("geometry")

function isPoint(geometry: any[]) {
return (
geometry.length === 2 && typeof geometry[0] === "number" && typeof geometry[1] === "number"
geometry?.length === 2 && typeof geometry[0] === "number" && typeof geometry[1] === "number"
)
}

const calculateLength = () => {
const geometry = getValues("geometry")
const calculatedLength = length(lineString(geometry))
const calculatedLength = Number(length(lineString(geometry)).toFixed(3))
setValue(props.name, calculatedLength)
}

Expand Down Expand Up @@ -48,7 +50,7 @@ export const LabeledFormatNumberFieldCalculateLength: React.FC<LabeledFormatNumb

<button
type="button"
disabled={isPoint(!getValues("geometry") || getValues("geometry")) || props.readOnly}
disabled={!isGeometry || isPoint(getValues("geometry")) || props.readOnly}
onClick={calculateLength}
className={clsx(blueButtonStyles, "!py-1 !px-2")}
>
Expand Down
14 changes: 14 additions & 0 deletions src/networkHierarchy/components/NetworkHierarchy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Form, FormProps, LabeledTextField } from "src/core/components/forms"
import { z } from "zod"
export { FORM_ERROR } from "src/core/components/forms"

export function NetworkHierarchyForm<S extends z.ZodType<any, any>>(props: FormProps<S>) {
const { ...formProps } = props

return (
<Form<S> {...formProps}>
<LabeledTextField type="text" name="slug" label="Kurz-Titel und URL-Teil" />
<LabeledTextField type="text" name="title" label="Titel" />
</Form>
)
}
24 changes: 24 additions & 0 deletions src/networkHierarchy/mutations/createNetworkHierarchy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { resolver } from "@blitzjs/rpc"
import db from "db"
import { authorizeProjectAdmin } from "src/authorization"
import { z } from "zod"
import getProjectIdBySlug from "../../projects/queries/getProjectIdBySlug"
import { OperatorSchema } from "src/operators/schema"

const CreateOperatorSchema = OperatorSchema.omit({ projectId: true }).merge(
z.object({
projectSlug: z.string(),
}),
)

export default resolver.pipe(
resolver.zod(CreateOperatorSchema),
authorizeProjectAdmin(getProjectIdBySlug),
async ({ projectSlug, ...input }) =>
await db.networkHierarchy.create({
data: {
...input,
projectId: await getProjectIdBySlug(projectSlug),
},
}),
)
15 changes: 15 additions & 0 deletions src/networkHierarchy/mutations/deleteNetworkHierarchy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { resolver } from "@blitzjs/rpc"
import db from "db"
import { authorizeProjectAdmin } from "src/authorization"
import { z } from "zod"
import getNetworkHierarchyProjectId from "../queries/getNetworkHierarchyProjectId"

const DeleteNetworkHierarchySchema = z.object({
id: z.number(),
})

export default resolver.pipe(
resolver.zod(DeleteNetworkHierarchySchema),
authorizeProjectAdmin(getNetworkHierarchyProjectId),
async ({ id }) => await db.networkHierarchy.deleteMany({ where: { id } }),
)
22 changes: 22 additions & 0 deletions src/networkHierarchy/mutations/updateNetworkHierarchy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { resolver } from "@blitzjs/rpc"
import db from "db"
import { authorizeProjectAdmin } from "src/authorization"
import { z } from "zod"
import getQualityLevelProjectId from "../queries/getNetworkHierarchyProjectId"
import { NetworkHierarchySchema } from "../schema"

const UpdateNetworkHierarchySchema = NetworkHierarchySchema.merge(
z.object({
id: z.number(),
}),
)

export default resolver.pipe(
resolver.zod(UpdateNetworkHierarchySchema),
authorizeProjectAdmin(getQualityLevelProjectId),
async ({ id, ...data }) =>
await db.networkHierarchy.update({
where: { id },
data,
}),
)
Loading

0 comments on commit 10d041c

Please sign in to comment.