Revize ff40cb89
Přidáno uživatelem Michal Schwob před téměř 3 roky(ů)
backend/src/main/java/cz/zcu/kiv/backendapi/security/SecurityConfig.java | ||
---|---|---|
62 | 62 |
PERMITTED_ENDPOINTS.put("/v3/api-docs/swagger-config", HttpMethod.GET); |
63 | 63 |
PERMITTED_ENDPOINTS.put("/catalog-items", HttpMethod.GET); |
64 | 64 |
PERMITTED_ENDPOINTS.put("/catalog-items/**", HttpMethod.GET); |
65 |
PERMITTED_ENDPOINTS.put("/title-page", HttpMethod.GET); |
|
65 | 66 |
} |
66 | 67 |
|
67 | 68 |
/** |
... | ... | |
90 | 91 |
.antMatchers(HttpMethod.POST, "/catalog-items").hasAuthority(Permission.WRITE.name()) |
91 | 92 |
.antMatchers(HttpMethod.PUT, "/catalog-items/*").hasAuthority(Permission.WRITE.name()) |
92 | 93 |
.antMatchers(HttpMethod.DELETE, "/catalog-items/*").hasAuthority(Permission.DELETE.name()) |
94 |
.antMatchers(HttpMethod.POST, "/title-page").hasRole(Role.ADMIN.name()) |
|
93 | 95 |
.anyRequest() |
94 | 96 |
.authenticated(); |
95 | 97 |
} |
frontend/package.json | ||
---|---|---|
21 | 21 |
"react-html-parser": "^2.0.2", |
22 | 22 |
"react-leaflet": "3.2.5", |
23 | 23 |
"react-leaflet-textpath": "^2.1.1", |
24 |
"react-quill": "^1.3.5", |
|
24 | 25 |
"react-redux": "^7.2.6", |
25 | 26 |
"react-router-dom": "^6.2.2", |
26 | 27 |
"react-scripts": "5.0.0", |
frontend/src/App.tsx | ||
---|---|---|
13 | 13 |
import TrackingTool from './features/TrackingTool/TrackingTool' |
14 | 14 |
import Logout from './features/Auth/Logout' |
15 | 15 |
import ThemeWrapper from './features/Theme/ThemeWrapper' |
16 |
import EditHome from "./features/Home/EditHome" |
|
16 | 17 |
|
17 | 18 |
const App = () => { |
18 | 19 |
|
... | ... | |
22 | 23 |
<Box sx={{mx: 10}}> |
23 | 24 |
<Routes> |
24 | 25 |
<Route path="/" element={<Home />} /> |
26 |
<Route path="/editHome" element={<EditHome />} /> |
|
25 | 27 |
<Route path="/catalog" element={<Catalog />} /> |
26 | 28 |
<Route |
27 | 29 |
path="/catalog/:itemId" |
frontend/src/features/Home/EditHome.tsx | ||
---|---|---|
1 |
import {Button, Paper} from '@mui/material' |
|
2 |
import {Fragment, useEffect, useState} from 'react' |
|
3 |
import { useDispatch, useSelector } from 'react-redux' |
|
4 |
import { logout } from '../Auth/userSlice' |
|
5 |
import { RootState } from '../redux/store' |
|
6 |
import {TitlePageDto} from "../../swagger/data-contracts" |
|
7 |
import axiosInstance from "../../api/api" |
|
8 |
import ReactQuill from "react-quill" |
|
9 |
import 'react-quill/dist/quill.snow.css' |
|
10 |
import ContentLoading from "../Reusables/ContentLoading" |
|
11 |
import {Link as RouterLink, useNavigate} from "react-router-dom" |
|
12 |
import ArrowBackIosIcon from "@mui/icons-material/ArrowBackIos" |
|
13 |
|
|
14 |
|
|
15 |
const apiError = |
|
16 |
'Error while fetching data from the server, please try again later.' |
|
17 |
|
|
18 |
const EditHome = () => { |
|
19 |
const [content, setContent] = useState<TitlePageDto | undefined>(undefined) |
|
20 |
const [isContentLoading, setIsContentLoading] = useState(true) |
|
21 |
const [err, setErr] = useState<string | undefined>(undefined) |
|
22 |
|
|
23 |
const navigate = useNavigate() |
|
24 |
|
|
25 |
const updateContent = (updated: string) => { |
|
26 |
console.log("updateContent: " + updated) |
|
27 |
if (content) { |
|
28 |
content["content"] = updated |
|
29 |
} |
|
30 |
} |
|
31 |
|
|
32 |
const handleSubmit = () => { |
|
33 |
postData() |
|
34 |
} |
|
35 |
|
|
36 |
const postData = async () => { |
|
37 |
const {data, status} = await axiosInstance.post('/title-page', content) |
|
38 |
if (status != 200) { |
|
39 |
console.error("Title page data submitting failed.") |
|
40 |
} |
|
41 |
} |
|
42 |
|
|
43 |
const roles = useSelector( |
|
44 |
(state: RootState) => state.user.roles |
|
45 |
) |
|
46 |
|
|
47 |
// Fetch the item from the api after mounting the component |
|
48 |
useEffect(() => { |
|
49 |
// Function to fetch the item from the api |
|
50 |
const fetchItem = async () => { |
|
51 |
try { |
|
52 |
const { data, status } = await axiosInstance.get( |
|
53 |
`/title-page` |
|
54 |
) |
|
55 |
if (status !== 200) { |
|
56 |
setErr(apiError) |
|
57 |
return |
|
58 |
} |
|
59 |
|
|
60 |
setContent(data) |
|
61 |
setIsContentLoading(false) |
|
62 |
} catch (err: any) { |
|
63 |
setErr(apiError) |
|
64 |
} |
|
65 |
} |
|
66 |
|
|
67 |
fetchItem() |
|
68 |
}, []) |
|
69 |
|
|
70 |
return ( |
|
71 |
<Fragment> |
|
72 |
<Button |
|
73 |
startIcon={<ArrowBackIosIcon />} |
|
74 |
variant="contained" |
|
75 |
component={RouterLink} |
|
76 |
to="/" |
|
77 |
color="primary" |
|
78 |
sx={{ mb: 2 }} |
|
79 |
> |
|
80 |
Return To Catalog |
|
81 |
</Button> |
|
82 |
<Paper style={{ minHeight: '100vh' }} variant="outlined"> |
|
83 |
{isContentLoading && !err ? <ContentLoading /> : null} |
|
84 |
{!isContentLoading && content ? ( |
|
85 |
<div> |
|
86 |
<h1>Home</h1> |
|
87 |
<form onSubmit={handleSubmit}> |
|
88 |
<input type="submit" value="Submit" /> |
|
89 |
<ReactQuill |
|
90 |
theme='snow' |
|
91 |
value={content["content"]} |
|
92 |
onChange={updateContent} |
|
93 |
style={{minHeight: '300px'}} |
|
94 |
/> |
|
95 |
</form> |
|
96 |
</div> |
|
97 |
) : null} |
|
98 |
</Paper> |
|
99 |
</Fragment> |
|
100 |
) |
|
101 |
} |
|
102 |
|
|
103 |
export default EditHome |
frontend/src/features/Home/Home.tsx | ||
---|---|---|
1 |
import { Button } from '@mui/material'
|
|
2 |
import { Fragment } from 'react'
|
|
1 |
import {Button, Paper} from '@mui/material'
|
|
2 |
import {Fragment, useEffect, useState} from 'react'
|
|
3 | 3 |
import { useDispatch, useSelector } from 'react-redux' |
4 | 4 |
import { logout } from '../Auth/userSlice' |
5 | 5 |
import { RootState } from '../redux/store' |
6 |
import {TitlePageDto} from "../../swagger/data-contracts" |
|
7 |
import axiosInstance from "../../api/api" |
|
8 |
import ReactQuill from "react-quill" |
|
9 |
import 'react-quill/dist/quill.snow.css' |
|
10 |
import ContentLoading from "../Reusables/ContentLoading" |
|
11 |
import EditHome from "./EditHome" |
|
12 |
import {Link as RouterLink, useNavigate} from "react-router-dom" |
|
13 |
import EditIcon from '@mui/icons-material/Edit' |
|
14 |
import { formatHtmlStringToReactDom } from "../../utils/formatting/HtmlUtils" |
|
15 |
|
|
16 |
|
|
17 |
const apiError = |
|
18 |
'Error while fetching data from the server, please try again later.' |
|
6 | 19 |
|
7 | 20 |
const Home = () => { |
21 |
const [content, setContent] = useState<TitlePageDto | undefined>(undefined) |
|
22 |
const [isContentLoading, setIsContentLoading] = useState(true) |
|
23 |
const [err, setErr] = useState<string | undefined>(undefined) |
|
24 |
|
|
25 |
let navigate = useNavigate() |
|
26 |
const openEditHomePage = () => { |
|
27 |
let path = 'editHome' |
|
28 |
navigate(path) |
|
29 |
} |
|
30 |
|
|
31 |
const roles = useSelector( |
|
32 |
(state: RootState) => state.user.roles |
|
33 |
) |
|
34 |
|
|
35 |
const isAdmin = roles.includes("ROLE_ADMIN") |
|
36 |
|
|
37 |
// Fetch the item from the api after mounting the component |
|
38 |
useEffect(() => { |
|
39 |
// Function to fetch the item from the api |
|
40 |
console.log("useEffect called") |
|
41 |
const fetchItem = async () => { |
|
42 |
try { |
|
43 |
const { data, status } = await axiosInstance.get( |
|
44 |
`/title-page` |
|
45 |
) |
|
46 |
if (status !== 200) { |
|
47 |
setErr(apiError) |
|
48 |
return |
|
49 |
} |
|
50 |
|
|
51 |
setContent(data) |
|
52 |
setIsContentLoading(false) |
|
53 |
} catch (err: any) { |
|
54 |
setErr(apiError) |
|
55 |
} |
|
56 |
} |
|
57 |
fetchItem() |
|
58 |
}, [roles]) |
|
59 |
|
|
8 | 60 |
return ( |
9 | 61 |
<Fragment> |
10 |
<h1>Home</h1> |
|
62 |
<Paper style={{ minHeight: '100vh' }} variant="outlined"> |
|
63 |
{isContentLoading && !err ? <ContentLoading /> : null} |
|
64 |
{!isContentLoading && content ? ( |
|
65 |
<div> |
|
66 |
<h1>Home</h1> |
|
67 |
{formatHtmlStringToReactDom(content["content"] as string)} |
|
68 |
</div> |
|
69 |
) : null} |
|
70 |
{isAdmin ? ( |
|
71 |
<Button |
|
72 |
startIcon={<EditIcon />} |
|
73 |
variant="contained" |
|
74 |
component={RouterLink} |
|
75 |
to="/editHome" |
|
76 |
color="primary" |
|
77 |
sx={{ mb: 2 }} |
|
78 |
> |
|
79 |
Edit |
|
80 |
</Button> |
|
81 |
|
|
82 |
) : null} |
|
83 |
</Paper> |
|
11 | 84 |
</Fragment> |
12 | 85 |
) |
13 | 86 |
} |
Také k dispozici: Unified diff
Formating of Home page
re #9714