import React, {Component} from "react"; import {Button, Spinner, Col} from 'react-bootstrap' import '../Style.css' import SaisieAbs from "./Absences/SaisieAbs"; import SupprAbs from "./Absences/SupprAbs"; import JustAbs from "./Absences/JustAbs"; import {getJson} from "../Request"; /** Page de gestion des absences */ class Absences extends Component { constructor(props){ super(props) this.state = { // Gestion des fenetres modales // Ajout d'absences isOpen: false, // Suppression isDelOpen: false, // Justification isJustOpen: false, // Données de la liste des absences abs: [], absjust: [], // Données d'une absence selectionnée data: {}, // En cours de recuperation de données loading: false } } // Recuperation des données en cas de changement de props (dans notre cas, changement d'étudiant.e) componentDidUpdate(prevProps) { if (prevProps.id !== this.props.id) { this.setState({loading: true}) this.getData(); } } // Recuperation des données lors du chargement de la page si un étudiant est selectionné componentDidMount() { if (this.props.id !== "") {this.getData()} } /** * Gère l'ouverture des Modal * @param key {String} - Correspond au type de modal [isOpen, isDelOpen, isJustOpen] * @param data {Object} - Objet contenant les données à transmettre */ openModal(key, data) { this.setState({[key]: true}, () => setTimeout(() => { this.setState({[key]: false}) }, 500)) if (data) {this.setState({data: data})} } /** * Recupère les données d'absences depuis l'API */ getData() { let dept = window.location.href.split('/')[7] let BASE_URL = window.$api_url if (this.state.id !== "") { // Recuperation des absences non-justifiées getJson(BASE_URL + dept + "/Scolarite/Absences/ListeAbsEtud?format=json&absjust_only=0&etudid=" + this.props.id) .then(res => this.setState({abs: res.data})); // Recuperation des absences justifiées getJson(BASE_URL + dept + "/Scolarite/Absences/ListeAbsEtud?format=json&absjust_only=1&etudid=" + this.props.id) .then(res => this.setState({absjust: res.data, loading: false})); } } render() { return (
{this.props.id !== "" && // Gestion du modal de saisie } {this.props.id !== "" && // Gestion du modal de suppression } {this.props.id !== "" && // Gestion du modal de justification }

Gestion des absences

{this.props.name !== "" &&

Absences de {this.props.name + " "}

{this.state.loading === true && } {(this.state.abs.length + this.state.absjust.length === 0 && this.props.name !== "" && this.state.loading === false) &&
Aucune absence de l'étudiant.e
} {this.state.abs.map((abs) => { return (
{abs.datedmy} | {abs.matin}
{abs.motif !== "" && Motif: {abs.motif} } {abs.exams !== "" && Exam a rattraper: {abs.exams} } {abs.motif === "" && }
) })} {this.state.absjust.map((abs) => { return (
{abs.datedmy} | {abs.matin}
{abs.motif !== "" && Motif: {abs.motif} } {abs.exams !== "" && Exam a rattraper: {abs.exams} }
) })}
}
) } } export default Absences