Skip to content

Commit

Permalink
Feature/fix openingstijden (#93)
Browse files Browse the repository at this point in the history
* various updates and bugfixes
- improve opening/close times display and edit
- implement path for old NS links for google compatibility
- fix "koop abonnement" links
- improve typescript implementation

* Add extra check report for bad records
  • Loading branch information
mosbuma authored Jul 14, 2024
1 parent ad55183 commit 972d481
Show file tree
Hide file tree
Showing 20 changed files with 1,239 additions and 209 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,7 @@ mysql-db/export-db.sql
mysql-db/export-db.zip

#uploads
/public/uploads*
/public/uploads*

#auto generated test scripts
create-test-user.sql
63 changes: 63 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@
"@trpc/server": "^10.18.0",
"@turf/center": "^6.5.0",
"@turf/turf": "^6.5.0",
"@types/moment": "^2.13.0",
"@types/moment-timezone": "^0.5.30",
"bcrypt": "^5.1.1",
"formidable": "^3.5.1",
"keen-slider": "^6.8.5",
"mapbox-gl-draw-waypoint": "^1.0.3",
"mapbox-gl-utils": "^0.39.0",
"maplibre-gl": "^2.0.0-pre.1",
"mime": "^3.0.0",
"moment-timezone": "^0.5.45",
"next": "^13.4.18",
"next-auth": "^4.23.1",
"next-pwa": "^5.6.0",
Expand All @@ -50,6 +53,7 @@
"react-hot-toast": "^2.4.1",
"react-icons": "^4.8.0",
"react-redux": "^8.0.5",
"react-table": "^7.8.0",
"superjson": "1.12.2",
"zod": "^3.21.4"
},
Expand All @@ -65,6 +69,7 @@
"@types/prettier": "^2.7.2",
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11",
"@types/react-table": "^7.7.20",
"@typescript-eslint/eslint-plugin": "^5.56.0",
"@typescript-eslint/parser": "^5.56.0",
"autoprefixer": "^10.4.14",
Expand Down
1 change: 1 addition & 0 deletions src/components/Parking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const Parking = ({ id, stallingId, onStallingIdChanged, onClose }: { id: string,
if (null !== stalling) {
setCurrentStalling(stalling);
} else {
console.error("Failed to load stalling with ID: " + stallingId);
setCurrentStalling(null);
}
});
Expand Down
96 changes: 6 additions & 90 deletions src/components/ParkingFacilityBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,97 +1,13 @@
import { useRouter } from "next/navigation";
import moment from "moment";

import { getParkingColor } from "~/utils/theme";
import { openRoute } from "~/utils/map/index";

import Styles from "./ParkingFacilityBlock.module.css";

type ParkingType = {
ID: string;
Title: string;
Plaats?: string;
Location?: string;
Postcode?: any;
Status?: any;
Coordinaten?: any;
Type?: any;
Tariefcode?: number;
Openingstijden?: string;
Open_ma?: string;
Dicht_ma?: string;
Open_di?: string;
Dicht_di?: string;
Open_wo?: string;
Dicht_wo?: string;
Open_do?: string;
Dicht_do?: string;
Open_vr?: string;
Dicht_vr?: string;
Open_za?: string;
Dicht_za?: string;
Open_zo?: string;
Dicht_zo?: string;
Image?: string;
ExtraServices?: string;
}

const isOpen = (openingTime: Date, closingTime: Date, isNS: boolean = false): boolean => {
const now = new Date();
const currentTime = now.getHours() * 60 + now.getMinutes();
const opening = openingTime.getHours() - 1 * 60 + openingTime.getMinutes();//TODO
let closing = closingTime.getHours() - 1 * 60 + closingTime.getMinutes();//TODO

// #TODO: Combine functions with /src/utils/parkings.tsx
if (opening === closing && opening === 60 && closing === 60) {
// Exception for NS parkings: If NS parking AND open from 1am to 1am,
// then the parking is open 24 hours per day.
return isNS;
}

if (closing < opening) {
// Closing time is on the next day, add 24 hours to closing time
closing += 24 * 60;
}

return currentTime >= opening && currentTime <= closing;
};

