Merge branch 'main' of https://gitlab2.istic.univ-rennes1.fr/trochas/mmm-projet
This commit is contained in:
@@ -49,7 +49,7 @@ export default function TabLayout() {
|
|||||||
name="GestionOuvrier"
|
name="GestionOuvrier"
|
||||||
component={GestionOuvrier}
|
component={GestionOuvrier}
|
||||||
options={{
|
options={{
|
||||||
title: 'Bonjour',
|
title: 'Ouvriers',
|
||||||
tabBarIcon: ({ color }) => <IconSymbol size={28} name="person.fill" color={color} />,
|
tabBarIcon: ({ color }) => <IconSymbol size={28} name="person.fill" color={color} />,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -10,11 +10,11 @@ import { FlatList, Image, StyleSheet, Text, View } from "react-native";
|
|||||||
import { Ressources } from "../../class/class";
|
import { Ressources } from "../../class/class";
|
||||||
import { getRessources } from "../../services/ressourcesService";
|
import { getRessources } from "../../services/ressourcesService";
|
||||||
import SelectChantier from "@/components/selectChantier";
|
import SelectChantier from "@/components/selectChantier";
|
||||||
|
import { useRessources } from "../ContextRessource";
|
||||||
|
|
||||||
export default function GestionnaireRessource() {
|
export default function GestionnaireRessource() {
|
||||||
const { nom, prenom } = useLocalSearchParams();
|
|
||||||
const [search, setSearch] = useState("");
|
const [search, setSearch] = useState("");
|
||||||
const [ressource, setRessources] = useState<Ressources[]>([]);
|
const {ressources, setRessources} = useRessources();
|
||||||
const [filterType, setFilterType] = useState("tout");
|
const [filterType, setFilterType] = useState("tout");
|
||||||
const [showFilterMenu, setShowFilterMenu] = useState(false);
|
const [showFilterMenu, setShowFilterMenu] = useState(false);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@@ -31,7 +31,7 @@ export default function GestionnaireRessource() {
|
|||||||
loadData();
|
loadData();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const filteredData = ressource.filter((r) => {
|
const filteredData = ressources.filter((r) => {
|
||||||
const matchName = r.name.toLowerCase().includes(search.toLowerCase());
|
const matchName = r.name.toLowerCase().includes(search.toLowerCase());
|
||||||
const matchType = filterType === "tout" || r.type === filterType;
|
const matchType = filterType === "tout" || r.type === filterType;
|
||||||
return matchName && matchType;
|
return matchName && matchType;
|
||||||
@@ -43,7 +43,6 @@ export default function GestionnaireRessource() {
|
|||||||
<ThemedView lvl={1} shadow={true} style={styles.card}>
|
<ThemedView lvl={1} shadow={true} style={styles.card}>
|
||||||
<Image source={{ uri: item.Image }} style={styles.image} />
|
<Image source={{ uri: item.Image }} style={styles.image} />
|
||||||
<ThemedView lvl={1} style={styles.info}>
|
<ThemedView lvl={1} style={styles.info}>
|
||||||
<ThemedText>{item.id}</ThemedText>
|
|
||||||
<ThemedText>Nom : {item.name}</ThemedText>
|
<ThemedText>Nom : {item.name}</ThemedText>
|
||||||
<ThemedText>Type : {item.type}</ThemedText>
|
<ThemedText>Type : {item.type}</ThemedText>
|
||||||
<ThemedText>Quantité totale : {item.quantity}</ThemedText>
|
<ThemedText>Quantité totale : {item.quantity}</ThemedText>
|
||||||
@@ -75,9 +74,11 @@ export default function GestionnaireRessource() {
|
|||||||
lvl={1}
|
lvl={1}
|
||||||
shadow={true}
|
shadow={true}
|
||||||
style={{ padding: 10, borderRadius: 8, marginBottom: 10 }}
|
style={{ padding: 10, borderRadius: 8, marginBottom: 10 }}
|
||||||
onPress={() => {
|
onPress={async () => {
|
||||||
setFilterType(t);
|
setFilterType(t);
|
||||||
setShowFilterMenu(false);
|
setShowFilterMenu(false);
|
||||||
|
const updateRessource = await getRessources();
|
||||||
|
setRessources(updateRessource)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ThemedText style={{ textAlign: "center" }}>{t}</ThemedText>
|
<ThemedText style={{ textAlign: "center" }}>{t}</ThemedText>
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export type User = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type Ressources = {
|
export type Ressources = {
|
||||||
id: number;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
type: string; //"machine","outil","ouvrier"
|
type: string; //"machine","outil","ouvrier"
|
||||||
Image: string;
|
Image: string;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { StyleSheet, ScrollView, Button, TextInput, Text, View, Modal } from 're
|
|||||||
import { useChantier } from '@/app/ContextChantier';
|
import { useChantier } from '@/app/ContextChantier';
|
||||||
import { useRessources } from '@/app/ContextRessource';
|
import { useRessources } from '@/app/ContextRessource';
|
||||||
import { useUser } from '@/app/ContextUser';
|
import { useUser } from '@/app/ContextUser';
|
||||||
import { getRessources, getUsers, addChantier } from '@/services/ressourcesService';
|
import { getRessources, getUsers, addChantier , addRessources} from '@/services/ressourcesService';
|
||||||
import { Chantier, Ressources, User } from '@/class/class';
|
import { Chantier, Ressources, User } from '@/class/class';
|
||||||
import { ThemedText } from '@/components/theme/themed-text';
|
import { ThemedText } from '@/components/theme/themed-text';
|
||||||
import { ThemedButton } from '@/components/theme/themed-button';
|
import { ThemedButton } from '@/components/theme/themed-button';
|
||||||
@@ -58,20 +58,40 @@ export default function AddRessource({ressourceType, ...otherProps }: Props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function onConfirm(): Promise<void> {
|
async function onConfirm(): Promise<void> {
|
||||||
//TODO
|
|
||||||
//await changeChantierStatus(chantier.id,tempStatus)
|
|
||||||
//Il faut changer le UX
|
|
||||||
//setChantier({...chantier,etat: tempStatus})
|
|
||||||
if(isValidRessource()){
|
if(isValidRessource()){
|
||||||
|
try{
|
||||||
|
setLoading(true);
|
||||||
|
const nouvelleRessource : Ressources = {
|
||||||
|
id : '',
|
||||||
|
name: nom,
|
||||||
|
type : ressourceType,
|
||||||
|
quantity : parseInt(quantite),
|
||||||
|
available_quantity : parseInt(quantite),
|
||||||
|
Image : "",
|
||||||
|
allocation : [],
|
||||||
|
};
|
||||||
|
const id = await addRessources(nouvelleRessource);
|
||||||
|
|
||||||
|
if(id){
|
||||||
|
setRessources([...ressources,{...nouvelleRessource, id}]);
|
||||||
|
setOpenConfirmation(false);
|
||||||
|
setNom('');
|
||||||
|
setQuantite('');
|
||||||
|
setQuantiteDisponible('');
|
||||||
|
}
|
||||||
|
}catch(error){
|
||||||
|
}finally{
|
||||||
setOpenConfirmation(false);
|
setOpenConfirmation(false);
|
||||||
|
setLoading(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function onCancel(): void {
|
function onCancel(): void {
|
||||||
setOpenConfirmation(false);
|
setOpenConfirmation(false);
|
||||||
}
|
}
|
||||||
function isValidRessource():Boolean{
|
function isValidRessource():Boolean{
|
||||||
return nom!= "" && quantite != "" && quantiteDisponible != ""
|
return nom!= "" && quantite != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
const renderValidationScreen = () => {
|
const renderValidationScreen = () => {
|
||||||
@@ -98,8 +118,7 @@ export default function AddRessource({ressourceType, ...otherProps }: Props) {
|
|||||||
</View>
|
</View>
|
||||||
</Modal>
|
</Modal>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const renderInut = (name : string, preFill : string, value : string, setValue : ((text:string) => void),numeric:boolean) => {
|
const renderInut = (name : string, preFill : string, value : string, setValue : ((text:string) => void),numeric:boolean) => {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ export default function Anomaly({data,style}: Props) {
|
|||||||
{data.chantier.anomalies.length > 0 ? (
|
{data.chantier.anomalies.length > 0 ? (
|
||||||
data.chantier.anomalies.map((anomaly, index) => (
|
data.chantier.anomalies.map((anomaly, index) => (
|
||||||
<ThemedView key={index} lvl={2} style={styles.anomalyItem}>
|
<ThemedView key={index} lvl={2} style={styles.anomalyItem}>
|
||||||
<ThemedText>• {anomaly}</ThemedText>
|
<ThemedText style={styles.anomalyText}>• {anomaly}</ThemedText>
|
||||||
<TouchableOpacity onPress={() => handleDelete(anomaly)} style={styles.deleteButton}>
|
<TouchableOpacity onPress={() => handleDelete(anomaly)} style={styles.deleteButton}>
|
||||||
<Text style={styles.deleteText}>✕</Text>
|
<Text style={styles.deleteText}>✕</Text>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
@@ -99,7 +99,7 @@ const styles = StyleSheet.create({
|
|||||||
anomaliesContainer: {
|
anomaliesContainer: {
|
||||||
padding: 5,
|
padding: 5,
|
||||||
borderRadius: 10,
|
borderRadius: 10,
|
||||||
height: 150,
|
//height: 150,
|
||||||
},
|
},
|
||||||
anomaliesTitle: {
|
anomaliesTitle: {
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
@@ -107,10 +107,16 @@ const styles = StyleSheet.create({
|
|||||||
marginBottom: 8,
|
marginBottom: 8,
|
||||||
},
|
},
|
||||||
anomalyItem: {
|
anomalyItem: {
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "flex-start",
|
||||||
padding: 8,
|
padding: 8,
|
||||||
marginBottom: 5,
|
marginBottom: 5,
|
||||||
borderRadius: 8,
|
borderRadius: 8,
|
||||||
},
|
},
|
||||||
|
anomalyText: {
|
||||||
|
flex: 1,
|
||||||
|
marginLeft: 5,
|
||||||
|
},
|
||||||
noAnomaly: {
|
noAnomaly: {
|
||||||
fontStyle: "italic",
|
fontStyle: "italic",
|
||||||
opacity: 0.7,
|
opacity: 0.7,
|
||||||
@@ -133,6 +139,7 @@ const styles = StyleSheet.create({
|
|||||||
//add anomaly styles
|
//add anomaly styles
|
||||||
addContainer: {
|
addContainer: {
|
||||||
marginTop: 10,
|
marginTop: 10,
|
||||||
|
marginLeft: 2,
|
||||||
flexDirection: "row",
|
flexDirection: "row",
|
||||||
alignItems: "center"
|
alignItems: "center"
|
||||||
},
|
},
|
||||||
@@ -144,6 +151,7 @@ const styles = StyleSheet.create({
|
|||||||
marginRight: 8,
|
marginRight: 8,
|
||||||
},
|
},
|
||||||
addButton: {
|
addButton: {
|
||||||
|
color: "white",
|
||||||
paddingVertical: 8,
|
paddingVertical: 8,
|
||||||
paddingHorizontal: 12,
|
paddingHorizontal: 12,
|
||||||
borderRadius: 8,
|
borderRadius: 8,
|
||||||
|
|||||||
@@ -37,6 +37,19 @@ export async function getRessources(): Promise<Ressources[]> {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//ADD RESSOURCES
|
||||||
|
export async function addRessources(ressourceData: Omit<Ressources, 'id'>): Promise<string | null> {
|
||||||
|
try {
|
||||||
|
const colRef = collection(db, "ressources");
|
||||||
|
const ressourcesRef = await addDoc(colRef, ressourceData);
|
||||||
|
console.log(`Ressource ajoutée avec ID: ${ressourcesRef.id}`);
|
||||||
|
return ressourcesRef.id;
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Error adding:", err);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
///////////////////////////////////CHANTIER/////////////////////////////////
|
///////////////////////////////////CHANTIER/////////////////////////////////
|
||||||
export async function getChantiers(): Promise<Chantier[]> {
|
export async function getChantiers(): Promise<Chantier[]> {
|
||||||
const snap = await getDocs(collection(db, "chantier"));
|
const snap = await getDocs(collection(db, "chantier"));
|
||||||
|
|||||||
Reference in New Issue
Block a user