@@ -4,38 +4,38 @@ document.getElementById('staticBackdrop').addEventListener('show.bs.modal',(even
4
4
var button = event . relatedTarget ;
5
5
//get the data of the result box we clicked
6
6
var details = {
7
- //save the useful data as key-value pairs
8
- "Weight" : button . getAttribute ( 'data-weight' ) , "BMI" :button . getAttribute ( 'data-bmi' ) ,
9
- "Waist-circ" :button . getAttribute ( 'data-waist' ) , "Oxymetry" : button . getAttribute ( "data-oxymetry" ) ,
10
- "Grain" : button . getAttribute ( "data-grain" ) , "Fruit" : button . getAttribute ( 'data-fruit' ) ,
11
- "Vegetables" :button . getAttribute ( 'data-vegan' ) , "Dairy" : button . getAttribute ( 'data-dairy' ) ,
12
- "Protein" :button . getAttribute ( 'data-protein' ) , "Total Calories" :button . getAttribute ( "data-total_cal" ) ,
13
- "Date" :button . getAttribute ( 'data-dt' ) , "Risk probability" :button . getAttribute ( 'data-prob' ) } ;
7
+ //save the useful data as key-value pairs
8
+ "Weight" : button . getAttribute ( 'data-weight' ) , "BMI" :button . getAttribute ( 'data-bmi' ) ,
9
+ "Waist-circ" :button . getAttribute ( 'data-waist' ) , "Oxymetry" : button . getAttribute ( "data-oxymetry" ) ,
10
+ "Grain" : button . getAttribute ( "data-grain" ) , "Fruit" : button . getAttribute ( 'data-fruit' ) ,
11
+ "Vegetables" :button . getAttribute ( 'data-vegan' ) , "Dairy" : button . getAttribute ( 'data-dairy' ) ,
12
+ "Protein" :button . getAttribute ( 'data-protein' ) , "Total Calories" :button . getAttribute ( "data-total_cal" ) ,
13
+ "Date" :button . getAttribute ( 'data-dt' ) , "Risk probability" :button . getAttribute ( 'data-prob' ) } ;
14
14
var list = document . getElementById ( 'display-card' ) . children [ 1 ] //select the list which lies inside display card
15
15
list . style . setProperty ( 'list-style' , 'none' , 'important' ) //remove li dots
16
16
var display_card = document . getElementById ( 'display-card' ) ;
17
17
// select the display card
18
- let color = details [ 'Risk probability' ] < 0.5 ?"lightgreen" :"coral"
18
+ let color = details [ 'Risk probability' ] < 0.3 ?"lightgreen" :"coral"
19
19
display_card . style . setProperty ( "background-color" , color , "important" ) ;
20
20
console . log ( list ) ;
21
21
console . log ( display_card ) ;
22
22
for ( [ key , value ] of Object . entries ( details ) ) {
23
- //for every key-value pair inside our dictionary
24
- var list_item = document . createElement ( 'li' ) ;
25
- // create a list element
26
- list_item . appendChild ( document . createTextNode ( "" + key + ": " + value + "" ) ) ;
27
- //put the useful data context inside list_item
28
- list . appendChild ( list_item ) ;
29
- // finally append the element to the list parent
23
+ //for every key-value pair inside our dictionary
24
+ var list_item = document . createElement ( 'li' ) ;
25
+ // create a list element
26
+ list_item . appendChild ( document . createTextNode ( "" + key + ": " + value + "" ) ) ;
27
+ //put the useful data context inside list_item
28
+ list . appendChild ( list_item ) ;
29
+ // finally append the element to the list parent
30
30
}
31
31
}
32
- )
32
+ )
33
33
//case we close the modal, it is critical to delete the list content in order accomondate the next result context without problem ;)
34
34
document . getElementById ( 'staticBackdrop' ) . addEventListener ( 'hide.bs.modal' , ( event ) => {
35
35
var list = document . getElementById ( 'display-card' ) . children [ 1 ]
36
36
list . innerHTML = "" ;
37
37
}
38
- )
38
+ )
39
39
//this is the view button, it has 2 functionalities
40
40
document . getElementById ( 'iy4ml' ) . onclick = ( event ) => {
41
41
document . getElementById ( 'history-container' ) . style . setProperty ( 'display' , 'inline-block' , 'important' ) ;
@@ -50,82 +50,36 @@ readlocalstorage()
50
50
function readlocalstorage ( ) {
51
51
var retrievedata = JSON . parse ( localStorage . getItem ( 'records' ) )
52
52
if ( retrievedata === null ) {
53
- const kouti = document . getElementById ( 'history-container' )
54
- kouti . children [ 0 ] . remove ( ) ;
55
- console . log ( "empty array" ) }
53
+ const kouti = document . getElementById ( 'history-container' )
54
+ kouti . children [ 0 ] . remove ( ) ;
55
+ console . log ( "empty array" ) }
56
56
else {
57
- const container = document . getElementById ( 'history-container' ) ;
58
- const record = document . getElementById ( 'history-record' ) ;
59
- if ( ! Array . isArray ( retrievedata ) ) {
60
- retrievedata = [ retrievedata ]
61
- }
62
- //retrieve data and save each record value to its appropriate data-* attributes
63
- retrievedata . forEach ( element => {
64
- const clone = record . cloneNode ( true ) ;
65
- for ( const [ key , value ] of Object . entries ( element ) ) {
66
- clone . setAttribute ( 'data-' + key + '' , '' + value + '' ) ;
67
- if ( clone . getAttribute ( 'data-prob' ) < 0.5 ) {
68
- //some coloring depending on result
69
- clone . style . setProperty ( 'background-color' , 'lightgreen' , 'important' ) ;
70
- }
71
- else {
72
- //clone the style for every box-result element
73
- clone . style . setProperty ( 'border-color' , 'coral' , 'important' ) ;
74
- clone . style . setProperty ( 'background-color' , 'coral' , 'important' ) ;
75
- }
76
- }
77
- //as button label place the probability
78
- clone . textContent = clone . getAttribute ( 'data-prob' ) ;
79
- container . appendChild ( clone ) ;
80
- console . log ( element )
81
- }
82
- ) ;
83
- container . children [ 0 ] . remove ( )
57
+ const container = document . getElementById ( 'history-container' ) ;
58
+ const record = document . getElementById ( 'history-record' ) ;
59
+ if ( ! Array . isArray ( retrievedata ) ) {
60
+ retrievedata = [ retrievedata ]
61
+ }
62
+ //retrieve data and save each record value to its appropriate data-* attributes
63
+ retrievedata . forEach ( element => {
64
+ const clone = record . cloneNode ( true ) ;
65
+ for ( const [ key , value ] of Object . entries ( element ) ) {
66
+ clone . setAttribute ( 'data-' + key + '' , '' + value + '' ) ;
67
+ if ( clone . getAttribute ( 'data-prob' ) < 0.5 ) {
68
+ //some coloring depending on result
69
+ clone . style . setProperty ( 'background-color' , 'lightgreen' , 'important' ) ;
70
+ }
71
+ else {
72
+ //clone the style for every box-result element
73
+ clone . style . setProperty ( 'border-color' , 'coral' , 'important' ) ;
74
+ clone . style . setProperty ( 'background-color' , 'coral' , 'important' ) ;
75
+ }
76
+ }
77
+ //as button label place the probability
78
+ clone . textContent = clone . getAttribute ( 'data-prob' ) ;
79
+ container . appendChild ( clone ) ;
80
+ console . log ( element )
81
+ }
82
+ ) ;
83
+ container . children [ 0 ] . remove ( )
84
84
}
85
85
}
86
- document . getElementById ( 'hide-button' ) . onclick = ( event ) => {
87
- document . getElementById ( 'history-container' ) . style . setProperty ( 'display' , 'none' , 'important' ) ;
88
- } ;
89
- document . getElementById ( 'delete-history-button' ) . onclick = ( event ) => {
90
- document . getElementById ( 'history-container' ) . remove ( ) ;
91
- localStorage . removeItem ( 'records' ) ;
92
- document . getElementById ( 'footer' ) . style . setProperty ( 'position' , 'relative' , 'important' ) ;
93
- } ;
94
- document . getElementById ( 'ip1e' ) . onclick = ( event ) => {
95
- event . preventDefault ( ) ;
96
- {
97
- window . document . location = '/' ;
98
- }
99
- } ;
100
- document . getElementById ( 'izxo' ) . onclick = ( event ) => {
101
- event . preventDefault ( ) ;
102
- {
103
- window . document . location = '/' ;
104
- }
105
- } ;
106
- document . getElementById ( 'itked' ) . onclick = ( event ) => {
107
- event . preventDefault ( ) ;
108
- {
109
- window . document . location = '/assess/' ;
110
- }
111
- } ;
112
- document . getElementById ( 'i5z9m' ) . onclick = ( event ) => {
113
- event . preventDefault ( ) ;
114
- {
115
- window . document . location = '/history/' ;
116
- }
117
- } ;
118
- document . getElementById ( 'ijxfk' ) . onclick = ( event ) => {
119
- event . preventDefault ( ) ;
120
- {
121
- window . document . location = '/upload/' ;
122
- }
123
- } ;
124
- document . getElementById ( 'i04p6' ) . onclick = ( event ) => {
125
- event . preventDefault ( ) ;
126
- {
127
- window . document . location = '/upload/' ;
128
- }
129
- } ;
130
- window . onload = ( ) => {
131
- } ;
0 commit comments