Skip to content

Commit

Permalink
feat: show function end information
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin-Guillemin committed Feb 9, 2024
1 parent 3b2c02d commit fa770cd
Show file tree
Hide file tree
Showing 16 changed files with 180 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/main/java/fr/recia/glc/configuration/GLCProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import fr.recia.glc.configuration.bean.CustomLdapProperties;
import fr.recia.glc.configuration.bean.CustomMailProperties;
import fr.recia.glc.configuration.bean.CustomMetricsProperties;
import fr.recia.glc.configuration.bean.FrontProperties;
import fr.recia.glc.configuration.bean.IpRangeProperties;
import fr.recia.glc.configuration.bean.RoleMappingProperties;
import fr.recia.glc.configuration.bean.SecurityProperties;
Expand All @@ -47,6 +48,7 @@ public class GLCProperties {
private CorsProperties cors = new CorsProperties();
private CustomConfigProperties customConfig = new CustomConfigProperties();
private SecurityProperties security = new SecurityProperties();
private FrontProperties front = new FrontProperties();

private RoleMappingProperties admins = new RoleMappingProperties();
private RoleMappingProperties users = new RoleMappingProperties();
Expand All @@ -67,6 +69,7 @@ public String toString() {
"\n\"cors\" : " + cors + "," +
"\n\"customConfig\" : " + customConfig + "," +
"\n\"security\" : " + security + "," +
"\n\"front\" : " + front + "," +
"\n\"admins\" : " + admins + "," +
"\n\"users\" : " + users + "," +
"\n\"mail\" : " + mail + "," +
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/fr/recia/glc/configuration/bean/FrontProperties.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2023 GIP-RECIA, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package fr.recia.glc.configuration.bean;

import lombok.Data;

@Data
public class FrontProperties {

private Long endFunctionWarning;

@Override
public String toString() {
return "\"FrontProperties\": {" +
"\n\t\"endFunctionWarning\": \"" + endFunctionWarning + "\"" +
"\n}";
}

}
11 changes: 11 additions & 0 deletions src/main/java/fr/recia/glc/db/dto/fonction/FonctionDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import lombok.Setter;
import lombok.ToString;

import java.util.Date;

@Getter
@Setter
@AllArgsConstructor
Expand All @@ -33,6 +35,7 @@ public class FonctionDto {
private Long filiere;
private String source;
private Long structure;
private Date dateFin;

public FonctionDto(Long disciplinePoste, Long filiere, String source) {
this.disciplinePoste = disciplinePoste;
Expand All @@ -47,6 +50,14 @@ public FonctionDto(Long disciplinePoste, Long filiere, String source, Long struc
this.structure = structure;
}

public FonctionDto(Long disciplinePoste, Long filiere, String source, Long structure, Date dateFin) {
this.disciplinePoste = disciplinePoste;
this.filiere = filiere;
this.source = source;
this.structure = structure;
this.dateFin = dateFin;
}

public FonctionDto(Long personne, Long disciplinePoste, Long filiere, String source) {
this.personne = personne;
this.disciplinePoste = disciplinePoste;
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/fr/recia/glc/db/entities/fonction/AFonction.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import java.util.Date;

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
Expand Down Expand Up @@ -58,6 +61,9 @@ public abstract class AFonction extends AbstractTracedEntity {
@JoinColumn(name = "personne_fk")
private APersonne personne;

@Temporal(TemporalType.DATE)
private Date dateFin;

/**
* Constructeur de l'objet AFonction.java.
*/
Expand All @@ -84,7 +90,8 @@ public String toString() {
return "AFonction [" +
super.toString() + ", " +
this.categorie + ", " +
this.source +
this.source + ", " +
this.dateFin +
"]";
}

Expand All @@ -107,6 +114,11 @@ public int hashCode() {
} else {
result = prime * result + this.personne.hashCode();
}
if (this.dateFin == null) {
result = prime * result;
} else {
result = prime * result + this.dateFin.hashCode();
}
return result;
}

Expand Down Expand Up @@ -143,6 +155,13 @@ public boolean equals(final Object obj) {
} else if (!personne.equals(other.personne)) {
return false;
}
if (dateFin == null) {
if (other.dateFin != null) {
return false;
}
} else if (!dateFin.equals(other.dateFin)) {
return false;
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public interface FonctionRepository<T extends Fonction> extends AbstractRepository<T, Long> {

@Query("SELECT DISTINCT new fr.recia.glc.db.dto.fonction.FonctionDto(f.disciplinePoste.id, f.filiere.id, f.source, " +
"f.structure.id) " +
"f.structure.id, f.dateFin) " +
"FROM Fonction f " +
"WHERE f.personne.id = :id " +
"ORDER BY f.filiere.libelleFiliere")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import fr.recia.glc.configuration.GLCProperties;
import fr.recia.glc.db.enums.CategoriePersonne;
import fr.recia.glc.db.enums.Etat;
import fr.recia.glc.ldap.enums.PermissionType;
import fr.recia.glc.models.mappers.LoginMapping;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -40,6 +42,9 @@
@RequestMapping(value = "/api/config")
public class ConfigurationController {

@Autowired
private GLCProperties glcProperties;

@GetMapping()
public ResponseEntity<Object> getConfiguration() {
Map<String, Object> data = new HashMap<>();
Expand Down Expand Up @@ -82,6 +87,8 @@ public ResponseEntity<Object> getConfiguration() {
}
data.put("loginOffices", loginOffices);

data.put("endFunctionWarning", glcProperties.getFront().getEndFunctionWarning());

return new ResponseEntity<>(data, HttpStatus.OK);
}

Expand Down
39 changes: 36 additions & 3 deletions src/main/webapp/src/components/layouts/FonctionsLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
import { useConfigurationStore } from '@/stores/configurationStore.ts';
import type { Filiere } from '@/types/filiereType.ts';
import type { PersonneFonction } from '@/types/fonctionType.ts';
import { getDateFin } from '@/utils/accountUtils.ts';
import { format } from 'date-fns';
import { storeToRefs } from 'pinia';
import { ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
const configurationStore = useConfigurationStore();
const { currentStructureId } = storeToRefs(configurationStore);
const { t } = useI18n();
const props = defineProps<{
filieres: Array<Filiere> | undefined;
fonctions: Array<PersonneFonction> | undefined;
Expand All @@ -20,11 +25,19 @@ const filterFilieres = (): void => {
const etabFonctions = props.fonctions.filter((fonction) => fonction.structure == currentStructureId.value);
const filiereIds = [...new Set(etabFonctions.map((fonction) => fonction.filiere))];
const disciplineIds = [...new Set(etabFonctions.map((fonction) => fonction.disciplinePoste))];
const datesFin = etabFonctions.map((fonction) => {
return { disciplinePoste: fonction.disciplinePoste, dateFin: fonction.dateFin };
});
filteredFilieres.value = props.filieres
.filter((filiere) => filiereIds.includes(filiere.id))
.map((filiere) => {
const disciplines = filiere.disciplines.filter((discipline) => disciplineIds.includes(discipline.id));
let disciplines = filiere.disciplines.filter((discipline) => disciplineIds.includes(discipline.id));
disciplines = disciplines.map((discipline) => {
const dateFin = datesFin.find((endDate) => endDate.disciplinePoste == discipline.id)?.dateFin;
return { ...discipline, endInfo: dateFin ? getDateFin(dateFin) : undefined };
});
return { ...filiere, disciplines };
});
Expand All @@ -48,10 +61,30 @@ watch(
v-for="(discipline, index) in filiere.disciplines"
:key="index"
:text="discipline.disciplinePoste"
color="primary"
:color="discipline.endInfo?.color ?? 'primary'"
:ripple="false"
rounded
/>
>
<template #append v-if="discipline.endInfo">
<v-tooltip
:text="
t(
discipline.endInfo.i18n,
{
date: format(discipline.endInfo.date!, 'P'),
months: discipline.endInfo.months,
},
discipline.endInfo.months ?? 1,
)
"
location="bottom start"
>
<template v-slot:activator="{ props }">
<v-icon v-bind="props" :icon="discipline.endInfo.icon" size="x-small" class="ml-1" />
</template>
</v-tooltip>
</template>
</v-chip>
</div>
</v-card-text>
</v-card>
Expand Down
7 changes: 7 additions & 0 deletions src/main/webapp/src/locales/en/persons.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
"function": "Fonction | Fonctions",
"additionalFunction": "Additional function | Additional functions",
"additionalTeaching": "Additional teaching | Additional teachings"
},
"function": {
"hourglass": {
"start": "Will expire in {months} month ({date}) | Will expire in {months} months ({date}) ",
"half": "Expires in {months} month ({date}) | Expires in {months} months ({date})",
"end": "Expired on {date}"
}
}
}
}
7 changes: 7 additions & 0 deletions src/main/webapp/src/locales/fr/persons.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
"function": "Fonction | Fonctions",
"additionalFunction": "Fonction complémentaire | Fonctions complémentaires",
"additionalTeaching": "Enseignement complémentaire | Enseignements complémentaires"
},
"function": {
"hourglass": {
"start": "Expirera dans {months} mois ({date})",
"half": "Expire dans {months} mois ({date})",
"end": "A expiré le {date}"
}
}
}
}
6 changes: 6 additions & 0 deletions src/main/webapp/src/plugins/fontawsome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import {
faFilter,
faFilterCircleXmark,
faFloppyDisk,
faHourglassEnd,
faHourglassHalf,
faHourglassStart,
faLink,
faLinkSlash,
faMoon,
Expand Down Expand Up @@ -53,6 +56,9 @@ const register = (app: App) => {
faFilter,
faFilterCircleXmark,
faFloppyDisk,
faHourglassEnd,
faHourglassHalf,
faHourglassStart,
faLink,
faLinkSlash,
faMoon,
Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/src/stores/configurationStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export const useConfigurationStore = defineStore('configuration', () => {
const isAuthenticated = computed<boolean>(() => !isEmpty(identity.value));

return {
configuration,
init,
isInit,
administrativeStaff,
Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/src/types/configurationType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export type Configuration = {
categoriesPersonne: Array<string>;
}>;
}>;
endFunctionWarning: number;
};
2 changes: 2 additions & 0 deletions src/main/webapp/src/types/disciplineType.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { endInfo } from '@/types/endInfoType.ts';
import type { SimplePersonne } from '@/types/personneType.ts';

export type Discipline = {
Expand All @@ -6,4 +7,5 @@ export type Discipline = {
disciplinePoste: string;
source: string;
personnes: Array<SimplePersonne>;
endInfo?: endInfo;
};
7 changes: 7 additions & 0 deletions src/main/webapp/src/types/endInfoType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { enumValues } from '@/types/enumValuesType.ts';

export type endInfo = {
date?: string;
months?: number;
isPast: boolean;
} & enumValues;
1 change: 1 addition & 0 deletions src/main/webapp/src/types/fonctionType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export type PersonneFonction = {
filiere: number;
source: string;
structure: number;
dateFin?: string;
};
39 changes: 38 additions & 1 deletion src/main/webapp/src/utils/accountUtils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { useConfigurationStore } from '@/stores/configurationStore.ts';
import type { endInfo } from '@/types/endInfoType.ts';
import type { enumValues } from '@/types/enumValuesType.ts';
import { CategoriePersonne } from '@/types/enums/CategoriePersonne.ts';
import { Etat } from '@/types/enums/Etat.ts';
import type { PersonneFonction } from '@/types/fonctionType.ts';
import { differenceInCalendarMonths, isPast } from 'date-fns';
import { storeToRefs } from 'pinia';

const isLocal = (source: string): boolean => source.startsWith('SarapisUi_');

Expand Down Expand Up @@ -61,7 +65,40 @@ const getCategoriePersonne = (categorie: string): enumValues => {
}
};

const getDateFin = (date: string): endInfo => {
const configurationStore = useConfigurationStore();
const { configuration } = storeToRefs(configurationStore);

if (isPast(date))
return {
date,
isPast: true,
i18n: 'person.function.hourglass.end',
color: '',
icon: 'fas fa-hourglass-end',
};
const months: number = differenceInCalendarMonths(date, new Date());
if (months < (configuration.value?.endFunctionWarning ?? 2))
return {
date,
months,
isPast: false,
i18n: 'person.function.hourglass.half',
color: 'warning',
icon: 'fas fa-hourglass-half',
};

return {
date,
months,
isPast: false,
i18n: 'person.function.hourglass.start',
color: 'primary',
icon: 'fas fa-hourglass-start',
};
};

const toIdentifier = (fonctions: Array<PersonneFonction> | undefined): Array<string> =>
fonctions ? fonctions.map((fonction) => `${fonction.filiere}-${fonction.disciplinePoste}`) : [];

export { isLocal, getIcon, getEtat, getCategoriePersonne, toIdentifier };
export { isLocal, getIcon, getEtat, getCategoriePersonne, getDateFin, toIdentifier };

0 comments on commit fa770cd

Please sign in to comment.