const formatTime = (time: Date): string => {
const hours = (time.getHours() - 1).toString().padStart(2, "0");//TODO
const minutes = time.getMinutes().toString().padStart(2, "0");
return `${hours}:${minutes}`;
};
import { formatOpeningToday } from "~/utils/parkings-openclose";
import type { ParkingDetailsType } from "~/types/";

const formatOpeningToday = (parkingdata: any): string => {
const dayidx = new Date().getDay();
const daytxt = ["za", "zo", "ma", "di", "wo", "do", "vr"];

const openstr = parkingdata["Open_" + daytxt[dayidx]];
const closestr = parkingdata["Dicht_" + daytxt[dayidx]];

if (null === openstr || null === closestr) {
return "";
}

const openinfo = new Date(openstr);
const closeinfo = new Date(closestr);

const isNS = parkingdata.EditorCreated === "NS-connector";
if (isOpen(openinfo, closeinfo, isNS)) {
let str = `open`;

// Exception: If this is a 24/h a day
// NS parking -> don't show "until ..."
if (openstr === closestr) {
return str;
}

str += `, sluit om ${formatTime(closeinfo)}`;

return str;
} else {
return "gesloten";
}
};
import Styles from "./ParkingFacilityBlock.module.css";

function ParkingFacilityBlock({
parking,
Expand All @@ -102,7 +18,7 @@ function ParkingFacilityBlock({
showButtons,
}: {
id?: any,
parking: ParkingType,
parking: ParkingDetailsType,
compact: boolean
openParkingHandler?: Function,
expandParkingHandler?: Function,
Expand Down Expand Up @@ -139,7 +55,7 @@ function ParkingFacilityBlock({
break;
}

const openingDescription = formatOpeningToday(parking);
const openingDescription = formatOpeningToday(parking, moment()).message;

// const detailsLine = `${costDescription}${costDescription && openingDescription ? "| " : ""
// }${openingDescription}`;
Expand Down
11 changes: 9 additions & 2 deletions src/components/parking/ParkingEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const ParkingEdit = ({ parkingdata, onClose, onChange }: { parkingdata: ParkingD
const [newServices, setNewServices] = React.useState<ChangedType[]>([]);

const [newCapaciteit, setNewCapaciteit] = React.useState<ParkingSections>([]); // capaciteitschema
const [newOpening, setNewOpening] = React.useState<any>(undefined); // openingstijdenschema
const [newOpening, setNewOpening] = React.useState<OpeningChangedType | undefined>(undefined); // openingstijdenschema
const [newOpeningstijden, setNewOpeningstijden] = React.useState<string | undefined>(undefined); // textveld afwijkende openingstijden

type StallingType = { id: string, name: string, sequence: number };
Expand Down Expand Up @@ -275,7 +275,13 @@ const ParkingEdit = ({ parkingdata, onClose, onChange }: { parkingdata: ParkingD
if (undefined !== newOpening) {
for (const keystr in newOpening) {
const key = keystr as keyof ParkingEditUpdateStructure;
update[key] = new Date(newOpening[key]).toISOString();
if (newOpening[key] === null) {
update[key] = null
} else if (newOpening[key] !== undefined) {
update[key] = newOpening[key].format("YYYY-MM-DDTHH:mm:ss.SSS[Z]");
} else {
// do nothing
}
}
}

Expand Down Expand Up @@ -757,6 +763,7 @@ const ParkingEdit = ({ parkingdata, onClose, onChange }: { parkingdata: ParkingD

const renderTabOpeningstijden = (visible: boolean = false) => {
const handlerSetNewOpening = (tijden: OpeningChangedType, Openingstijden: string): void => {
console.log("set new opening", tijden, Openingstijden);
setNewOpening(tijden);
setNewOpeningstijden(Openingstijden);
return;
Expand Down
Loading

0 comments on commit 972d481

Please sign in to comment.