Browse Source

jsais plus, plein de choses

master
DemiSel 2 years ago
parent
commit
08a0493684
5 changed files with 100 additions and 10 deletions
  1. 1
    0
      App.js
  2. 6
    2
      components/depense_edit/depense_form.js
  3. 18
    8
      components/depenses_list.js
  4. 64
    0
      components/list/day_list.js
  5. 11
    0
      utils/util.js

+ 1
- 0
App.js View File

43
           <DepensesList 
43
           <DepensesList 
44
             depensesFetched={() => onFetchDepenses(false)} 
44
             depensesFetched={() => onFetchDepenses(false)} 
45
             fetchDepenses={fetchDepenses} 
45
             fetchDepenses={fetchDepenses} 
46
+            dailyObjective={dailyObjective}
46
             durationMode={durationMode} />
47
             durationMode={durationMode} />
47
           <StatusBar hidden />
48
           <StatusBar hidden />
48
       </View>
49
       </View>

+ 6
- 2
components/depense_edit/depense_form.js View File

61
                         is24Hour={true}
61
                         is24Hour={true}
62
                         display="default"
62
                         display="default"
63
                         onChange={(event, value) => {
63
                         onChange={(event, value) => {
64
-                            onDatePicker(false);
65
-                            onDateChange(new Date(value));
64
+                            
65
+                            if(event.type != "dismissed")
66
+                            {
67
+                                onDatePicker(false);
68
+                                onDateChange(new Date(value));
69
+                            }else{onDatePicker(false);}
66
                         }}
70
                         }}
67
                         />
71
                         />
68
                     }
72
                     }

+ 18
- 8
components/depenses_list.js View File

1
 import React, { useEffect } from 'react';
1
 import React, { useEffect } from 'react';
2
-import { StyleSheet, Text, View, TextInput, FlatList, SafeAreaView  } from 'react-native';
2
+import { StyleSheet, Text, View, TextInput, FlatList, SafeAreaView, ColorPropType  } from 'react-native';
3
 import { ScrollView } from 'react-native-gesture-handler';
3
 import { ScrollView } from 'react-native-gesture-handler';
4
 import { sqlite_exec_query } from '../db/query';
4
 import { sqlite_exec_query } from '../db/query';
5
 import DepenseListEntry from './depense_list_entry';
5
 import DepenseListEntry from './depense_list_entry';
6
+import DayList from './list/day_list';
7
+
8
+var getDaysArray = function(s,e) {for(var a=[],d=new Date(s);d<=e;d.setDate(d.getDate()+1)){ a.push(new Date(d));}return a;};
6
 
9
 
7
 function DepensesList(props)
10
 function DepensesList(props)
8
 {
11
 {
23
 
26
 
24
     let content = []
27
     let content = []
25
 
28
 
26
-
27
     if(depenses.length > 0)
29
     if(depenses.length > 0)
28
     {
30
     {
29
         // get latest and oldest depense
31
         // get latest and oldest depense
31
         let oldest_depense = depenses[depenses.length - 1]
33
         let oldest_depense = depenses[depenses.length - 1]
32
         let curDate = new Date(latest_depense.date);
34
         let curDate = new Date(latest_depense.date);
33
         let oldestDate = new Date(oldest_depense.date);
35
         let oldestDate = new Date(oldest_depense.date);
34
-    }
35
-        depenses
36
-            .forEach( function(depense){
36
+
37
+        let days = getDaysArray(oldestDate, curDate ).reverse();
38
+        let days_disp = {};
39
+        days.forEach( (day) => {
40
+            // get depenses that are on the current day
41
+            var depenses_day = depenses.filter( obj => {return new Date(obj.date).getDate() == day.getDate()} )
37
             content.push(
42
             content.push(
38
-                <DepenseListEntry fetchDepenses={() => preventFetchDepenses(false)} key={"depense_list_depense"+depense.id} depense={depense}/>
39
-            )
43
+            <DayList 
44
+                dailyObjective={props.dailyObjective}
45
+                fetchDepenses={() => preventFetchDepenses(false)}
46
+                key={"day_list_"+day.toDateString()} 
47
+                date={day} 
48
+                depenses={depenses_day}/>)
40
         });
49
         });
41
-    
50
+    }
51
+
42
 
52
 
43
     return(
53
     return(
44
     <SafeAreaView>
54
     <SafeAreaView>

+ 64
- 0
components/list/day_list.js View File

1
+import React from 'react';
2
+import { StyleSheet, Text, View, TextInput, Alert, Pressable } from 'react-native';
3
+import DepenseListEntry from '../depense_list_entry';
4
+
5
+
6
+export default function DayList(props)
7
+{
8
+    const [ showDepenses, onToggleDepenses] = React.useState(true);
9
+    let content = []
10
+
11
+    let total = 0;
12
+
13
+    
14
+    props.depenses.forEach( function(depense){
15
+        content.push(
16
+            <DepenseListEntry fetchDepenses={props.fetchDepenses} key={"depense_list_depense"+depense.id} depense={depense}/>
17
+        )
18
+        total += depense.value;
19
+    });
20
+    
21
+
22
+    let result = props.dailyObjective - total 
23
+    let text_color = "#000000";
24
+    let bg_color = "#FFFFFF";
25
+    console.log(" "+props.dailyObjective +" - "+total +" = " + result)
26
+    if( result > 0)
27
+        text_color = "#00"+parseInt(100 + (result / props.dailyObjective) * 100).toString(16) + "00"
28
+    else
29
+        bg_color = "#FF"+
30
+            parseInt(255 + (result / props.dailyObjective) * 100).toString(16) + 
31
+            parseInt(255 + (result / props.dailyObjective) * 100).toString(16)
32
+
33
+    console.log(text_color)
34
+    return (
35
+        <View style={[day_list_styles.day_list_container, {backgroundColor: bg_color}]}>
36
+            <Pressable 
37
+                style={day_list_styles.day_list_entry}
38
+                onPress={() => {onToggleDepenses(!showDepenses)}}>
39
+            
40
+                <Text style={day_list_styles.day_list_day}>{props.date.toDateString()}</Text>
41
+                <Text style={[day_list_styles.day_list_day, {color: text_color}]}>{"Total : "+total}</Text>
42
+            </Pressable>
43
+            {showDepenses ? content : <View/>}
44
+        </View>
45
+    )
46
+}
47
+
48
+
49
+const day_list_styles = StyleSheet.create({
50
+    day_list_container: {
51
+        borderWidth: 1,
52
+        margin: 1,
53
+    },
54
+    day_list_entry: {
55
+        display: 'flex',
56
+        flexDirection: 'row',
57
+        justifyContent: 'space-between',
58
+        marginTop: 5,
59
+    },
60
+    day_list_day: {
61
+        fontWeight: '900',
62
+        margin: 4,
63
+    }
64
+});

+ 11
- 0
utils/util.js View File

1
+export function colorForUUID(iStrUUID)
2
+    {
3
+        return '#' + Util.zeroFill(( Math.abs( parseInt( iStrUUID.replace( "-", "" ), 16 )) % 16777215 ) & 0x1F0F3F , 6, '0' ).toString( 16 );
4
+    }
5
+
6
+export function zeroFill( number, width, padchar )
7
+    {
8
+        var pad_char = typeof padchar !== 'undefined' ? padchar : '0';
9
+        var pad = new Array(1 + width).join(pad_char);
10
+        return ( pad + number ).slice(-pad.length);
11
+    }

Loading…
Cancel
Save