Procházet zdrojové kódy

jsais plus, plein de choses

master
DemiSel před 3 roky
rodič
revize
08a0493684

+ 1
- 0
App.js Zobrazit soubor

@@ -43,6 +43,7 @@ export default function App() {
43 43
           <DepensesList 
44 44
             depensesFetched={() => onFetchDepenses(false)} 
45 45
             fetchDepenses={fetchDepenses} 
46
+            dailyObjective={dailyObjective}
46 47
             durationMode={durationMode} />
47 48
           <StatusBar hidden />
48 49
       </View>

+ 6
- 2
components/depense_edit/depense_form.js Zobrazit soubor

@@ -61,8 +61,12 @@ export default function DepenseForm(props){
61 61
                         is24Hour={true}
62 62
                         display="default"
63 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 Zobrazit soubor

@@ -1,8 +1,11 @@
1 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 3
 import { ScrollView } from 'react-native-gesture-handler';
4 4
 import { sqlite_exec_query } from '../db/query';
5 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 10
 function DepensesList(props)
8 11
 {
@@ -23,7 +26,6 @@ function DepensesList(props)
23 26
 
24 27
     let content = []
25 28
 
26
-
27 29
     if(depenses.length > 0)
28 30
     {
29 31
         // get latest and oldest depense
@@ -31,14 +33,22 @@ function DepensesList(props)
31 33
         let oldest_depense = depenses[depenses.length - 1]
32 34
         let curDate = new Date(latest_depense.date);
33 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 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 53
     return(
44 54
     <SafeAreaView>

+ 64
- 0
components/list/day_list.js Zobrazit soubor

@@ -0,0 +1,64 @@
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 Zobrazit soubor

@@ -0,0 +1,11 @@
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
+    }

Načítá se…
Zrušit
Uložit