Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c0e354c2b1 | ||
|
|
bcbdb8db5c | ||
|
|
78fd2fb2e2 | ||
|
|
0ff09533e8 | ||
|
|
8c50577ca1 | ||
|
|
5d8ef45265 | ||
|
|
a928397ebe | ||
|
|
bff6196f77 | ||
|
|
2556b8bf50 | ||
|
|
abaa81faa1 | ||
|
|
fe1cc9c479 | ||
|
|
624731ed18 |
No files matched your search
@@ -1,5 +0,0 @@
|
|||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
||||||
# Editor-based HTTP Client requests
|
|
||||||
/httpRequests/
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="WEB_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager">
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<component name="InspectionProjectProfileManager">
|
|
||||||
<profile version="1.0">
|
|
||||||
<option name="myName" value="Project Default" />
|
|
||||||
<inspection_tool class="CssUnknownProperty" enabled="true" level="WARNING" enabled_by_default="true">
|
|
||||||
<option name="myCustomPropertiesEnabled" value="true" />
|
|
||||||
<option name="myIgnoreVendorSpecificProperties" value="false" />
|
|
||||||
<option name="myCustomPropertiesList">
|
|
||||||
<value>
|
|
||||||
<list size="1">
|
|
||||||
<item index="0" class="java.lang.String" itemvalue="font-color" />
|
|
||||||
</list>
|
|
||||||
</value>
|
|
||||||
</option>
|
|
||||||
</inspection_tool>
|
|
||||||
</profile>
|
|
||||||
</component>
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="JavaScriptLibraryMappings">
|
|
||||||
<includedPredefinedLibrary name="Node.js Core" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectModuleManager">
|
|
||||||
<modules>
|
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/anwendungsprojekt.iml" filepath="$PROJECT_DIR$/.idea/anwendungsprojekt.iml" />
|
|
||||||
</modules>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="" vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
|
Before Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 8.4 MiB |
|
Before Width: | Height: | Size: 2.1 MiB |
@@ -1,4 +0,0 @@
|
|||||||
# TIF22A_AnwProjekt_B
|
|
||||||
Team B im Anwendungsprojekt (TIF22A)
|
|
||||||
|
|
||||||
Website can be accessed under: http://lectureplanner.de/ (caution no https, only http)
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
|
||||||
|
|
||||||
# dependencies
|
|
||||||
/node_modules
|
|
||||||
/.pnp
|
|
||||||
.pnp.js
|
|
||||||
|
|
||||||
# testing
|
|
||||||
/coverage
|
|
||||||
|
|
||||||
# next.js
|
|
||||||
/.next/
|
|
||||||
/out/
|
|
||||||
|
|
||||||
# production
|
|
||||||
/build
|
|
||||||
|
|
||||||
# misc
|
|
||||||
.DS_Store
|
|
||||||
*.pem
|
|
||||||
|
|
||||||
# debug
|
|
||||||
npm-debug.log*
|
|
||||||
yarn-debug.log*
|
|
||||||
yarn-error.log*
|
|
||||||
|
|
||||||
# local env files
|
|
||||||
.env*.local
|
|
||||||
|
|
||||||
# vercel
|
|
||||||
.vercel
|
|
||||||
|
|
||||||
# typescript
|
|
||||||
*.tsbuildinfo
|
|
||||||
next-env.d.ts
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
||||||
# Editor-based HTTP Client requests
|
|
||||||
/httpRequests/
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="WEB_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager">
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
<component name="ProjectCodeStyleConfiguration">
|
|
||||||
<state>
|
|
||||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
|
||||||
</state>
|
|
||||||
</component>
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectModuleManager">
|
|
||||||
<modules>
|
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/anwendung.iml" filepath="$PROJECT_DIR$/.idea/anwendung.iml" />
|
|
||||||
</modules>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
|
|
||||||
|
|
||||||
## Getting Started
|
|
||||||
|
|
||||||
First, run the development server:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
npm run dev
|
|
||||||
# or
|
|
||||||
yarn dev
|
|
||||||
# or
|
|
||||||
pnpm dev
|
|
||||||
```
|
|
||||||
|
|
||||||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
|
||||||
|
|
||||||
You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the file.
|
|
||||||
|
|
||||||
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.js`.
|
|
||||||
|
|
||||||
The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.
|
|
||||||
|
|
||||||
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
|
|
||||||
|
|
||||||
## Learn More
|
|
||||||
|
|
||||||
To learn more about Next.js, take a look at the following resources:
|
|
||||||
|
|
||||||
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
|
|
||||||
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
|
|
||||||
|
|
||||||
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
|
|
||||||
|
|
||||||
## Deploy on Vercel
|
|
||||||
|
|
||||||
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
|
|
||||||
|
|
||||||
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"paths": {
|
|
||||||
"@/*": ["./src/*"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
/** @type {import('next').NextConfig} */
|
|
||||||
const nextConfig = {
|
|
||||||
reactStrictMode: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = nextConfig
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "anwendung",
|
|
||||||
"version": "0.1.0",
|
|
||||||
"private": true,
|
|
||||||
"scripts": {
|
|
||||||
"dev": "next dev",
|
|
||||||
"build": "next build",
|
|
||||||
"start": "next start",
|
|
||||||
"lint": "next lint"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"autoprefixer": "10.4.14",
|
|
||||||
"next": "13.3.4",
|
|
||||||
"postcss": "8.4.23",
|
|
||||||
"react": "18.2.0",
|
|
||||||
"react-dom": "18.2.0",
|
|
||||||
"tailwindcss": "3.3.2"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
plugins: {
|
|
||||||
tailwindcss: {},
|
|
||||||
autoprefixer: {},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
Before Width: | Height: | Size: 25 KiB |
@@ -1 +0,0 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 394 80"><path fill="#000" d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.7zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.6h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z"/><path fill="#000" d="M81 79.3 17 0H0v79.3h13.6V17l50.2 62.3H81Zm252.6-.4c-1 0-1.8-.4-2.5-1s-1.1-1.6-1.1-2.6.3-1.8 1-2.5 1.6-1 2.6-1 1.8.3 2.5 1a3.4 3.4 0 0 1 .6 4.3 3.7 3.7 0 0 1-3 1.8zm23.2-33.5h6v23.3c0 2.1-.4 4-1.3 5.5a9.1 9.1 0 0 1-3.8 3.5c-1.6.8-3.5 1.3-5.7 1.3-2 0-3.7-.4-5.3-1s-2.8-1.8-3.7-3.2c-.9-1.3-1.4-3-1.4-5h6c.1.8.3 1.6.7 2.2s1 1.2 1.6 1.5c.7.4 1.5.5 2.4.5 1 0 1.8-.2 2.4-.6a4 4 0 0 0 1.6-1.8c.3-.8.5-1.8.5-3V45.5zm30.9 9.1a4.4 4.4 0 0 0-2-3.3 7.5 7.5 0 0 0-4.3-1.1c-1.3 0-2.4.2-3.3.5-.9.4-1.6 1-2 1.6a3.5 3.5 0 0 0-.3 4c.3.5.7.9 1.3 1.2l1.8 1 2 .5 3.2.8c1.3.3 2.5.7 3.7 1.2a13 13 0 0 1 3.2 1.8 8.1 8.1 0 0 1 3 6.5c0 2-.5 3.7-1.5 5.1a10 10 0 0 1-4.4 3.5c-1.8.8-4.1 1.2-6.8 1.2-2.6 0-4.9-.4-6.8-1.2-2-.8-3.4-2-4.5-3.5a10 10 0 0 1-1.7-5.6h6a5 5 0 0 0 3.5 4.6c1 .4 2.2.6 3.4.6 1.3 0 2.5-.2 3.5-.6 1-.4 1.8-1 2.4-1.7a4 4 0 0 0 .8-2.4c0-.9-.2-1.6-.7-2.2a11 11 0 0 0-2.1-1.4l-3.2-1-3.8-1c-2.8-.7-5-1.7-6.6-3.2a7.2 7.2 0 0 1-2.4-5.7 8 8 0 0 1 1.7-5 10 10 0 0 1 4.3-3.5c2-.8 4-1.2 6.4-1.2 2.3 0 4.4.4 6.2 1.2 1.8.8 3.2 2 4.3 3.4 1 1.4 1.5 3 1.5 5h-5.8z"/></svg>
|
|
||||||
|
Before Width: | Height: | Size: 1.3 KiB |
@@ -1 +0,0 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 283 64"><path fill="black" d="M141 16c-11 0-19 7-19 18s9 18 20 18c7 0 13-3 16-7l-7-5c-2 3-6 4-9 4-5 0-9-3-10-7h28v-3c0-11-8-18-19-18zm-9 15c1-4 4-7 9-7s8 3 9 7h-18zm117-15c-11 0-19 7-19 18s9 18 20 18c6 0 12-3 16-7l-8-5c-2 3-5 4-8 4-5 0-9-3-11-7h28l1-3c0-11-8-18-19-18zm-10 15c2-4 5-7 10-7s8 3 9 7h-19zm-39 3c0 6 4 10 10 10 4 0 7-2 9-5l8 5c-3 5-9 8-17 8-11 0-19-7-19-18s8-18 19-18c8 0 14 3 17 8l-8 5c-2-3-5-5-9-5-6 0-10 4-10 10zm83-29v46h-9V5h9zM37 0l37 64H0L37 0zm92 5-27 48L74 5h10l18 30 17-30h10zm59 12v10l-3-1c-6 0-10 4-10 10v15h-9V17h9v9c0-5 6-9 13-9z"/></svg>
|
|
||||||
|
Before Width: | Height: | Size: 629 B |
@@ -1,21 +0,0 @@
|
|||||||
import Button from "@/components/Button";
|
|
||||||
import {useRouter} from "next/router";
|
|
||||||
import {baseURL} from "@/components/Constants";
|
|
||||||
import {arrowLeft} from "@/components/Icons";
|
|
||||||
|
|
||||||
|
|
||||||
export default function Back(p)
|
|
||||||
{
|
|
||||||
return(
|
|
||||||
<div style={{
|
|
||||||
position : "absolute",
|
|
||||||
left : 20,
|
|
||||||
top : 20,
|
|
||||||
width : 60,
|
|
||||||
height : 60
|
|
||||||
|
|
||||||
}}>
|
|
||||||
<Button onClick={() => p.onClick()} icon={arrowLeft} color={"#77932b"} width={75} height={40}/>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
import React from "react";
|
|
||||||
|
|
||||||
export default function Background()
|
|
||||||
{
|
|
||||||
return (
|
|
||||||
<div style={{
|
|
||||||
position: "absolute",
|
|
||||||
width: "100%",
|
|
||||||
height: "100%",
|
|
||||||
overflow: "clip",
|
|
||||||
pointerEvents: "none"
|
|
||||||
}}>
|
|
||||||
<div style={{
|
|
||||||
position: "absolute",
|
|
||||||
transform: "skew(20deg)",
|
|
||||||
width: "100%",
|
|
||||||
height: "100%",
|
|
||||||
zIndex: -10,
|
|
||||||
backgroundColor: "#f2f2f2",
|
|
||||||
borderTopLeftRadius: 400,
|
|
||||||
borderBottomRightRadius: 800,
|
|
||||||
|
|
||||||
}}></div>
|
|
||||||
<div style={{
|
|
||||||
position: "absolute",
|
|
||||||
width: "100%",
|
|
||||||
height: "100%",
|
|
||||||
zIndex: -11,
|
|
||||||
backgroundColor: "#346991",
|
|
||||||
}}></div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
/**
|
|
||||||
* Function Takes in Paramter for:
|
|
||||||
* text: text to be shown on the button
|
|
||||||
* width, height: width and height of the button
|
|
||||||
* icon: an icon that should be shown on the button (HTML <svg> tag) (see Icons.js for example)
|
|
||||||
* iconWidth, iconHeight: width and height of the icon
|
|
||||||
* onClick: a function that should be run if the button is clicked
|
|
||||||
* Example for onClick:
|
|
||||||
* <Button onClick={onClick={() => {console.log("do something")}}
|
|
||||||
* Example for icon:
|
|
||||||
*/
|
|
||||||
export default function Button(p) {
|
|
||||||
|
|
||||||
//default parameters for the button
|
|
||||||
let text = p.text;
|
|
||||||
let width = p.width, height = p.height;
|
|
||||||
let iconHTML = p.icon;
|
|
||||||
let iconWidth = p.iconWidth, iconHeight = p.iconHeight;
|
|
||||||
let onClick = p.onClick;
|
|
||||||
let color = p.color;
|
|
||||||
let fontColor = p.fontColor;
|
|
||||||
let font_size = p.fontSize;
|
|
||||||
|
|
||||||
//if parameters are not set, they are set to default values
|
|
||||||
if (height == null) height = 0;
|
|
||||||
if (width == null) width = 0;
|
|
||||||
if (iconWidth == null) iconWidth = width-10;
|
|
||||||
if (iconHeight == null) iconHeight = height-10;
|
|
||||||
if (onClick == null) onClick = () => {};
|
|
||||||
if (color == null) color = "#363636";
|
|
||||||
if (fontColor == null) fontColor = "white";
|
|
||||||
if (font_size == null) font_size = 16;
|
|
||||||
|
|
||||||
//build in the icon width and height to the svg tag (svg tag should not contain any size information by default)
|
|
||||||
if (iconHTML != null) {
|
|
||||||
let split = iconHTML.split("fill=");
|
|
||||||
split[1] = "fill=" + split[1];
|
|
||||||
split[0] += " width=" + iconWidth + " height=" + iconHeight + " ";
|
|
||||||
iconHTML = split[0] + split[1]
|
|
||||||
} else {
|
|
||||||
iconHTML = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
//return the button
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<button className={"round-border button font font-small"}
|
|
||||||
style={{
|
|
||||||
display: "flex",
|
|
||||||
alignItems: "center",
|
|
||||||
justifyContent: "center",
|
|
||||||
backgroundColor: color,
|
|
||||||
color: fontColor,
|
|
||||||
fontSize: font_size,
|
|
||||||
minWidth: width,
|
|
||||||
minHeight: height,
|
|
||||||
textAlign: "center",
|
|
||||||
}}
|
|
||||||
onClick={onClick}>
|
|
||||||
{text}
|
|
||||||
<div dangerouslySetInnerHTML={{__html: iconHTML}}/>
|
|
||||||
</button>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,184 +0,0 @@
|
|||||||
import {useEffect, useRef} from "react";
|
|
||||||
|
|
||||||
let startParts = []
|
|
||||||
let endParts = []
|
|
||||||
const months = [["Januar", 31], ["Februar", 28], ["März", 31], ["April", 30], ["Mai", 31], ["Juni", 30], ["Juli", 31], ["August", 31], ["September", 30], ["Oktober", 31], ["November", 30], ["Dezember", 31]]
|
|
||||||
const days = months.map((month => month[1]))
|
|
||||||
let result = []
|
|
||||||
let startDate
|
|
||||||
let calculatedDay = []
|
|
||||||
const weekdays = ["Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"]
|
|
||||||
let lastMonth = 0
|
|
||||||
|
|
||||||
export default function BasicDateCalendar(p) {
|
|
||||||
|
|
||||||
const ref = useRef(null)
|
|
||||||
|
|
||||||
function getBackMonthColor(monthIndex)
|
|
||||||
{
|
|
||||||
let date = new Date(parseInt(startParts[2]), parseInt(startParts[1]) + monthIndex - 1, 1)
|
|
||||||
if (date.getFullYear() === p.highlightYear && date.getMonth() === p.highlightMonth)
|
|
||||||
{
|
|
||||||
if(lastMonth !== p.highlightMonth)
|
|
||||||
{
|
|
||||||
ref.current.scrollTo({top: 290 * monthIndex - 270, behavior: "smooth"})
|
|
||||||
}
|
|
||||||
lastMonth = p.highlightMonth
|
|
||||||
return true
|
|
||||||
}else
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
startParts = []
|
|
||||||
endParts = []
|
|
||||||
result = []
|
|
||||||
calculatedDay = []
|
|
||||||
|
|
||||||
startDate = new Date(p.startyear, 0 ,p.startday)
|
|
||||||
let endDate = new Date(p.endyear, 0 , p.endday)
|
|
||||||
let startString = startDate.getDate() + "." + (startDate.getMonth() + 1) + "." + p.startyear
|
|
||||||
let endString = endDate.getDate() + "." + (endDate.getMonth() + 1) + "." + p.endyear
|
|
||||||
generateCalendar(startString, endString)
|
|
||||||
})
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className={"Allround"} ref={ref}>
|
|
||||||
<div className={"Down"}>
|
|
||||||
{result.map((monthResult, index) => (
|
|
||||||
<div className={"A box-shadow"} onClick={() => p.onMonthClick(
|
|
||||||
(parseInt(startParts[1]) + index),
|
|
||||||
startParts
|
|
||||||
)} >
|
|
||||||
<p style={{
|
|
||||||
textAlign : "center",
|
|
||||||
marginBottom : 10,
|
|
||||||
fontSize: 19,
|
|
||||||
pointerEvents: "none",
|
|
||||||
backgroundColor: getBackMonthColor(index) ? "#346991":"rgba(0,0,0,0)",
|
|
||||||
color : getBackMonthColor(index) ? "white":"black",
|
|
||||||
borderRadius : 10
|
|
||||||
}}>{getMonthName(index) + " " + new Date(parseInt(startParts[2]), parseInt(startParts[1]) + index - 1, 1).getFullYear()}</p>
|
|
||||||
<div className={"Days"} style={{
|
|
||||||
pointerEvents: "none"
|
|
||||||
}}>
|
|
||||||
{weekdays.map((weekday) => (
|
|
||||||
<p key={weekday} style={{
|
|
||||||
pointerEvents: "none"
|
|
||||||
}}>{weekday}</p>
|
|
||||||
))}
|
|
||||||
{freeSpaces(index)}
|
|
||||||
{monthResult.map((date) => (
|
|
||||||
<p key={date} style={{
|
|
||||||
pointerEvents: "none"
|
|
||||||
}}>{date}</p>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function getMonthName(monthIndex) {
|
|
||||||
if (startParts[1] - 1 + monthIndex < 12) {
|
|
||||||
return months[startParts[1] - 1 + monthIndex][0];
|
|
||||||
} else {
|
|
||||||
return months[startParts[1] - 1 + monthIndex - 12][0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function generateCalendar(start, ende)
|
|
||||||
{
|
|
||||||
splitter(start, ende)
|
|
||||||
if (startParts[2] < endParts[2])
|
|
||||||
{
|
|
||||||
for (let i = startParts[1] - 1; i <= 11; i++)
|
|
||||||
{
|
|
||||||
let monthResult = [];
|
|
||||||
for (let j = 1; j <= days[i]; j++)
|
|
||||||
{
|
|
||||||
if (
|
|
||||||
new Date(startParts[2], i, j) >= new Date(startParts[2], startParts[1] - 1, startParts[0]) &&
|
|
||||||
new Date(startParts[2], i, j) <= new Date(startParts[2], 11, 31)
|
|
||||||
)
|
|
||||||
{
|
|
||||||
monthResult.push(j);
|
|
||||||
calculateDay(startParts[2], i, j)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result.push(monthResult);
|
|
||||||
if (i == 11)
|
|
||||||
{
|
|
||||||
for (let h = 0; h <= endParts[1] - 1; h++)
|
|
||||||
{
|
|
||||||
let monthResultNewYear = [];
|
|
||||||
for (let g = 1; g <= days[h]; g++)
|
|
||||||
{
|
|
||||||
if (new Date(endParts[2], h, g) <= new Date(endParts[2], endParts[1] - 1, endParts[0]))
|
|
||||||
{
|
|
||||||
monthResultNewYear.push(g);
|
|
||||||
calculateDay(endParts[2], h, g)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result.push(monthResultNewYear);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
for (let i = startParts[1] - 1; i <= endParts[1] - 1; i++)
|
|
||||||
{
|
|
||||||
let monthResult = [];
|
|
||||||
for (let j = 1; j <= days[i]; j++)
|
|
||||||
{
|
|
||||||
if (
|
|
||||||
new Date(startParts[2], i, j) >= new Date(startParts[2], startParts[1] - 1, startParts[0]) &&
|
|
||||||
new Date(startParts[2], i, j) <= new Date(startParts[2], endParts[1] - 1, endParts[0])
|
|
||||||
)
|
|
||||||
{
|
|
||||||
monthResult.push(j)
|
|
||||||
calculateDay(startParts[2], i, j)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result.push(monthResult);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function calculateDay(x, i, j){
|
|
||||||
if (j == startDate.getDate() && i == startDate.getMonth() || j == 1){
|
|
||||||
let monthStart = new Date(x, i, j)
|
|
||||||
if (monthStart.getDay() == 0)
|
|
||||||
calculatedDay.push(6)
|
|
||||||
else calculatedDay.push(monthStart.getDay() - 1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function freeSpaces(index)
|
|
||||||
{
|
|
||||||
let arrayTest = []
|
|
||||||
for (let i = 0; i < calculatedDay[index]; i++) {
|
|
||||||
arrayTest.push(<p style={{
|
|
||||||
pointerEvents: "none"
|
|
||||||
}}></p>)
|
|
||||||
}
|
|
||||||
return arrayTest
|
|
||||||
}
|
|
||||||
|
|
||||||
function splitter(startDate, endDate)
|
|
||||||
{
|
|
||||||
startParts = startDate.split(".")
|
|
||||||
if (startParts[1][0] === 0) //prüft ob die erste Stelle des Monats eine 0 vorne stehen hat
|
|
||||||
{
|
|
||||||
startParts[1] = startParts[1][1] //überschreibt den Monat ohne die 0
|
|
||||||
}
|
|
||||||
endParts = endDate.split(".") //prüft ob die erste Stelle des Monats eine 0 vorne stehen hat
|
|
||||||
if (endParts[1][0] === 0)
|
|
||||||
{
|
|
||||||
endParts[1] = endParts[1][1] //überschreibt den Monat ohne die 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,815 +0,0 @@
|
|||||||
import {useEffect, useRef, useState} from "react";
|
|
||||||
import Button from "@/components/Button";
|
|
||||||
import {list} from "postcss";
|
|
||||||
import Background from "@/components/Background";
|
|
||||||
import WeekSelector from "@/components/WeekSelector";
|
|
||||||
import {baseURL} from "@/components/Constants";
|
|
||||||
import {ErrorType} from "@/components/ErrorType";
|
|
||||||
import BasicDateCalendar from "@/components/CalendarSideBar";
|
|
||||||
import feiertagejs from "feiertagejs";
|
|
||||||
|
|
||||||
let cellHeight = 20;
|
|
||||||
|
|
||||||
let colors = ["#f80000", "#414141"]
|
|
||||||
|
|
||||||
let semesterStart;
|
|
||||||
let semesterEnd;
|
|
||||||
let currentWeekStartDay;
|
|
||||||
let currentYear;
|
|
||||||
let semesterStartYear;
|
|
||||||
let semesterEndYear;
|
|
||||||
let selectedElement;
|
|
||||||
let grabbedDown;
|
|
||||||
|
|
||||||
let isDayOkay = [true, true, true, true, true, true]
|
|
||||||
|
|
||||||
let errorState = [ErrorType.Okay, ErrorType.Okay, ErrorType.Okay, ErrorType.Okay, ErrorType.Okay, ErrorType.Okay]
|
|
||||||
let grayedOut = [false, false, false, false, false, false]
|
|
||||||
|
|
||||||
export default function CalenderView(p) {
|
|
||||||
|
|
||||||
const [entries, setEntries] = useState([[], [], [], [], [], []])
|
|
||||||
const [update, setUpdate] = useState(false)
|
|
||||||
const scrollRef = useRef(null);
|
|
||||||
|
|
||||||
const [startDayCalenderSideBar, setStartDayCalenderSideBar] = useState(0)
|
|
||||||
const [startYearCalenderSideBar, setStartYearCalenderSideBar] = useState(2000)
|
|
||||||
const [endDayCalenderSideBar, setEndDayCalenderSideBar] = useState(0)
|
|
||||||
const [endYearCalenderSideBar, setEndYearCalenderSideBar] = useState(2000)
|
|
||||||
const [highlightMonth, setHighlightMonth] = useState(0)
|
|
||||||
const [highlightYear, setHighlightYear] = useState(2000)
|
|
||||||
|
|
||||||
|
|
||||||
function readEntries() {
|
|
||||||
let url = baseURL + "/entries?semesterid=" + localStorage.getItem("currentsid") +
|
|
||||||
"&daynumber=" + currentWeekStartDay + "&yearnumber=" + currentYear + "&sessionid=" + localStorage.getItem("sessionid");
|
|
||||||
let currentsid = localStorage.getItem("currentsid")
|
|
||||||
let userid = localStorage.getItem("userid")
|
|
||||||
|
|
||||||
try {
|
|
||||||
fetch(url).then(r => r.json()).then(en => {
|
|
||||||
|
|
||||||
|
|
||||||
for (let i = 0; i < en.length; i++) {
|
|
||||||
isDayOkay[i] = true
|
|
||||||
let maxLunchBreak = 0
|
|
||||||
let daySum = 0
|
|
||||||
for (let j = 0; j < en[i].length; j++) {
|
|
||||||
if (en[i][j] != null && currentsid == (en[i][j]).semesterid) {
|
|
||||||
let elem = en[i][j]
|
|
||||||
|
|
||||||
if ((elem.timestart - 1) / 4 < 8) {
|
|
||||||
errorState[i] = ErrorType.TooEarly
|
|
||||||
isDayOkay[i] = false
|
|
||||||
break
|
|
||||||
} else if ((elem.timeend - 1) / 4 > 17) {
|
|
||||||
errorState[i] = ErrorType.TooLate
|
|
||||||
isDayOkay[i] = false
|
|
||||||
break
|
|
||||||
}
|
|
||||||
else if(new Date(currentYear, 0, elem.daynumber).getUTCDay() === 5) {
|
|
||||||
errorState[i] = ErrorType.Saturday
|
|
||||||
isDayOkay[i] = false
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if ((elem.timestart - 1) / 4 <= 11 && (elem.timeend - 1) / 4 >= 14) {
|
|
||||||
errorState[i] = ErrorType.NotEnoughLunchTime
|
|
||||||
isDayOkay[i] = false
|
|
||||||
break
|
|
||||||
} else if ((elem.timeend - 1) / 4 >= 11 && (elem.timeend - 1) / 4 <= 14) {
|
|
||||||
let min = 24 * 3
|
|
||||||
|
|
||||||
for (let j2 = 0; j2 < en[i].length; j2++) {
|
|
||||||
if (en[i][j2] != null && (en[i][j2].timestart - 1) / 4 >= 11 && (en[i][j2].timestart - 1) / 4 <= 14 && currentsid == (en[i][j2]).semesterid) {
|
|
||||||
if (en[i][j2].timestart < min && en[i][j2].timestart >= elem.timeend) {
|
|
||||||
min = en[i][j2].timestart
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (min - elem.timeend < 3) {
|
|
||||||
errorState[i] = ErrorType.NotEnoughLunchTime
|
|
||||||
isDayOkay[i] = false
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
errorState[i] = ErrorType.Okay
|
|
||||||
}
|
|
||||||
|
|
||||||
daySum += elem.timeend - elem.timestart
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (daySum / 4 > 8) {
|
|
||||||
errorState[i] = ErrorType.TooLong
|
|
||||||
isDayOkay[i] = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < 6; i++) {
|
|
||||||
for (let k = 0; k < 20; k++) {
|
|
||||||
if (en[i][k] != null){
|
|
||||||
|
|
||||||
if (en[i][k].semesterid != currentsid)
|
|
||||||
{
|
|
||||||
for (let l = 0; l < 20; l++) {
|
|
||||||
if (en[i][l] != null && en[i][l].usercreatedbyid != userid) {
|
|
||||||
if (en[i][l].timestart <= en[i][k].timestart && en[i][l].timeend >= en[i][k].timeend) {
|
|
||||||
en[i][k] = null;
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if (en[i][k].timestart <= en[i][l].timeend && en[i][k].timestart >= en[i][l].timestart) {
|
|
||||||
en[i][k].timestart = en[i][l].timeend
|
|
||||||
}
|
|
||||||
if (en[i][k].timeend >= en[i][l].timestart && en[i][k].timeend <= en[i][l].timeend) {
|
|
||||||
en[i][k].timeend = en[i][l].timestart
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (en[i][k] != null && en[i][k].usercreatedbyid != userid) {
|
|
||||||
for (let l = 0; l < 20; l++) {
|
|
||||||
if (en[i][l] != null && en[i][l].semesterid != currentsid) {
|
|
||||||
if (en[i][l].timestart <= en[i][k].timestart && en[i][l].timeend >= en[i][k].timeend) {
|
|
||||||
en[i][k] = null;
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
let j = 0;
|
|
||||||
for(let i = Math.round(((new Date(currentYear, 0, currentWeekStartDay) - new Date(currentYear, 0, 0)) / (1000 * 60 * 60 * 24))); i <= Math.round(((new Date(currentYear, 0, currentWeekStartDay + 5) - new Date(currentYear, 0, 0)) / (1000 * 60 * 60 * 24))); i++)
|
|
||||||
{
|
|
||||||
grayedOut[j] = i % Math.round(((new Date(currentYear, 11, 31) - new Date(currentYear, 0, 0)) / (1000 * 60 * 60 * 24))) < semesterStart && semesterEnd && new Date(currentYear, 0, currentWeekStartDay + j).getFullYear() == semesterStartYear || i % Math.round(((new Date(currentYear, 11, 31) - new Date(currentYear, 0, 0)) / (1000 * 60 * 60 * 24))) > semesterEnd && new Date(currentYear, 0, currentWeekStartDay + j).getFullYear() == semesterEndYear
|
|
||||||
j++
|
|
||||||
}
|
|
||||||
for (let i = 0; i < 6; i++) {
|
|
||||||
let date = new Date(currentYear, 0, currentWeekStartDay+i)
|
|
||||||
grayedOut[i] = holiday(currentYear, date.getMonth(), date.getDate()) ? holiday(currentYear, date.getMonth(), date.getDate()) : grayedOut[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
setEntries(en)
|
|
||||||
})
|
|
||||||
} catch (e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function pushEntry(currentColumnID, row) {
|
|
||||||
let url = baseURL + "/entries" + "?sessionid=" + localStorage.getItem("sessionid")
|
|
||||||
let json = {
|
|
||||||
"id": 0,
|
|
||||||
"daynumber": currentWeekStartDay + currentColumnID,
|
|
||||||
"yearnumber": currentYear,
|
|
||||||
"semesterid": localStorage.getItem("currentsid"),
|
|
||||||
"usercreatedbyid": localStorage.getItem("userid"),
|
|
||||||
"timestart": row,
|
|
||||||
"timeend": row + 3,
|
|
||||||
"info": localStorage.getItem("currentmodulename")
|
|
||||||
}
|
|
||||||
fetch(url, {
|
|
||||||
method: "POST",
|
|
||||||
headers: {"Content-Type": "application/json"},
|
|
||||||
body: JSON.stringify(json)
|
|
||||||
}).then(r => {
|
|
||||||
readEntries()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function deleteEntry(id) {
|
|
||||||
let url = baseURL + "/entries?id=" + id + "&sessionid=" + localStorage.getItem("sessionid");
|
|
||||||
fetch(url, {
|
|
||||||
method: "DELETE"
|
|
||||||
}).then(r => readEntries())
|
|
||||||
}
|
|
||||||
|
|
||||||
function holiday(year, month, day){
|
|
||||||
var feiertagejs = require('feiertagejs');
|
|
||||||
let today = new Date(year, month, day)
|
|
||||||
return feiertagejs.isHoliday(today, 'BW')
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkForElementAtRow(row, column) {
|
|
||||||
let currentList = entries[column];
|
|
||||||
for (let i = 0; i < currentList.length; i++) {
|
|
||||||
if (currentList[i] != null) {
|
|
||||||
if (row >= currentList[i].timestart && row <= currentList[i].timeend) {
|
|
||||||
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getElementInColumn(id, column) {
|
|
||||||
let currentList = entries[column];
|
|
||||||
for (let i = 0; i < currentList.length; i++) {
|
|
||||||
if (currentList[i] != null) {
|
|
||||||
if (currentList[i].id === id) {
|
|
||||||
return currentList[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function onMouseUp(e) {
|
|
||||||
if (selectedElement != null) {
|
|
||||||
let id = selectedElement.id;
|
|
||||||
|
|
||||||
if ((selectedElement.timestart - 1) / 4 >= 7 && (selectedElement.timeend - 1) / 4 <= 18) {
|
|
||||||
let url = baseURL + "/entries?sessionid=" + localStorage.getItem("sessionid");
|
|
||||||
let json = {
|
|
||||||
"id": id,
|
|
||||||
"daynumber": 0,
|
|
||||||
"yearnumber": 0,
|
|
||||||
"semesterid": 0,
|
|
||||||
"usercreatedbyid": 0,
|
|
||||||
"timestart": selectedElement.timestart,
|
|
||||||
"timeend": selectedElement.timeend,
|
|
||||||
"info": ""
|
|
||||||
}
|
|
||||||
fetch(url, {
|
|
||||||
method: "PUT",
|
|
||||||
headers: {"Content-Type": "application/json"},
|
|
||||||
body: JSON.stringify(json)
|
|
||||||
}).then(r => {
|
|
||||||
readEntries()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
selectedElement = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function onMouseMove(e) {
|
|
||||||
if (selectedElement != null) {
|
|
||||||
let y_window = e.clientY;
|
|
||||||
let y_target_offset = e.currentTarget.getBoundingClientRect().top;
|
|
||||||
let row = Math.floor((y_window - y_target_offset) / cellHeight) + 1;
|
|
||||||
let currentColumnID = parseInt(e.currentTarget.id)
|
|
||||||
|
|
||||||
if (grabbedDown) {
|
|
||||||
if (row - 1 > selectedElement.timestart) {
|
|
||||||
|
|
||||||
let free = true;
|
|
||||||
for (let i = 0; i < entries[currentColumnID].length; i++) {
|
|
||||||
if (entries[currentColumnID][i] != null && selectedElement !== entries[currentColumnID][i]) {
|
|
||||||
if (row <= entries[currentColumnID][i].timeend &&
|
|
||||||
row >= entries[currentColumnID][i].timestart ||
|
|
||||||
row > entries[currentColumnID][i].timeend &&
|
|
||||||
selectedElement.timestart < entries[currentColumnID][i].timestart) {
|
|
||||||
free = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (free) {
|
|
||||||
selectedElement.timeend = row + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (row + 2 < selectedElement.timeend) {
|
|
||||||
let free = true;
|
|
||||||
for (let i = 0; i < entries[currentColumnID].length; i++) {
|
|
||||||
if (entries[currentColumnID][i] != null && selectedElement !== entries[currentColumnID][i]) {
|
|
||||||
if (row < entries[currentColumnID][i].timeend &&
|
|
||||||
row >= entries[currentColumnID][i].timestart ||
|
|
||||||
row < entries[currentColumnID][i].timestart &&
|
|
||||||
selectedElement.timeend > entries[currentColumnID][i].timestart) {
|
|
||||||
free = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (free) {
|
|
||||||
selectedElement.timestart = row;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setUpdate(!update);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function onMouseDown(e) {
|
|
||||||
let y_window = e.clientY;
|
|
||||||
let y_target_offset = e.currentTarget.getBoundingClientRect().top;
|
|
||||||
let row = Math.floor((y_window - y_target_offset) / cellHeight) + 1;
|
|
||||||
let currentColumnID = parseInt(e.currentTarget.id)
|
|
||||||
let currentId = e.target.id;
|
|
||||||
let currentUserID = localStorage.getItem("userid");
|
|
||||||
let currentsid = localStorage.getItem("currentsid")
|
|
||||||
|
|
||||||
if (e.button === 0) {
|
|
||||||
if (!currentId.includes("e")) {
|
|
||||||
if (!currentId.includes("grab")) {
|
|
||||||
if (!checkForElementAtRow(row + 2, currentColumnID) && !checkForElementAtRow(row+1, currentColumnID)) {
|
|
||||||
if ((row - 1) / 4 >= 7 && (row + 2) / 4 <= 18) {
|
|
||||||
if(!grayedOut[currentColumnID]) {
|
|
||||||
pushEntry(currentColumnID, row)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let parentID = parseInt(e.target.parentElement.id.replace("e", ""));
|
|
||||||
if (currentUserID == getElementInColumn(parentID, currentColumnID).usercreatedbyid && getElementInColumn(parentID, currentColumnID).semesterid == currentsid) {
|
|
||||||
grabbedDown = currentId.includes("down")
|
|
||||||
selectedElement = getElementInColumn(parentID, currentColumnID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (e.button === 2) {
|
|
||||||
let parentID = parseInt(e.target.id.replace("e", ""));
|
|
||||||
if (currentUserID == getElementInColumn(parentID, currentColumnID).usercreatedbyid && currentId.includes("e") && getElementInColumn(parentID, currentColumnID).semesterid == currentsid) {
|
|
||||||
let id = parseInt(currentId.replace("e", ""))
|
|
||||||
errorState[currentColumnID] = ErrorType.Okay
|
|
||||||
deleteEntry(id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function onWeekLeft() {
|
|
||||||
currentWeekStartDay -= 7;
|
|
||||||
let date = new Date(currentYear, 0, currentWeekStartDay + 5)
|
|
||||||
setHighlightMonth(date.getMonth())
|
|
||||||
setHighlightYear(date.getFullYear())
|
|
||||||
|
|
||||||
for(let i = 0; i < errorState.length; i++)
|
|
||||||
{
|
|
||||||
errorState[i] = ErrorType.Okay
|
|
||||||
}
|
|
||||||
|
|
||||||
readEntries()
|
|
||||||
}
|
|
||||||
|
|
||||||
function onWeekRight() {
|
|
||||||
currentWeekStartDay += 7;
|
|
||||||
let date = new Date(currentYear, 0, currentWeekStartDay + 5)
|
|
||||||
setHighlightMonth(date.getMonth())
|
|
||||||
setHighlightYear(date.getFullYear())
|
|
||||||
|
|
||||||
for(let i = 0; i < errorState.length; i++)
|
|
||||||
{
|
|
||||||
errorState[i] = ErrorType.Okay
|
|
||||||
}
|
|
||||||
|
|
||||||
readEntries()
|
|
||||||
}
|
|
||||||
|
|
||||||
function getEntryColor(userCreatedByID, columnID, semesterid) {
|
|
||||||
let id = localStorage.getItem("userid");
|
|
||||||
let currentsid = localStorage.getItem("currentsid")
|
|
||||||
if (id == userCreatedByID) {
|
|
||||||
if (isDayOkay[columnID] && semesterid == currentsid) {
|
|
||||||
return "#77932b";
|
|
||||||
}else if(semesterid != currentsid){
|
|
||||||
return "#346991";
|
|
||||||
}else {
|
|
||||||
return "#e5a10e";
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return "#a2a2a2";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getResizeBarColor(userCreatedByID, columnID, semesterid) {
|
|
||||||
let id = localStorage.getItem("userid");
|
|
||||||
let currentsid = localStorage.getItem("currentsid")
|
|
||||||
if (id == userCreatedByID) {
|
|
||||||
if (isDayOkay[columnID] && currentsid == semesterid) {
|
|
||||||
return "#5a6c20";
|
|
||||||
} else if(currentsid != semesterid)
|
|
||||||
{
|
|
||||||
return "#346991"
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return "#c08809";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return "#a2a2a2";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
semesterStart = 0;
|
|
||||||
semesterEnd = 0;
|
|
||||||
semesterStartYear = 0;
|
|
||||||
semesterEndYear = 0;
|
|
||||||
currentWeekStartDay = 0;
|
|
||||||
currentYear = 2000;
|
|
||||||
selectedElement = null;
|
|
||||||
grabbedDown = false;
|
|
||||||
errorState = [ErrorType.Okay, ErrorType.Okay, ErrorType.Okay, ErrorType.Okay, ErrorType.Okay, ErrorType.Okay]
|
|
||||||
|
|
||||||
let url = baseURL + "/semester/id?sessionid=" + localStorage.getItem("sessionid") +
|
|
||||||
"&id=" + localStorage.getItem("currentsid");
|
|
||||||
|
|
||||||
|
|
||||||
fetch(url).then(r => r.json()).then(s => {
|
|
||||||
currentWeekStartDay = s.startday - new Date(s.startyear, 0, s.startday).getUTCDay();
|
|
||||||
currentYear = s.startyear;
|
|
||||||
setStartYearCalenderSideBar(currentYear)
|
|
||||||
setEndYearCalenderSideBar(s.endyear)
|
|
||||||
setHighlightMonth(new Date(s.startyear, 0, s.startday).getMonth())
|
|
||||||
setHighlightYear(currentYear)
|
|
||||||
|
|
||||||
semesterStart = s.startday;
|
|
||||||
semesterEnd = s.endday;
|
|
||||||
semesterStartYear = s.startyear;
|
|
||||||
semesterEndYear = s.endyear;
|
|
||||||
setStartDayCalenderSideBar(semesterStart)
|
|
||||||
setEndDayCalenderSideBar(s.endday)
|
|
||||||
}).then(readEntries)
|
|
||||||
|
|
||||||
scrollRef.current.scrollTop = 600;
|
|
||||||
window.addEventListener("contextmenu", (e) => (e.preventDefault()))
|
|
||||||
|
|
||||||
window.addEventListener("keypress", (e) => {
|
|
||||||
try {
|
|
||||||
if (e.key === "+") {
|
|
||||||
cellHeight += 2
|
|
||||||
} else if (e.key === "-") {
|
|
||||||
if (cellHeight - 2 >= 8) {
|
|
||||||
cellHeight -= 2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
setInterval(function () {
|
|
||||||
if (selectedElement == null) {
|
|
||||||
readEntries()
|
|
||||||
}
|
|
||||||
}, 500);
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
|
|
||||||
//returns internal format (0 - 96) to a string
|
|
||||||
function internal_to_time(internal) {
|
|
||||||
internal -= 1
|
|
||||||
internal /= 4
|
|
||||||
let integer = Math.floor(internal)
|
|
||||||
let decimal = internal.toFixed(2);
|
|
||||||
let minutes = Math.floor((decimal - integer) * 60);
|
|
||||||
let minutes_string = minutes.toString().length === 1 ? "0" + minutes : minutes
|
|
||||||
return integer + ":" + minutes_string;
|
|
||||||
}
|
|
||||||
|
|
||||||
let temp = []
|
|
||||||
for (let i = 2; i <= 96; i += 2) {
|
|
||||||
temp.push(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
function onMonthClick(monthIndex, startParts) {
|
|
||||||
monthIndex--
|
|
||||||
let date = new Date(parseInt(startParts[2]), monthIndex, 1)
|
|
||||||
let start = new Date(date.getFullYear(), 0, 0)
|
|
||||||
currentWeekStartDay = Math.round((date - start) / (1000 * 60 * 60 * 24))
|
|
||||||
currentWeekStartDay = currentWeekStartDay - new Date(date.getFullYear(), 0, currentWeekStartDay).getUTCDay()
|
|
||||||
currentYear = date.getFullYear()
|
|
||||||
setHighlightMonth(date.getMonth())
|
|
||||||
setHighlightYear(currentYear)
|
|
||||||
|
|
||||||
for(let i = 0; i < errorState.length; i++)
|
|
||||||
{
|
|
||||||
errorState[i] = ErrorType.Okay
|
|
||||||
}
|
|
||||||
|
|
||||||
readEntries()
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
|
|
||||||
<div className={"calender-direction-wrapper"}>
|
|
||||||
<div>
|
|
||||||
<BasicDateCalendar startyear={startYearCalenderSideBar} startday={startDayCalenderSideBar}
|
|
||||||
endyear={endYearCalenderSideBar} endday={endDayCalenderSideBar}
|
|
||||||
highlightYear={highlightYear} highlightMonth={highlightMonth}
|
|
||||||
onMonthClick={onMonthClick}/>
|
|
||||||
</div>
|
|
||||||
<div style={{
|
|
||||||
display: "flex",
|
|
||||||
height: "73vh",
|
|
||||||
flexDirection: "column",
|
|
||||||
justifyContent: "center",
|
|
||||||
alignItems: "center",
|
|
||||||
}} id={update}>
|
|
||||||
<WeekSelector year={currentYear} startday={currentWeekStartDay} onFunctionLeft={() => onWeekLeft()}
|
|
||||||
onFunctionRight={() => onWeekRight()}/>
|
|
||||||
<div style={{
|
|
||||||
display: "flex",
|
|
||||||
flexDirection: "row",
|
|
||||||
justifyContent: "center",
|
|
||||||
alignItems: "center",
|
|
||||||
backgroundColor: "white",
|
|
||||||
gap: 5,
|
|
||||||
}}>
|
|
||||||
<div style={{borderRadius: 10, padding: 10, backgroundColor: "#f1f1f1"}} className={"box-shadow"}>
|
|
||||||
<div>
|
|
||||||
<div className={"wochen-tag-container"}>
|
|
||||||
<div
|
|
||||||
className={"wochen-tag font-big"}>Montag {new Date(currentYear, 0, currentWeekStartDay).getDate()}.
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
className={"wochen-tag font-big"}>Dienstag {new Date(currentYear, 0, currentWeekStartDay + 1).getDate()}.
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
className={"wochen-tag font-big"}>Mittwoch {new Date(currentYear, 0, currentWeekStartDay + 2).getDate()}.
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
className={"wochen-tag font-big"}>Donnerstag {new Date(currentYear, 0, currentWeekStartDay + 3).getDate()}.
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
className={"wochen-tag font-big"}>Freitag {new Date(currentYear, 0, currentWeekStartDay + 4).getDate()}.
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
className={"wochen-tag font-big"}>Samstag {new Date(currentYear, 0, currentWeekStartDay + 5).getDate()}.
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className={"calender-container"} ref={scrollRef}>
|
|
||||||
|
|
||||||
<div className={"calender-view content"} style={{height: cellHeight * 96 + 10}}>
|
|
||||||
|
|
||||||
|
|
||||||
<div className={"spalte"}
|
|
||||||
id={"0"} style={{gridTemplateRows: `repeat(96, ${cellHeight}px)`, backgroundColor: grayedOut[0] ? "#aaaaaa" : "#ffffff"}}
|
|
||||||
onMouseDown={e => onMouseDown(e)}
|
|
||||||
onMouseMove={e => onMouseMove(e)}
|
|
||||||
onMouseUp={e => onMouseUp(e)}>
|
|
||||||
|
|
||||||
{entries[0].map(d => (d != null && <div className={"entry"} style={{
|
|
||||||
width: "100%",
|
|
||||||
gridRowStart: d.timestart,
|
|
||||||
gridRowEnd: d.timeend,
|
|
||||||
backgroundColor: getEntryColor(d.usercreatedbyid, 0, d.semesterid)
|
|
||||||
}} id={d.id + "e"}>
|
|
||||||
<div className={"resize-grab"} id={"grabup"} style={{
|
|
||||||
backgroundColor: getResizeBarColor(d.usercreatedbyid, 0, d.semesterid)
|
|
||||||
}}></div>
|
|
||||||
<div style={{maxHeight: "60%"}} className={"no-pointer-events"}>
|
|
||||||
<p>{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}</p>
|
|
||||||
<p>{d.info}</p>
|
|
||||||
</div>
|
|
||||||
<div className={"resize-grab"} id={"grabdown"} style={{
|
|
||||||
backgroundColor: getResizeBarColor(d.usercreatedbyid, 0, d.semesterid)
|
|
||||||
}}></div>
|
|
||||||
</div>))}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div className={"spalte"}
|
|
||||||
id={"1"} style={{gridTemplateRows: `repeat(96, ${cellHeight}px)`, backgroundColor: grayedOut[1] ? "#aaaaaa" : "#ffffff"}}
|
|
||||||
onMouseDown={e => onMouseDown(e)}
|
|
||||||
onMouseMove={e => onMouseMove(e)}
|
|
||||||
onMouseUp={e => onMouseUp(e)}>
|
|
||||||
|
|
||||||
{entries[1].map(d => (d != null && <div className={"entry"} style={{
|
|
||||||
width: "100%",
|
|
||||||
gridRowStart: d.timestart,
|
|
||||||
gridRowEnd: d.timeend,
|
|
||||||
backgroundColor: getEntryColor(d.usercreatedbyid, 1, d.semesterid)
|
|
||||||
}} id={d.id + "e"}>
|
|
||||||
|
|
||||||
<div className={"resize-grab"} id={"grabup"} style={{
|
|
||||||
backgroundColor: getResizeBarColor(d.usercreatedbyid, 1, d.semesterid)
|
|
||||||
}}></div>
|
|
||||||
<div style={{maxHeight: "60%"}} className={"no-pointer-events"}>
|
|
||||||
<p>{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}</p>
|
|
||||||
<p>{d.info}</p>
|
|
||||||
</div>
|
|
||||||
<div className={"resize-grab"} id={"grabdown"} style={{
|
|
||||||
backgroundColor: getResizeBarColor(d.usercreatedbyid, 1, d.semesterid)
|
|
||||||
}}></div>
|
|
||||||
</div>))}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div className={"spalte"}
|
|
||||||
id={"2"} style={{gridTemplateRows: `repeat(96, ${cellHeight}px)`, backgroundColor: grayedOut[2] ? "#aaaaaa" : "#ffffff"}}
|
|
||||||
onMouseDown={e => onMouseDown(e)}
|
|
||||||
onMouseMove={e => onMouseMove(e)}
|
|
||||||
onMouseUp={e => onMouseUp(e)}>
|
|
||||||
|
|
||||||
|
|
||||||
{entries[2].map(d => (d != null && <div className={"entry"} style={{
|
|
||||||
width: "100%",
|
|
||||||
gridRowStart: d.timestart,
|
|
||||||
gridRowEnd: d.timeend,
|
|
||||||
backgroundColor: getEntryColor(d.usercreatedbyid, 2, d.semesterid)
|
|
||||||
}} id={d.id + "e"}>
|
|
||||||
|
|
||||||
<div className={"resize-grab"} id={"grabup"} style={{
|
|
||||||
backgroundColor: getResizeBarColor(d.usercreatedbyid, 2, d.semesterid)
|
|
||||||
}}></div>
|
|
||||||
<div style={{maxHeight: "60%"}} className={"no-pointer-events"}>
|
|
||||||
<p>{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}</p>
|
|
||||||
<p>{d.info}</p>
|
|
||||||
</div>
|
|
||||||
<div className={"resize-grab"} id={"grabdown"} style={{
|
|
||||||
backgroundColor: getResizeBarColor(d.usercreatedbyid, 2, d.semesterid)
|
|
||||||
}}></div>
|
|
||||||
</div>))}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div className={"spalte"}
|
|
||||||
id={"3"} style={{gridTemplateRows: `repeat(96, ${cellHeight}px)`, backgroundColor: grayedOut[3] ? "#aaaaaa" : "#ffffff"}}
|
|
||||||
onMouseDown={e => onMouseDown(e)}
|
|
||||||
onMouseMove={e => onMouseMove(e)}
|
|
||||||
onMouseUp={e => onMouseUp(e)}>
|
|
||||||
|
|
||||||
{entries[3].map(d => (d != null && <div className={"entry"} style={{
|
|
||||||
width: "100%",
|
|
||||||
gridRowStart: d.timestart,
|
|
||||||
gridRowEnd: d.timeend,
|
|
||||||
backgroundColor: getEntryColor(d.usercreatedbyid, 3, d.semesterid)
|
|
||||||
}} id={d.id + "e"}>
|
|
||||||
|
|
||||||
<div className={"resize-grab"} id={"grabup"} style={{
|
|
||||||
backgroundColor: getResizeBarColor(d.usercreatedbyid, 3, d.semesterid)
|
|
||||||
}}></div>
|
|
||||||
<div style={{maxHeight: "60%"}} className={"no-pointer-events"}>
|
|
||||||
<p>{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}</p>
|
|
||||||
<p>{d.info}</p>
|
|
||||||
</div>
|
|
||||||
<div className={"resize-grab"} id={"grabdown"} style={{
|
|
||||||
backgroundColor: getResizeBarColor(d.usercreatedbyid, 3, d.semesterid)
|
|
||||||
}}></div>
|
|
||||||
</div>))}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div className={"spalte"}
|
|
||||||
id={"4"} style={{gridTemplateRows: `repeat(96, ${cellHeight}px)`, backgroundColor: grayedOut[4] ? "#aaaaaa" : "#ffffff"}}
|
|
||||||
onMouseDown={e => onMouseDown(e)}
|
|
||||||
onMouseMove={e => onMouseMove(e)}
|
|
||||||
onMouseUp={e => onMouseUp(e)}>
|
|
||||||
|
|
||||||
|
|
||||||
{entries[4].map(d => (d != null && <div className={"entry"} style={{
|
|
||||||
width: "100%",
|
|
||||||
gridRowStart: d.timestart,
|
|
||||||
gridRowEnd: d.timeend,
|
|
||||||
backgroundColor: getEntryColor(d.usercreatedbyid, 4, d.semesterid)
|
|
||||||
}} id={d.id + "e"}>
|
|
||||||
<div className={"resize-grab"} id={"grabup"} style={{
|
|
||||||
backgroundColor: getResizeBarColor(d.usercreatedbyid, 4, d.semesterid)
|
|
||||||
}}></div>
|
|
||||||
<div style={{maxHeight: "60%"}} className={"no-pointer-events"}>
|
|
||||||
<p>{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}</p>
|
|
||||||
<p>{d.info}</p>
|
|
||||||
</div>
|
|
||||||
<div className={"resize-grab"} id={"grabdown"} style={{
|
|
||||||
backgroundColor: getResizeBarColor(d.usercreatedbyid, 4, d.semesterid)
|
|
||||||
}}></div>
|
|
||||||
</div>))}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div className={"spalte"}
|
|
||||||
id={"5"} style={{gridTemplateRows: `repeat(96, ${cellHeight}px)`, backgroundColor: grayedOut[5] ? "#aaaaaa" : "#ffffff"}}
|
|
||||||
onMouseDown={e => onMouseDown(e)}
|
|
||||||
onMouseMove={e => onMouseMove(e)}
|
|
||||||
onMouseUp={e => onMouseUp(e)}>
|
|
||||||
|
|
||||||
|
|
||||||
{entries[5].map(d => (d != null && <div className={"entry"} style={{
|
|
||||||
width: "100%",
|
|
||||||
gridRowStart: d.timestart,
|
|
||||||
gridRowEnd: d.timeend,
|
|
||||||
backgroundColor: getEntryColor(d.usercreatedbyid, 5, d.semesterid)
|
|
||||||
}} id={d.id + "e"}>
|
|
||||||
<div className={"resize-grab"} id={"grabup"} style={{
|
|
||||||
backgroundColor: getResizeBarColor(d.usercreatedbyid, 5, d.semesterid)
|
|
||||||
}}></div>
|
|
||||||
<div style={{maxHeight: "60%"}} className={"no-pointer-events"}>
|
|
||||||
<p>{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}</p>
|
|
||||||
<p>{d.info}</p>
|
|
||||||
</div>
|
|
||||||
<div className={"resize-grab"} id={"grabdown"} style={{
|
|
||||||
backgroundColor: getResizeBarColor(d.usercreatedbyid, 5, d.semesterid)
|
|
||||||
}}></div>
|
|
||||||
</div>))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div className={"overlay"} style={{backgroundColor: "rgba(0, 0, 0, 0)"}}>
|
|
||||||
{/*maps a list of internal time stamps to lines and time stamps*/}
|
|
||||||
{temp.map(i => (<div style={{
|
|
||||||
width: "100%",
|
|
||||||
height: cellHeight * 2,
|
|
||||||
display: "flex",
|
|
||||||
flexDirection: "row",
|
|
||||||
justifyContent: "space-around",
|
|
||||||
alignItems: "center",
|
|
||||||
}} className={"no-pointer-events"}>
|
|
||||||
<div style={{
|
|
||||||
borderBottom: (i / 4 === 7 || i / 4 === 18 ? "3px solid #fc3d03" : "1px solid #363636"),
|
|
||||||
}}><p style={{
|
|
||||||
color: "gray",
|
|
||||||
marginTop: cellHeight - 3,
|
|
||||||
marginRight: 120,
|
|
||||||
fontSize: 12,
|
|
||||||
textAlign: "center"
|
|
||||||
}}>{internal_to_time(i + 1)}</p></div>
|
|
||||||
|
|
||||||
<div style={{
|
|
||||||
borderBottom: (i / 4 === 7 || i / 4 === 18 ? "3px solid #fc3d03" : "1px solid #363636"),
|
|
||||||
}}><p style={{
|
|
||||||
color: "gray",
|
|
||||||
marginTop: cellHeight - 3,
|
|
||||||
marginRight: 120,
|
|
||||||
fontSize: 12,
|
|
||||||
textAlign: "center"
|
|
||||||
}}>{internal_to_time(i + 1)}</p></div>
|
|
||||||
<div style={{
|
|
||||||
borderBottom: (i / 4 === 7 || i / 4 === 18 ? "3px solid #fc3d03" : "1px solid #363636"),
|
|
||||||
}}><p style={{
|
|
||||||
color: "gray",
|
|
||||||
marginTop: cellHeight - 3,
|
|
||||||
marginRight: 120,
|
|
||||||
fontSize: 12,
|
|
||||||
textAlign: "center"
|
|
||||||
}}>{internal_to_time(i + 1)}</p></div>
|
|
||||||
<div style={{
|
|
||||||
borderBottom: (i / 4 === 7 || i / 4 === 18 ? "3px solid #fc3d03" : "1px solid #363636"),
|
|
||||||
}}><p style={{
|
|
||||||
color: "gray",
|
|
||||||
marginTop: cellHeight - 3,
|
|
||||||
marginRight: 120,
|
|
||||||
fontSize: 12,
|
|
||||||
textAlign: "center"
|
|
||||||
}}>{internal_to_time(i + 1)}</p></div>
|
|
||||||
<div style={{
|
|
||||||
borderBottom: (i / 4 === 7 || i / 4 === 18 ? "3px solid #fc3d03" : "1px solid #363636"),
|
|
||||||
}}><p style={{
|
|
||||||
color: "gray",
|
|
||||||
marginTop: cellHeight - 3,
|
|
||||||
marginRight: 120,
|
|
||||||
fontSize: 12,
|
|
||||||
textAlign: "center"
|
|
||||||
}}>{internal_to_time(i + 1)}</p></div>
|
|
||||||
<div style={{
|
|
||||||
borderBottom: (i / 4 === 7 || i / 4 === 18 ? "3px solid #fc3d03" : "1px solid #363636"),
|
|
||||||
}}><p style={{
|
|
||||||
color: "gray",
|
|
||||||
marginTop: cellHeight - 3,
|
|
||||||
marginRight: 120,
|
|
||||||
fontSize: 12,
|
|
||||||
textAlign: "center"
|
|
||||||
}}>{internal_to_time(i + 1)}</p></div>
|
|
||||||
</div>))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className={"error-bar"}>
|
|
||||||
{errorState.map((e, index) => (
|
|
||||||
<div style={{
|
|
||||||
display: e === ErrorType.Okay ? "none" : "flex",
|
|
||||||
width: "90%",
|
|
||||||
backgroundColor: e === ErrorType.Okay ? "white" : "#e5a10e",
|
|
||||||
borderRadius: 15,
|
|
||||||
flexDirection: "column",
|
|
||||||
justifyContent: "center",
|
|
||||||
gap: 10,
|
|
||||||
alignItems: "center",
|
|
||||||
minHeight: 120,
|
|
||||||
maxHeight: 120,
|
|
||||||
padding: 10
|
|
||||||
}} className={"box-shadow"}>
|
|
||||||
<p style={{
|
|
||||||
borderRadius: 15,
|
|
||||||
backgroundColor: "#346991",
|
|
||||||
width: "90%",
|
|
||||||
paddingTop: 1,
|
|
||||||
paddingBottom: 1,
|
|
||||||
color: "white",
|
|
||||||
textAlign: "center"
|
|
||||||
}}>{new Date(currentYear, 0, currentWeekStartDay + index).toLocaleDateString()}</p>
|
|
||||||
<p style={{
|
|
||||||
textAlign: "center"
|
|
||||||
}}>{e}</p>
|
|
||||||
</div>))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
//export const baseURL = "http://185.245.96.48:8080"
|
|
||||||
export const baseURL = "http://localhost:8080"
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
function addDays(date, days) {
|
|
||||||
let result = new Date(date);
|
|
||||||
result.setDate(result.getDate() + days);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function DateElement(p){
|
|
||||||
|
|
||||||
let startDate = new Date(p.year, 0, p.startday);
|
|
||||||
let endDate = new Date(p.year, 0, p.startday + 5);
|
|
||||||
|
|
||||||
let startDateString = `${startDate.getDate()}.${startDate.getMonth()+1}.${startDate.getFullYear()}`;
|
|
||||||
let endDateString = `${endDate.getDate()}.${endDate.getMonth()+1}.${endDate.getFullYear()}`;
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<div className="dateElement round-border box-shadow">
|
|
||||||
<p>{startDateString} - {endDateString}</p>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
export const ErrorType = {
|
|
||||||
Okay: "Okay",
|
|
||||||
TooLong: "Zu lang, maximal 8h pro Tag!",
|
|
||||||
TooEarly: "Wenn möglich nicht vor 8:00",
|
|
||||||
TooLate: "Wenn möglich nicht nach 17:00",
|
|
||||||
NotEnoughLunchTime: "Mind. 45min Pause zwischen 11:00 - 14:00",
|
|
||||||
Saturday: "Wenn möglich nicht am Samstag"
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
import Button from "@/components/Button";
|
|
||||||
import {helpButton} from "@/components/Icons";
|
|
||||||
import {useRouter} from "next/router";
|
|
||||||
|
|
||||||
export default function HelpButton(p)
|
|
||||||
{
|
|
||||||
const router = useRouter()
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div style={{
|
|
||||||
position: "absolute",
|
|
||||||
bottom: 20,
|
|
||||||
right: 20,
|
|
||||||
borderRadius: 15
|
|
||||||
}} className={"box-shadow"}>
|
|
||||||
<Button width={40} height={40} color={"white"} icon={helpButton} onClick={() => router.push("/help")}/>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
export const arrowLeft = `<svg xmlns="http://www.w3.org/2000/svg" fill="white" class="bi bi-arrow-left" viewBox="0 0 16 16">
|
|
||||||
<path fill-rule="evenodd" d="M15 8a.5.5 0 0 0-.5-.5H2.707l3.147-3.146a.5.5 0 1 0-.708-.708l-4 4a.5.5 0 0 0 0 .708l4 4a.5.5 0 0 0 .708-.708L2.707 8.5H14.5A.5.5 0 0 0 15 8z"/>
|
|
||||||
</svg>`
|
|
||||||
|
|
||||||
export const arrowRight = `<svg xmlns="http://www.w3.org/2000/svg" fill="white" class="bi bi-arrow-right" viewBox="0 0 16 16">
|
|
||||||
<path fill-rule="evenodd" d="M1 8a.5.5 0 0 1 .5-.5h11.793l-3.147-3.146a.5.5 0 0 1 .708-.708l4 4a.5.5 0 0 1 0 .708l-4 4a.5.5 0 0 1-.708-.708L13.293 8.5H1.5A.5.5 0 0 1 1 8z"/>
|
|
||||||
</svg>`
|
|
||||||
|
|
||||||
export const deleteItem = `<svg xmlns="http://www.w3.org/2000/svg" fill="black" class="bi bi-trash-fill" viewBox="0 0 16 16">
|
|
||||||
<path d="M2.5 1a1 1 0 0 0-1 1v1a1 1 0 0 0 1 1H3v9a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V4h.5a1 1 0 0 0 1-1V2a1 1 0 0 0-1-1H10a1 1 0 0 0-1-1H7a1 1 0 0 0-1 1H2.5zm3 4a.5.5 0 0 1 .5.5v7a.5.5 0 0 1-1 0v-7a.5.5 0 0 1 .5-.5zM8 5a.5.5 0 0 1 .5.5v7a.5.5 0 0 1-1 0v-7A.5.5 0 0 1 8 5zm3 .5v7a.5.5 0 0 1-1 0v-7a.5.5 0 0 1 1 0z"/>
|
|
||||||
</svg>`
|
|
||||||
|
|
||||||
export const editItem = `<svg xmlns="http://www.w3.org/2000/svg" fill="black" class="bi bi-pencil-fill" viewBox="0 0 16 16">
|
|
||||||
<path d="M12.854.146a.5.5 0 0 0-.707 0L10.5 1.793 14.207 5.5l1.647-1.646a.5.5 0 0 0 0-.708l-3-3zm.646 6.061L9.793 2.5 3.293 9H3.5a.5.5 0 0 1 .5.5v.5h.5a.5.5 0 0 1 .5.5v.5h.5a.5.5 0 0 1 .5.5v.5h.5a.5.5 0 0 1 .5.5v.207l6.5-6.5zm-7.468 7.468A.5.5 0 0 1 6 13.5V13h-.5a.5.5 0 0 1-.5-.5V12h-.5a.5.5 0 0 1-.5-.5V11h-.5a.5.5 0 0 1-.5-.5V10h-.5a.499.499 0 0 1-.175-.032l-.179.178a.5.5 0 0 0-.11.168l-2 5a.5.5 0 0 0 .65.65l5-2a.5.5 0 0 0 .168-.11l.178-.178z"/>
|
|
||||||
</svg>`
|
|
||||||
|
|
||||||
export const helpButton = `<svg xmlns="http://www.w3.org/2000/svg" fill="black" class="bi bi-question" viewBox="0 0 16 16">
|
|
||||||
<path d="M5.255 5.786a.237.237 0 0 0 .241.247h.825c.138 0 .248-.113.266-.25.09-.656.54-1.134 1.342-1.134.686 0 1.314.343 1.314 1.168 0 .635-.374.927-.965 1.371-.673.489-1.206 1.06-1.168 1.987l.003.217a.25.25 0 0 0 .25.246h.811a.25.25 0 0 0 .25-.25v-.105c0-.718.273-.927 1.01-1.486.609-.463 1.244-.977 1.244-2.056 0-1.511-1.276-2.241-2.673-2.241-1.267 0-2.655.59-2.75 2.286zm1.557 5.763c0 .533.425.927 1.01.927.609 0 1.028-.394 1.028-.927 0-.552-.42-.94-1.029-.94-.584 0-1.009.388-1.009.94z"/>
|
|
||||||
</svg>`
|
|
||||||
@@ -1,361 +0,0 @@
|
|||||||
import Button from "@/components/Button";
|
|
||||||
import {useRouter} from "next/router";
|
|
||||||
import {useEffect, useState} from "react";
|
|
||||||
import Background from "@/components/Background";
|
|
||||||
import {baseURL} from "@/components/Constants";
|
|
||||||
import Back from "@/components/Back";
|
|
||||||
|
|
||||||
let modulesDummy = [
|
|
||||||
["Analysis", "Theo Inf 1"],
|
|
||||||
["Lineare Algebra", "Anwendungsprojekt"],
|
|
||||||
["Theo Inf 3", "Software Eng"],
|
|
||||||
["Security", "BWL"],
|
|
||||||
["Software Eng", "Security"],
|
|
||||||
["Studienarbeit", "Bachelor"]
|
|
||||||
]
|
|
||||||
|
|
||||||
let tempSemesterNumber = 0
|
|
||||||
let update = false
|
|
||||||
|
|
||||||
let baseMapping = []
|
|
||||||
|
|
||||||
export default function InputForm(p) {
|
|
||||||
|
|
||||||
const [startDate, setStartDate] = useState("0000-00-00")
|
|
||||||
const [endDate, setEndDate] = useState("0000-00-00")
|
|
||||||
const [courseName, setCourseName] = useState("")
|
|
||||||
const [semesterNumber, setSemesterNumber] = useState(0)
|
|
||||||
const [users, setUsers] = useState([])
|
|
||||||
const [modulesSelectorValues, setModulesSelectorValues] = useState(["nothing", "nothing"])
|
|
||||||
const [userModulesMapping, setUserModulesMapping] = useState({})
|
|
||||||
const [isChecked, setIsChecked] = useState([])
|
|
||||||
const [isActivated, setIsActivated] = useState([])
|
|
||||||
const router = useRouter()
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
|
|
||||||
let base = baseURL + "/semester/id?sessionid=" + localStorage.getItem("sessionid") + "&id=" + localStorage.getItem("currentsid")
|
|
||||||
fetch(base).then(r => r.json()).then(j => {
|
|
||||||
setCourseName(j.name)
|
|
||||||
|
|
||||||
let tempStartDate = new Date(parseInt(j.startyear), 0, parseInt(j.startday))
|
|
||||||
let tempEndDate = new Date(parseInt(j.endyear), 0, parseInt(j.endday))
|
|
||||||
|
|
||||||
setStartDate(tempStartDate.getFullYear() + "-" + ((tempStartDate.getMonth() + 1).toString().padStart(2, "0")) + "-" + tempStartDate.getDate().toString().padStart(2, "0"))
|
|
||||||
setEndDate(tempEndDate.getFullYear() + "-" + ((tempEndDate.getMonth() + 1).toString().padStart(2, "0")) + "-" + tempEndDate.getDate().toString().padStart(2, "0"))
|
|
||||||
|
|
||||||
setSemesterNumber(j.number)
|
|
||||||
tempSemesterNumber = j.number
|
|
||||||
|
|
||||||
}).then(() => {
|
|
||||||
readModules()
|
|
||||||
update = true
|
|
||||||
}).catch(() => readModules())
|
|
||||||
|
|
||||||
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
function readModules() {
|
|
||||||
let usersTemp = []
|
|
||||||
|
|
||||||
let userURL = baseURL + "/users/all?sessionid=" + localStorage.getItem("sessionid")
|
|
||||||
fetch(userURL).then(r => r.json()).then(j => {
|
|
||||||
setUsers(j)
|
|
||||||
usersTemp = j
|
|
||||||
let temp = [false, false, false]
|
|
||||||
let temp2 = []
|
|
||||||
for (let i = 0; i < j.length; i++) {
|
|
||||||
temp.push(false)
|
|
||||||
temp2.push(false)
|
|
||||||
}
|
|
||||||
setIsChecked(temp)
|
|
||||||
setIsActivated(temp2)
|
|
||||||
}).then(() => {
|
|
||||||
let modulesURL = baseURL + "/module/bysemesterid?sessionid=" + localStorage.getItem("sessionid") + "&semesterid=" + localStorage.getItem("currentsid");
|
|
||||||
fetch(modulesURL).then(r => r.json()).then(j => {
|
|
||||||
|
|
||||||
setUserModulesMapping(j)
|
|
||||||
baseMapping = j
|
|
||||||
|
|
||||||
let temp = isChecked.slice()
|
|
||||||
let temp2 = isActivated.slice()
|
|
||||||
|
|
||||||
for (let i = 0; i < usersTemp.length; i++) {
|
|
||||||
let currentUser = usersTemp[i]
|
|
||||||
|
|
||||||
let found = false
|
|
||||||
let foundModuleLast = null
|
|
||||||
for (let f = 0; f < j.length; f++) {
|
|
||||||
let currentModule = j[f]
|
|
||||||
|
|
||||||
if (currentModule.userid === currentUser.id) {
|
|
||||||
found = true
|
|
||||||
foundModuleLast = currentModule
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (found) {
|
|
||||||
temp[i] = true
|
|
||||||
|
|
||||||
temp2[i] = foundModuleLast.activated === 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setIsChecked(temp)
|
|
||||||
setIsActivated(temp2)
|
|
||||||
})
|
|
||||||
}).then(() => {
|
|
||||||
setModulesSelectorValues(modulesDummy[tempSemesterNumber])
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function onCourseNameChange(e) {
|
|
||||||
setCourseName(e.target.value)
|
|
||||||
}
|
|
||||||
|
|
||||||
function onStartDateChange(e) {
|
|
||||||
setStartDate(e.target.value)
|
|
||||||
}
|
|
||||||
|
|
||||||
function onEndDateChange(e) {
|
|
||||||
setEndDate(e.target.value)
|
|
||||||
}
|
|
||||||
|
|
||||||
function onSemesterNumberChange(e) {
|
|
||||||
setSemesterNumber(e.target.value)
|
|
||||||
setModulesSelectorValues(modulesDummy[e.target.value])
|
|
||||||
}
|
|
||||||
|
|
||||||
function isOptionSelected(e, userid) {
|
|
||||||
let found = false;
|
|
||||||
|
|
||||||
for (let i = 0; i < userModulesMapping.length; i++) {
|
|
||||||
let current = userModulesMapping[i]
|
|
||||||
if (current.name === e && current.userid === userid) {
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return found;
|
|
||||||
}
|
|
||||||
|
|
||||||
function onCheckedChange(e, index) {
|
|
||||||
let temp = isChecked.slice()
|
|
||||||
temp[index] = e.target.checked
|
|
||||||
setIsChecked(temp)
|
|
||||||
|
|
||||||
if (!e.target.checked) {
|
|
||||||
let temp = []
|
|
||||||
let currentUser = users[index]
|
|
||||||
for (let j = 0; j < userModulesMapping.length; j++) {
|
|
||||||
if (userModulesMapping[j].userid !== currentUser.id) {
|
|
||||||
temp.push(userModulesMapping[j])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setUserModulesMapping(temp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function onActivatedChange(e, index) {
|
|
||||||
|
|
||||||
let temp = isActivated.slice()
|
|
||||||
temp[index] = e.target.checked
|
|
||||||
setIsActivated(temp)
|
|
||||||
|
|
||||||
let userid = users[index].id
|
|
||||||
|
|
||||||
for (let j = 0; j < userModulesMapping.length; j++) {
|
|
||||||
if (userModulesMapping[j].userid === userid) {
|
|
||||||
userModulesMapping[j].activated = e.target.checked ? 1 : 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function onModuleSelectionChange(e, index) {
|
|
||||||
let userid = users[index].id
|
|
||||||
|
|
||||||
let newMapping = []
|
|
||||||
let oldNamesIds = new Map()
|
|
||||||
|
|
||||||
for (let j = 0; j < userModulesMapping.length; j++) {
|
|
||||||
let currentModuleMapping = userModulesMapping[j]
|
|
||||||
if (currentModuleMapping.userid != userid) {
|
|
||||||
newMapping.push(currentModuleMapping)
|
|
||||||
} else {
|
|
||||||
oldNamesIds.set(currentModuleMapping.name, currentModuleMapping.id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let found = false
|
|
||||||
for (let i = 0; i < e.target.options.length; i++) {
|
|
||||||
|
|
||||||
let currentOption = e.target.options[i]
|
|
||||||
if (currentOption.selected) {
|
|
||||||
found = true
|
|
||||||
|
|
||||||
newMapping.push({
|
|
||||||
"id": oldNamesIds.has(currentOption.value) ? oldNamesIds.get(currentOption.value) : -1,
|
|
||||||
"userid": userid,
|
|
||||||
"semesterid": -1,
|
|
||||||
"name": currentOption.value,
|
|
||||||
"activated": isActivated[index] ? 1 : 0
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let temp = isChecked.slice()
|
|
||||||
temp[index] = found
|
|
||||||
setIsChecked(temp)
|
|
||||||
|
|
||||||
setUserModulesMapping(newMapping)
|
|
||||||
}
|
|
||||||
|
|
||||||
function onButtonAbort() {
|
|
||||||
router.back()
|
|
||||||
}
|
|
||||||
|
|
||||||
function onButtonSave() {
|
|
||||||
let tempDateStart = new Date(parseInt(startDate.split("-")[0]), parseInt(startDate.split("-")[1]) - 1, parseInt(startDate.split("-")[2]))
|
|
||||||
let tempDateEnd = new Date(parseInt(endDate.split("-")[0]), parseInt(endDate.split("-")[1]) - 1, parseInt(endDate.split("-")[2]))
|
|
||||||
|
|
||||||
let startDayInYear = Math.round((tempDateStart - new Date(tempDateStart.getFullYear(), 0, 0)) / (1000 * 60 * 60 * 24))
|
|
||||||
let endDayInYear = Math.round((tempDateEnd - new Date(tempDateEnd.getFullYear(), 0, 0)) / (1000 * 60 * 60 * 24))
|
|
||||||
|
|
||||||
|
|
||||||
let semesterJson = {
|
|
||||||
"id": update ? localStorage.getItem("currentsid") : 0,
|
|
||||||
"startday": startDayInYear,
|
|
||||||
"endday": endDayInYear,
|
|
||||||
"name": courseName,
|
|
||||||
"startyear": tempDateStart.getFullYear(),
|
|
||||||
"endyear": tempDateEnd.getFullYear(),
|
|
||||||
"number": semesterNumber
|
|
||||||
}
|
|
||||||
|
|
||||||
fetch(baseURL + "/semester?sessionid=" + localStorage.getItem("sessionid"), {
|
|
||||||
method: update ? "PUT" : "POST",
|
|
||||||
headers: {"Content-Type": "application/json"},
|
|
||||||
body: JSON.stringify(semesterJson)
|
|
||||||
}).then(r => r.json()).then(async sem => {
|
|
||||||
let semesterID = sem.id
|
|
||||||
|
|
||||||
for (let i = 0; i < baseMapping.length; i++) {
|
|
||||||
let found = false
|
|
||||||
for (let j = 0; j < userModulesMapping.length; j++) {
|
|
||||||
if (baseMapping[i].name === userModulesMapping[j].name) {
|
|
||||||
found = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found) {
|
|
||||||
fetch(baseURL + "/module?sessionid=" + localStorage.getItem("sessionid") + "&id=" + baseMapping[i].id, {
|
|
||||||
method: "DELETE"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < userModulesMapping.length; i++) {
|
|
||||||
|
|
||||||
userModulesMapping[i].semesterid = semesterID
|
|
||||||
setTimeout(() => {
|
|
||||||
console.log(userModulesMapping[i])
|
|
||||||
fetch(baseURL + "/module?sessionid=" + localStorage.getItem("sessionid"), {
|
|
||||||
method: userModulesMapping[i].id === -1 ? "POST" : "PUT",
|
|
||||||
headers: {"Content-Type": "application/json"},
|
|
||||||
body: JSON.stringify(userModulesMapping[i])
|
|
||||||
})
|
|
||||||
}, i * 100)
|
|
||||||
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
router.back()
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Background/>
|
|
||||||
<div className={"box-shadow input-form round-border"}>
|
|
||||||
|
|
||||||
<p>Kursname</p>
|
|
||||||
<input type={"text"} className={"box-shadow round-border"} style={{padding: 8, width: "100%"}}
|
|
||||||
onChange={e => onCourseNameChange(e)} value={courseName}/>
|
|
||||||
|
|
||||||
<div style={{display: "flex", justifyContent: "flex-start", gap: 40}}>
|
|
||||||
<p>Theorie Anfang</p>
|
|
||||||
<p>Theorie Ende</p>
|
|
||||||
</div>
|
|
||||||
<div style={{display: "flex", justifyContent: "flex-start", gap: 20}}>
|
|
||||||
<input type={"date"} className={"box-shadow round-border"} style={{padding: 8}}
|
|
||||||
onChange={e => onStartDateChange(e)} value={startDate}/>
|
|
||||||
<input type={"date"} className={"box-shadow round-border"} style={{padding: 8}}
|
|
||||||
onChange={e => onEndDateChange(e)} value={endDate}/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p>Semester Wählen</p>
|
|
||||||
<select className={"round-border box-shadow"} style={{padding: 5, width: "100%"}} value={semesterNumber}
|
|
||||||
onChange={e => onSemesterNumberChange(e)}>
|
|
||||||
<option value={0}>1. Semester</option>
|
|
||||||
<option value={1}>2. Semester</option>
|
|
||||||
<option value={2}>3. Semester</option>
|
|
||||||
<option value={3}>4. Semester</option>
|
|
||||||
<option value={4}>5. Semester</option>
|
|
||||||
<option value={5}>6. Semester</option>
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<div className={"table-wrapper"}>
|
|
||||||
<table>
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<th>Wählen</th>
|
|
||||||
<th>Freischalten</th>
|
|
||||||
<th>Dozent</th>
|
|
||||||
<th>Modul</th>
|
|
||||||
</tr>
|
|
||||||
{
|
|
||||||
users.map((user, index) => (
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<input type={"checkbox"} checked={isChecked[index]}
|
|
||||||
onChange={e => onCheckedChange(e, index)}/>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<input type={"checkbox"} checked={isActivated[index]}
|
|
||||||
onChange={e => onActivatedChange(e, index)}/>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
{user.firstName + " " + user.lastName}
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<select multiple={true} className={"box-shadow round-border"}
|
|
||||||
style={{padding: 5}}
|
|
||||||
onChange={e => onModuleSelectionChange(e, index)}>
|
|
||||||
{modulesSelectorValues.map(msv => (
|
|
||||||
<option value={msv}
|
|
||||||
selected={isOptionSelected(msv, user.id)}>{msv}</option>
|
|
||||||
))}
|
|
||||||
</select>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
))
|
|
||||||
}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div style={{
|
|
||||||
display: "flex",
|
|
||||||
justifyContent: "flex-end",
|
|
||||||
alignItems: "center",
|
|
||||||
width: "100%",
|
|
||||||
gap: 10
|
|
||||||
}}>
|
|
||||||
<Button text={"Abbrechen"} onClick={onButtonAbort}/>
|
|
||||||
<Button text={"Speichern"} color={"#77932b"} onClick={onButtonSave}/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
import React, {useState} from "react";
|
|
||||||
import Button from "@/components/Button";
|
|
||||||
import {NextResponse} from "next/server";
|
|
||||||
import Link from "next/link";
|
|
||||||
import {useRouter} from "next/router";
|
|
||||||
import {baseURL} from "@/components/Constants";
|
|
||||||
|
|
||||||
export default function Login() {
|
|
||||||
|
|
||||||
let url = baseURL + "/users"
|
|
||||||
|
|
||||||
async function on_login_click() {
|
|
||||||
url += "?mail=" + inputUserName + "&password=" + inputPassword;
|
|
||||||
|
|
||||||
let response = await fetch(url, {
|
|
||||||
method: "GET",
|
|
||||||
});
|
|
||||||
|
|
||||||
let reader = response.body.getReader();
|
|
||||||
let value = String.fromCharCode.apply(null, ((await reader.read()).value))
|
|
||||||
if (value != "failed") {
|
|
||||||
localStorage.setItem("sessionid", value);
|
|
||||||
|
|
||||||
url = baseURL + "/users/check?sessionid=" + value;
|
|
||||||
fetch(url).then(r => r.json()).then(u => localStorage.setItem("userid", u.id))
|
|
||||||
let admin = 0
|
|
||||||
await fetch(url).then(o => o.json()).then(user => {
|
|
||||||
admin = user.permissions})
|
|
||||||
localStorage.setItem("admin", admin)
|
|
||||||
if(admin === 1) {
|
|
||||||
await router.push("/semesteroverview")
|
|
||||||
}else await router.push("/semesteroverviewLecturer")
|
|
||||||
|
|
||||||
} else {
|
|
||||||
setInputPassword("");
|
|
||||||
setInputUserName("");
|
|
||||||
setHint("wrong login credentials")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const [inputUserName, setInputUserName] = useState("")
|
|
||||||
const [inputPassword, setInputPassword] = useState("")
|
|
||||||
const [hint, setHint] = useState("type here")
|
|
||||||
const [backgroundColor, setBackgroundColor] = useState("rgb(255, 255, 255)")
|
|
||||||
const router = useRouter()
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
|
||||||
// <div className="border">
|
|
||||||
<login className={"login-container box-shadow"}>
|
|
||||||
<p className={"font-big-fat placement"}>Login</p>
|
|
||||||
<div className={"placement"}>
|
|
||||||
<br/>
|
|
||||||
<p className={"font-kinda-big"}>Username</p>
|
|
||||||
<input type="text" value={inputUserName} onChange={e => setInputUserName(e.target.value.toLowerCase())}
|
|
||||||
placeholder={hint} className="input input-bordered input-sm w-full max-w-xs box-shadow"
|
|
||||||
style={{
|
|
||||||
backgroundColor: backgroundColor
|
|
||||||
}}/>
|
|
||||||
<br/>
|
|
||||||
<p className={"font-kinda-big"}>Password</p>
|
|
||||||
<input type="password" value={inputPassword} onChange={e => setInputPassword(e.target.value)}
|
|
||||||
placeholder={hint} className="input input-bordered input-sm w-full max-w-xs box-shadow"
|
|
||||||
style={{
|
|
||||||
backgroundColor: backgroundColor
|
|
||||||
}}/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Button text={"Login"} color={"#77932b"} width={100} height={40} onClick={() => on_login_click()}/>
|
|
||||||
|
|
||||||
|
|
||||||
</login>
|
|
||||||
// </div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
import Button from "@/components/Button";
|
|
||||||
import {useRouter} from "next/router";
|
|
||||||
import {baseURL} from "@/components/Constants";
|
|
||||||
|
|
||||||
export default function Logout()
|
|
||||||
{
|
|
||||||
const router = useRouter()
|
|
||||||
|
|
||||||
async function logout()
|
|
||||||
{
|
|
||||||
let url = baseURL + "/users/logout?sessionid=" + localStorage.getItem("sessionid");
|
|
||||||
await fetch(url)
|
|
||||||
await router.push("/")
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div style={{
|
|
||||||
position: "absolute",
|
|
||||||
right: 20,
|
|
||||||
top: 20,
|
|
||||||
width: 130,
|
|
||||||
height: 60,
|
|
||||||
borderBottomRightRadius: 10,
|
|
||||||
|
|
||||||
}}>
|
|
||||||
<Button onClick={() => logout()} text={"Logout"} color={"#77932b"} width={100} height={40}/>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
import Button from "@/components/Button";
|
|
||||||
import {useState} from "react";
|
|
||||||
|
|
||||||
let shown = false;
|
|
||||||
|
|
||||||
export default function PopUp(p) {
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<div style={{
|
|
||||||
display: p.displayState
|
|
||||||
}}>
|
|
||||||
|
|
||||||
<div className={"modal-container"}>
|
|
||||||
<div className={"modal box-shadow"}>
|
|
||||||
<p className={"font-middle"}>{p.hint}</p>
|
|
||||||
<div>
|
|
||||||
<Button text={p.text1} color={"rgba(54,54,54,0.64)"} onClick={p.function1}/>
|
|
||||||
<Button text={p.text2} color={"#77932b"} onClick={p.function2}/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
import StatusBar from "@/components/StatusBar";
|
|
||||||
import React, {useEffect} from "react";
|
|
||||||
import Button from "@/components/Button";
|
|
||||||
import {deleteItem, editItem} from "@/components/Icons";
|
|
||||||
|
|
||||||
export default function SemesterTile(p)
|
|
||||||
{
|
|
||||||
let editable = true;
|
|
||||||
let color = "#ffffff"
|
|
||||||
if (p.color != null)
|
|
||||||
{
|
|
||||||
color = p.color;
|
|
||||||
}
|
|
||||||
if (p.editable != null)
|
|
||||||
{
|
|
||||||
editable = p.editable
|
|
||||||
}
|
|
||||||
useEffect(() =>
|
|
||||||
{
|
|
||||||
window.addEventListener("contextmenu", (e) => (e.preventDefault()))
|
|
||||||
})
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: "flex",
|
|
||||||
flexDirection: "column",
|
|
||||||
justifyContent: "center",
|
|
||||||
alignItems: "center",
|
|
||||||
backgroundColor: "rgba(0,0,0,0)"
|
|
||||||
}}
|
|
||||||
onClick={(e) => p.onClick(e)}>
|
|
||||||
<p className={"semester-tile-p"} style={{
|
|
||||||
}}>{p.text}</p>
|
|
||||||
<p className={"semester-tile-p"} style={{
|
|
||||||
color: "gray"
|
|
||||||
}}>{p.text2}</p>
|
|
||||||
<div style={{
|
|
||||||
display: editable ? "flex" : "none",
|
|
||||||
flexDirection: "row",
|
|
||||||
justifyContent: "center",
|
|
||||||
alignItems: "center",
|
|
||||||
gap: 5
|
|
||||||
}}>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
import React from "react"
|
|
||||||
|
|
||||||
export default function StatusBar(p)
|
|
||||||
{
|
|
||||||
if(p.progress > 100) p.progress = 100;
|
|
||||||
let classNames = ["not-started", "started", "finished"];
|
|
||||||
let index = p.progress / 50;
|
|
||||||
|
|
||||||
let actives = ["", "", ""]
|
|
||||||
actives[index] = "active";
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className={"step-container"}>
|
|
||||||
<div className={"steps"}>
|
|
||||||
<span className={"step " + classNames[0] + " " + actives[0]}>1</span>
|
|
||||||
<span className={"step " + classNames[1] + " " + actives[1]}>2</span>
|
|
||||||
<span className={"step " + classNames[2] + " " + actives[2]}>3</span>
|
|
||||||
<div className={"progress-bar " + classNames[index]}
|
|
||||||
style={{
|
|
||||||
width: p.progress + "%"
|
|
||||||
}}
|
|
||||||
></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
import Button from "@/components/Button";
|
|
||||||
import { baseURL } from "@/components/Constants";
|
|
||||||
import {useRouter} from "next/router";
|
|
||||||
|
|
||||||
export default function SubmitButton() {
|
|
||||||
|
|
||||||
const router = useRouter();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
position: "absolute",
|
|
||||||
right: 70,
|
|
||||||
bottom: 20,
|
|
||||||
borderBottomRightRadius: 10,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Button onClick={() => router.push("/submit")} text={"Abgeben"} color={"#77932b"} width={100} height={40} />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
import {baseURL} from "@/components/Constants";
|
|
||||||
import Button from "@/components/Button";
|
|
||||||
|
|
||||||
export default function SubmitWarning(p){
|
|
||||||
|
|
||||||
async function submit() {
|
|
||||||
let url = baseURL + "/module?sessionid=" + localStorage.getItem("sessionid");
|
|
||||||
|
|
||||||
let json1 = {
|
|
||||||
"id": 0,
|
|
||||||
"userid": localStorage.getItem("userid"),
|
|
||||||
"semesterid": localStorage.getItem("currentsid"),
|
|
||||||
"name": localStorage.getItem("currentmodulename"),
|
|
||||||
"activated": 0
|
|
||||||
}
|
|
||||||
|
|
||||||
await fetch(url, {
|
|
||||||
method: "PUT",
|
|
||||||
headers: {"Content-Type": "application/json"},
|
|
||||||
body: JSON.stringify(json1)
|
|
||||||
})
|
|
||||||
|
|
||||||
p.onClick();
|
|
||||||
p.onClick();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="box-shadow" style={{
|
|
||||||
position: "absolute",
|
|
||||||
top: 300,
|
|
||||||
left: 0,
|
|
||||||
right: 0,
|
|
||||||
borderRadius: 5,
|
|
||||||
textAlign: "center",
|
|
||||||
fontSize: 20,
|
|
||||||
margin: "auto",
|
|
||||||
width: 600
|
|
||||||
|
|
||||||
}}>
|
|
||||||
<p style={{paddingTop: 20, paddingBottom: 5}}>Möchten Sie wirklich abgeben?</p>
|
|
||||||
<p>Danach können Sie keine Änderungen mehr vornehmen!</p>
|
|
||||||
<div style={{
|
|
||||||
display: "flex",
|
|
||||||
flexDirection: "row",
|
|
||||||
justifyContent: "center",
|
|
||||||
paddingTop: 40,
|
|
||||||
paddingBottom: 20
|
|
||||||
}}>
|
|
||||||
<Button onClick={() => submit()} text={"Bestätigen"} color={"#77932b"} width={100} height={40} />
|
|
||||||
<div style={{width: 20}}></div>
|
|
||||||
<Button onClick={() => p.onClick()} text={"Abbrechen"} color={"red"} width={100} height={40} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
export default function Test(p)
|
|
||||||
{
|
|
||||||
|
|
||||||
// let datum = new Date(2023, 1, 10);
|
|
||||||
// let start = new Date(datum.getFullYear(), 0, 0);
|
|
||||||
//
|
|
||||||
// let difference = (datum - start) / (1000 * 60 * 60 * 24)
|
|
||||||
|
|
||||||
|
|
||||||
let day = 41
|
|
||||||
let datum = new Date(2023, 0, 30)
|
|
||||||
|
|
||||||
return (
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<p>{datum.getMonth()}</p>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
|
|
||||||
const Tile = () => {
|
|
||||||
const [isHovered, setIsHovered] = React.useState(false);
|
|
||||||
const [cursorPosition, setCursorPosition] = React.useState({ x: 0, y: 0 });
|
|
||||||
const tileRef = React.useRef(null);
|
|
||||||
|
|
||||||
const handleMouseEnter = () => {
|
|
||||||
setIsHovered(true);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleMouseLeave = () => {
|
|
||||||
setIsHovered(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleMouseMove = (event) => {
|
|
||||||
if (tileRef.current) {
|
|
||||||
const rect = tileRef.current.getBoundingClientRect();
|
|
||||||
setCursorPosition({
|
|
||||||
x: event.clientX - rect.left,
|
|
||||||
y: event.clientY - rect.top,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
ref={tileRef}
|
|
||||||
onMouseEnter={handleMouseEnter}
|
|
||||||
onMouseLeave={handleMouseLeave}
|
|
||||||
onMouseMove={handleMouseMove}
|
|
||||||
style={{
|
|
||||||
backgroundColor: 'rgba(255,0,0,0.89)',
|
|
||||||
width: '250px',
|
|
||||||
height: '150px',
|
|
||||||
margin: '10px',
|
|
||||||
transition: 'transform 0.2s',
|
|
||||||
transform: isHovered ? 'translateY(-5px)' : 'none',
|
|
||||||
position: 'relative',
|
|
||||||
borderRadius: '10px',
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'center',
|
|
||||||
alignItems: 'center',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<span style = {{ color: 'white', fontWeight: 'bold'}}>Kalender</span>
|
|
||||||
|
|
||||||
|
|
||||||
{isHovered && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
top: cursorPosition.y - 10,
|
|
||||||
left: cursorPosition.x - 10,
|
|
||||||
width: '20px',
|
|
||||||
height: '20px',
|
|
||||||
borderRadius: '50%',
|
|
||||||
background:
|
|
||||||
'radial-gradient(circle at center, rgba(255, 255, 255) 0%, rgba(255,255,255,0) 70%)',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Tile;
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
import Button from "@/components/Button";
|
|
||||||
import DateElement from "@/components/DateElement";
|
|
||||||
import { arrowLeft } from "./Icons"
|
|
||||||
import { arrowRight } from "./Icons"
|
|
||||||
import { useState } from 'react'
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export default function WeekSelector(p){
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<div className="weekSelector">
|
|
||||||
<Button icon={arrowLeft} onClick={() => p.onFunctionLeft()} width={50} color={"#346991"}/>
|
|
||||||
<DateElement year={p.year} startday={p.startday}/>
|
|
||||||
<Button icon={arrowRight} onClick={() => p.onFunctionRight()} width={50} color={"#346991"}/>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
Before Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 59 KiB |
|
Before Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 31 KiB |
@@ -1,7 +0,0 @@
|
|||||||
import '@/styles/globals.css'
|
|
||||||
import '@/styles/calendarSideBar.css'
|
|
||||||
import '@/styles/helppage.css'
|
|
||||||
|
|
||||||
export default function App({ Component, pageProps }) {
|
|
||||||
return <Component {...pageProps} />
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
|
||||||
|
|
||||||
export default function handler(req, res) {
|
|
||||||
res.status(200).json({ name: 'John Doe' })
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
export default function BrowserNotSupported(p)
|
|
||||||
{
|
|
||||||
return (
|
|
||||||
<div style={{
|
|
||||||
display: "flex",
|
|
||||||
flexDirection: "column",
|
|
||||||
justifyContent: "center",
|
|
||||||
alignItems: "center",
|
|
||||||
height: "100vh",
|
|
||||||
}} >
|
|
||||||
<p style={{
|
|
||||||
fontSize: 40,
|
|
||||||
color: "red"
|
|
||||||
}}>Sorry but your browser is not supported right now</p>
|
|
||||||
<p style={{
|
|
||||||
fontSize: 30
|
|
||||||
}}>We recommend using Microsoft Edge or Google Chrome</p>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
import InputForm from "@/components/InputForm";
|
|
||||||
import {useRouter} from "next/router";
|
|
||||||
import Logout from "@/components/Logout";
|
|
||||||
|
|
||||||
export default function CreateSemester()
|
|
||||||
{
|
|
||||||
const router = useRouter();
|
|
||||||
let {courseName, startDate, endDate} = router.query;
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className={"normal-centered"}>
|
|
||||||
<Logout/>
|
|
||||||
<InputForm startDate={startDate} endDate={endDate} courseName={courseName}/>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
import Background from "@/components/Background";
|
|
||||||
import Back from "@/components/Back";
|
|
||||||
import {useRouter} from "next/router";
|
|
||||||
import screen1 from "@/images/screen1.png"
|
|
||||||
import screen2 from "@/images/screen2.png"
|
|
||||||
import screen3 from "@/images/screen3.png"
|
|
||||||
import screen4 from "@/images/screen4.png"
|
|
||||||
import screen5 from "@/images/screen5.png"
|
|
||||||
import screen6 from "@/images/screen6.png"
|
|
||||||
import screen7 from "@/images/screen7.png"
|
|
||||||
|
|
||||||
export default function Help(p)
|
|
||||||
{
|
|
||||||
const router = useRouter()
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
|
|
||||||
<div className={"help-line"}>
|
|
||||||
<img src={screen1.src}/>
|
|
||||||
<div className={"text-form"}>
|
|
||||||
<h1>Die Monats-Seiten-Leiste</h1>
|
|
||||||
<p>- Hier kannst du sehen in welchem Monat du dich aktuell befindest (blau hinterlegt).</p>
|
|
||||||
<p>- Durch einen Links-Klick auf eine Monatskacheln kannst du direkt an den Anfang dieses Monats springen</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className={"help-line"}>
|
|
||||||
<img src={screen2.src}/>
|
|
||||||
<div className={"text-form"}>
|
|
||||||
<h1>Die Planungs-Ansicht</h1>
|
|
||||||
<p>- Hier siehst du alle deine Termine in grün (bzw. gelb bei Warnungen) und von anderen Dozenten in grau</p>
|
|
||||||
<p>- Durch einen Links-Klick kannst du eine neue Vorlesung an einem Tag erstellen</p>
|
|
||||||
<p>- Durch Halten der dunkleren Leisten kannst du die Zeiten des Termins anpassen</p>
|
|
||||||
<p>- Durch Rechts-Klick kannst du eine Vorlesung löschen</p>
|
|
||||||
<p>- Durch Klicken auf die Pfeiltasten oben kannst du die Woche wechseln</p>
|
|
||||||
<p>- Bitte beachte, dass du Vorlesungen nur zwischen den beiden Roten linien erstellen kannst</p>
|
|
||||||
<p>- Ausgegraute Tage liegen nicht im Semester, hier kannst du nicht planen</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className={"help-line"}>
|
|
||||||
<img src={screen3.src}/>
|
|
||||||
<div className={"text-form"}>
|
|
||||||
<h1>Die Warnungs-Ansicht</h1>
|
|
||||||
<p>- Sollte ein Termin gelb erscheinen kannst du hier sehen woran das liegt</p>
|
|
||||||
<p>- Warnung sind empfohlene Verbesserungsverschläge aber müssen nicht zwangshaft beachtet werden</p>
|
|
||||||
<p>- Sollte hier "Okay" für einen Tag stehen ist alles perfekt</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className={"help-line"}>
|
|
||||||
<img src={screen5.src}/>
|
|
||||||
<div className={"text-form"}>
|
|
||||||
<h1>Der Login</h1>
|
|
||||||
<p>- Hier kannst du dich mit deiner Email und deinem Passwort einloggen</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className={"help-line"}>
|
|
||||||
<img src={screen4.src}/>
|
|
||||||
<div className={"text-form"}>
|
|
||||||
<h1>Der Logout</h1>
|
|
||||||
<p>- Über diesen Button kannst du dich ausloggen</p>
|
|
||||||
<p>- Loggst du dich nicht selbst aus, wirst du nach 2 Stunden automatisch ausgeloggt</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className={"help-line"}>
|
|
||||||
<img src={screen6.src}/>
|
|
||||||
<div className={"text-form"}>
|
|
||||||
<h1>Das Dashboard</h1>
|
|
||||||
<h2>Für Admins:</h2>
|
|
||||||
<p>- Über den "+" Knopf kannst du ein neues Semester erstellen</p>
|
|
||||||
<p>- Über den Stift kannst du ein bestehendes Semester editieren</p>
|
|
||||||
<p>- Über den Mülleimer kannst du ein bestehndes Semester löschen</p>
|
|
||||||
<h2>Für Dozenten (und Admins):</h2>
|
|
||||||
<p>- Hier siehst du deine Semester mit den jeweiligen Modulen</p>
|
|
||||||
<p>- Sollte ein Semester bei dir Ausgegraut sein, wurdest du für dieses schon gewählt aber noch nicht freigeschalten</p>
|
|
||||||
<p>- Duch einen Links-Klick auf ein weises Semester kann in die Planungsübersicht gewechselt werden</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className={"help-line"}>
|
|
||||||
<img src={screen7.src}/>
|
|
||||||
<div className={"text-form"}>
|
|
||||||
<h1>Semester erstellen / bearbeiten</h1>
|
|
||||||
<p>- Hier kannst du alle daten wie Name, Start- und Endzeitpunkt eines Semesters eintragen</p>
|
|
||||||
<p>- Du kannst einen Dozenten "wählen" d.h. er soll in diesem Semester dozieren</p>
|
|
||||||
<p>- Jedem Dozenten kannst du ein Modul zuordnen, welches er dozieren soll</p>
|
|
||||||
<p>- Sobald du die Schaltfläche "Freischalten" aktiviert hast, kann der Dozent mit der eigenständigen Planung beginnen.</p>
|
|
||||||
<p>- Jeder genannte Schritt, insbesondere der Letzte kann auch nachträglich im Bearbeitungsmodus ausgeführt werden</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
import {Inter} from 'next/font/google'
|
|
||||||
import React, {useEffect, useState} from "react";
|
|
||||||
import Login from "@/components/Login";
|
|
||||||
import Background from "@/components/Background";
|
|
||||||
import {useRouter} from "next/router";
|
|
||||||
import HelpButton from "@/components/HelpButton";
|
|
||||||
|
|
||||||
|
|
||||||
const inter = Inter({subsets: ['latin']})
|
|
||||||
|
|
||||||
export default function Home(p) {
|
|
||||||
const router = useRouter()
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
let isEdge = window.navigator.userAgent.indexOf("Edg") > -1
|
|
||||||
let isChrome = window.navigator.userAgent.indexOf("Chrome") > -1
|
|
||||||
|
|
||||||
if(!(isEdge || isChrome))
|
|
||||||
{
|
|
||||||
router.push("/browserNotSupported")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return (
|
|
||||||
|
|
||||||
|
|
||||||
<div className={"normal-centered"}>
|
|
||||||
<Background/>
|
|
||||||
<HelpButton/>
|
|
||||||
<h1 style={{
|
|
||||||
fontSize: 40,
|
|
||||||
fontWeight: "bold",
|
|
||||||
color: "#77932b",
|
|
||||||
marginBottom: "5%",
|
|
||||||
textShadow: "2px 2px 2px rgba(0, 0, 0, 0.2)",
|
|
||||||
textAlign: "center"
|
|
||||||
}}>Willkommen in deinem Vorlesungsplaner</h1>
|
|
||||||
<Login/>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
import CalenderView from "@/components/CalenderView";
|
|
||||||
import Background from "@/components/Background";
|
|
||||||
import Logout from "@/components/Logout";
|
|
||||||
import Back from "@/components/Back";
|
|
||||||
import BasicDateCalendar from "@/components/CalendarSideBar";
|
|
||||||
import {useRouter} from "next/router";
|
|
||||||
import HelpButton from "@/components/HelpButton";
|
|
||||||
import SubmitButton from "@/components/SubmitButton";
|
|
||||||
|
|
||||||
|
|
||||||
export default function planning(p)
|
|
||||||
{
|
|
||||||
let router = useRouter()
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className={"normal-centered"}>
|
|
||||||
<Logout/>
|
|
||||||
<Back onClick={() => router.back()}/>
|
|
||||||
<HelpButton/>
|
|
||||||
<Background/>
|
|
||||||
<CalenderView/>
|
|
||||||
<SubmitButton />
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,141 +0,0 @@
|
|||||||
import Button from "@/components/Button";
|
|
||||||
import React, {useEffect, useState} from "react";
|
|
||||||
import SemesterTile from "@/components/SemesterTile";
|
|
||||||
import InputForm from "@/components/InputForm";
|
|
||||||
import {useRouter} from "next/router";
|
|
||||||
import PopUp from "@/components/PopUp";
|
|
||||||
import Background from "@/components/Background";
|
|
||||||
import Logout from "@/components/Logout";
|
|
||||||
import {baseURL} from "@/components/Constants";
|
|
||||||
import HelpButton from "@/components/HelpButton";
|
|
||||||
import StatusBar from "@/components/StatusBar";
|
|
||||||
import {deleteItem, editItem} from "@/components/Icons";
|
|
||||||
|
|
||||||
export default function SemesterOverview(p) {
|
|
||||||
async function getSemesters() {
|
|
||||||
let urlTest = baseURL + "/semester/all?sessionid=" + localStorage.getItem("sessionid");
|
|
||||||
|
|
||||||
|
|
||||||
await fetch(urlTest).then(response => response.json()).then(s => {
|
|
||||||
setEntries(s)
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function onClickSemester(e, m) {
|
|
||||||
if (m.target === m.currentTarget) {
|
|
||||||
localStorage.setItem("currentsid", e.id)
|
|
||||||
router.push("/planning")
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function onClickNewSemester() {
|
|
||||||
localStorage.setItem("currentsid", 0);
|
|
||||||
router.push("/createSemester");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function togglePopup() {
|
|
||||||
if (modalDisplay === "block") {
|
|
||||||
setModalDisplay("none");
|
|
||||||
} else {
|
|
||||||
setModalDisplay("block");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function funcButtonAbort() {
|
|
||||||
togglePopup();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function funcButtonDelete() {
|
|
||||||
let id = localStorage.getItem("currentsid");
|
|
||||||
let url = baseURL + "/semester?sessionid=" + localStorage.getItem("sessionid") + "&id=" + id;
|
|
||||||
await fetch(url, {
|
|
||||||
method: "DELETE"
|
|
||||||
});
|
|
||||||
|
|
||||||
togglePopup();
|
|
||||||
getSemesters();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function funcButtonEdit(e, m) {
|
|
||||||
|
|
||||||
localStorage.setItem("currentsid", e.id);
|
|
||||||
let semester = e;
|
|
||||||
|
|
||||||
let startYear = semester.startyear;
|
|
||||||
let endYear = semester.endyear;
|
|
||||||
let startDay = semester.startday;
|
|
||||||
let endDay = semester.endday;
|
|
||||||
//+1 because input field shows date in another way then the date object does
|
|
||||||
let startDate = new Date(startYear, 0, startDay + 1);
|
|
||||||
let endDate = new Date(endYear, 0, endDay + 1);
|
|
||||||
|
|
||||||
await router.push({
|
|
||||||
pathname: "/createSemester",
|
|
||||||
query: {
|
|
||||||
courseName: semester.name,
|
|
||||||
startDate: startDate.toISOString().slice(0, 10),
|
|
||||||
endDate: endDate.toISOString().slice(0, 10)
|
|
||||||
},
|
|
||||||
});
|
|
||||||
getSemesters();
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
getSemesters();
|
|
||||||
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
|
|
||||||
const [entries, setEntries] = useState([])
|
|
||||||
const [modalDisplay, setModalDisplay] = useState("none");
|
|
||||||
const [modalHint, setModalHint] = useState("");
|
|
||||||
const router = useRouter()
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className={"semester-overview"}>
|
|
||||||
<Logout/>
|
|
||||||
<HelpButton/>
|
|
||||||
<Background/>
|
|
||||||
{
|
|
||||||
entries.map(e => (
|
|
||||||
<div className={"semester-tile box-shadow"} onClick={(f) => onClickSemester(e, f)}>
|
|
||||||
<SemesterTile text={e.name} onClick={(f) => onClickSemester(e, f)} onButtonDeleteClick={() => {
|
|
||||||
localStorage.setItem("currentsid", e.id)
|
|
||||||
setModalHint(e.name + " Löschen?");
|
|
||||||
togglePopup();
|
|
||||||
}} onButtonEditClick={(m) => {
|
|
||||||
localStorage.setItem("currentsid", e.id)
|
|
||||||
funcButtonEdit(e, m);
|
|
||||||
}}/>
|
|
||||||
<StatusBar progress={0}/>
|
|
||||||
<div style={
|
|
||||||
{
|
|
||||||
display:"flex",
|
|
||||||
justifyContent:"center",
|
|
||||||
alignItems:"center"
|
|
||||||
}
|
|
||||||
}>
|
|
||||||
<Button icon={deleteItem} width={30} height={30} color={"#ffffff"}
|
|
||||||
onClick={(m) => {
|
|
||||||
localStorage.setItem("currentsid", e.id)
|
|
||||||
setModalHint(e.name + " Löschen?");
|
|
||||||
togglePopup()
|
|
||||||
}}/>
|
|
||||||
<Button icon={editItem} width={30} height={30} color={"#ffffff"}
|
|
||||||
onClick={(m) => {
|
|
||||||
localStorage.setItem("currentsid", e.id)
|
|
||||||
funcButtonEdit(e, m)
|
|
||||||
}}/>
|
|
||||||
</div>
|
|
||||||
</div>))
|
|
||||||
}
|
|
||||||
<Button color={"#dcdcdc"} text={"+"} width={240} height={160} fontColor={"black"} fontSize={50}
|
|
||||||
onClick={() => onClickNewSemester()}/>
|
|
||||||
<PopUp hint={modalHint} text1={"Abbrechen"} text2={"Löschen"} displayState={modalDisplay}
|
|
||||||
function1={funcButtonAbort} function2={funcButtonDelete}/>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
import React, {useEffect, useState} from "react";
|
|
||||||
import SemesterTile from "@/components/SemesterTile";
|
|
||||||
import {useRouter} from "next/router";
|
|
||||||
import Background from "@/components/Background";
|
|
||||||
import Logout from "@/components/Logout";
|
|
||||||
import {baseURL} from "@/components/Constants"
|
|
||||||
import HelpButton from "@/components/HelpButton";
|
|
||||||
import StatusBar from "@/components/StatusBar";
|
|
||||||
|
|
||||||
export default function SemesteroverviewLecturer(p) {
|
|
||||||
function getModules() {
|
|
||||||
let urlTest = baseURL + "/module/id?sessionid=" + localStorage.getItem("sessionid");
|
|
||||||
|
|
||||||
fetch(urlTest).then(response => response.json()).then(m => {
|
|
||||||
setEntries(m);
|
|
||||||
let args = "";
|
|
||||||
for (let i = 0; i < m.length; i++) {
|
|
||||||
args += m[i].semesterid;
|
|
||||||
|
|
||||||
if (i < m.length - 1) {
|
|
||||||
args += "a";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let temp = []
|
|
||||||
let semesterURL = baseURL + "/semester/id/all?ids=" + args + "&sessionid=" + localStorage.getItem("sessionid");
|
|
||||||
fetch(semesterURL).then(r => r.json()).then(sem => {
|
|
||||||
sem.map(e => {
|
|
||||||
temp.push(e.name)
|
|
||||||
})
|
|
||||||
}).then(() => setSemesterNames(temp))
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function onClickSemester(e, m) {
|
|
||||||
if (e.activated == 1) {
|
|
||||||
if (m.target === m.currentTarget) {
|
|
||||||
localStorage.setItem("currentsid", e.semesterid)
|
|
||||||
localStorage.setItem("currentmodulename", e.name)
|
|
||||||
localStorage.setItem("moduleid", e.id)
|
|
||||||
router.push("/planning")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
getModules();
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
const [entries, setEntries] = useState([]);
|
|
||||||
const [semesterNames, setSemesterNames] = useState([]);
|
|
||||||
const router = useRouter();
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className={"semester-overview"}>
|
|
||||||
<Logout/>
|
|
||||||
<Background/>
|
|
||||||
<HelpButton/>
|
|
||||||
{entries.map((e, index) => (
|
|
||||||
<div className={"semester-tile box-shadow"} style={{
|
|
||||||
backgroundColor: e.activated == 1 ? "#ffffff" : "#aaaaaa"
|
|
||||||
}} onClick={(f) => onClickSemester(e, f)}>
|
|
||||||
<SemesterTile
|
|
||||||
editable={false} text={semesterNames[index]} text2={e.name}
|
|
||||||
onClick={(f) => onClickSemester(e, f)}
|
|
||||||
/>
|
|
||||||
<StatusBar progress={0}/>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
import Logout from "@/components/Logout";
|
|
||||||
import SubmitWarning from "@/components/SubmitWarning";
|
|
||||||
import Back from "@/components/Back";
|
|
||||||
import {useRouter} from "next/router";
|
|
||||||
import Background from "@/components/Background";
|
|
||||||
|
|
||||||
export default function Submit(){
|
|
||||||
|
|
||||||
const router = useRouter();
|
|
||||||
|
|
||||||
return(
|
|
||||||
<div>
|
|
||||||
<Background />
|
|
||||||
<Logout />
|
|
||||||
<SubmitWarning onClick={() => router.back()}/>
|
|
||||||
<Back onClick={() => router.back()}/>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
.A
|
|
||||||
{
|
|
||||||
border: 0px solid;
|
|
||||||
border-radius: 20px;
|
|
||||||
margin: 10px;
|
|
||||||
background-color: white;
|
|
||||||
padding: 15px;
|
|
||||||
height: 270px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.A P
|
|
||||||
{
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.Days
|
|
||||||
{
|
|
||||||
display: inline-grid;
|
|
||||||
grid-template-columns: repeat(7, 1fr);
|
|
||||||
grid-template-rows: repeat(5, 1fr);
|
|
||||||
height: 200px;
|
|
||||||
width: 250px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.Down
|
|
||||||
{
|
|
||||||
border-radius: 20px;
|
|
||||||
display: inline-grid;
|
|
||||||
grid-column: auto;
|
|
||||||
height: 200%;
|
|
||||||
width: 20%;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media only screen and (min-width: 1650px)
|
|
||||||
{
|
|
||||||
.Allround
|
|
||||||
{
|
|
||||||
position: relative;
|
|
||||||
max-height : 73vh;
|
|
||||||
overflow-y: scroll;
|
|
||||||
overflow-anchor: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.Allround::-webkit-scrollbar
|
|
||||||
{
|
|
||||||
background-color: rgba(0, 0, 0, 0);
|
|
||||||
width: 12px;
|
|
||||||
}
|
|
||||||
.Allround::-webkit-scrollbar-thumb
|
|
||||||
{
|
|
||||||
background-color: gray;
|
|
||||||
border-radius: 15px;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@media only screen and (max-width: 1650px)
|
|
||||||
{
|
|
||||||
.Allround
|
|
||||||
{
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,533 +0,0 @@
|
|||||||
@tailwind base;
|
|
||||||
@tailwind components;
|
|
||||||
@tailwind utilities;
|
|
||||||
|
|
||||||
:root {
|
|
||||||
--foreground-rgb: 0, 0, 0;
|
|
||||||
--background-start-rgb: 255, 255, 255;
|
|
||||||
--background-end-rgb: 255, 255, 255;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
|
||||||
background-color: #f2f2f2;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
::-webkit-scrollbar
|
|
||||||
{
|
|
||||||
background-color: rgba(0, 0, 0, 0);
|
|
||||||
width: 12px;
|
|
||||||
}
|
|
||||||
::-webkit-scrollbar-thumb
|
|
||||||
{
|
|
||||||
background-color: gray;
|
|
||||||
border-radius: 15px;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
.splash {
|
|
||||||
position: absolute;
|
|
||||||
border-radius: 70px;
|
|
||||||
background-color: #c77c0c;
|
|
||||||
|
|
||||||
z-index: -5;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
Page Layouts
|
|
||||||
*/
|
|
||||||
|
|
||||||
.normal-centered {
|
|
||||||
height: 100vh;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.semester-overview {
|
|
||||||
height: 100vh;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
align-content: center;
|
|
||||||
gap: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
|
||||||
height: 100vh;
|
|
||||||
}
|
|
||||||
|
|
||||||
.box-shadow
|
|
||||||
{
|
|
||||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
|
|
||||||
}
|
|
||||||
|
|
||||||
.box-shadow-heavy
|
|
||||||
{
|
|
||||||
box-shadow: 0 0 10px rgba(0, 0, 0,1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Input Form
|
|
||||||
*/
|
|
||||||
|
|
||||||
.input-form
|
|
||||||
{
|
|
||||||
width: 600px;
|
|
||||||
background-color: white;
|
|
||||||
padding: 30px;
|
|
||||||
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: space-around;
|
|
||||||
align-items: flex-start;
|
|
||||||
gap: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
table
|
|
||||||
{
|
|
||||||
width: 550px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.table-wrapper
|
|
||||||
{
|
|
||||||
max-height: 40%;
|
|
||||||
overflow-y: scroll;
|
|
||||||
}
|
|
||||||
|
|
||||||
td
|
|
||||||
{
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.input-form p, .input-form th
|
|
||||||
{
|
|
||||||
font-size: 18px;
|
|
||||||
font-weight: bold;
|
|
||||||
color: #5e5e5e;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
Button
|
|
||||||
*/
|
|
||||||
.round-border {
|
|
||||||
border-radius: 10px;
|
|
||||||
border-width: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.font-small {
|
|
||||||
font-size: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.font-middle {
|
|
||||||
font-size: 16px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.font-big {
|
|
||||||
font-size: 22px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.button {
|
|
||||||
background-color: #363636;
|
|
||||||
padding: 5px;
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.button:hover
|
|
||||||
{
|
|
||||||
filter: brightness(0.65);
|
|
||||||
}
|
|
||||||
|
|
||||||
.button:hover {
|
|
||||||
background-color: #585858;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Step Progress Bar
|
|
||||||
*/
|
|
||||||
|
|
||||||
.step-container {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
|
||||||
max-width: 400px;
|
|
||||||
pointer-events: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.steps {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: space-between;
|
|
||||||
gap: 20px;
|
|
||||||
width: 100%;
|
|
||||||
position: relative;
|
|
||||||
pointer-events: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.step {
|
|
||||||
width: 40px;
|
|
||||||
height: 40px;
|
|
||||||
border-radius: 50%;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
color: white;
|
|
||||||
font-weight: bold;
|
|
||||||
pointer-events: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.steps .not-started {
|
|
||||||
/*background-image: linear-gradient(#b42121, #b44821);*/
|
|
||||||
background-color: #77932b;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
.steps .started {
|
|
||||||
/*background-image: linear-gradient(#c75c0c, #c77c0c);*/
|
|
||||||
background-color: #77932b;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
.steps .finished {
|
|
||||||
/*background-image: linear-gradient(#43C20BFF, #0bc27c);*/
|
|
||||||
background-color: #77932b;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
.steps .active {
|
|
||||||
/*border-width: 2px;*/
|
|
||||||
/*border-color: #1e2428;*/
|
|
||||||
background-color: #346991;
|
|
||||||
}
|
|
||||||
|
|
||||||
.progress-bar {
|
|
||||||
position: absolute;
|
|
||||||
height: 8px;
|
|
||||||
background-color: #5d606e;
|
|
||||||
z-index: -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
weekSelector
|
|
||||||
*/
|
|
||||||
|
|
||||||
.dateElement {
|
|
||||||
display: flex;
|
|
||||||
max-width: 900px;
|
|
||||||
width: 900px;
|
|
||||||
margin-left: 20px;
|
|
||||||
margin-right: 20px;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
font-weight: bold;
|
|
||||||
color: black;
|
|
||||||
font-size: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.weekSelector {
|
|
||||||
height: 13vh;
|
|
||||||
display: flex;
|
|
||||||
padding: 5px 5px;
|
|
||||||
background-color: rgba(0, 0, 0, 0);
|
|
||||||
border-radius: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Popup
|
|
||||||
*/
|
|
||||||
|
|
||||||
.modal-container {
|
|
||||||
z-index: 1;
|
|
||||||
position: fixed;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
background-color: rgba(0, 0, 0, 0.5);
|
|
||||||
}
|
|
||||||
|
|
||||||
.modal {
|
|
||||||
height: 180px;
|
|
||||||
width: 300px;
|
|
||||||
border-radius: 10px;
|
|
||||||
background-color: rgb(255, 255, 255);
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: space-between;
|
|
||||||
padding: 20px;
|
|
||||||
animation-name: modalgrow;
|
|
||||||
animation-duration: 0.2s;
|
|
||||||
animation-play-state: running;
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes modalgrow {
|
|
||||||
from
|
|
||||||
{
|
|
||||||
height: 90px;
|
|
||||||
width: 150px;
|
|
||||||
}
|
|
||||||
to
|
|
||||||
{
|
|
||||||
height: 180px;
|
|
||||||
width: 300px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.modal p {
|
|
||||||
text-align: center;
|
|
||||||
pointer-events: none;
|
|
||||||
font-weight: bold;
|
|
||||||
font-size: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.modal div {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
width: 100%;
|
|
||||||
justify-content: flex-end;
|
|
||||||
gap: 5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Calender View
|
|
||||||
*/
|
|
||||||
|
|
||||||
@media (max-width: 1300px) {
|
|
||||||
.error-bar
|
|
||||||
{
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (min-width: 1300px) {
|
|
||||||
.error-bar
|
|
||||||
{
|
|
||||||
width: 250px;
|
|
||||||
border-radius: 15px;
|
|
||||||
height: 73vh;
|
|
||||||
max-height: 73vh;
|
|
||||||
overflow-y: scroll;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: flex-start;
|
|
||||||
align-items: center;
|
|
||||||
gap: 10px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.calender-direction-wrapper
|
|
||||||
{
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
.calender-container {
|
|
||||||
position: relative;
|
|
||||||
max-height: 60vh;
|
|
||||||
overflow-y: scroll;
|
|
||||||
overflow-anchor: none;
|
|
||||||
display: grid;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
.content {
|
|
||||||
grid-area: 1 / 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.overlay {
|
|
||||||
padding: 2px 0 0 0;
|
|
||||||
grid-area: 1 / 1;
|
|
||||||
pointer-events: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.no-pointer-events {
|
|
||||||
pointer-events: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.wochen-tag-container {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
justify-content: space-between;
|
|
||||||
height: 60px;
|
|
||||||
width: 1000px;
|
|
||||||
gap: 5px;
|
|
||||||
padding: 0 0 5px 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.calender-view {
|
|
||||||
width: 1000px;
|
|
||||||
height: 2400px;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
align-items: stretch;
|
|
||||||
justify-content: stretch;
|
|
||||||
gap: 5px;
|
|
||||||
user-select: none;
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.calender-view .spalte {
|
|
||||||
border-radius: 10px;
|
|
||||||
width: 400px;
|
|
||||||
/*background-color: #ffffff;*/
|
|
||||||
display: grid;
|
|
||||||
padding: 0 3px;
|
|
||||||
grid-template-columns: 100%;
|
|
||||||
background-color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.wochen-tag-container .wochen-tag {
|
|
||||||
text-align: center;
|
|
||||||
background-color: #346991;
|
|
||||||
width: 400px;
|
|
||||||
color: white;
|
|
||||||
border-radius: 10px;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
|
|
||||||
grid-row-start: 1;
|
|
||||||
grid-row-end: 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
.entry {
|
|
||||||
border-radius: 10px;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: space-between;
|
|
||||||
padding: 0 2px;
|
|
||||||
align-items: center;
|
|
||||||
/*cursor: move;*/
|
|
||||||
z-index: 10;
|
|
||||||
overflow: hidden;
|
|
||||||
margin-top: 1px;
|
|
||||||
margin-bottom: 1px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.entry .resize-grab {
|
|
||||||
height: 6px;
|
|
||||||
cursor: ns-resize;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
.entry p {
|
|
||||||
color: white;
|
|
||||||
font-size: 16px;
|
|
||||||
cursor: default;
|
|
||||||
pointer-events: none;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Login
|
|
||||||
*/
|
|
||||||
|
|
||||||
.login-container {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: space-evenly;
|
|
||||||
/*gap: 10px;*/
|
|
||||||
border-radius: 10px;
|
|
||||||
background-color: rgba(255, 255, 255, 0.5);
|
|
||||||
width: 375px;
|
|
||||||
height: 350px;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
.input-bordered {
|
|
||||||
border: none;
|
|
||||||
border-radius: 5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.input {
|
|
||||||
padding: 5px;
|
|
||||||
border: none;
|
|
||||||
background-color: white;
|
|
||||||
border-radius: 5px;
|
|
||||||
font-size: 16px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.input:focus
|
|
||||||
{
|
|
||||||
outline: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
.placement {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: flex-start;
|
|
||||||
justify-content: left;
|
|
||||||
}
|
|
||||||
|
|
||||||
.font-kinda-big {
|
|
||||||
font-size: 18px;
|
|
||||||
color: #777777;
|
|
||||||
font-weight: 500;
|
|
||||||
}
|
|
||||||
|
|
||||||
.font-big-fat {
|
|
||||||
font-size: 22px;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
.input-sm {
|
|
||||||
height: 2rem /* 32px */;
|
|
||||||
padding-left: 0.75rem /* 12px */;
|
|
||||||
padding-right: 0.75rem /* 12px */;
|
|
||||||
font-size: 0.875rem /* 14px */;
|
|
||||||
line-height: 2rem /* 32px */;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
SemesterTile
|
|
||||||
*/
|
|
||||||
|
|
||||||
.semester-tile {
|
|
||||||
width: 240px;
|
|
||||||
height: 160px;
|
|
||||||
color: black;
|
|
||||||
border-radius: 10px;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
font-size: 20px;
|
|
||||||
gap: 10px;
|
|
||||||
background-color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.semester-tile:hover {
|
|
||||||
background-color: #e1e1e1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.semester-tile-p {
|
|
||||||
pointer-events: none;
|
|
||||||
font-weight: bold;
|
|
||||||
font-size: 23px;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
.Error
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
.help-line
|
|
||||||
{
|
|
||||||
padding: 30px;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
gap: 50px;
|
|
||||||
}
|
|
||||||
.text-form
|
|
||||||
{
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: flex-start;
|
|
||||||
height: 100%;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
.text-form h1
|
|
||||||
{
|
|
||||||
font-size: 30px;
|
|
||||||
}
|
|
||||||
.text-form p
|
|
||||||
{
|
|
||||||
font-size: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.text-form h2
|
|
||||||
{
|
|
||||||
font-size: 26px;
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
/** @type {import('tailwindcss').Config} */
|
|
||||||
module.exports = {
|
|
||||||
content: [
|
|
||||||
'./src/pages/**/*.{js,ts,jsx,tsx,mdx}',
|
|
||||||
'./src/components/**/*.{js,ts,jsx,tsx,mdx}',
|
|
||||||
'./src/app/**/*.{js,ts,jsx,tsx,mdx}',
|
|
||||||
],
|
|
||||||
theme: {
|
|
||||||
extend: {
|
|
||||||
backgroundImage: {
|
|
||||||
'gradient-radial': 'radial-gradient(var(--tw-gradient-stops))',
|
|
||||||
'gradient-conic':
|
|
||||||
'conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
@@ -27,12 +27,6 @@
|
|||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.h2database</groupId>
|
|
||||||
<artifactId>h2</artifactId>
|
|
||||||
<version>2.1.214</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@@ -41,27 +35,6 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-install-plugin</artifactId>
|
|
||||||
<version>2.5.2</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>validate</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>install-file</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<groupId>com.example</groupId>
|
|
||||||
<artifactId>example</artifactId>
|
|
||||||
<version>1.0</version>
|
|
||||||
<packaging>jar</packaging>
|
|
||||||
<file>${basedir}/H2JDBCDriver/h2-2.1.214.jar</file>
|
|
||||||
<generatePom>true</generatePom>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,461 @@
|
|||||||
|
package com.example.backend.anwprj;
|
||||||
|
|
||||||
|
import com.example.backend.anwprj.Encryption.RSA;
|
||||||
|
import com.example.backend.anwprj.Days.Day;
|
||||||
|
import com.example.backend.anwprj.Entries.Entry;
|
||||||
|
import com.example.backend.anwprj.Semesters.Semester;
|
||||||
|
import com.example.backend.anwprj.Users.User;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DataBaseHandler
|
||||||
|
{
|
||||||
|
//singleton instance of database handler
|
||||||
|
private static DataBaseHandler instance = null;
|
||||||
|
|
||||||
|
public static DataBaseHandler getInstance()
|
||||||
|
{
|
||||||
|
if (instance == null)
|
||||||
|
{
|
||||||
|
instance = new DataBaseHandler();
|
||||||
|
}
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
//connection to the database
|
||||||
|
private Connection connection;
|
||||||
|
//sql statement
|
||||||
|
private Statement st;
|
||||||
|
private boolean encrypted = false;
|
||||||
|
|
||||||
|
public DataBaseHandler()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//connect to the local database
|
||||||
|
connection = DriverManager.getConnection("jdbc:h2:./database", "adm", "73bgjfdsfJ!934");
|
||||||
|
st = connection.createStatement();
|
||||||
|
} catch (SQLException e)
|
||||||
|
{
|
||||||
|
System.out.println("No Connection!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
TEMPPPPPP
|
||||||
|
*/
|
||||||
|
public static class Week
|
||||||
|
{
|
||||||
|
public int semesterid, id, weeknumber;
|
||||||
|
|
||||||
|
public Week(int id, int semesterid, int weeknumber)
|
||||||
|
{
|
||||||
|
this.semesterid = semesterid;
|
||||||
|
this.weeknumber = weeknumber;
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public Week addWeek(Week week)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
st.executeUpdate("insert into weeks (semesterid, weeknumber) values (" + week.semesterid + ", " + week.weeknumber + ")");
|
||||||
|
return getWeek(week.semesterid, week.weeknumber);
|
||||||
|
} catch (SQLException e)
|
||||||
|
{
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Week getWeek(int semesterid, int weeknumber)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ResultSet rs = st.executeQuery("select w.* from weeks w, semester s where s.id=" + semesterid + " and " + "w.weeknumber=" + weeknumber);
|
||||||
|
rs.next();
|
||||||
|
return new Week(rs.getInt("id"), rs.getInt("semesterid"), rs.getInt("weeknumber"));
|
||||||
|
} catch (SQLException e)
|
||||||
|
{
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Week getWeekById(int id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ResultSet rs = st.executeQuery("select * from weeks where id=" + id);
|
||||||
|
rs.next();
|
||||||
|
return new Week(rs.getInt("id"), rs.getInt("semesterid"), rs.getInt("weeknumber"));
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
TEMP END!!!!!!!!!!!!
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
DAYS
|
||||||
|
*/
|
||||||
|
public Day addDay(Day day)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
st.executeUpdate("insert into days (dayinweek, weekid) values (" + day.getDayinweek() + ", " + day.getWeekid() + ")");
|
||||||
|
Week w = getWeekById(day.getWeekid());
|
||||||
|
return getDay(day.getDayinweek(), w.weeknumber, w.semesterid);
|
||||||
|
} catch (SQLException e)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Day getDay(int id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ResultSet rs = st.executeQuery("select * from days where id=" + id);
|
||||||
|
|
||||||
|
return resultSetToDay(rs);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Day getDay(int dayinweek, int weeknumber, int semesterid)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ResultSet rs = st.executeQuery("select d.* from days d, weeks w, semester s " +
|
||||||
|
"where d.weekid = w.id and " +
|
||||||
|
"w.semesterid = s.id and " +
|
||||||
|
"d.dayinweek = " + dayinweek + " and " +
|
||||||
|
"w.weeknumber = " + weeknumber + " and " +
|
||||||
|
"s.id = " + semesterid);
|
||||||
|
|
||||||
|
return resultSetToDay(rs);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Day resultSetToDay(ResultSet rs)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
rs.next();
|
||||||
|
|
||||||
|
return new Day(
|
||||||
|
rs.getInt("id"),
|
||||||
|
rs.getInt("dayinweek"),
|
||||||
|
rs.getInt("weekid")
|
||||||
|
);
|
||||||
|
} catch (SQLException e)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
ENTRIES
|
||||||
|
*/
|
||||||
|
//method that returns all entries of a day based on the given parameters
|
||||||
|
public Entry[] getEntries(int dayinweek, int weeknumber, int semesterid, User user)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//search the correct data in the database
|
||||||
|
ResultSet rs = st.executeQuery("select distinct e.id, e.dayid, e.usercreatedbyid, e.timestart, e.timeend, e.info " +
|
||||||
|
"from entries e, days d, weeks w, semester s " +
|
||||||
|
"where e.dayid = d.id and " +
|
||||||
|
"d.weekid = w.id and " +
|
||||||
|
"w.semesterid = s.id and " +
|
||||||
|
"d.dayinweek = " + dayinweek + " and " +
|
||||||
|
"w.weeknumber = " + weeknumber + " and " +
|
||||||
|
"s.id = " + semesterid);
|
||||||
|
|
||||||
|
|
||||||
|
int editable = 0;
|
||||||
|
|
||||||
|
//a temporary list to save entry objects in
|
||||||
|
List<Entry> temp = new ArrayList<>();
|
||||||
|
//while there a still entries for the day
|
||||||
|
while(rs.next())
|
||||||
|
{
|
||||||
|
editable = 0;
|
||||||
|
//if entry has been created by the requesting user set the entry to editable (or the user is admin)
|
||||||
|
if(rs.getInt("usercreatedbyid") == user.getId() || user.getPermissions() == 1)
|
||||||
|
{
|
||||||
|
editable = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
temp.add(
|
||||||
|
new Entry(
|
||||||
|
rs.getInt("id"),
|
||||||
|
rs.getInt("dayid"),
|
||||||
|
rs.getInt("usercreatedbyid"),
|
||||||
|
rs.getInt("timestart"),
|
||||||
|
rs.getInt("timeend"),
|
||||||
|
rs.getString("info"),
|
||||||
|
editable
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//return the temporary list as an array
|
||||||
|
return temp.toArray(new Entry[0]);
|
||||||
|
|
||||||
|
} catch (SQLException e)
|
||||||
|
{
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
SEMESTER
|
||||||
|
*/
|
||||||
|
//get a semester object by its name
|
||||||
|
public Semester getSemester(String name)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ResultSet rs = st.executeQuery("select * from SEMESTER where name = '" + name + "'");
|
||||||
|
return resultSetToSemester(rs);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Semester getSemester(int id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ResultSet rs = st.executeQuery("select * from semester where id=" + id);
|
||||||
|
return resultSetToSemester(rs);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//write a new semester to the database returns if process was successful
|
||||||
|
public Semester addSemester(Semester s)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
st.executeUpdate("insert into SEMESTER (startweeknumber, endweeknumber, name, startyear, endyear) values (" + s.getStartweeknumber() + ", " + s.getEndweeknumber() + ", '" + s.getName() + "', " + s.getStartyear() + ", " + s.getEndyear() + ")");
|
||||||
|
return getSemester(s.getName());
|
||||||
|
|
||||||
|
} catch (Exception e)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Semester updateSemester(Semester semester)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
st.executeUpdate("update semester set startweeknumber=" + semester.getStartweeknumber() + ", " +
|
||||||
|
"endweeknumber=" + semester.getEndweeknumber() + ", " +
|
||||||
|
"name='" + semester.getName() + "', " +
|
||||||
|
"startyear=" + semester.getStartyear() + ", " +
|
||||||
|
"endyear=" + semester.getEndyear() + " where id=" + semester.getId());
|
||||||
|
|
||||||
|
return getSemester(semester.getId());
|
||||||
|
} catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Semester resultSetToSemester(ResultSet rs)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
rs.next();
|
||||||
|
return new Semester(
|
||||||
|
rs.getInt("id"),
|
||||||
|
rs.getInt("startweeknumber"),
|
||||||
|
rs.getInt("endweeknumber"),
|
||||||
|
rs.getString("name"),
|
||||||
|
rs.getInt("startyear"),
|
||||||
|
rs.getInt("endyear")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
USER
|
||||||
|
*/
|
||||||
|
//get a user object by mail and password from the database
|
||||||
|
public User getUser(String mail, String password)
|
||||||
|
{
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ResultSet rs = st.executeQuery("select * from users where mail = '" + mail + "' and password = '" + password + "'");
|
||||||
|
return resultSetToUser(rs);
|
||||||
|
} catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public User getUser(int id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ResultSet rs = st.executeQuery("select * from users where id=" + id);
|
||||||
|
return resultSetToUser(rs);
|
||||||
|
} catch (Exception e)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public User getUser(String mail)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ResultSet rs = st.executeQuery("select * from users where mail='" + mail + "'");
|
||||||
|
User u = resultSetToUser(rs);
|
||||||
|
if(u != null) u.clearOutPassword();
|
||||||
|
|
||||||
|
return u;
|
||||||
|
} catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public User resultSetToUser(ResultSet rs)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
rs.next();
|
||||||
|
return new User(
|
||||||
|
rs.getInt("id"),
|
||||||
|
rs.getString("firstname"),
|
||||||
|
rs.getString("lastname"),
|
||||||
|
rs.getString("mail"),
|
||||||
|
rs.getString("password"),
|
||||||
|
rs.getInt("permission")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//add a new user object to the database returns if process was successful
|
||||||
|
public User addUser(User user)
|
||||||
|
{
|
||||||
|
//check if mail and passwort (key user information) is given
|
||||||
|
if (user.getMail() == null || user.getPassword() == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String password = user.getPassword();
|
||||||
|
if(encrypted)
|
||||||
|
{
|
||||||
|
RSA rsa = RSA.getInstance();
|
||||||
|
byte[] psw = rsa.loadByteArray(password);
|
||||||
|
try {
|
||||||
|
password = rsa.decrypt(psw);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
st.executeUpdate("insert into users (firstname, lastname, mail, password, permission) values (" + "'" + user.getFirstName() + "', '" + user.getLastName() + "', '" + user.getMail() + "', '" + password + "', " + 0 + ")");
|
||||||
|
return getUser(user.getMail(), user.getPassword());
|
||||||
|
} catch (Exception e)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public User updateUser(User user, int id, boolean elevationRequestByAdmin)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String password = user.getPassword();
|
||||||
|
if(encrypted)
|
||||||
|
{
|
||||||
|
RSA rsa = RSA.getInstance();
|
||||||
|
byte[] psw = rsa.loadByteArray(password);
|
||||||
|
try {
|
||||||
|
password = rsa.decrypt(psw);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!elevationRequestByAdmin)
|
||||||
|
{
|
||||||
|
st.executeUpdate("update users set " +
|
||||||
|
"firstname='" + user.getFirstName() + "', " +
|
||||||
|
"lastname='" + user.getLastName() + "', " +
|
||||||
|
"mail='" + user.getMail() + "', " +
|
||||||
|
"password='" + password + "' " +
|
||||||
|
"where id=" + id);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
st.executeUpdate("update users set " +
|
||||||
|
"firstname='" + user.getFirstName() + "', " +
|
||||||
|
"lastname='" + user.getLastName() + "', " +
|
||||||
|
"mail='" + user.getMail() + "', " +
|
||||||
|
"password='" + password + "'," +
|
||||||
|
"permission=" + user.getPermissions() +
|
||||||
|
"where id=" + id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return getUser(id);
|
||||||
|
} catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean deleteUser(String mail)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
st.executeUpdate("delete from users where mail='" + mail + "'");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,517 +0,0 @@
|
|||||||
package com.example.backend.anwprj.Database;
|
|
||||||
|
|
||||||
import com.example.backend.discard.Encryption.RSA;
|
|
||||||
import com.example.backend.anwprj.Entries.Entry;
|
|
||||||
import com.example.backend.anwprj.Semesters.Semester;
|
|
||||||
import com.example.backend.anwprj.Users.User;
|
|
||||||
import com.example.backend.anwprj.Module.Module;
|
|
||||||
|
|
||||||
import java.sql.*;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class DataBaseHandler {
|
|
||||||
//singleton instance of database handler
|
|
||||||
private static DataBaseHandler instance = null;
|
|
||||||
|
|
||||||
public static DataBaseHandler getInstance() {
|
|
||||||
if (instance == null) {
|
|
||||||
instance = new DataBaseHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
//connection to the database
|
|
||||||
private Connection connection;
|
|
||||||
//sql statement
|
|
||||||
private Statement st;
|
|
||||||
private boolean encrypted = false;
|
|
||||||
|
|
||||||
public DataBaseHandler() {
|
|
||||||
try {
|
|
||||||
//connect to the local database
|
|
||||||
connection = DriverManager.getConnection("jdbc:h2:./database", "adm", "73bgjfdsfJ!934");
|
|
||||||
st = connection.createStatement();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ENTRIES
|
|
||||||
*/
|
|
||||||
public void addEntry(Entry entry) {
|
|
||||||
try {
|
|
||||||
st.executeUpdate("insert into entries (daynumber, yearnumber, semesterid, usercreatedbyid, timestart, timeend, info) values (" +
|
|
||||||
entry.getDaynumber() + ", " + entry.getYearnumber() + ", " + entry.getSemesterid() + ", " +
|
|
||||||
entry.getUsercreatedbyid() + ", " + entry.getTimestart() + ", " + entry.getTimeend() + ", '" + entry.getInfo() + "')"
|
|
||||||
);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Entry[][] getEntries(int semesterid, int daynumber, int yearnumber) {
|
|
||||||
try {
|
|
||||||
ResultSet rs = st.executeQuery("select * from entries where " +
|
|
||||||
"semesterid=" + semesterid +
|
|
||||||
" and yearnumber=" + yearnumber +
|
|
||||||
" and daynumber between " + daynumber + " and " + daynumber + 6);
|
|
||||||
|
|
||||||
List<Entry> entryList = new ArrayList<>();
|
|
||||||
Entry current = null;
|
|
||||||
while ((current = resultSetToEntry(rs)) != null) {
|
|
||||||
entryList.add(current);
|
|
||||||
}
|
|
||||||
|
|
||||||
Entry[][] entries = new Entry[6][20];
|
|
||||||
for (int i = 0; i < 6; i++) {
|
|
||||||
int f = 0;
|
|
||||||
|
|
||||||
for (int j = 0; j < entryList.size(); j++) {
|
|
||||||
if (entryList.get(j).getDaynumber() == i + daynumber) {
|
|
||||||
entries[i][f] = entryList.get(j);
|
|
||||||
f++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return entries;
|
|
||||||
} catch (Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Entry[][] getAllEntrys(int semesterid, int daynumber, int yearnumber, int userid) {
|
|
||||||
try {
|
|
||||||
ResultSet rs = st.executeQuery("select * from entries where " +
|
|
||||||
"semesterid<>" + semesterid +
|
|
||||||
" and yearnumber=" + yearnumber +
|
|
||||||
" and usercreatedbyid=" + userid +
|
|
||||||
" and daynumber between " + daynumber + " and " + daynumber + 6);
|
|
||||||
List<Entry> entryList = new ArrayList<>();
|
|
||||||
Entry current = null;
|
|
||||||
while ((current = resultSetToEntry(rs)) != null) {
|
|
||||||
entryList.add(current);
|
|
||||||
}
|
|
||||||
Entry[][] entries = new Entry[6][20];
|
|
||||||
for (int i = 0; i < 6; i++) {
|
|
||||||
int f = 0;
|
|
||||||
|
|
||||||
for (int j = 0; j < entryList.size(); j++) {
|
|
||||||
if (entryList.get(j).getDaynumber() == i + daynumber) {
|
|
||||||
entries[i][f] = entryList.get(j);
|
|
||||||
f++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return entries;
|
|
||||||
} catch (Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Entry[] getAllEntries(int semesterid, int userid) {
|
|
||||||
try {
|
|
||||||
ResultSet rs = st.executeQuery("select * from entries where " +
|
|
||||||
"semesterid=" + semesterid +
|
|
||||||
" and usercreatedbyid=" + userid);
|
|
||||||
List<Entry> entriestate = new ArrayList<>();
|
|
||||||
Entry current = null;
|
|
||||||
while ((current = resultSetToEntry(rs)) != null) {
|
|
||||||
entriestate.add(current);
|
|
||||||
}
|
|
||||||
return entriestate.toArray(new Entry[0]);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deleteEntry(int id) {
|
|
||||||
try {
|
|
||||||
st.executeUpdate("delete from entries where id=" + id);
|
|
||||||
} catch (Exception e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateEntry(Entry entry) {
|
|
||||||
try {
|
|
||||||
st.executeUpdate("update entries set timeend=" + entry.getTimeend() + ", timestart=" + entry.getTimestart() + " where id=" + entry.getId());
|
|
||||||
} catch (Exception e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Entry resultSetToEntry(ResultSet rs) {
|
|
||||||
try {
|
|
||||||
rs.next();
|
|
||||||
return new Entry(
|
|
||||||
rs.getInt("id"),
|
|
||||||
rs.getInt("daynumber"),
|
|
||||||
rs.getInt("yearnumber"),
|
|
||||||
rs.getInt("usercreatedbyid"),
|
|
||||||
rs.getInt("timestart"),
|
|
||||||
rs.getInt("timeend"),
|
|
||||||
rs.getInt("semesterid"),
|
|
||||||
rs.getString("info")
|
|
||||||
);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SEMESTER
|
|
||||||
*/
|
|
||||||
//get a semester object by its name
|
|
||||||
public Semester getSemester(String name) {
|
|
||||||
try {
|
|
||||||
ResultSet rs = st.executeQuery("select * from SEMESTER where name = '" + name + "'");
|
|
||||||
return resultSetToSemester(rs);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Semester getSemester(int id) {
|
|
||||||
try {
|
|
||||||
ResultSet rs = st.executeQuery("select * from semester where id=" + id);
|
|
||||||
return resultSetToSemester(rs);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//write a new semester to the database returns if process was successful
|
|
||||||
public Semester addSemester(Semester s) {
|
|
||||||
try {
|
|
||||||
st.executeUpdate("insert into SEMESTER (startday, endday, name, startyear, endyear, number) values (" + s.getStartday() + ", " + s.getEndday() + ", '" + s.getName() + "', " + s.getStartyear() + ", " + s.getEndyear() + ", " + s.getNumber() + ")");
|
|
||||||
return getSemester(s.getName());
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Semester[] getAllSemesters() {
|
|
||||||
try {
|
|
||||||
ResultSet rs = st.executeQuery("select * from semester");
|
|
||||||
List<Semester> semestersList = new ArrayList<>();
|
|
||||||
Semester s = null;
|
|
||||||
while ((s = resultSetToSemester(rs)) != null) {
|
|
||||||
semestersList.add(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
return semestersList.toArray(new Semester[0]);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Semester updateSemester(Semester semester) {
|
|
||||||
try {
|
|
||||||
st.executeUpdate("update semester set startday=" + semester.getStartday() + ", " +
|
|
||||||
"endday=" + semester.getEndday() + ", " +
|
|
||||||
"name='" + semester.getName() + "', " +
|
|
||||||
"startyear=" + semester.getStartyear() + ", " +
|
|
||||||
"number=" + semester.getNumber() + ", " +
|
|
||||||
"endyear=" + semester.getEndyear() + " where id=" + semester.getId());
|
|
||||||
|
|
||||||
return getSemester(semester.getId());
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deleteSemester(int id) {
|
|
||||||
try {
|
|
||||||
st.executeUpdate("DELETE FROM modules WHERE semesterid=" + id);
|
|
||||||
|
|
||||||
st.executeUpdate("delete from semester where id=" + id);
|
|
||||||
} catch (Exception e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Semester resultSetToSemester(ResultSet rs) {
|
|
||||||
try {
|
|
||||||
rs.next();
|
|
||||||
return new Semester(
|
|
||||||
rs.getInt("id"),
|
|
||||||
rs.getInt("startday"),
|
|
||||||
rs.getInt("endday"),
|
|
||||||
rs.getString("name"),
|
|
||||||
rs.getInt("startyear"),
|
|
||||||
rs.getInt("endyear"),
|
|
||||||
rs.getInt("number")
|
|
||||||
);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* MODULE
|
|
||||||
*/
|
|
||||||
|
|
||||||
//get a module object by its id
|
|
||||||
public Module getModule(int id) {
|
|
||||||
try {
|
|
||||||
ResultSet rs = st.executeQuery("SELECT * FROM modules WHERE id=" + id);
|
|
||||||
return resultSetToModule(rs);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Module getModule(int userid, int semesterid) {
|
|
||||||
try {
|
|
||||||
ResultSet rs = st.executeQuery("select * from modules where userid=" + userid + " and semesterid=" + semesterid);
|
|
||||||
|
|
||||||
return resultSetToModule(rs);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//get module objects by its semester and its lecturer
|
|
||||||
public Module[] getModules(int userid) {
|
|
||||||
try {
|
|
||||||
ResultSet rs = st.executeQuery("SELECT * FROM modules WHERE userid = " + userid);
|
|
||||||
List<Module> moduleList = new ArrayList<>();
|
|
||||||
Module m = null;
|
|
||||||
while ((m = resultSetToModule(rs)) != null) {
|
|
||||||
moduleList.add(m);
|
|
||||||
}
|
|
||||||
|
|
||||||
return moduleList.toArray(new Module[0]);
|
|
||||||
|
|
||||||
} catch (Exception ex) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Module addModule(Module m) {
|
|
||||||
try {
|
|
||||||
st.executeUpdate("insert into modules (userid, semesterid, name, activated) " +
|
|
||||||
"Values (" + m.getUserid() + ", " + m.getsemesterid() + ", '" + m.getName() + "', " + m.getActivated() + ")");
|
|
||||||
return getModule(m.getUserid(), m.getsemesterid());
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Module[] getAllModules() {
|
|
||||||
try {
|
|
||||||
ResultSet rs = st.executeQuery("SELECT * FROM modules");
|
|
||||||
List<Module> moduleList = new ArrayList<>();
|
|
||||||
Module m = null;
|
|
||||||
while ((m = resultSetToModule(rs)) != null) {
|
|
||||||
moduleList.add(m);
|
|
||||||
}
|
|
||||||
|
|
||||||
return moduleList.toArray(new Module[0]);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Module updateModule(Module m) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
|
|
||||||
st.executeUpdate("update modules set activated=" + m.getActivated() + ", semesterid=" + m.getsemesterid() + ", name='" + m.getName() + "' where id=" + m.getid());
|
|
||||||
|
|
||||||
|
|
||||||
return null;
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean deleteModule(int id) {
|
|
||||||
try {
|
|
||||||
st.executeUpdate("delete from modules where id=" + id);
|
|
||||||
return true;
|
|
||||||
} catch (Exception ex) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Module resultSetToModule(ResultSet rs) {
|
|
||||||
try {
|
|
||||||
rs.next();
|
|
||||||
return new Module(
|
|
||||||
rs.getInt("id"),
|
|
||||||
rs.getInt("userid"),
|
|
||||||
rs.getInt("semesterid"),
|
|
||||||
rs.getString("name"),
|
|
||||||
rs.getInt("activated"));
|
|
||||||
} catch (Exception ex) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* USER
|
|
||||||
*/
|
|
||||||
|
|
||||||
//Alle User, die nicht admin sind
|
|
||||||
public User[] getAllUsers() {
|
|
||||||
try {
|
|
||||||
ResultSet rs = st.executeQuery("select * from users where permission=0");
|
|
||||||
|
|
||||||
User u = null;
|
|
||||||
|
|
||||||
List<User> output = new ArrayList<>();
|
|
||||||
|
|
||||||
while ((u = resultSetToUser(rs)) != null) {
|
|
||||||
u.clearOutPassword();
|
|
||||||
output.add(u);
|
|
||||||
}
|
|
||||||
|
|
||||||
return output.toArray(new User[0]);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//einen User
|
|
||||||
public User getUser(String mail, String password) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
ResultSet rs = st.executeQuery("select * from users where mail = '" + mail + "' and password = '" + password + "'");
|
|
||||||
return resultSetToUser(rs);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public User getUser(int id) {
|
|
||||||
try {
|
|
||||||
ResultSet rs = st.executeQuery("select * from users where id=" + id);
|
|
||||||
return resultSetToUser(rs);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public User getUser(String mail) {
|
|
||||||
try {
|
|
||||||
ResultSet rs = st.executeQuery("select * from users where mail='" + mail + "'");
|
|
||||||
User u = resultSetToUser(rs);
|
|
||||||
if (u != null) u.clearOutPassword();
|
|
||||||
|
|
||||||
return u;
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public User resultSetToUser(ResultSet rs) {
|
|
||||||
try {
|
|
||||||
rs.next();
|
|
||||||
return new User(
|
|
||||||
rs.getInt("id"),
|
|
||||||
rs.getString("firstname"),
|
|
||||||
rs.getString("lastname"),
|
|
||||||
rs.getString("mail"),
|
|
||||||
rs.getString("password"),
|
|
||||||
rs.getInt("permission")
|
|
||||||
);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//add a new user object to the database returns if process was successful
|
|
||||||
public User addUser(User user) {
|
|
||||||
//check if mail and passwort (key user information) is given
|
|
||||||
if (user.getMail() == null || user.getPassword() == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
String password = user.getPassword();
|
|
||||||
if (encrypted) {
|
|
||||||
RSA rsa = RSA.getInstance();
|
|
||||||
byte[] psw = rsa.loadByteArray(password);
|
|
||||||
try {
|
|
||||||
password = rsa.decrypt(psw);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
st.executeUpdate("insert into users (firstname, lastname, mail, password, permission) values (" + "'" + user.getFirstName() + "', '" + user.getLastName() + "', '" + user.getMail() + "', '" + password + "', " + 0 + ")");
|
|
||||||
return getUser(user.getMail(), user.getPassword());
|
|
||||||
} catch (Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public User updateUser(User user, int id, boolean elevationRequestByAdmin) {
|
|
||||||
try {
|
|
||||||
String password = user.getPassword();
|
|
||||||
if (encrypted) {
|
|
||||||
RSA rsa = RSA.getInstance();
|
|
||||||
byte[] psw = rsa.loadByteArray(password);
|
|
||||||
try {
|
|
||||||
password = rsa.decrypt(psw);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!elevationRequestByAdmin) {
|
|
||||||
st.executeUpdate("update users set " +
|
|
||||||
"firstname='" + user.getFirstName() + "', " +
|
|
||||||
"lastname='" + user.getLastName() + "', " +
|
|
||||||
"mail='" + user.getMail() + "', " +
|
|
||||||
"password='" + password + "' " +
|
|
||||||
"where id=" + id);
|
|
||||||
} else {
|
|
||||||
st.executeUpdate("update users set " +
|
|
||||||
"firstname='" + user.getFirstName() + "', " +
|
|
||||||
"lastname='" + user.getLastName() + "', " +
|
|
||||||
"mail='" + user.getMail() + "', " +
|
|
||||||
"password='" + password + "'," +
|
|
||||||
"permission=" + user.getPermissions() +
|
|
||||||
"where id=" + id);
|
|
||||||
}
|
|
||||||
|
|
||||||
return getUser(id);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean deleteUser(String mail) {
|
|
||||||
try {
|
|
||||||
ResultSet rs = st.executeQuery("SELECT id FROM user WHERE mail='" + mail + "'");
|
|
||||||
rs.next();
|
|
||||||
int id = rs.getInt("id");
|
|
||||||
st.executeUpdate("DELETE FROM modules WHERE lecturerId = " + id);
|
|
||||||
|
|
||||||
st.executeUpdate("delete from users where mail='" + mail + "'");
|
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.example.backend.anwprj.Days;
|
||||||
|
|
||||||
|
public class Day
|
||||||
|
{
|
||||||
|
private int id;
|
||||||
|
private int dayinweek;
|
||||||
|
private int weekid;
|
||||||
|
|
||||||
|
public Day(int id, int dayinweek, int weekid)
|
||||||
|
{
|
||||||
|
this.id = id;
|
||||||
|
this.dayinweek = dayinweek;
|
||||||
|
this.weekid = weekid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId()
|
||||||
|
{
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDayinweek()
|
||||||
|
{
|
||||||
|
return dayinweek;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWeekid()
|
||||||
|
{
|
||||||
|
return weekid;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.example.backend.discard.Encryption;
|
package com.example.backend.anwprj.Encryption;
|
||||||
|
|
||||||
import javax.crypto.Cipher;
|
import javax.crypto.Cipher;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
@@ -4,24 +4,22 @@ package com.example.backend.anwprj.Entries;
|
|||||||
public class Entry
|
public class Entry
|
||||||
{
|
{
|
||||||
private int id;
|
private int id;
|
||||||
private int daynumber;
|
private int dayid;
|
||||||
private int yearnumber;
|
|
||||||
private int usercreatedbyid;
|
private int usercreatedbyid;
|
||||||
private int timestart;
|
private int timestart;
|
||||||
private int timeend;
|
private int timeend;
|
||||||
private int semesterid;
|
|
||||||
private String info;
|
private String info;
|
||||||
|
private int editable;
|
||||||
|
|
||||||
public Entry(int id, int daynumber, int yearnumber, int usercreatedbyid, int timestart, int timeend, int semesterid, String info)
|
public Entry(int id, int dayid, int usercreatedbyid, int timestart, int timeend, String info, int editable)
|
||||||
{
|
{
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.daynumber = daynumber;
|
this.dayid = dayid;
|
||||||
this.yearnumber = yearnumber;
|
|
||||||
this.usercreatedbyid = usercreatedbyid;
|
this.usercreatedbyid = usercreatedbyid;
|
||||||
this.timestart = timestart;
|
this.timestart = timestart;
|
||||||
this.timeend = timeend;
|
this.timeend = timeend;
|
||||||
this.semesterid = semesterid;
|
|
||||||
this.info = info;
|
this.info = info;
|
||||||
|
this.editable = editable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId()
|
public int getId()
|
||||||
@@ -29,14 +27,9 @@ public class Entry
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDaynumber()
|
public int getDayid()
|
||||||
{
|
{
|
||||||
return daynumber;
|
return dayid;
|
||||||
}
|
|
||||||
|
|
||||||
public int getYearnumber()
|
|
||||||
{
|
|
||||||
return yearnumber;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getUsercreatedbyid()
|
public int getUsercreatedbyid()
|
||||||
@@ -54,13 +47,33 @@ public class Entry
|
|||||||
return timeend;
|
return timeend;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSemesterid()
|
|
||||||
{
|
|
||||||
return semesterid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getInfo()
|
public String getInfo()
|
||||||
{
|
{
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setDayid(int dayid)
|
||||||
|
{
|
||||||
|
this.dayid = dayid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimestart(int timestart)
|
||||||
|
{
|
||||||
|
this.timestart = timestart;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimeend(int timeend)
|
||||||
|
{
|
||||||
|
this.timeend = timeend;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInfo(String info)
|
||||||
|
{
|
||||||
|
this.info = info;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEditable()
|
||||||
|
{
|
||||||
|
return editable;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
package com.example.backend.anwprj.Module;
|
|
||||||
|
|
||||||
//module data class
|
|
||||||
public class Module {
|
|
||||||
private int id;
|
|
||||||
private int userid;
|
|
||||||
private int semesterid;
|
|
||||||
private String name;
|
|
||||||
private int activated;
|
|
||||||
|
|
||||||
|
|
||||||
public Module(int id, int userid, int semesterid, String name, int activated)
|
|
||||||
{
|
|
||||||
this.id = id;
|
|
||||||
this.userid = userid;
|
|
||||||
this.semesterid = semesterid;
|
|
||||||
this.name = name;
|
|
||||||
this.activated = activated;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getid() { return id; }
|
|
||||||
|
|
||||||
public int getUserid() { return userid; }
|
|
||||||
|
|
||||||
public int getsemesterid() { return semesterid; }
|
|
||||||
|
|
||||||
public String getName() { return name; }
|
|
||||||
|
|
||||||
public int getActivated() { return activated; }
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -4,46 +4,49 @@ package com.example.backend.anwprj.Semesters;
|
|||||||
public class Semester
|
public class Semester
|
||||||
{
|
{
|
||||||
private int id;
|
private int id;
|
||||||
private int startday;
|
private int startweeknumber;
|
||||||
private int endday;
|
private int endweeknumber;
|
||||||
private String name;
|
private String name;
|
||||||
private int startyear;
|
private int startyear;
|
||||||
private int endyear;
|
private int endyear;
|
||||||
private int number;
|
|
||||||
|
|
||||||
public Semester(int id, int startday, int endday, String name, int startyear, int endyear, int number) {
|
public Semester(int id, int startweeknumber, int endweeknumber, String name, int startyear, int endyear)
|
||||||
|
{
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.startday = startday;
|
this.startweeknumber = startweeknumber;
|
||||||
this.endday = endday;
|
this.endweeknumber = endweeknumber;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.startyear = startyear;
|
this.startyear = startyear;
|
||||||
this.endyear = endyear;
|
this.endyear = endyear;
|
||||||
this.number = number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId()
|
||||||
|
{
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getStartday() {
|
public int getStartweeknumber()
|
||||||
return startday;
|
{
|
||||||
|
return startweeknumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getEndday() {
|
public int getEndweeknumber()
|
||||||
return endday;
|
{
|
||||||
|
return endweeknumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName()
|
||||||
|
{
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getStartyear() {
|
public int getStartyear()
|
||||||
|
{
|
||||||
return startyear;
|
return startyear;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getEndyear() {
|
public int getEndyear()
|
||||||
|
{
|
||||||
return endyear;
|
return endyear;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNumber(){return number; }
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.example.backend.anwprj.Users;
|
package com.example.backend.anwprj.Users;
|
||||||
|
|
||||||
import com.example.backend.anwprj.Database.DataBaseHandler;
|
import com.example.backend.anwprj.DataBaseHandler;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -63,6 +63,6 @@ public class UserSessionIDHandler
|
|||||||
return generatedString;
|
return generatedString;
|
||||||
}
|
}
|
||||||
|
|
||||||
return "failed";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package com.example.backend.anwprj.controller;
|
||||||
|
|
||||||
|
import com.example.backend.anwprj.DataBaseHandler;
|
||||||
|
import com.example.backend.anwprj.Days.Day;
|
||||||
|
import com.example.backend.anwprj.Users.User;
|
||||||
|
import com.example.backend.anwprj.Users.UserPermissions;
|
||||||
|
import com.example.backend.anwprj.Users.UserSessionIDHandler;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class DayController
|
||||||
|
{
|
||||||
|
|
||||||
|
private DataBaseHandler db;
|
||||||
|
|
||||||
|
{
|
||||||
|
db = DataBaseHandler.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
@CrossOrigin
|
||||||
|
@GetMapping("/days")
|
||||||
|
public ResponseEntity<Day> getDay(
|
||||||
|
@RequestParam(name="sessionid") String sessionID,
|
||||||
|
@RequestParam(name="dayinweek") int dayInWeek,
|
||||||
|
@RequestParam(name="weeknumber") int weekNumber,
|
||||||
|
@RequestParam(name="semesterid") int semesterID)
|
||||||
|
{
|
||||||
|
User u = UserSessionIDHandler.getUserBySessionID(sessionID);
|
||||||
|
|
||||||
|
if(u != null)
|
||||||
|
{
|
||||||
|
Day d = db.getDay(dayInWeek, weekNumber, semesterID);
|
||||||
|
|
||||||
|
if (d != null)
|
||||||
|
{
|
||||||
|
return new ResponseEntity<>(d, HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
@CrossOrigin
|
||||||
|
@PostMapping("/days")
|
||||||
|
public ResponseEntity<Day> addDay(@RequestBody Day day, @RequestParam(name="sessionid") String sessionID)
|
||||||
|
{
|
||||||
|
User u = UserSessionIDHandler.getUserBySessionID(sessionID);
|
||||||
|
|
||||||
|
if(u != null && u.getPermissions() == UserPermissions.admin.getValue())
|
||||||
|
{
|
||||||
|
return new ResponseEntity<>(db.addDay(day), HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ResponseEntity<>(null, HttpStatus.FORBIDDEN);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
package com.example.backend.anwprj.controller;
|
package com.example.backend.anwprj.controller;
|
||||||
|
|
||||||
import com.example.backend.anwprj.Database.DataBaseHandler;
|
import com.example.backend.anwprj.DataBaseHandler;
|
||||||
import com.example.backend.anwprj.Entries.Entry;
|
import com.example.backend.anwprj.Entries.Entry;
|
||||||
import com.example.backend.anwprj.Users.User;
|
import com.example.backend.anwprj.Users.User;
|
||||||
import com.example.backend.anwprj.Users.UserPermissions;
|
|
||||||
import com.example.backend.anwprj.Users.UserSessionIDHandler;
|
import com.example.backend.anwprj.Users.UserSessionIDHandler;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
@@ -18,122 +17,29 @@ public class EntriesController
|
|||||||
db = DataBaseHandler.getInstance();
|
db = DataBaseHandler.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
GET
|
|
||||||
a set of entries for a week, based on the semester, the startdaynumber of the week and the year
|
|
||||||
Every user is allowed
|
|
||||||
*/
|
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@GetMapping("/entries")
|
@GetMapping("/entries")
|
||||||
public ResponseEntity<Entry[][]> getEntries(@RequestParam(name = "semesterid") int semesterid,
|
public ResponseEntity<Entry[]> getEntries(
|
||||||
@RequestParam(name = "daynumber") int daynumber,
|
@RequestParam(name = "sessionid") String sessionID,
|
||||||
@RequestParam(name = "yearnumber") int yearnumber,
|
@RequestParam(name = "dayinweek") int dayinweek,
|
||||||
@RequestParam(name = "sessionid") String sessionid)
|
@RequestParam(name = "weeknumber") int weeknumber,
|
||||||
|
@RequestParam(name = "semesterid") int semesterid)
|
||||||
{
|
{
|
||||||
User sessionUser = UserSessionIDHandler.getUserBySessionID(sessionid);
|
User user = UserSessionIDHandler.getUserBySessionID(sessionID);
|
||||||
|
|
||||||
if (sessionUser != null)
|
if(user == null)
|
||||||
{
|
{
|
||||||
var lonelyEntry = db.getEntries(semesterid, daynumber, yearnumber);
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
var happyEntry = db.getAllEntrys(semesterid, daynumber, yearnumber, sessionUser.getId());
|
|
||||||
var combinedEntry = new Entry[6][20];
|
|
||||||
for (int i = 0; i < 6; i++) {
|
|
||||||
var idx = 0;
|
|
||||||
for (int j = 0; j < 20; j++) {
|
|
||||||
if (lonelyEntry != null && lonelyEntry[i][j] != null){
|
|
||||||
combinedEntry[i][idx] = lonelyEntry[i][j];
|
|
||||||
idx++;
|
|
||||||
}
|
|
||||||
if (happyEntry != null && happyEntry[i][j] != null){
|
|
||||||
combinedEntry[i][idx] = happyEntry[i][j];
|
|
||||||
idx++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Entry[] entries = db.getEntries(dayinweek, weeknumber, semesterid, user);
|
||||||
return new ResponseEntity<>(combinedEntry, HttpStatus.OK);
|
return new ResponseEntity<>(entries, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ResponseEntity<>(null, HttpStatus.FORBIDDEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
@CrossOrigin
|
|
||||||
@GetMapping("/entries/planned")
|
|
||||||
public ResponseEntity<Integer[]> getEntries(@RequestParam(name = "semesterid") int semesterid,
|
|
||||||
@RequestParam(name = "sessionid") String sessionid)
|
|
||||||
{
|
|
||||||
User sessionUser = UserSessionIDHandler.getUserBySessionID(sessionid);
|
|
||||||
if (sessionUser != null)
|
|
||||||
{
|
|
||||||
var entries = db.getAllEntries(semesterid, sessionUser.getId());
|
|
||||||
var count = 0;
|
|
||||||
for (int i = 0; i < entries.length; i++) {
|
|
||||||
count += entries[i].getTimeend()-entries[i].getTimestart();
|
|
||||||
}
|
|
||||||
return new ResponseEntity<>(new Integer[]{count}, HttpStatus.OK);
|
|
||||||
}
|
|
||||||
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
POST
|
|
||||||
A new entry to the database. Every user except of admins is allowed
|
|
||||||
*/
|
|
||||||
|
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@PostMapping("/entries")
|
@PostMapping("/entries")
|
||||||
public ResponseEntity<Boolean> postEntry(@RequestBody Entry entry, @RequestParam(name = "sessionid") String sessionid)
|
public ResponseEntity<Entry[]> postEntries(@RequestBody Entry[] entries, @RequestParam(name="sessionid") String sessionID)
|
||||||
{
|
{
|
||||||
User sessionUser = UserSessionIDHandler.getUserBySessionID(sessionid);
|
return null;
|
||||||
|
|
||||||
if (sessionUser != null && sessionUser.getPermissions() == UserPermissions.self.getValue())
|
|
||||||
{
|
|
||||||
db.addEntry(entry);
|
|
||||||
return new ResponseEntity<>(true, HttpStatus.OK);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ResponseEntity<>(false, HttpStatus.FORBIDDEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
PUT
|
|
||||||
Update the endTime of an existing entry in the database. Every user except of admins is allowed
|
|
||||||
*/
|
|
||||||
|
|
||||||
@CrossOrigin
|
|
||||||
@PutMapping("/entries")
|
|
||||||
public ResponseEntity<Boolean> updateEntry(@RequestParam(name="sessionid") String sessionid, @RequestBody Entry entry)
|
|
||||||
{
|
|
||||||
User sessionUser = UserSessionIDHandler.getUserBySessionID(sessionid);
|
|
||||||
if (sessionUser != null)
|
|
||||||
{
|
|
||||||
db.updateEntry(entry);
|
|
||||||
return new ResponseEntity<>(true, HttpStatus.OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ResponseEntity<>(false, HttpStatus.FORBIDDEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
Delete
|
|
||||||
an existing entry from the database
|
|
||||||
*/
|
|
||||||
@CrossOrigin
|
|
||||||
@DeleteMapping("/entries")
|
|
||||||
public ResponseEntity<Boolean> deleteEntry(@RequestParam(name = "id") int id, @RequestParam(name = "sessionid") String sessionid)
|
|
||||||
{
|
|
||||||
User sessionUser = UserSessionIDHandler.getUserBySessionID(sessionid);
|
|
||||||
|
|
||||||
if (sessionUser != null)
|
|
||||||
{
|
|
||||||
db.deleteEntry(id);
|
|
||||||
return new ResponseEntity<>(true, HttpStatus.OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ResponseEntity<>(false, HttpStatus.FORBIDDEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,168 +0,0 @@
|
|||||||
package com.example.backend.anwprj.controller;
|
|
||||||
|
|
||||||
import com.example.backend.anwprj.Database.DataBaseHandler;
|
|
||||||
import com.example.backend.anwprj.Module.Module;
|
|
||||||
import com.example.backend.anwprj.Users.User;
|
|
||||||
import com.example.backend.anwprj.Users.UserPermissions;
|
|
||||||
import com.example.backend.anwprj.Users.UserSessionIDHandler;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ein Modul hier entspricht nicht z.b. Analysis im Allgemeinen.
|
|
||||||
* Es beschreibt die Verbindung zwischen einem Dozenten und Analysis in einem Speziellen Semester.
|
|
||||||
*/
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
public class ModuleController
|
|
||||||
{
|
|
||||||
private final DataBaseHandler db;
|
|
||||||
|
|
||||||
{
|
|
||||||
db = DataBaseHandler.getInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
GET
|
|
||||||
A Module by its id
|
|
||||||
*/
|
|
||||||
@CrossOrigin
|
|
||||||
@GetMapping("/module/id")
|
|
||||||
public ResponseEntity<Module[]> getModules(
|
|
||||||
@RequestParam(name = "sessionid") String sessionID)
|
|
||||||
{
|
|
||||||
|
|
||||||
User user = UserSessionIDHandler.getUserBySessionID(sessionID);
|
|
||||||
|
|
||||||
if (user != null)
|
|
||||||
{
|
|
||||||
Module[] modules = db.getModules(user.getId());
|
|
||||||
if (modules != null)
|
|
||||||
{
|
|
||||||
return new ResponseEntity<>(modules, HttpStatus.OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
@CrossOrigin
|
|
||||||
@GetMapping("/module/bysemesterid")
|
|
||||||
public ResponseEntity<Module[]> getModulesBySemesterID(@RequestParam(name="sessionid") String sessionID, @RequestParam(name="semesterid") int semesterid)
|
|
||||||
{
|
|
||||||
User user = UserSessionIDHandler.getUserBySessionID(sessionID);
|
|
||||||
|
|
||||||
if(user != null && user.getPermissions() == UserPermissions.admin.getValue())
|
|
||||||
{
|
|
||||||
Module[] tempModuleArray = db.getAllModules();
|
|
||||||
List<Module> result = new ArrayList<>();
|
|
||||||
|
|
||||||
for(int i = 0; i < tempModuleArray.length; i++)
|
|
||||||
{
|
|
||||||
if(tempModuleArray[i].getsemesterid() == semesterid)
|
|
||||||
{
|
|
||||||
result.add(tempModuleArray[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ResponseEntity<>(result.toArray(new Module[0]), HttpStatus.OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
GET
|
|
||||||
all modules from the database. (Not used now)
|
|
||||||
*/
|
|
||||||
@CrossOrigin
|
|
||||||
@GetMapping("/module/all")
|
|
||||||
public ResponseEntity<Module[]> getModule(@RequestParam(name = "sessionid") String sessionid)
|
|
||||||
{
|
|
||||||
User u = UserSessionIDHandler.getUserBySessionID(sessionid);
|
|
||||||
|
|
||||||
if (u != null)
|
|
||||||
{
|
|
||||||
if (u.getPermissions() == UserPermissions.admin.getValue())
|
|
||||||
{
|
|
||||||
return new ResponseEntity<>(db.getAllModules(), HttpStatus.OK);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
POST
|
|
||||||
a new module entry. (When a user is selected in a semester.)
|
|
||||||
*/
|
|
||||||
@CrossOrigin
|
|
||||||
@PostMapping("/module")
|
|
||||||
public ResponseEntity<Module> addModule(@RequestBody Module module, @RequestParam(name = "sessionid") String sessionID)
|
|
||||||
{
|
|
||||||
|
|
||||||
User user = UserSessionIDHandler.getUserBySessionID(sessionID);
|
|
||||||
|
|
||||||
if (user.getPermissions() == UserPermissions.admin.getValue())
|
|
||||||
{
|
|
||||||
Module m = db.addModule(module);
|
|
||||||
if (m != null)
|
|
||||||
{
|
|
||||||
return new ResponseEntity<>(m, HttpStatus.OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
PUT
|
|
||||||
Update a Module
|
|
||||||
*/
|
|
||||||
@CrossOrigin
|
|
||||||
@PutMapping("/module")
|
|
||||||
public ResponseEntity<Module> updateModule(@RequestBody Module module, @RequestParam(name = "sessionid") String sessionID)
|
|
||||||
{
|
|
||||||
|
|
||||||
User u = UserSessionIDHandler.getUserBySessionID(sessionID);
|
|
||||||
if (u != null)
|
|
||||||
{
|
|
||||||
Module m = db.updateModule(module);
|
|
||||||
|
|
||||||
if (m != null)
|
|
||||||
{
|
|
||||||
return new ResponseEntity<>(m, HttpStatus.OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
DELETE
|
|
||||||
Delete A Module
|
|
||||||
*/
|
|
||||||
@CrossOrigin
|
|
||||||
@DeleteMapping("/module")
|
|
||||||
public void deleteModule(@RequestParam(name = "sessionid") String sessionid, @RequestParam(name="id") int id)
|
|
||||||
{
|
|
||||||
User u = UserSessionIDHandler.getUserBySessionID(sessionid);
|
|
||||||
if (u != null && u.getPermissions() == UserPermissions.admin.getValue())
|
|
||||||
{
|
|
||||||
db.deleteModule(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.example.backend.anwprj.controller;
|
package com.example.backend.anwprj.controller;
|
||||||
|
|
||||||
import com.example.backend.anwprj.Database.DataBaseHandler;
|
import com.example.backend.anwprj.DataBaseHandler;
|
||||||
import com.example.backend.anwprj.Semesters.Semester;
|
import com.example.backend.anwprj.Semesters.Semester;
|
||||||
import com.example.backend.anwprj.Users.User;
|
import com.example.backend.anwprj.Users.User;
|
||||||
import com.example.backend.anwprj.Users.UserPermissions;
|
import com.example.backend.anwprj.Users.UserPermissions;
|
||||||
@@ -9,9 +9,6 @@ import org.springframework.http.HttpStatus;
|
|||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
public class SemesterController
|
public class SemesterController
|
||||||
{
|
{
|
||||||
@@ -22,6 +19,28 @@ public class SemesterController
|
|||||||
db = DataBaseHandler.getInstance();
|
db = DataBaseHandler.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//a new semester add is requested (only allowed for admin users)
|
||||||
|
@CrossOrigin
|
||||||
|
@PostMapping("/semester")
|
||||||
|
public ResponseEntity<Semester> addSemester(@RequestBody Semester semester, @RequestParam(name="sessionid") String sessionID)
|
||||||
|
{
|
||||||
|
User user = UserSessionIDHandler.getUserBySessionID(sessionID);
|
||||||
|
|
||||||
|
if(user.getPermissions() == UserPermissions.admin.getValue())
|
||||||
|
{
|
||||||
|
Semester s = db.addSemester(semester);
|
||||||
|
if(s != null)
|
||||||
|
{
|
||||||
|
return new ResponseEntity<>(s, HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ResponseEntity<>(s, HttpStatus.NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
||||||
|
}
|
||||||
|
|
||||||
//get a semester object by its name
|
//get a semester object by its name
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@GetMapping("/semester")
|
@GetMapping("/semester")
|
||||||
@@ -57,71 +76,12 @@ public class SemesterController
|
|||||||
return new ResponseEntity<>(s, HttpStatus.OK);
|
return new ResponseEntity<>(s, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ResponseEntity<>(null, HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@CrossOrigin
|
|
||||||
@GetMapping("/semester/id/all")
|
|
||||||
public ResponseEntity<Semester[]> getSemestersAll(@RequestParam(name="ids") String ids, @RequestParam(name="sessionid") String sessionid)
|
|
||||||
{
|
|
||||||
String[] idsSplit = ids.split("a");
|
|
||||||
|
|
||||||
List<Semester> resultList = new ArrayList<>();
|
|
||||||
|
|
||||||
for(int i = 0; i < idsSplit.length; i++)
|
|
||||||
{
|
|
||||||
int currentID = Integer.parseInt(idsSplit[i]);
|
|
||||||
resultList.add(db.getSemester(currentID));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ResponseEntity<>(resultList.toArray(new Semester[0]), HttpStatus.OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
@CrossOrigin
|
|
||||||
@GetMapping("/semester/all")
|
|
||||||
public ResponseEntity<Semester[]> getSemester(@RequestParam(name="sessionid") String sessionid)
|
|
||||||
{
|
|
||||||
User u = UserSessionIDHandler.getUserBySessionID(sessionid);
|
|
||||||
|
|
||||||
if(u != null)
|
|
||||||
{
|
|
||||||
if(u.getPermissions() == UserPermissions.admin.getValue())
|
|
||||||
{
|
|
||||||
return new ResponseEntity<>(db.getAllSemesters(), HttpStatus.OK);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//a new semester add is requested (only allowed for admin users)
|
|
||||||
@CrossOrigin
|
|
||||||
@PostMapping("/semester")
|
|
||||||
public ResponseEntity<Semester> addSemester(@RequestBody Semester semester, @RequestParam(name="sessionid") String sessionID)
|
|
||||||
{
|
|
||||||
User user = UserSessionIDHandler.getUserBySessionID(sessionID);
|
|
||||||
|
|
||||||
if(user.getPermissions() == UserPermissions.admin.getValue())
|
|
||||||
{
|
|
||||||
Semester s = db.addSemester(semester);
|
|
||||||
if(s != null)
|
|
||||||
{
|
|
||||||
|
|
||||||
return new ResponseEntity<>(s, HttpStatus.OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ResponseEntity<>(null, HttpStatus.NOT_FOUND);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@PutMapping("/semester")
|
@PutMapping("/semester")
|
||||||
public ResponseEntity<Semester> updateSemester(@RequestBody Semester semester, @RequestParam(name="sessionid") String sessionID)
|
public ResponseEntity<Semester> updateSemester(@RequestBody Semester semester, @RequestParam(name="sessionid") String sessionID)
|
||||||
@@ -129,6 +89,7 @@ public class SemesterController
|
|||||||
User u = UserSessionIDHandler.getUserBySessionID(sessionID);
|
User u = UserSessionIDHandler.getUserBySessionID(sessionID);
|
||||||
if(u != null && u.getPermissions() == UserPermissions.admin.getValue())
|
if(u != null && u.getPermissions() == UserPermissions.admin.getValue())
|
||||||
{
|
{
|
||||||
|
System.out.println(semester.getId());
|
||||||
Semester s = db.updateSemester(semester);
|
Semester s = db.updateSemester(semester);
|
||||||
|
|
||||||
if(s != null)
|
if(s != null)
|
||||||
@@ -141,16 +102,4 @@ public class SemesterController
|
|||||||
|
|
||||||
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@CrossOrigin
|
|
||||||
@DeleteMapping("/semester")
|
|
||||||
public void deleteSemester(@RequestParam(name="sessionid") String sessionid, @RequestParam(name="id") int id)
|
|
||||||
{
|
|
||||||
User u = UserSessionIDHandler.getUserBySessionID(sessionid);
|
|
||||||
if(u != null && u.getPermissions() == UserPermissions.admin.getValue())
|
|
||||||
{
|
|
||||||
db.deleteSemester(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.example.backend.anwprj.controller;
|
package com.example.backend.anwprj.controller;
|
||||||
|
|
||||||
import com.example.backend.discard.Encryption.RSA;
|
import com.example.backend.anwprj.Encryption.RSA;
|
||||||
import com.example.backend.anwprj.Database.DataBaseHandler;
|
import com.example.backend.anwprj.DataBaseHandler;
|
||||||
import com.example.backend.anwprj.Users.User;
|
import com.example.backend.anwprj.Users.User;
|
||||||
import com.example.backend.anwprj.Users.UserPermissions;
|
import com.example.backend.anwprj.Users.UserPermissions;
|
||||||
import com.example.backend.anwprj.Users.UserSessionIDHandler;
|
import com.example.backend.anwprj.Users.UserSessionIDHandler;
|
||||||
@@ -18,84 +18,6 @@ public class UserController {
|
|||||||
db = DataBaseHandler.getInstance();
|
db = DataBaseHandler.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@CrossOrigin
|
|
||||||
@GetMapping("/users/all")
|
|
||||||
public ResponseEntity<User[]> getAllUsers(@RequestParam(name = "sessionid") String sessionid)
|
|
||||||
{
|
|
||||||
User u = UserSessionIDHandler.getUserBySessionID(sessionid);
|
|
||||||
|
|
||||||
if(u != null && u.getPermissions() == UserPermissions.admin.getValue())
|
|
||||||
{
|
|
||||||
User[] output = db.getAllUsers();
|
|
||||||
return new ResponseEntity<>(output, HttpStatus.OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//a user wants to login
|
|
||||||
@CrossOrigin
|
|
||||||
@GetMapping("/users")
|
|
||||||
public ResponseEntity<String> login(@RequestParam(name = "mail") String mail, @RequestParam(name = "password") String password) {
|
|
||||||
//generate a session id for the user trying to login
|
|
||||||
boolean isEncrypted = false;
|
|
||||||
if(isEncrypted)
|
|
||||||
{
|
|
||||||
RSA rsa = RSA.getInstance();
|
|
||||||
byte[] psw = rsa.loadByteArray(password);
|
|
||||||
try {
|
|
||||||
password = rsa.decrypt(psw);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mail = mail.toLowerCase();
|
|
||||||
String sessionID = UserSessionIDHandler.addUser(mail, password);
|
|
||||||
|
|
||||||
return new ResponseEntity<>(sessionID, HttpStatus.OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
@CrossOrigin
|
|
||||||
@GetMapping("/users/logout")
|
|
||||||
public ResponseEntity<Boolean> logout(@RequestParam(name = "sessionid") String sessionID) {
|
|
||||||
boolean success = UserSessionIDHandler.removeUser(sessionID);
|
|
||||||
return new ResponseEntity<>(success, HttpStatus.OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
@CrossOrigin
|
|
||||||
@GetMapping("/users/data")
|
|
||||||
public ResponseEntity<User> getUserData(
|
|
||||||
@RequestParam(name = "sessionid") String sessionID,
|
|
||||||
@RequestParam(name = "mail") String mail) {
|
|
||||||
User sessionUser = UserSessionIDHandler.getUserBySessionID(sessionID);
|
|
||||||
|
|
||||||
if (sessionUser != null) {
|
|
||||||
System.out.println(sessionUser.getMail() + " " + mail);
|
|
||||||
|
|
||||||
if (sessionUser.getMail().equals(mail) || sessionUser.getPermissions() == UserPermissions.admin.getValue()) {
|
|
||||||
User searchedUser = db.getUser(mail);
|
|
||||||
return new ResponseEntity<>(searchedUser, HttpStatus.OK);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
@CrossOrigin
|
|
||||||
@GetMapping("/users/check")
|
|
||||||
public ResponseEntity<User> checkLogin(@RequestParam(name="sessionid") String sessionid)
|
|
||||||
{
|
|
||||||
User u = UserSessionIDHandler.getUserBySessionID(sessionid);
|
|
||||||
|
|
||||||
if(u != null)
|
|
||||||
{
|
|
||||||
return new ResponseEntity<>(db.getUser(u.getId()), HttpStatus.OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
|
||||||
}
|
|
||||||
|
|
||||||
//adds a new user to the database (cannot create an admin user)
|
//adds a new user to the database (cannot create an admin user)
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@@ -118,6 +40,35 @@ public class UserController {
|
|||||||
return new ResponseEntity<String>(HttpStatus.BAD_REQUEST);
|
return new ResponseEntity<String>(HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//a user wants to login
|
||||||
|
@CrossOrigin
|
||||||
|
@GetMapping("/users")
|
||||||
|
public ResponseEntity<String> login(@RequestParam(name = "mail") String mail, @RequestParam(name = "password") String password) {
|
||||||
|
//generate a session id for the user trying to login
|
||||||
|
boolean isEncrypted = true;
|
||||||
|
if(isEncrypted)
|
||||||
|
{
|
||||||
|
RSA rsa = RSA.getInstance();
|
||||||
|
byte[] psw = rsa.loadByteArray(password);
|
||||||
|
try {
|
||||||
|
password = rsa.decrypt(psw);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String sessionID = UserSessionIDHandler.addUser(mail, password);
|
||||||
|
|
||||||
|
return new ResponseEntity<>(sessionID, HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@CrossOrigin
|
||||||
|
@GetMapping("/users/logout")
|
||||||
|
public ResponseEntity<Boolean> logout(@RequestParam(name = "sessionid") String sessionID) {
|
||||||
|
boolean success = UserSessionIDHandler.removeUser(sessionID);
|
||||||
|
return new ResponseEntity<>(success, HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@PutMapping("/users")
|
@PutMapping("/users")
|
||||||
public ResponseEntity<Boolean> updateUser(@RequestParam(name = "sessionid") String sessionID, @RequestBody User u, @RequestParam(name = "mail") String mail) {
|
public ResponseEntity<Boolean> updateUser(@RequestParam(name = "sessionid") String sessionID, @RequestBody User u, @RequestParam(name = "mail") String mail) {
|
||||||
@@ -170,6 +121,25 @@ public class UserController {
|
|||||||
return new ResponseEntity<>(false, HttpStatus.FORBIDDEN);
|
return new ResponseEntity<>(false, HttpStatus.FORBIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CrossOrigin
|
||||||
|
@GetMapping("/users/data")
|
||||||
|
public ResponseEntity<User> getUserData(
|
||||||
|
@RequestParam(name = "sessionid") String sessionID,
|
||||||
|
@RequestParam(name = "mail") String mail) {
|
||||||
|
User sessionUser = UserSessionIDHandler.getUserBySessionID(sessionID);
|
||||||
|
|
||||||
|
if (sessionUser != null) {
|
||||||
|
System.out.println(sessionUser.getMail() + " " + mail);
|
||||||
|
|
||||||
|
if (sessionUser.getMail().equals(mail) || sessionUser.getPermissions() == UserPermissions.admin.getValue()) {
|
||||||
|
User searchedUser = db.getUser(mail);
|
||||||
|
return new ResponseEntity<>(searchedUser, HttpStatus.OK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
||||||
|
}
|
||||||
|
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@DeleteMapping("/users")
|
@DeleteMapping("/users")
|
||||||
public ResponseEntity<Boolean> deleteUser(@RequestParam(name = "sessionid") String sessionID, @RequestParam(name = "mail") String mail) {
|
public ResponseEntity<Boolean> deleteUser(@RequestParam(name = "sessionid") String sessionID, @RequestParam(name = "mail") String mail) {
|
||||||
@@ -181,5 +151,4 @@ public class UserController {
|
|||||||
|
|
||||||
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
package com.example.backend.discard;
|
|
||||||
|
|
||||||
import com.example.backend.anwprj.Database.DataBaseHandler;
|
|
||||||
import com.example.backend.discard.Days.Day;
|
|
||||||
import com.example.backend.anwprj.Users.User;
|
|
||||||
import com.example.backend.anwprj.Users.UserPermissions;
|
|
||||||
import com.example.backend.anwprj.Users.UserSessionIDHandler;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
public class DayController
|
|
||||||
{
|
|
||||||
|
|
||||||
// private DataBaseHandler db;
|
|
||||||
//
|
|
||||||
// {
|
|
||||||
// db = DataBaseHandler.getInstance();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @CrossOrigin
|
|
||||||
// @GetMapping("/days")
|
|
||||||
// public ResponseEntity<Day> getDay(
|
|
||||||
// @RequestParam(name="sessionid") String sessionID,
|
|
||||||
// @RequestParam(name="dayinyear") int dayinyear,
|
|
||||||
// @RequestParam(name="yearnumber") int yearnumber,
|
|
||||||
// @RequestParam(name="semesterid") int semesterID)
|
|
||||||
// {
|
|
||||||
// User u = UserSessionIDHandler.getUserBySessionID(sessionID);
|
|
||||||
//
|
|
||||||
// if(u != null)
|
|
||||||
// {
|
|
||||||
// Day d = db.getDay(dayinyear, yearnumber, semesterID);
|
|
||||||
//
|
|
||||||
// if (d != null)
|
|
||||||
// {
|
|
||||||
// return new ResponseEntity<>(d, HttpStatus.OK);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @CrossOrigin
|
|
||||||
// @PostMapping("/days")
|
|
||||||
// public ResponseEntity<Day> addDay(@RequestBody Day day, @RequestParam(name="sessionid") String sessionID)
|
|
||||||
// {
|
|
||||||
// User u = UserSessionIDHandler.getUserBySessionID(sessionID);
|
|
||||||
//
|
|
||||||
// if(u != null && u.getPermissions() == UserPermissions.admin.getValue())
|
|
||||||
// {
|
|
||||||
// return new ResponseEntity<>(db.addDay(day), HttpStatus.OK);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return new ResponseEntity<>(null, HttpStatus.FORBIDDEN);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
package com.example.backend.discard.Days;
|
|
||||||
|
|
||||||
public class Day
|
|
||||||
{
|
|
||||||
private int id;
|
|
||||||
private int dayinyear;
|
|
||||||
private int yearnumber;
|
|
||||||
private int semesterid;
|
|
||||||
|
|
||||||
public Day(int id, int dayinyear, int yearnumber, int semesterid) {
|
|
||||||
this.id = id;
|
|
||||||
this.dayinyear = dayinyear;
|
|
||||||
this.yearnumber = yearnumber;
|
|
||||||
this.semesterid = semesterid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getDayinyear() {
|
|
||||||
return dayinyear;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getYearnumber() {
|
|
||||||
return yearnumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSemesterid() {
|
|
||||||
return semesterid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,124 +0,0 @@
|
|||||||
/**
|
|
||||||
* WEEKS
|
|
||||||
*/
|
|
||||||
|
|
||||||
public Week addWeek(Week week)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
st.executeUpdate("insert into weeks (semesterid, weeknumber) values (" + week.getSemesterid() + ", " + week.getWeeknumber() + ")");
|
|
||||||
|
|
||||||
return getWeek(week.getSemesterid(), week.getWeeknumber());
|
|
||||||
|
|
||||||
} catch (SQLException e)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Week getWeek(int id)
|
|
||||||
{
|
|
||||||
ResultSet rs = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
rs = st.executeQuery("select * from weeks where id=" + id);
|
|
||||||
|
|
||||||
return resultSetToWeek(rs);
|
|
||||||
|
|
||||||
} catch (SQLException e)
|
|
||||||
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public Week getWeek(int semesterid, int weeknumber)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ResultSet rs = st.executeQuery("select * from weeks where semesterid =" + semesterid + " and weeknumber=" + weeknumber);
|
|
||||||
|
|
||||||
return resultSetToWeek(rs);
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private Week resultSetToWeek(ResultSet rs) {
|
|
||||||
try {
|
|
||||||
rs.next();
|
|
||||||
|
|
||||||
return new Week(
|
|
||||||
rs.getInt("id"),
|
|
||||||
rs.getInt("semesterid"),
|
|
||||||
rs.getInt("weeknumber")
|
|
||||||
);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
DAYS
|
|
||||||
*/
|
|
||||||
public Day addDay(Day day)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
st.executeUpdate("insert into days (dayinyear, yearnumber, semesterid) values (" + day.getDayinyear() + ", " + day.getYearnumber() + ", " + day.getSemesterid() + ")");
|
|
||||||
return getDay(day.getDayinyear(), day.getYearnumber(), day.getSemesterid());
|
|
||||||
} catch (SQLException e)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Day getDay(int id)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ResultSet rs = st.executeQuery("select * from days where id=" + id);
|
|
||||||
|
|
||||||
return resultSetToDay(rs);
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Day getDay(int dayinyear, int yearnumber, int semesterid)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ResultSet rs = st.executeQuery("select * from days where dayinyear =" + dayinyear + " and yearnumber =" + yearnumber + " and semesterid =" + semesterid);
|
|
||||||
|
|
||||||
return resultSetToDay(rs);
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Day resultSetToDay(ResultSet rs)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
rs.next();
|
|
||||||
|
|
||||||
return new Day(
|
|
||||||
rs.getInt("id"),
|
|
||||||
rs.getInt("dayinyear"),
|
|
||||||
rs.getInt("yearnumber"),
|
|
||||||
rs.getInt("semesterid")
|
|
||||||
);
|
|
||||||
} catch (SQLException e)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
package com.example.backend.discard.Week;
|
|
||||||
|
|
||||||
public class Week {
|
|
||||||
|
|
||||||
private int id;
|
|
||||||
private int semesterid;
|
|
||||||
private int weeknumber;
|
|
||||||
|
|
||||||
public Week(int id, int semesterid, int weeknumber) {
|
|
||||||
this.id = id;
|
|
||||||
this.semesterid = semesterid;
|
|
||||||
this.weeknumber = weeknumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSemesterid() {
|
|
||||||
return semesterid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getWeeknumber() {
|
|
||||||
return weeknumber;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
package com.example.backend.discard;
|
|
||||||
|
|
||||||
import com.example.backend.anwprj.Database.DataBaseHandler;
|
|
||||||
import com.example.backend.anwprj.Users.User;
|
|
||||||
import com.example.backend.anwprj.Users.UserPermissions;
|
|
||||||
import com.example.backend.anwprj.Users.UserSessionIDHandler;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import com.example.backend.discard.Week.Week;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
public class WeekController
|
|
||||||
{
|
|
||||||
|
|
||||||
// private DataBaseHandler db;
|
|
||||||
//
|
|
||||||
// {
|
|
||||||
// db = DataBaseHandler.getInstance();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @CrossOrigin
|
|
||||||
// @GetMapping("/weeks")
|
|
||||||
// public ResponseEntity<Week> getWeek(
|
|
||||||
// @RequestParam(name="sessionid") String sessionID,
|
|
||||||
// @RequestParam(name="semesterid") int semesterID,
|
|
||||||
// @RequestParam(name="weeknumber") int weekNumber) throws SQLException {
|
|
||||||
// User u = UserSessionIDHandler.getUserBySessionID(sessionID);
|
|
||||||
//
|
|
||||||
// if(u != null)
|
|
||||||
// {
|
|
||||||
// Week w = db.getWeek(semesterID,weekNumber);
|
|
||||||
//
|
|
||||||
// if(w != null)
|
|
||||||
// {
|
|
||||||
// return new ResponseEntity<>(w, HttpStatus.OK);
|
|
||||||
// }
|
|
||||||
// return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
|
||||||
// }
|
|
||||||
// return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @CrossOrigin
|
|
||||||
// @PostMapping("/weeks")
|
|
||||||
// public ResponseEntity<Week> addWeek(@RequestBody Week week, @RequestParam(name="sessionid") String sessionID)
|
|
||||||
// {
|
|
||||||
// User u = UserSessionIDHandler.getUserBySessionID(sessionID);
|
|
||||||
//
|
|
||||||
// if(u !=null && u.getPermissions() == UserPermissions.admin.getValue())
|
|
||||||
// {
|
|
||||||
// return new ResponseEntity<>(db.addWeek(week), HttpStatus.OK);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return new ResponseEntity<>(null, HttpStatus.FORBIDDEN);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "TIF22A_AnwProjekt_B",
|
|
||||||
"lockfileVersion": 3,
|
|
||||||
"requires": true,
|
|
||||||
"packages": {
|
|
||||||
"node_modules/feiertagejs": {
|
|
||||||
"version": "1.3.9",
|
|
||||||
"resolved": "https://registry.npmjs.org/feiertagejs/-/feiertagejs-1.3.9.tgz",
|
|
||||||
"integrity": "sha512-tUP+WBv2OWBhPwe3NfqwCtjMq+ym598a42tfqmL0FySswEb9xs96p2iKwqqx+lxKieu1njJBRZKsFm92bJhxZw==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=8.0.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2015 Simon Fakir
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
# Feiertage.js
|
|
||||||
|
|
||||||
[](https://badge.fury.io/js/feiertagejs)
|
|
||||||
[](https://travis-ci.org/sfakir/feiertagejs)
|
|
||||||
|
|
||||||
|
|
||||||
Feiertage.js is a small *typescript* npm module without dependencies to calculate German holidays for each Bundesland.
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
- [yarn](https://yarnpkg.com/en/): `yarn add feiertagejs`
|
|
||||||
- [npm](https://www.npmjs.com/): `npm install feiertagejs`
|
|
||||||
- [bower](https://bower.io/): `bower install feiertagejs` *outdated!*
|
|
||||||
- [Plain Javascript](http://extern.fakir.it/feiertagejs/feiertagejs.zip) *outdated!*
|
|
||||||
|
|
||||||
## Quick Examples
|
|
||||||
|
|
||||||
### ES Modules (Typescript/Javasript)
|
|
||||||
|
|
||||||
The prefered whay is to directly import the typescript module. However, you can also use .js.
|
|
||||||
Please find here some examples and full api [here](docs.md).
|
|
||||||
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
import { getHolidays, isHoliday, isSpecificHoliday } from 'feiertagejs';
|
|
||||||
|
|
||||||
const today = new Date();
|
|
||||||
|
|
||||||
console.log(isHoliday(today, 'BW'));
|
|
||||||
// probably false, because you are working ;)
|
|
||||||
|
|
||||||
// check if a day is a specific holiday:
|
|
||||||
console.log(isSpecificHoliday(today, 'CHRISTIHIMMELFAHRT','ALL'));
|
|
||||||
|
|
||||||
// get all holiday for a single year: getHolidays()
|
|
||||||
// returns an array of "Holiday" Objects. Please see the docs.md for all properties.
|
|
||||||
const holidays2023 = getHolidays('2023','BUND');
|
|
||||||
|
|
||||||
|
|
||||||
console.log('date', holidays2023[0].date); // = Date("2023-01-01");
|
|
||||||
console.log('name', holidays2023[0].name); // 'NEUJAHRSTAG' (constant)
|
|
||||||
console.log('translation', holidays2023[0].trans('de')); // German translation: Neujahrstag
|
|
||||||
console.log('equals?', holidays2023[0].equals(date)); // Compare days only (ignore time)
|
|
||||||
```
|
|
||||||
|
|
||||||
### Usage in Node.js
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var feiertagejs = require('feiertagejs');
|
|
||||||
|
|
||||||
var today = new Date();
|
|
||||||
|
|
||||||
console.log(feiertagejs.isHoliday(today, 'BW'));
|
|
||||||
// probably false, because you are working ;)
|
|
||||||
|
|
||||||
// check if a day is a specific holiday:
|
|
||||||
console.log(feiertagejs.isSpecificHoliday(today, 'CHRISTIHIMMELFAHRT'));
|
|
||||||
|
|
||||||
// get all holiday for a single year: getHolidays()
|
|
||||||
// returns an array of "Holiday" Objects. Please see the docs.md for all properties.
|
|
||||||
|
|
||||||
var holidays2023 = feiertagejs.getHolidays('2023', 'BUND');
|
|
||||||
|
|
||||||
console.log('date', holidays2023[0].date); // = Date("2023-01-01");
|
|
||||||
console.log('name', holidays2023[0].name); // 'NEUJAHRSTAG' (constant)
|
|
||||||
console.log('translation', holidays2023[0].translate()); // German translation: Neujahrstag
|
|
||||||
console.log('equals?', holidays2023[0].equals(date)); // Compare days only (ignore time)
|
|
||||||
```
|
|
||||||
|
|
||||||
## API doc
|
|
||||||
|
|
||||||
The full API doc can be found [here](docs.md).
|
|
||||||
|
|
||||||
|
|
||||||
## Feedback and Questions
|
|
||||||
|
|
||||||
You have two options two give feedback or ask questions:
|
|
||||||
|
|
||||||
* Comment the official release [post](https://fakir.tech/de/feiertage-js-deutsche-feiertage-fuer-node-js-und-browser-javascript/)
|
|
||||||
* Open issues or pullrequests on [github](https://github.com/sfakir/feiertagejs)
|
|
||||||
|
|
||||||
|
|
||||||
## Contributors
|
|
||||||
|
|
||||||
Thank you for contributing:
|
|
||||||
|
|
||||||
* thetric
|
|
||||||
* SteveOswald
|
|
||||||
|
|
||||||
|
|
||||||
## Feedback
|
|
||||||
|
|
||||||
If you have any questions, feel free to open an issue.
|
|
||||||
@@ -1,476 +0,0 @@
|
|||||||
const germanTranslations = {
|
|
||||||
NEUJAHRSTAG: 'Neujahrstag',
|
|
||||||
HEILIGEDREIKOENIGE: 'Heilige Drei Könige',
|
|
||||||
KARFREITAG: 'Karfreitag',
|
|
||||||
OSTERSONNTAG: 'Ostersonntag',
|
|
||||||
OSTERMONTAG: 'Ostermontag',
|
|
||||||
TAG_DER_ARBEIT: 'Tag der Arbeit',
|
|
||||||
CHRISTIHIMMELFAHRT: 'Christi Himmelfahrt',
|
|
||||||
PFINGSTSONNTAG: 'Pfingstsonntag',
|
|
||||||
PFINGSTMONTAG: 'Pfingstmontag',
|
|
||||||
FRONLEICHNAM: 'Fronleichnam',
|
|
||||||
MARIAHIMMELFAHRT: 'Mariä Himmelfahrt',
|
|
||||||
DEUTSCHEEINHEIT: 'Tag der Deutschen Einheit',
|
|
||||||
REFORMATIONSTAG: 'Reformationstag',
|
|
||||||
ALLERHEILIGEN: 'Allerheiligen',
|
|
||||||
BUBETAG: 'Buß- und Bettag',
|
|
||||||
ERSTERWEIHNACHTSFEIERTAG: '1. Weihnachtstag',
|
|
||||||
ZWEITERWEIHNACHTSFEIERTAG: '2. Weihnachtstag',
|
|
||||||
WELTKINDERTAG: 'Weltkindertag',
|
|
||||||
WELTFRAUENTAG: 'Weltfrauentag',
|
|
||||||
AUGSBURGER_FRIEDENSFEST: 'Augsburger Friedensfest',
|
|
||||||
};
|
|
||||||
|
|
||||||
const allHolidays = [
|
|
||||||
'NEUJAHRSTAG',
|
|
||||||
'HEILIGEDREIKOENIGE',
|
|
||||||
'KARFREITAG',
|
|
||||||
'OSTERSONNTAG',
|
|
||||||
'OSTERMONTAG',
|
|
||||||
'TAG_DER_ARBEIT',
|
|
||||||
'CHRISTIHIMMELFAHRT',
|
|
||||||
'MARIAHIMMELFAHRT',
|
|
||||||
'PFINGSTSONNTAG',
|
|
||||||
'PFINGSTMONTAG',
|
|
||||||
'FRONLEICHNAM',
|
|
||||||
'DEUTSCHEEINHEIT',
|
|
||||||
'REFORMATIONSTAG',
|
|
||||||
'ALLERHEILIGEN',
|
|
||||||
'BUBETAG',
|
|
||||||
'ERSTERWEIHNACHTSFEIERTAG',
|
|
||||||
'ZWEITERWEIHNACHTSFEIERTAG',
|
|
||||||
'WELTKINDERTAG',
|
|
||||||
'WELTFRAUENTAG',
|
|
||||||
'AUGSBURGER_FRIEDENSFEST',
|
|
||||||
];
|
|
||||||
|
|
||||||
const allRegions = [
|
|
||||||
'BW',
|
|
||||||
'BY',
|
|
||||||
'BE',
|
|
||||||
'BB',
|
|
||||||
'HB',
|
|
||||||
'HE',
|
|
||||||
'HH',
|
|
||||||
'MV',
|
|
||||||
'NI',
|
|
||||||
'NW',
|
|
||||||
'RP',
|
|
||||||
'SL',
|
|
||||||
'SN',
|
|
||||||
'ST',
|
|
||||||
'SH',
|
|
||||||
'TH',
|
|
||||||
'BUND',
|
|
||||||
'AUGSBURG',
|
|
||||||
'ALL',
|
|
||||||
];
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* feiertage.js
|
|
||||||
* @repository https://github.com/sfakir/feiertagejs
|
|
||||||
* @docs https://github.com/sfakir/feiertagejs/blob/master/docs.md
|
|
||||||
*
|
|
||||||
* Copyright 2015-2021 Simon Fakir
|
|
||||||
* Released under the MIT license
|
|
||||||
*/
|
|
||||||
// translations
|
|
||||||
const defaultLanguage = 'de';
|
|
||||||
let currentLanguage = defaultLanguage;
|
|
||||||
const translations = {
|
|
||||||
de: germanTranslations,
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* adds a translation for the holidays (e.g. english).
|
|
||||||
* This also allows to override the German names.
|
|
||||||
* Hint: Interpolates German for missing translations
|
|
||||||
* @param {string} isoCode of the new language
|
|
||||||
* @param {TranslationTable} newTranslation map of {HolidayType} to translation stringg
|
|
||||||
*/
|
|
||||||
function addTranslation(isoCode, newTranslation) {
|
|
||||||
const code = isoCode.toLowerCase();
|
|
||||||
const defaultTranslation = translations[defaultLanguage];
|
|
||||||
let missingFields = false;
|
|
||||||
// fill new Translation with default Language
|
|
||||||
for (const holiday of allHolidays) {
|
|
||||||
if (!newTranslation[holiday]) {
|
|
||||||
missingFields = true;
|
|
||||||
newTranslation[holiday] = defaultTranslation[holiday];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (missingFields) {
|
|
||||||
console.warn('[feiertagejs] addTranslation: you did not add all holidays in your translation! Took German as fallback');
|
|
||||||
}
|
|
||||||
translations[code] = newTranslation;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Set a language to default language
|
|
||||||
* @param {string} isoCode
|
|
||||||
*/
|
|
||||||
function setLanguage(isoCode) {
|
|
||||||
const code = isoCode.toLowerCase();
|
|
||||||
if (!translations[code]) {
|
|
||||||
throw new TypeError(`[feiertagejs] tried to set language to ${code} but the translation is missing. Please use addTranslation(isoCode,object) first`);
|
|
||||||
}
|
|
||||||
currentLanguage = isoCode;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Get currently set language
|
|
||||||
* @returns {string}
|
|
||||||
*/
|
|
||||||
function getLanguage() {
|
|
||||||
return currentLanguage;
|
|
||||||
}
|
|
||||||
// holidays api
|
|
||||||
/**
|
|
||||||
* Checks if a specific date is sunday or holiday.
|
|
||||||
* @param date
|
|
||||||
* @param region
|
|
||||||
* @returns {boolean}
|
|
||||||
*/
|
|
||||||
function isSunOrHoliday(date, region) {
|
|
||||||
checkRegion(region);
|
|
||||||
return date.getDay() === 0 || isHoliday(date, region);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Check is specific date is holiday.
|
|
||||||
* @param date
|
|
||||||
* @param {Region} region two character {@link Region} code
|
|
||||||
* @returns {boolean}
|
|
||||||
*/
|
|
||||||
function isHoliday(date, region) {
|
|
||||||
checkRegion(region);
|
|
||||||
const year = date.getFullYear();
|
|
||||||
const internalDate = toUtcTimestamp(date);
|
|
||||||
const holidays = getHolidaysAsUtcTimestamps(year, region);
|
|
||||||
return holidays.indexOf(internalDate) !== -1;
|
|
||||||
}
|
|
||||||
function getHolidayByDate(date, region = 'ALL') {
|
|
||||||
checkRegion(region);
|
|
||||||
const holidays = getHolidaysOfYear(date.getFullYear(), region);
|
|
||||||
return holidays.find((holiday) => holiday.equals(date));
|
|
||||||
}
|
|
||||||
// additional runtime checks
|
|
||||||
/**
|
|
||||||
* Checks if the given region is a valid {@link Region}.
|
|
||||||
*
|
|
||||||
* @param region {@link Region} to check
|
|
||||||
* @throws {Error}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function checkRegion(region) {
|
|
||||||
if (region === null || region === undefined) {
|
|
||||||
throw new Error(`Region must not be undefined or null`);
|
|
||||||
}
|
|
||||||
if (allRegions.indexOf(region) === -1) {
|
|
||||||
throw new Error(`Invalid region: ${region}! Must be one of ${allRegions.toString()}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Checks if the given holidayName is a valid {@link HolidayType}.
|
|
||||||
* @param holidayName {@link HolidayType} to check
|
|
||||||
* @throws {Error}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function checkHolidayType(holidayName) {
|
|
||||||
if (holidayName === null || holidayName === undefined) {
|
|
||||||
throw new TypeError('holidayName must not be null or undefined');
|
|
||||||
}
|
|
||||||
if (allHolidays.indexOf(holidayName) === -1) {
|
|
||||||
throw new Error(`feiertage.js: invalid holiday type "${holidayName}"! Must be one of ${allHolidays.toString()}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function isSpecificHoliday(date, holidayName, region = 'ALL') {
|
|
||||||
checkRegion(region);
|
|
||||||
checkHolidayType(holidayName);
|
|
||||||
const holidays = getHolidaysOfYear(date.getFullYear(), region);
|
|
||||||
const foundHoliday = holidays.find((holiday) => holiday.equals(date));
|
|
||||||
if (!foundHoliday) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return foundHoliday.name === holidayName;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Returns all holidays of a year in a {@link Region}.
|
|
||||||
* @param year
|
|
||||||
* @param region
|
|
||||||
* @returns {Array.<Holiday>}
|
|
||||||
*/
|
|
||||||
function getHolidays(year, region) {
|
|
||||||
let y;
|
|
||||||
if (typeof year === 'string') {
|
|
||||||
y = parseInt(year, 10);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
y = year;
|
|
||||||
}
|
|
||||||
checkRegion(region);
|
|
||||||
return getHolidaysOfYear(y, region);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {number} year
|
|
||||||
* @param region
|
|
||||||
* @returns {number[]}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function getHolidaysAsUtcTimestamps(year, region) {
|
|
||||||
const holidays = getHolidaysOfYear(year, region);
|
|
||||||
return holidays.map((holiday) => toUtcTimestamp(holiday.date));
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {number} year
|
|
||||||
* @param region
|
|
||||||
* @returns {{objects: Array.<Holiday>, integers}}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function getHolidaysOfYear(year, region) {
|
|
||||||
const easterDate = getEasterDate(year);
|
|
||||||
const karfreitag = addDays(new Date(easterDate.getTime()), -2);
|
|
||||||
const ostermontag = addDays(new Date(easterDate.getTime()), 1);
|
|
||||||
const christiHimmelfahrt = addDays(new Date(easterDate.getTime()), 39);
|
|
||||||
const pfingstsonntag = addDays(new Date(easterDate.getTime()), 49);
|
|
||||||
const pfingstmontag = addDays(new Date(easterDate.getTime()), 50);
|
|
||||||
const holidays = [
|
|
||||||
...getCommonHolidays(year),
|
|
||||||
newHoliday('KARFREITAG', karfreitag),
|
|
||||||
newHoliday('OSTERMONTAG', ostermontag),
|
|
||||||
newHoliday('CHRISTIHIMMELFAHRT', christiHimmelfahrt),
|
|
||||||
newHoliday('PFINGSTMONTAG', pfingstmontag),
|
|
||||||
];
|
|
||||||
addHeiligeDreiKoenige(year, region, holidays);
|
|
||||||
addEasterAndPfingsten(year, region, easterDate, pfingstsonntag, holidays);
|
|
||||||
addFronleichnam(region, easterDate, holidays);
|
|
||||||
addMariaeHimmelfahrt(year, region, holidays);
|
|
||||||
addReformationstag(year, region, holidays);
|
|
||||||
addAllerheiligen(year, region, holidays);
|
|
||||||
addBussUndBetttag(year, region, holidays);
|
|
||||||
addWeltkindertag(year, region, holidays);
|
|
||||||
addWeltfrauenTag(year, region, holidays);
|
|
||||||
addRegionalHolidays(year, region, holidays);
|
|
||||||
return holidays.sort((a, b) => a.date.getTime() - b.date.getTime());
|
|
||||||
}
|
|
||||||
function getCommonHolidays(year) {
|
|
||||||
return [
|
|
||||||
newHoliday('NEUJAHRSTAG', makeDate(year, 1, 1)),
|
|
||||||
newHoliday('TAG_DER_ARBEIT', makeDate(year, 5, 1)),
|
|
||||||
newHoliday('DEUTSCHEEINHEIT', makeDate(year, 10, 3)),
|
|
||||||
newHoliday('ERSTERWEIHNACHTSFEIERTAG', makeDate(year, 12, 25)),
|
|
||||||
newHoliday('ZWEITERWEIHNACHTSFEIERTAG', makeDate(year, 12, 26)),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
function addRegionalHolidays(year, region, feiertageObjects) {
|
|
||||||
if (region === 'AUGSBURG') {
|
|
||||||
feiertageObjects.push(newHoliday('AUGSBURGER_FRIEDENSFEST', makeDate(year, 8, 8)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function addHeiligeDreiKoenige(year, region, feiertageObjects) {
|
|
||||||
if (region === 'BW' ||
|
|
||||||
region === 'BY' ||
|
|
||||||
region === 'AUGSBURG' ||
|
|
||||||
region === 'ST' ||
|
|
||||||
region === 'ALL') {
|
|
||||||
feiertageObjects.push(newHoliday('HEILIGEDREIKOENIGE', makeDate(year, 1, 6)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function addEasterAndPfingsten(year, region, easterDate, pfingstsonntag, feiertageObjects) {
|
|
||||||
if (region === 'BB' || region === 'ALL') {
|
|
||||||
feiertageObjects.push(newHoliday('OSTERSONNTAG', easterDate), newHoliday('PFINGSTSONNTAG', pfingstsonntag));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function addFronleichnam(region, easterDate, holidays) {
|
|
||||||
if (region === 'BW' ||
|
|
||||||
region === 'BY' ||
|
|
||||||
region === 'AUGSBURG' ||
|
|
||||||
region === 'HE' ||
|
|
||||||
region === 'NW' ||
|
|
||||||
region === 'RP' ||
|
|
||||||
region === 'SL' ||
|
|
||||||
region === 'ALL') {
|
|
||||||
const fronleichnam = addDays(new Date(easterDate.getTime()), 60);
|
|
||||||
holidays.push(newHoliday('FRONLEICHNAM', fronleichnam));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function addMariaeHimmelfahrt(year, region, holidays) {
|
|
||||||
if (region === 'SL' ||
|
|
||||||
region === 'BY' ||
|
|
||||||
region === 'AUGSBURG' ||
|
|
||||||
region === 'ALL') {
|
|
||||||
holidays.push(newHoliday('MARIAHIMMELFAHRT', makeDate(year, 8, 15)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function addReformationstag(year, region, holidays) {
|
|
||||||
if (year === 2017 ||
|
|
||||||
region === 'NI' ||
|
|
||||||
region === 'BB' ||
|
|
||||||
region === 'HB' ||
|
|
||||||
region === 'HH' ||
|
|
||||||
region === 'MV' ||
|
|
||||||
region === 'SN' ||
|
|
||||||
region === 'ST' ||
|
|
||||||
region === 'TH' ||
|
|
||||||
region === 'SH' ||
|
|
||||||
region === 'ALL') {
|
|
||||||
holidays.push(newHoliday('REFORMATIONSTAG', makeDate(year, 10, 31)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function addAllerheiligen(year, region, holidays) {
|
|
||||||
if (region === 'BW' ||
|
|
||||||
region === 'BY' ||
|
|
||||||
region === 'AUGSBURG' ||
|
|
||||||
region === 'NW' ||
|
|
||||||
region === 'RP' ||
|
|
||||||
region === 'SL' ||
|
|
||||||
region === 'ALL') {
|
|
||||||
holidays.push(newHoliday('ALLERHEILIGEN', makeDate(year, 11, 1)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function addBussUndBetttag(year, region, holidays) {
|
|
||||||
if (region === 'SN' || region === 'ALL') {
|
|
||||||
// @todo write test
|
|
||||||
const bussbettag = getBussBettag(year);
|
|
||||||
holidays.push(newHoliday('BUBETAG', makeDate(bussbettag.getUTCFullYear(), bussbettag.getUTCMonth() + 1, bussbettag.getUTCDate())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function addWeltkindertag(year, region, holidays) {
|
|
||||||
if (year >= 2019 && (region === 'TH' || region === 'ALL')) {
|
|
||||||
holidays.push(newHoliday('WELTKINDERTAG', makeDate(year, 9, 20)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function addWeltfrauenTag(year, region, feiertageObjects) {
|
|
||||||
if (year <= 2018) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (region === 'BE' || region === 'ALL') {
|
|
||||||
// in Berlin ist der Weltfrauentag ein Feiertag seit 2018
|
|
||||||
feiertageObjects.push(newHoliday('WELTFRAUENTAG', makeDate(year, 3, 8)));
|
|
||||||
}
|
|
||||||
if (region === 'MV' && year >= 2023) {
|
|
||||||
// in MV wird der Weltfrauentag erst ab 2023 eingeführt
|
|
||||||
feiertageObjects.push(newHoliday('WELTFRAUENTAG', makeDate(year, 3, 8)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Calculates the Easter date of a given year.
|
|
||||||
* @param year {number}
|
|
||||||
* @returns {Date} Easter date
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function getEasterDate(year) {
|
|
||||||
const C = Math.floor(year / 100);
|
|
||||||
// tslint:disable:binary-expression-operand-order
|
|
||||||
// tslint generates false positives in the following blocks
|
|
||||||
const N = year - 19 * Math.floor(year / 19);
|
|
||||||
const K = Math.floor((C - 17) / 25);
|
|
||||||
let I = C - Math.floor(C / 4) - Math.floor((C - K) / 3) + 19 * N + 15;
|
|
||||||
I -= 30 * Math.floor(I / 30);
|
|
||||||
I -=
|
|
||||||
Math.floor(I / 28) *
|
|
||||||
(1 -
|
|
||||||
Math.floor(I / 28) *
|
|
||||||
Math.floor(29 / (I + 1)) *
|
|
||||||
Math.floor((21 - N) / 11));
|
|
||||||
let J = year + Math.floor(year / 4) + I + 2 - C + Math.floor(C / 4);
|
|
||||||
J -= 7 * Math.floor(J / 7);
|
|
||||||
const L = I - J;
|
|
||||||
const M = 3 + Math.floor((L + 40) / 44);
|
|
||||||
const D = L + 28 - 31 * Math.floor(M / 4);
|
|
||||||
// tslint:enable:binary-expression-operand-order
|
|
||||||
return new Date(year, M - 1, D);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Computes the "Buss- und Bettag"'s date.
|
|
||||||
* @param jahr {number}
|
|
||||||
* @returns {Date} the year's "Buss- und Bettag" date
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function getBussBettag(jahr) {
|
|
||||||
const weihnachten = new Date(jahr, 11, 25, 12, 0, 0);
|
|
||||||
const ersterAdventOffset = 32;
|
|
||||||
let wochenTagOffset = weihnachten.getDay() % 7;
|
|
||||||
if (wochenTagOffset === 0) {
|
|
||||||
wochenTagOffset = 7;
|
|
||||||
}
|
|
||||||
const tageVorWeihnachten = wochenTagOffset + ersterAdventOffset;
|
|
||||||
let bbtag = new Date(weihnachten.getTime());
|
|
||||||
bbtag = addDays(bbtag, -tageVorWeihnachten);
|
|
||||||
return bbtag;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Adds {@code days} days to the given {@link Date}.
|
|
||||||
* @param date
|
|
||||||
* @param days
|
|
||||||
* @returns {Date}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function addDays(date, days) {
|
|
||||||
const changedDate = new Date(date);
|
|
||||||
changedDate.setDate(date.getDate() + days);
|
|
||||||
return changedDate;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Creates a new {@link Date}.
|
|
||||||
* @param year
|
|
||||||
* @param naturalMonth month (1-12)
|
|
||||||
* @param day
|
|
||||||
* @returns {Date}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function makeDate(year, naturalMonth, day) {
|
|
||||||
return new Date(year, naturalMonth - 1, day);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param name
|
|
||||||
* @param date
|
|
||||||
* @returns {Holiday}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function newHoliday(name, date) {
|
|
||||||
return {
|
|
||||||
name,
|
|
||||||
date,
|
|
||||||
dateString: localeDateObjectToDateString(date),
|
|
||||||
trans(lang = currentLanguage) {
|
|
||||||
console.warn('FeiertageJs: You are using "Holiday.trans() method. This will be replaced in the next major version with translate()"');
|
|
||||||
return this.translate(lang);
|
|
||||||
},
|
|
||||||
translate(lang = currentLanguage) {
|
|
||||||
return lang === undefined || lang === null
|
|
||||||
? undefined
|
|
||||||
: translations[lang][this.name];
|
|
||||||
},
|
|
||||||
getNormalizedDate() {
|
|
||||||
return toUtcTimestamp(this.date);
|
|
||||||
},
|
|
||||||
equals(otherDate) {
|
|
||||||
const dateString = localeDateObjectToDateString(otherDate);
|
|
||||||
return this.dateString === dateString;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param date
|
|
||||||
* @returns {string}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function localeDateObjectToDateString(date) {
|
|
||||||
const normalizedDate = new Date(date.getTime() - date.getTimezoneOffset() * 60 * 1000);
|
|
||||||
normalizedDate.setUTCHours(0, 0, 0, 0);
|
|
||||||
return normalizedDate.toISOString().slice(0, 10);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Returns the UTC timestamp of the given date with hours, minutes, seconds, and milliseconds set to zero.
|
|
||||||
* @param date
|
|
||||||
* @returns {number} UTC timestamp
|
|
||||||
*/
|
|
||||||
function toUtcTimestamp(date) {
|
|
||||||
const internalDate = new Date(date);
|
|
||||||
internalDate.setHours(0, 0, 0, 0);
|
|
||||||
return internalDate.getTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
export { addTranslation, getHolidayByDate, getHolidays, getLanguage, isHoliday, isSpecificHoliday, isSunOrHoliday, setLanguage };
|
|
||||||
//# sourceMappingURL=feiertage.esm.js.map
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
{"version":3,"file":"feiertage.esm.js","sources":["../src/german-translations.ts","../src/holiday-type.ts","../src/regions.ts","../src/feiertage.ts"],"sourcesContent":["import { TranslationTable } from './feiertage';\n\nexport const germanTranslations: TranslationTable = {\n NEUJAHRSTAG: 'Neujahrstag',\n HEILIGEDREIKOENIGE: 'Heilige Drei Könige',\n KARFREITAG: 'Karfreitag',\n OSTERSONNTAG: 'Ostersonntag',\n OSTERMONTAG: 'Ostermontag',\n TAG_DER_ARBEIT: 'Tag der Arbeit',\n CHRISTIHIMMELFAHRT: 'Christi Himmelfahrt',\n PFINGSTSONNTAG: 'Pfingstsonntag',\n PFINGSTMONTAG: 'Pfingstmontag',\n FRONLEICHNAM: 'Fronleichnam',\n MARIAHIMMELFAHRT: 'Mariä Himmelfahrt',\n DEUTSCHEEINHEIT: 'Tag der Deutschen Einheit',\n REFORMATIONSTAG: 'Reformationstag',\n ALLERHEILIGEN: 'Allerheiligen',\n BUBETAG: 'Buß- und Bettag',\n ERSTERWEIHNACHTSFEIERTAG: '1. Weihnachtstag',\n ZWEITERWEIHNACHTSFEIERTAG: '2. Weihnachtstag',\n WELTKINDERTAG: 'Weltkindertag',\n WELTFRAUENTAG: 'Weltfrauentag',\n AUGSBURGER_FRIEDENSFEST: 'Augsburger Friedensfest',\n};\n","export type HolidayType =\n | 'NEUJAHRSTAG'\n | 'HEILIGEDREIKOENIGE'\n | 'KARFREITAG'\n | 'OSTERSONNTAG'\n | 'OSTERMONTAG'\n | 'TAG_DER_ARBEIT'\n | 'CHRISTIHIMMELFAHRT'\n | 'MARIAHIMMELFAHRT'\n | 'PFINGSTSONNTAG'\n | 'PFINGSTMONTAG'\n | 'FRONLEICHNAM'\n | 'DEUTSCHEEINHEIT'\n | 'REFORMATIONSTAG'\n | 'ALLERHEILIGEN'\n | 'BUBETAG'\n | 'ERSTERWEIHNACHTSFEIERTAG'\n | 'ZWEITERWEIHNACHTSFEIERTAG'\n | 'WELTKINDERTAG'\n | 'WELTFRAUENTAG'\n | 'AUGSBURGER_FRIEDENSFEST';\n\nexport const allHolidays: HolidayType[] = [\n 'NEUJAHRSTAG',\n 'HEILIGEDREIKOENIGE',\n 'KARFREITAG',\n 'OSTERSONNTAG',\n 'OSTERMONTAG',\n 'TAG_DER_ARBEIT',\n 'CHRISTIHIMMELFAHRT',\n 'MARIAHIMMELFAHRT',\n 'PFINGSTSONNTAG',\n 'PFINGSTMONTAG',\n 'FRONLEICHNAM',\n 'DEUTSCHEEINHEIT',\n 'REFORMATIONSTAG',\n 'ALLERHEILIGEN',\n 'BUBETAG',\n 'ERSTERWEIHNACHTSFEIERTAG',\n 'ZWEITERWEIHNACHTSFEIERTAG',\n 'WELTKINDERTAG',\n 'WELTFRAUENTAG',\n 'AUGSBURGER_FRIEDENSFEST',\n];\n","export type Region =\n | 'BW' // Baden-Württemberg\n | 'BY' // Bayern\n | 'BE' // Berlin\n | 'BB' // Brandenburg\n | 'HB' // Bremen\n | 'HE' // Hessen\n | 'HH' // Hamburg\n | 'MV' // Mecklenburg-Vorpommern\n | 'NI' // Niedersachsen\n | 'NW' // Nordrhein-Westfalen\n | 'RP' // Rheinland-Pfalz\n | 'SL' // Saarland\n | 'SN' // Sachsen\n | 'ST' // Sachsen-Anhalt\n | 'SH' // Schleswig-Holstein\n | 'TH' // Thüringen\n | 'BUND' // Gesamt-Deutschland\n // Custom regions with local holidays (incompelte) !\n | 'AUGSBURG'\n | 'ALL';\n\nexport const allRegions: Region[] = [\n 'BW',\n 'BY',\n 'BE',\n 'BB',\n 'HB',\n 'HE',\n 'HH',\n 'MV',\n 'NI',\n 'NW',\n 'RP',\n 'SL',\n 'SN',\n 'ST',\n 'SH',\n 'TH',\n 'BUND',\n 'AUGSBURG',\n 'ALL',\n];\n","/*!\n * feiertage.js\n * @repository https://github.com/sfakir/feiertagejs\n * @docs https://github.com/sfakir/feiertagejs/blob/master/docs.md\n *\n * Copyright 2015-2021 Simon Fakir\n * Released under the MIT license\n */\n\n//\n// Additional readings\n// - how to format a javascript date: http://blog.stevenlevithan.com/archives/date-time-format\n// - the right javascript date: http://stackoverflow.com/questions/10286204/the-right-json-date-format\n//\n\nimport { germanTranslations } from './german-translations';\nimport { Holiday } from './holiday';\nimport { allHolidays, HolidayType } from './holiday-type';\nimport { allRegions, Region } from './regions';\n\n// translations\n\nconst defaultLanguage = 'de';\nlet currentLanguage: string = defaultLanguage;\n\n/**\n * Map of {@link HolidayType} to translation string.\n */\nexport type TranslationTable = { [key in HolidayType]?: string };\n\nconst translations: { [key: string]: TranslationTable } = {\n de: germanTranslations,\n};\n\n/**\n * adds a translation for the holidays (e.g. english).\n * This also allows to override the German names.\n * Hint: Interpolates German for missing translations\n * @param {string} isoCode of the new language\n * @param {TranslationTable} newTranslation map of {HolidayType} to translation stringg\n */\nexport function addTranslation(\n isoCode: string,\n newTranslation: TranslationTable,\n): void {\n const code = isoCode.toLowerCase();\n const defaultTranslation = translations[defaultLanguage];\n let missingFields = false;\n\n // fill new Translation with default Language\n for (const holiday of allHolidays) {\n if (!newTranslation[holiday]) {\n missingFields = true;\n newTranslation[holiday] = defaultTranslation[holiday];\n }\n }\n if (missingFields) {\n console.warn(\n '[feiertagejs] addTranslation: you did not add all holidays in your translation! Took German as fallback',\n );\n }\n\n translations[code] = newTranslation;\n}\n\n/**\n * Set a language to default language\n * @param {string} isoCode\n */\nexport function setLanguage(isoCode: string): void {\n const code = isoCode.toLowerCase();\n if (!translations[code])Line truncated
|
|
||||||
@@ -1,476 +0,0 @@
|
|||||||
const germanTranslations = {
|
|
||||||
NEUJAHRSTAG: 'Neujahrstag',
|
|
||||||
HEILIGEDREIKOENIGE: 'Heilige Drei Könige',
|
|
||||||
KARFREITAG: 'Karfreitag',
|
|
||||||
OSTERSONNTAG: 'Ostersonntag',
|
|
||||||
OSTERMONTAG: 'Ostermontag',
|
|
||||||
TAG_DER_ARBEIT: 'Tag der Arbeit',
|
|
||||||
CHRISTIHIMMELFAHRT: 'Christi Himmelfahrt',
|
|
||||||
PFINGSTSONNTAG: 'Pfingstsonntag',
|
|
||||||
PFINGSTMONTAG: 'Pfingstmontag',
|
|
||||||
FRONLEICHNAM: 'Fronleichnam',
|
|
||||||
MARIAHIMMELFAHRT: 'Mariä Himmelfahrt',
|
|
||||||
DEUTSCHEEINHEIT: 'Tag der Deutschen Einheit',
|
|
||||||
REFORMATIONSTAG: 'Reformationstag',
|
|
||||||
ALLERHEILIGEN: 'Allerheiligen',
|
|
||||||
BUBETAG: 'Buß- und Bettag',
|
|
||||||
ERSTERWEIHNACHTSFEIERTAG: '1. Weihnachtstag',
|
|
||||||
ZWEITERWEIHNACHTSFEIERTAG: '2. Weihnachtstag',
|
|
||||||
WELTKINDERTAG: 'Weltkindertag',
|
|
||||||
WELTFRAUENTAG: 'Weltfrauentag',
|
|
||||||
AUGSBURGER_FRIEDENSFEST: 'Augsburger Friedensfest',
|
|
||||||
};
|
|
||||||
|
|
||||||
const allHolidays = [
|
|
||||||
'NEUJAHRSTAG',
|
|
||||||
'HEILIGEDREIKOENIGE',
|
|
||||||
'KARFREITAG',
|
|
||||||
'OSTERSONNTAG',
|
|
||||||
'OSTERMONTAG',
|
|
||||||
'TAG_DER_ARBEIT',
|
|
||||||
'CHRISTIHIMMELFAHRT',
|
|
||||||
'MARIAHIMMELFAHRT',
|
|
||||||
'PFINGSTSONNTAG',
|
|
||||||
'PFINGSTMONTAG',
|
|
||||||
'FRONLEICHNAM',
|
|
||||||
'DEUTSCHEEINHEIT',
|
|
||||||
'REFORMATIONSTAG',
|
|
||||||
'ALLERHEILIGEN',
|
|
||||||
'BUBETAG',
|
|
||||||
'ERSTERWEIHNACHTSFEIERTAG',
|
|
||||||
'ZWEITERWEIHNACHTSFEIERTAG',
|
|
||||||
'WELTKINDERTAG',
|
|
||||||
'WELTFRAUENTAG',
|
|
||||||
'AUGSBURGER_FRIEDENSFEST',
|
|
||||||
];
|
|
||||||
|
|
||||||
const allRegions = [
|
|
||||||
'BW',
|
|
||||||
'BY',
|
|
||||||
'BE',
|
|
||||||
'BB',
|
|
||||||
'HB',
|
|
||||||
'HE',
|
|
||||||
'HH',
|
|
||||||
'MV',
|
|
||||||
'NI',
|
|
||||||
'NW',
|
|
||||||
'RP',
|
|
||||||
'SL',
|
|
||||||
'SN',
|
|
||||||
'ST',
|
|
||||||
'SH',
|
|
||||||
'TH',
|
|
||||||
'BUND',
|
|
||||||
'AUGSBURG',
|
|
||||||
'ALL',
|
|
||||||
];
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* feiertage.js
|
|
||||||
* @repository https://github.com/sfakir/feiertagejs
|
|
||||||
* @docs https://github.com/sfakir/feiertagejs/blob/master/docs.md
|
|
||||||
*
|
|
||||||
* Copyright 2015-2021 Simon Fakir
|
|
||||||
* Released under the MIT license
|
|
||||||
*/
|
|
||||||
// translations
|
|
||||||
const defaultLanguage = 'de';
|
|
||||||
let currentLanguage = defaultLanguage;
|
|
||||||
const translations = {
|
|
||||||
de: germanTranslations,
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* adds a translation for the holidays (e.g. english).
|
|
||||||
* This also allows to override the German names.
|
|
||||||
* Hint: Interpolates German for missing translations
|
|
||||||
* @param {string} isoCode of the new language
|
|
||||||
* @param {TranslationTable} newTranslation map of {HolidayType} to translation stringg
|
|
||||||
*/
|
|
||||||
function addTranslation(isoCode, newTranslation) {
|
|
||||||
const code = isoCode.toLowerCase();
|
|
||||||
const defaultTranslation = translations[defaultLanguage];
|
|
||||||
let missingFields = false;
|
|
||||||
// fill new Translation with default Language
|
|
||||||
for (const holiday of allHolidays) {
|
|
||||||
if (!newTranslation[holiday]) {
|
|
||||||
missingFields = true;
|
|
||||||
newTranslation[holiday] = defaultTranslation[holiday];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (missingFields) {
|
|
||||||
console.warn('[feiertagejs] addTranslation: you did not add all holidays in your translation! Took German as fallback');
|
|
||||||
}
|
|
||||||
translations[code] = newTranslation;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Set a language to default language
|
|
||||||
* @param {string} isoCode
|
|
||||||
*/
|
|
||||||
function setLanguage(isoCode) {
|
|
||||||
const code = isoCode.toLowerCase();
|
|
||||||
if (!translations[code]) {
|
|
||||||
throw new TypeError(`[feiertagejs] tried to set language to ${code} but the translation is missing. Please use addTranslation(isoCode,object) first`);
|
|
||||||
}
|
|
||||||
currentLanguage = isoCode;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Get currently set language
|
|
||||||
* @returns {string}
|
|
||||||
*/
|
|
||||||
function getLanguage() {
|
|
||||||
return currentLanguage;
|
|
||||||
}
|
|
||||||
// holidays api
|
|
||||||
/**
|
|
||||||
* Checks if a specific date is sunday or holiday.
|
|
||||||
* @param date
|
|
||||||
* @param region
|
|
||||||
* @returns {boolean}
|
|
||||||
*/
|
|
||||||
function isSunOrHoliday(date, region) {
|
|
||||||
checkRegion(region);
|
|
||||||
return date.getDay() === 0 || isHoliday(date, region);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Check is specific date is holiday.
|
|
||||||
* @param date
|
|
||||||
* @param {Region} region two character {@link Region} code
|
|
||||||
* @returns {boolean}
|
|
||||||
*/
|
|
||||||
function isHoliday(date, region) {
|
|
||||||
checkRegion(region);
|
|
||||||
const year = date.getFullYear();
|
|
||||||
const internalDate = toUtcTimestamp(date);
|
|
||||||
const holidays = getHolidaysAsUtcTimestamps(year, region);
|
|
||||||
return holidays.indexOf(internalDate) !== -1;
|
|
||||||
}
|
|
||||||
function getHolidayByDate(date, region = 'ALL') {
|
|
||||||
checkRegion(region);
|
|
||||||
const holidays = getHolidaysOfYear(date.getFullYear(), region);
|
|
||||||
return holidays.find((holiday) => holiday.equals(date));
|
|
||||||
}
|
|
||||||
// additional runtime checks
|
|
||||||
/**
|
|
||||||
* Checks if the given region is a valid {@link Region}.
|
|
||||||
*
|
|
||||||
* @param region {@link Region} to check
|
|
||||||
* @throws {Error}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function checkRegion(region) {
|
|
||||||
if (region === null || region === undefined) {
|
|
||||||
throw new Error(`Region must not be undefined or null`);
|
|
||||||
}
|
|
||||||
if (allRegions.indexOf(region) === -1) {
|
|
||||||
throw new Error(`Invalid region: ${region}! Must be one of ${allRegions.toString()}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Checks if the given holidayName is a valid {@link HolidayType}.
|
|
||||||
* @param holidayName {@link HolidayType} to check
|
|
||||||
* @throws {Error}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function checkHolidayType(holidayName) {
|
|
||||||
if (holidayName === null || holidayName === undefined) {
|
|
||||||
throw new TypeError('holidayName must not be null or undefined');
|
|
||||||
}
|
|
||||||
if (allHolidays.indexOf(holidayName) === -1) {
|
|
||||||
throw new Error(`feiertage.js: invalid holiday type "${holidayName}"! Must be one of ${allHolidays.toString()}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function isSpecificHoliday(date, holidayName, region = 'ALL') {
|
|
||||||
checkRegion(region);
|
|
||||||
checkHolidayType(holidayName);
|
|
||||||
const holidays = getHolidaysOfYear(date.getFullYear(), region);
|
|
||||||
const foundHoliday = holidays.find((holiday) => holiday.equals(date));
|
|
||||||
if (!foundHoliday) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return foundHoliday.name === holidayName;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Returns all holidays of a year in a {@link Region}.
|
|
||||||
* @param year
|
|
||||||
* @param region
|
|
||||||
* @returns {Array.<Holiday>}
|
|
||||||
*/
|
|
||||||
function getHolidays(year, region) {
|
|
||||||
let y;
|
|
||||||
if (typeof year === 'string') {
|
|
||||||
y = parseInt(year, 10);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
y = year;
|
|
||||||
}
|
|
||||||
checkRegion(region);
|
|
||||||
return getHolidaysOfYear(y, region);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {number} year
|
|
||||||
* @param region
|
|
||||||
* @returns {number[]}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function getHolidaysAsUtcTimestamps(year, region) {
|
|
||||||
const holidays = getHolidaysOfYear(year, region);
|
|
||||||
return holidays.map((holiday) => toUtcTimestamp(holiday.date));
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {number} year
|
|
||||||
* @param region
|
|
||||||
* @returns {{objects: Array.<Holiday>, integers}}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function getHolidaysOfYear(year, region) {
|
|
||||||
const easterDate = getEasterDate(year);
|
|
||||||
const karfreitag = addDays(new Date(easterDate.getTime()), -2);
|
|
||||||
const ostermontag = addDays(new Date(easterDate.getTime()), 1);
|
|
||||||
const christiHimmelfahrt = addDays(new Date(easterDate.getTime()), 39);
|
|
||||||
const pfingstsonntag = addDays(new Date(easterDate.getTime()), 49);
|
|
||||||
const pfingstmontag = addDays(new Date(easterDate.getTime()), 50);
|
|
||||||
const holidays = [
|
|
||||||
...getCommonHolidays(year),
|
|
||||||
newHoliday('KARFREITAG', karfreitag),
|
|
||||||
newHoliday('OSTERMONTAG', ostermontag),
|
|
||||||
newHoliday('CHRISTIHIMMELFAHRT', christiHimmelfahrt),
|
|
||||||
newHoliday('PFINGSTMONTAG', pfingstmontag),
|
|
||||||
];
|
|
||||||
addHeiligeDreiKoenige(year, region, holidays);
|
|
||||||
addEasterAndPfingsten(year, region, easterDate, pfingstsonntag, holidays);
|
|
||||||
addFronleichnam(region, easterDate, holidays);
|
|
||||||
addMariaeHimmelfahrt(year, region, holidays);
|
|
||||||
addReformationstag(year, region, holidays);
|
|
||||||
addAllerheiligen(year, region, holidays);
|
|
||||||
addBussUndBetttag(year, region, holidays);
|
|
||||||
addWeltkindertag(year, region, holidays);
|
|
||||||
addWeltfrauenTag(year, region, holidays);
|
|
||||||
addRegionalHolidays(year, region, holidays);
|
|
||||||
return holidays.sort((a, b) => a.date.getTime() - b.date.getTime());
|
|
||||||
}
|
|
||||||
function getCommonHolidays(year) {
|
|
||||||
return [
|
|
||||||
newHoliday('NEUJAHRSTAG', makeDate(year, 1, 1)),
|
|
||||||
newHoliday('TAG_DER_ARBEIT', makeDate(year, 5, 1)),
|
|
||||||
newHoliday('DEUTSCHEEINHEIT', makeDate(year, 10, 3)),
|
|
||||||
newHoliday('ERSTERWEIHNACHTSFEIERTAG', makeDate(year, 12, 25)),
|
|
||||||
newHoliday('ZWEITERWEIHNACHTSFEIERTAG', makeDate(year, 12, 26)),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
function addRegionalHolidays(year, region, feiertageObjects) {
|
|
||||||
if (region === 'AUGSBURG') {
|
|
||||||
feiertageObjects.push(newHoliday('AUGSBURGER_FRIEDENSFEST', makeDate(year, 8, 8)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function addHeiligeDreiKoenige(year, region, feiertageObjects) {
|
|
||||||
if (region === 'BW' ||
|
|
||||||
region === 'BY' ||
|
|
||||||
region === 'AUGSBURG' ||
|
|
||||||
region === 'ST' ||
|
|
||||||
region === 'ALL') {
|
|
||||||
feiertageObjects.push(newHoliday('HEILIGEDREIKOENIGE', makeDate(year, 1, 6)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function addEasterAndPfingsten(year, region, easterDate, pfingstsonntag, feiertageObjects) {
|
|
||||||
if (region === 'BB' || region === 'ALL') {
|
|
||||||
feiertageObjects.push(newHoliday('OSTERSONNTAG', easterDate), newHoliday('PFINGSTSONNTAG', pfingstsonntag));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function addFronleichnam(region, easterDate, holidays) {
|
|
||||||
if (region === 'BW' ||
|
|
||||||
region === 'BY' ||
|
|
||||||
region === 'AUGSBURG' ||
|
|
||||||
region === 'HE' ||
|
|
||||||
region === 'NW' ||
|
|
||||||
region === 'RP' ||
|
|
||||||
region === 'SL' ||
|
|
||||||
region === 'ALL') {
|
|
||||||
const fronleichnam = addDays(new Date(easterDate.getTime()), 60);
|
|
||||||
holidays.push(newHoliday('FRONLEICHNAM', fronleichnam));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function addMariaeHimmelfahrt(year, region, holidays) {
|
|
||||||
if (region === 'SL' ||
|
|
||||||
region === 'BY' ||
|
|
||||||
region === 'AUGSBURG' ||
|
|
||||||
region === 'ALL') {
|
|
||||||
holidays.push(newHoliday('MARIAHIMMELFAHRT', makeDate(year, 8, 15)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function addReformationstag(year, region, holidays) {
|
|
||||||
if (year === 2017 ||
|
|
||||||
region === 'NI' ||
|
|
||||||
region === 'BB' ||
|
|
||||||
region === 'HB' ||
|
|
||||||
region === 'HH' ||
|
|
||||||
region === 'MV' ||
|
|
||||||
region === 'SN' ||
|
|
||||||
region === 'ST' ||
|
|
||||||
region === 'TH' ||
|
|
||||||
region === 'SH' ||
|
|
||||||
region === 'ALL') {
|
|
||||||
holidays.push(newHoliday('REFORMATIONSTAG', makeDate(year, 10, 31)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function addAllerheiligen(year, region, holidays) {
|
|
||||||
if (region === 'BW' ||
|
|
||||||
region === 'BY' ||
|
|
||||||
region === 'AUGSBURG' ||
|
|
||||||
region === 'NW' ||
|
|
||||||
region === 'RP' ||
|
|
||||||
region === 'SL' ||
|
|
||||||
region === 'ALL') {
|
|
||||||
holidays.push(newHoliday('ALLERHEILIGEN', makeDate(year, 11, 1)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function addBussUndBetttag(year, region, holidays) {
|
|
||||||
if (region === 'SN' || region === 'ALL') {
|
|
||||||
// @todo write test
|
|
||||||
const bussbettag = getBussBettag(year);
|
|
||||||
holidays.push(newHoliday('BUBETAG', makeDate(bussbettag.getUTCFullYear(), bussbettag.getUTCMonth() + 1, bussbettag.getUTCDate())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function addWeltkindertag(year, region, holidays) {
|
|
||||||
if (year >= 2019 && (region === 'TH' || region === 'ALL')) {
|
|
||||||
holidays.push(newHoliday('WELTKINDERTAG', makeDate(year, 9, 20)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function addWeltfrauenTag(year, region, feiertageObjects) {
|
|
||||||
if (year <= 2018) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (region === 'BE' || region === 'ALL') {
|
|
||||||
// in Berlin ist der Weltfrauentag ein Feiertag seit 2018
|
|
||||||
feiertageObjects.push(newHoliday('WELTFRAUENTAG', makeDate(year, 3, 8)));
|
|
||||||
}
|
|
||||||
if (region === 'MV' && year >= 2023) {
|
|
||||||
// in MV wird der Weltfrauentag erst ab 2023 eingeführt
|
|
||||||
feiertageObjects.push(newHoliday('WELTFRAUENTAG', makeDate(year, 3, 8)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Calculates the Easter date of a given year.
|
|
||||||
* @param year {number}
|
|
||||||
* @returns {Date} Easter date
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function getEasterDate(year) {
|
|
||||||
const C = Math.floor(year / 100);
|
|
||||||
// tslint:disable:binary-expression-operand-order
|
|
||||||
// tslint generates false positives in the following blocks
|
|
||||||
const N = year - 19 * Math.floor(year / 19);
|
|
||||||
const K = Math.floor((C - 17) / 25);
|
|
||||||
let I = C - Math.floor(C / 4) - Math.floor((C - K) / 3) + 19 * N + 15;
|
|
||||||
I -= 30 * Math.floor(I / 30);
|
|
||||||
I -=
|
|
||||||
Math.floor(I / 28) *
|
|
||||||
(1 -
|
|
||||||
Math.floor(I / 28) *
|
|
||||||
Math.floor(29 / (I + 1)) *
|
|
||||||
Math.floor((21 - N) / 11));
|
|
||||||
let J = year + Math.floor(year / 4) + I + 2 - C + Math.floor(C / 4);
|
|
||||||
J -= 7 * Math.floor(J / 7);
|
|
||||||
const L = I - J;
|
|
||||||
const M = 3 + Math.floor((L + 40) / 44);
|
|
||||||
const D = L + 28 - 31 * Math.floor(M / 4);
|
|
||||||
// tslint:enable:binary-expression-operand-order
|
|
||||||
return new Date(year, M - 1, D);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Computes the "Buss- und Bettag"'s date.
|
|
||||||
* @param jahr {number}
|
|
||||||
* @returns {Date} the year's "Buss- und Bettag" date
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function getBussBettag(jahr) {
|
|
||||||
const weihnachten = new Date(jahr, 11, 25, 12, 0, 0);
|
|
||||||
const ersterAdventOffset = 32;
|
|
||||||
let wochenTagOffset = weihnachten.getDay() % 7;
|
|
||||||
if (wochenTagOffset === 0) {
|
|
||||||
wochenTagOffset = 7;
|
|
||||||
}
|
|
||||||
const tageVorWeihnachten = wochenTagOffset + ersterAdventOffset;
|
|
||||||
let bbtag = new Date(weihnachten.getTime());
|
|
||||||
bbtag = addDays(bbtag, -tageVorWeihnachten);
|
|
||||||
return bbtag;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Adds {@code days} days to the given {@link Date}.
|
|
||||||
* @param date
|
|
||||||
* @param days
|
|
||||||
* @returns {Date}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function addDays(date, days) {
|
|
||||||
const changedDate = new Date(date);
|
|
||||||
changedDate.setDate(date.getDate() + days);
|
|
||||||
return changedDate;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Creates a new {@link Date}.
|
|
||||||
* @param year
|
|
||||||
* @param naturalMonth month (1-12)
|
|
||||||
* @param day
|
|
||||||
* @returns {Date}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function makeDate(year, naturalMonth, day) {
|
|
||||||
return new Date(year, naturalMonth - 1, day);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param name
|
|
||||||
* @param date
|
|
||||||
* @returns {Holiday}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function newHoliday(name, date) {
|
|
||||||
return {
|
|
||||||
name,
|
|
||||||
date,
|
|
||||||
dateString: localeDateObjectToDateString(date),
|
|
||||||
trans(lang = currentLanguage) {
|
|
||||||
console.warn('FeiertageJs: You are using "Holiday.trans() method. This will be replaced in the next major version with translate()"');
|
|
||||||
return this.translate(lang);
|
|
||||||
},
|
|
||||||
translate(lang = currentLanguage) {
|
|
||||||
return lang === undefined || lang === null
|
|
||||||
? undefined
|
|
||||||
: translations[lang][this.name];
|
|
||||||
},
|
|
||||||
getNormalizedDate() {
|
|
||||||
return toUtcTimestamp(this.date);
|
|
||||||
},
|
|
||||||
equals(otherDate) {
|
|
||||||
const dateString = localeDateObjectToDateString(otherDate);
|
|
||||||
return this.dateString === dateString;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param date
|
|
||||||
* @returns {string}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function localeDateObjectToDateString(date) {
|
|
||||||
const normalizedDate = new Date(date.getTime() - date.getTimezoneOffset() * 60 * 1000);
|
|
||||||
normalizedDate.setUTCHours(0, 0, 0, 0);
|
|
||||||
return normalizedDate.toISOString().slice(0, 10);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Returns the UTC timestamp of the given date with hours, minutes, seconds, and milliseconds set to zero.
|
|
||||||
* @param date
|
|
||||||
* @returns {number} UTC timestamp
|
|
||||||
*/
|
|
||||||
function toUtcTimestamp(date) {
|
|
||||||
const internalDate = new Date(date);
|
|
||||||
internalDate.setHours(0, 0, 0, 0);
|
|
||||||
return internalDate.getTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
export { addTranslation, getHolidayByDate, getHolidays, getLanguage, isHoliday, isSpecificHoliday, isSunOrHoliday, setLanguage };
|
|
||||||
//# sourceMappingURL=feiertage.js.map
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
{"version":3,"file":"feiertage.js","sources":["../src/german-translations.ts","../src/holiday-type.ts","../src/regions.ts","../src/feiertage.ts"],"sourcesContent":["import { TranslationTable } from './feiertage';\n\nexport const germanTranslations: TranslationTable = {\n NEUJAHRSTAG: 'Neujahrstag',\n HEILIGEDREIKOENIGE: 'Heilige Drei Könige',\n KARFREITAG: 'Karfreitag',\n OSTERSONNTAG: 'Ostersonntag',\n OSTERMONTAG: 'Ostermontag',\n TAG_DER_ARBEIT: 'Tag der Arbeit',\n CHRISTIHIMMELFAHRT: 'Christi Himmelfahrt',\n PFINGSTSONNTAG: 'Pfingstsonntag',\n PFINGSTMONTAG: 'Pfingstmontag',\n FRONLEICHNAM: 'Fronleichnam',\n MARIAHIMMELFAHRT: 'Mariä Himmelfahrt',\n DEUTSCHEEINHEIT: 'Tag der Deutschen Einheit',\n REFORMATIONSTAG: 'Reformationstag',\n ALLERHEILIGEN: 'Allerheiligen',\n BUBETAG: 'Buß- und Bettag',\n ERSTERWEIHNACHTSFEIERTAG: '1. Weihnachtstag',\n ZWEITERWEIHNACHTSFEIERTAG: '2. Weihnachtstag',\n WELTKINDERTAG: 'Weltkindertag',\n WELTFRAUENTAG: 'Weltfrauentag',\n AUGSBURGER_FRIEDENSFEST: 'Augsburger Friedensfest',\n};\n","export type HolidayType =\n | 'NEUJAHRSTAG'\n | 'HEILIGEDREIKOENIGE'\n | 'KARFREITAG'\n | 'OSTERSONNTAG'\n | 'OSTERMONTAG'\n | 'TAG_DER_ARBEIT'\n | 'CHRISTIHIMMELFAHRT'\n | 'MARIAHIMMELFAHRT'\n | 'PFINGSTSONNTAG'\n | 'PFINGSTMONTAG'\n | 'FRONLEICHNAM'\n | 'DEUTSCHEEINHEIT'\n | 'REFORMATIONSTAG'\n | 'ALLERHEILIGEN'\n | 'BUBETAG'\n | 'ERSTERWEIHNACHTSFEIERTAG'\n | 'ZWEITERWEIHNACHTSFEIERTAG'\n | 'WELTKINDERTAG'\n | 'WELTFRAUENTAG'\n | 'AUGSBURGER_FRIEDENSFEST';\n\nexport const allHolidays: HolidayType[] = [\n 'NEUJAHRSTAG',\n 'HEILIGEDREIKOENIGE',\n 'KARFREITAG',\n 'OSTERSONNTAG',\n 'OSTERMONTAG',\n 'TAG_DER_ARBEIT',\n 'CHRISTIHIMMELFAHRT',\n 'MARIAHIMMELFAHRT',\n 'PFINGSTSONNTAG',\n 'PFINGSTMONTAG',\n 'FRONLEICHNAM',\n 'DEUTSCHEEINHEIT',\n 'REFORMATIONSTAG',\n 'ALLERHEILIGEN',\n 'BUBETAG',\n 'ERSTERWEIHNACHTSFEIERTAG',\n 'ZWEITERWEIHNACHTSFEIERTAG',\n 'WELTKINDERTAG',\n 'WELTFRAUENTAG',\n 'AUGSBURGER_FRIEDENSFEST',\n];\n","export type Region =\n | 'BW' // Baden-Württemberg\n | 'BY' // Bayern\n | 'BE' // Berlin\n | 'BB' // Brandenburg\n | 'HB' // Bremen\n | 'HE' // Hessen\n | 'HH' // Hamburg\n | 'MV' // Mecklenburg-Vorpommern\n | 'NI' // Niedersachsen\n | 'NW' // Nordrhein-Westfalen\n | 'RP' // Rheinland-Pfalz\n | 'SL' // Saarland\n | 'SN' // Sachsen\n | 'ST' // Sachsen-Anhalt\n | 'SH' // Schleswig-Holstein\n | 'TH' // Thüringen\n | 'BUND' // Gesamt-Deutschland\n // Custom regions with local holidays (incompelte) !\n | 'AUGSBURG'\n | 'ALL';\n\nexport const allRegions: Region[] = [\n 'BW',\n 'BY',\n 'BE',\n 'BB',\n 'HB',\n 'HE',\n 'HH',\n 'MV',\n 'NI',\n 'NW',\n 'RP',\n 'SL',\n 'SN',\n 'ST',\n 'SH',\n 'TH',\n 'BUND',\n 'AUGSBURG',\n 'ALL',\n];\n","/*!\n * feiertage.js\n * @repository https://github.com/sfakir/feiertagejs\n * @docs https://github.com/sfakir/feiertagejs/blob/master/docs.md\n *\n * Copyright 2015-2021 Simon Fakir\n * Released under the MIT license\n */\n\n//\n// Additional readings\n// - how to format a javascript date: http://blog.stevenlevithan.com/archives/date-time-format\n// - the right javascript date: http://stackoverflow.com/questions/10286204/the-right-json-date-format\n//\n\nimport { germanTranslations } from './german-translations';\nimport { Holiday } from './holiday';\nimport { allHolidays, HolidayType } from './holiday-type';\nimport { allRegions, Region } from './regions';\n\n// translations\n\nconst defaultLanguage = 'de';\nlet currentLanguage: string = defaultLanguage;\n\n/**\n * Map of {@link HolidayType} to translation string.\n */\nexport type TranslationTable = { [key in HolidayType]?: string };\n\nconst translations: { [key: string]: TranslationTable } = {\n de: germanTranslations,\n};\n\n/**\n * adds a translation for the holidays (e.g. english).\n * This also allows to override the German names.\n * Hint: Interpolates German for missing translations\n * @param {string} isoCode of the new language\n * @param {TranslationTable} newTranslation map of {HolidayType} to translation stringg\n */\nexport function addTranslation(\n isoCode: string,\n newTranslation: TranslationTable,\n): void {\n const code = isoCode.toLowerCase();\n const defaultTranslation = translations[defaultLanguage];\n let missingFields = false;\n\n // fill new Translation with default Language\n for (const holiday of allHolidays) {\n if (!newTranslation[holiday]) {\n missingFields = true;\n newTranslation[holiday] = defaultTranslation[holiday];\n }\n }\n if (missingFields) {\n console.warn(\n '[feiertagejs] addTranslation: you did not add all holidays in your translation! Took German as fallback',\n );\n }\n\n translations[code] = newTranslation;\n}\n\n/**\n * Set a language to default language\n * @param {string} isoCode\n */\nexport function setLanguage(isoCode: string): void {\n const code = isoCode.toLowerCase();\n if (!translations[code]) {\nLine truncated
|
|
||||||