-
Notifications
You must be signed in to change notification settings - Fork 1
/
objetives.html
242 lines (214 loc) · 11 KB
/
objetives.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Nutrição em um olhar</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"
integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"
integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy"
crossorigin="anonymous"></script>
<!-- Bootstrap Icons -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
<!-- Folha de estilos -->
<link rel="stylesheet" href="style.css">
<!-- Fontes -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link
href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;1,300;1,400;1,500;1,600;1,700;1,800&display=swap"
rel="stylesheet">
<!-- Importar scripts do Firebase -->
<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.22.1/firebase-app.js";
import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.22.1/firebase-analytics.js";
import { getAuth, createUserWithEmailAndPassword, signInWithEmailAndPassword } from "https://www.gstatic.com/firebasejs/9.22.1/firebase-auth.js";
import { getFirestore, doc, setDoc, getDoc } from "https://www.gstatic.com/firebasejs/9.22.1/firebase-firestore.js";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
apiKey: "AIzaSyAhS7zhyXHLNGLpQ9saPZZg8Aol8jWaGPA",
authDomain: "nutricao-em-um-olhar.firebaseapp.com",
projectId: "nutricao-em-um-olhar",
storageBucket: "nutricao-em-um-olhar.appspot.com",
messagingSenderId: "101019466395",
appId: "1:101019466395:web:d22a7fda84e635e544243e",
measurementId: "G-MNX0D151MB"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
const auth = getAuth();
const db = getFirestore(app);
// Signed in
const user_uid = localStorage.getItem('user');
console.log(user_uid);
const confirmar_elemente = document.getElementById('confirmar');
confirmar_elemente.addEventListener('click', confirmar);
// Recupera os dados do usuário
const docRef = doc(db, "user", user_uid);
getDoc(docRef)
.then((docSnap) => {
// Recupera os dados do documento (testes)
if (docSnap.exists()) {
if (docSnap.data()["initial"] == false) {
let fieldIds = ["weight", "daily_calories", "carbs_percent", "lipids_percent", "protein_percent", "tolerance"];
fieldIds.forEach(function (fieldId) {
// Define o valor do elemento como o valor no banco de dados
document.getElementById(fieldId).value = docSnap.data()[fieldId];
});
}
} else {
console.log("No such document!");
}
})
.catch((error) => {
console.error("Erro ao recuperar os dados:", error);
});
function confirmar() {
var fieldIds = ["weight", "daily_calories", "carbs_percent", "lipids_percent", "protein_percent", "tolerance"];
var data = {};
fieldIds.forEach(function (fieldId) {
var value = parseInt(document.getElementById(fieldId).value);
if (isNaN(value)) {
var placeholder = document.getElementById(fieldId).placeholder;
data[fieldId] = placeholder;
} else {
data[fieldId] = value;
}
});
// Cria (ou atualiza) o documento para o usuário no Firestore
setDoc(doc(db, "user", user_uid, "current_data"), {
weight: data["weight"],
daily_calories: data["daily_calories"],
carbs_percent: data["carbs_percent"],
lipids_percent: data["lipids_percent"],
protein_percent: data["protein_percent"],
tolerance: data["tolerance"],
initial: 1
})
.then(() => {
// Operação de gravação concluída com sucesso
// Troca para a página app.html
// window.location.href = "app.html";
// Muda para a página app.html
window.location.href = "app.html";
/*
// Recupera os dados do usuário
const docRef = doc(db, "user", user_uid);
getDoc(docRef)
.then((docSnap) => {
// Recupera os dados do documento (testes)
if (docSnap.exists()) {
console.log("Document data:", docSnap.data());
} else {
console.log("No such document!");
}
// // Muda para a página app.html
// window.location.href = "app.html";
})
.catch((error) => {
console.error("Erro ao recuperar os dados:", error);
});
*/
})
.catch((error) => {
// Ocorreu um erro ao gravar no Firestore
console.error("Erro ao criar o documento: ", error);
});
}
</script>
</head>
<body>
<!-- Título da página -->
<div class="row justify-content-center principal_container">
<div class="col">
<!-- Logo da página -->
</div>
<div class="col-md-auto">
<div class="row justify-content-center">
<!-- Título -->
<h1>NUTRIÇÃO EM UM OLHAR</h1>
</div>
</div>
<div class="col">
<div class="row justify-content-center align-items-center">
<!-- Drop down menu com a opção que leva a página de atualização de dados (objetives) -->
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<button class="navbar-toggler custom-toggler" type="button" data-toggle="collapse"
data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<i class="bi bi-justify custom-toggler-icon"></i>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="bi bi-justify"></i>
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="app.html">App</a>
<a class="dropdown-item" href="objetives.html">Atualizar dados</a>
<a class="dropdown-item" href="tutorial.html">Tutorial</a>
<a class="dropdown-item" href="about.html">Sobre</a>
</div>
</li>
</ul>
</div>
</nav>
</div>
</div>
</div>
<!-- Formulário de Inserção de dados -->
<form>
<div class="row justify-content-center">
<div class="col-md-4 principal_container">
<div class="form-group">
<label for="weight">Peso (Kg)</label>
<input type="number" class="form-control" id="weight" placeholder="70.00">
</div>
<div class="form-group">
<label for="daily_calories">Calorias Diárias (Kcal)</label>
<input type="number" class="form-control" id="daily_calories" placeholder="2000">
</div>
<div class="form-group">
<label for="carbs_percent">Percentual de Carboidratos (%)</label>
<input type="number" class="form-control" id="carbs_percent" placeholder="50">
</div>
<div class="form-group">
<label for="lipids_percent">Percentual de Lipídios (%)</label>
<input type="number" class="form-control" id="lipids_percent" placeholder="25">
</div>
<div class="form-group">
<label for="protein_percent">Percentual de Proteínas (%)</label>
<input type="number" class="form-control" id="protein_percent" placeholder="25">
</div>
<div class="form-group">
<label for="protein_percent">Tolerância (%)</label>
<input type="number" class="form-control" id="tolerance" placeholder="10">
</div>
<div class="row">
<div class="col text-center">
<button class="btn btn-primary" type="button" id="confirmar">Confirmar</button>
</div>
</div>
</div>
</div>
</form>
<!-- Se você precisar adicionar algum script adicional, coloque-o aqui -->
<script>
// Coloque scripts adicionais aqui, se necessário
</script>
</body>
</html>