mirror of
https://github.com/hubHarmony/servii-frontend.git
synced 2024-11-18 05:40:31 +00:00
history card design
This commit is contained in:
parent
bc8ad3f096
commit
2cb9663714
@ -1,25 +1,25 @@
|
|||||||
import { useEffect, useState, useRef } from 'react';
|
import { useEffect, useState, useRef } from 'react';
|
||||||
import { useParams, useNavigate, useLocation } from 'react-router-dom';
|
import { useParams, useNavigate } from 'react-router-dom';
|
||||||
import styles from './ServerHistory.module.scss';
|
import styles from './ServerHistory.module.scss';
|
||||||
import serviiApi from "../../service/api.tsx";
|
import serviiApi from "../../service/api.tsx";
|
||||||
import Loading from '../Loading/loading.jsx';
|
import Loading from '../Loading/loading.jsx';
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
|
|
||||||
const ServerHistory = ({ user }) => {
|
const ServerHistory = () => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { serverName } = useParams();
|
const { serverName } = useParams();
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState(null);
|
const [error, setError] = useState(null);
|
||||||
const [history, setHistory] = useState('');
|
const [history, setHistory] = useState([]);
|
||||||
const location = useLocation();
|
const [filter, setFilter] = useState({
|
||||||
const status = location.state?.status;
|
ServerCreate: true,
|
||||||
|
ServerRun: true,
|
||||||
|
Command: true,
|
||||||
|
UpdateProperties: true
|
||||||
|
});
|
||||||
|
|
||||||
const historyEndRef = useRef(null);
|
const historyEndRef = useRef(null);
|
||||||
|
|
||||||
const scrollToBottom = () => {
|
|
||||||
historyEndRef.current?.scrollIntoView({ behavior: "smooth" });
|
|
||||||
};
|
|
||||||
|
|
||||||
const fetchServerHistory = async () => {
|
const fetchServerHistory = async () => {
|
||||||
setError(null);
|
setError(null);
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
@ -30,14 +30,41 @@ const ServerHistory = ({ user }) => {
|
|||||||
let historyString = response.message;
|
let historyString = response.message;
|
||||||
historyString = historyString.slice(1, -1);
|
historyString = historyString.slice(1, -1);
|
||||||
historyString = historyString.replace(/\\n/g, '\n');
|
historyString = historyString.replace(/\\n/g, '\n');
|
||||||
historyString = historyString.replace(/\\\"/g, '"');
|
historyString = historyString.replace(/\\"/g, '"');
|
||||||
historyString = historyString.replace(/, ?/g, '');
|
historyString = historyString.replace(/, ?/g, '');
|
||||||
historyString = historyString.replace(/"{2,}/g, '');
|
historyString = historyString.replace(/"{2,}/g, '');
|
||||||
historyString = historyString.replace(/'{2,}/g, '');
|
historyString = historyString.replace(/'{2,}/g, '');
|
||||||
historyString = historyString.trim();
|
historyString = historyString.trim();
|
||||||
setHistory(historyString);
|
|
||||||
|
console.log("History string after parsing:", historyString);
|
||||||
|
|
||||||
|
historyString = historyString.replace(/(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})(type": ")/g, '$1", "$2');
|
||||||
|
historyString = historyString.replace(/(type": "ServerCreate|ServerRun|Command|UpdateProperties)(details": )/g, '$1", "$2');
|
||||||
|
|
||||||
|
const historyArray = historyString.split('\n').map(entry => {
|
||||||
|
const timestampMatch = entry.match(/"timestamp": "(.*?)"/);
|
||||||
|
const typeMatch = entry.match(/"type": "(.*?)"/);
|
||||||
|
const detailsMatch = entry.match(/"details": "(.*?)"/);
|
||||||
|
|
||||||
|
const parsedEntry = {
|
||||||
|
timestamp: timestampMatch ? timestampMatch[1] : "Unknown",
|
||||||
|
type: typeMatch ? typeMatch[1] : "Unknown",
|
||||||
|
details: detailsMatch ? detailsMatch[1] : null
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log("Parsed entry:", parsedEntry);
|
||||||
|
|
||||||
|
return parsedEntry;
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("Final history array:", historyArray);
|
||||||
|
|
||||||
|
setHistory(historyArray);
|
||||||
|
} else {
|
||||||
|
console.error("Failed to fetch history, response:", response);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
console.error("Error fetching history:", err);
|
||||||
setError(`Erreur: ${err.message}`);
|
setError(`Erreur: ${err.message}`);
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
@ -48,9 +75,17 @@ const ServerHistory = ({ user }) => {
|
|||||||
fetchServerHistory();
|
fetchServerHistory();
|
||||||
}, [serverName]);
|
}, [serverName]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
scrollToBottom();
|
|
||||||
}, [history]);
|
const handleFilterChange = (event) => {
|
||||||
|
const { name, checked } = event.target;
|
||||||
|
setFilter(prevFilter => ({
|
||||||
|
...prevFilter,
|
||||||
|
[name]: checked
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
|
const filteredHistory = history.filter(item => filter[item.type]);
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return <Loading />;
|
return <Loading />;
|
||||||
@ -69,11 +104,61 @@ const ServerHistory = ({ user }) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.container}>
|
<div className={styles.container}>
|
||||||
|
<div className={styles.filterContainer}>
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
name="ServerCreate"
|
||||||
|
checked={filter.ServerCreate}
|
||||||
|
onChange={handleFilterChange}
|
||||||
|
/>
|
||||||
|
Création du serveur
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
name="ServerRun"
|
||||||
|
checked={filter.ServerRun}
|
||||||
|
onChange={handleFilterChange}
|
||||||
|
/>
|
||||||
|
Lancement du serveur
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
name="Command"
|
||||||
|
checked={filter.Command}
|
||||||
|
onChange={handleFilterChange}
|
||||||
|
/>
|
||||||
|
Commande
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
name="UpdateProperties"
|
||||||
|
checked={filter.UpdateProperties}
|
||||||
|
onChange={handleFilterChange}
|
||||||
|
/>
|
||||||
|
Nouvelle propriété
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className={styles.containerHistory}>
|
<div className={styles.containerHistory}>
|
||||||
<div className={styles.header}>
|
<div className={styles.historyCards}>
|
||||||
<pre className={styles.logs}>
|
{filteredHistory.length > 0 ? (
|
||||||
{history}
|
filteredHistory.map((item, index) => (
|
||||||
</pre>
|
<div key={index} className={styles.historyCard}>
|
||||||
|
<div><strong>Timestamp:</strong> {item.timestamp}</div>
|
||||||
|
<div><strong>Type:</strong> {item.type}</div>
|
||||||
|
<div><strong>Details:</strong> {item.details || 'N/A'}</div>
|
||||||
|
</div>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<div className={styles.noHistory}>
|
||||||
|
Aucun historique à afficher.
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div ref={historyEndRef} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -2,7 +2,50 @@
|
|||||||
margin-top: var(--navbar-height);
|
margin-top: var(--navbar-height);
|
||||||
}
|
}
|
||||||
|
|
||||||
.extraMargin{
|
.filterContainer {
|
||||||
margin-bottom: 5rem;
|
display: flex;
|
||||||
color:red;
|
flex-direction: row;
|
||||||
|
gap: 1.5rem;
|
||||||
|
background-color: white;
|
||||||
|
color: black;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
padding: 2.5rem;
|
||||||
|
font-size: 1.2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.historyCards {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.historyCard {
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
padding: 1rem;
|
||||||
|
border-radius: 4px;
|
||||||
|
background-color: #f9f9f9;
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.filterContainer label {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filterContainer input[type="checkbox"] {
|
||||||
|
width: 1.5rem;
|
||||||
|
height: 1.5rem;
|
||||||
|
border: 2px solid #ccc;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filterContainer input[type="checkbox"]:checked::before {
|
||||||
|
display: block;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 1.5rem;
|
||||||
|
color: white;
|
||||||
|
font-weight: bold;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user