forked from hngi/Poseidon-Solar-Calculator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolar.js
210 lines (145 loc) · 5.27 KB
/
solar.js
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
const addBtn = document.querySelector('#btn');
let applianceValue = document.querySelector('#appliance_input');
let quantityValue = document.querySelector('#quantity_input');
let powerValue = document.querySelector('#power_input');
let timeValue = document.querySelector('#power_hr');
let tbody = document.querySelector(".app-list");
let result = document.querySelector("#result_num");
let email = document.querySelector("#email")
let butSend = document.querySelector(".but-send")
let daily = document.querySelector("#but-daily");
let weekly = document.querySelector("#but-week");
let monthly = document.querySelector("#but-month");
let total = 0
let total1 = 0
let total2 = 0
let total3 = 0
function click(evt) {
if (applianceValue.validity.valid && quantityValue.validity.valid
&& powerValue.validity.valid && timeValue.validity.valid) {
let td1 = document.createElement("span");
let td2 = document.createElement("span");
let td3 = document.createElement("span");
let td4 = document.createElement("span");
let td5 = document.createElement("span");
let div = document.createElement("div")
td1.textContent = applianceValue.value
td1.classList.add("space")
td2.textContent = quantityValue.value + " qty"
td2.classList.add("space")
td3.textContent = powerValue.value + " Watts"
td3.classList.add("space")
td4.textContent = timeValue.value + ' hr'
td4.classList.add("space")
td5.textContent = "X"
td5.classList.add("space")
td5.classList.add("delete")
div.appendChild(td1)
div.appendChild(td2)
div.appendChild(td3)
div.appendChild(td4)
div.appendChild(td5)
div.classList.add("div")
tbody.append(div)
applianceValue.value = ""
quantityValue.value = ""
powerValue.value = ""
timeValue.value = ""
value("daily")
}
}
const value = (data) => {
let allValue = document.querySelectorAll(".div")
let list = Array.from(allValue)
total = 0
for (let i = 0; i < list.length; i++){
let sum = list[i].children[1].textContent;
let sum2 = list[i].children[2].textContent;
let sum3 = list[i].children[3].textContent;
console.log(sum3)
let sumvalue = sum.split(" ")[0];
let sumvalue2 = sum2.split(" ")[0];
let sumvalue3 = sum3.split(" ")[0];
if (data === "daily"){
let num = sumvalue * sumvalue2 * sumvalue3
total += num
}
if (data === "weekly"){
let num = sumvalue * sumvalue2 * sumvalue3 * 7
console.log(sumvalue,sumvalue2)
total += num
}
if (data === "monthly") {
let num = sumvalue * sumvalue2 * sumvalue3 * 28
total += num
}
}
if (data === "weekly"){
document.querySelector(".but-active").classList.remove("but-active")
weekly.classList.add("but-active")
}
if (data === "monthly"){
document.querySelector(".but-active").classList.remove("but-active")
monthly.classList.add("but-active")
}
if (data === "daily"){
document.querySelector(".but-active").classList.remove("but-active")
daily.classList.add("but-active")
}
result.textContent = total
}
const deleteValue = (evt) => {
console.log(evt.target)
if (evt.target.className === "space delete"){
console.log("yes")
const vv = evt.target.parentNode
tbody.removeChild(vv)
value("daily")
}
}
const sendMail = () => {
let allValue = document.querySelectorAll(".div")
let list = Array.from(allValue)
total1 = 0
total2 = 0
total3 = 0
for (let i = 0; i < list.length; i++){
let sum = list[i].children[1].textContent;
let sum2 = list[i].children[2].textContent;
let sum3 = list[i].children[3].textContent;
let sumvalue = sum.split(" ")[0];
let sumvalue2 = sum2.split(" ")[0];
let sumvalue3 = sum3.split(" ")[0];
let num1 = sumvalue * sumvalue2 * sumvalue3
total1 += num1
let num2 = sumvalue * sumvalue2 * 7
total2 += num2
let num3 = sumvalue * sumvalue2 * 28
total3 += num3
}
const data = `The Daily Solar Consumption for your appliances is ${total1} watt`
const data1 = `The Weekly Solar Consumption for your appliances is ${total2} watt`
const data2 = `The Monthly Solar Consumption for your appliances is ${total3} watt`
var templateParams = {
message1: data,
message2: data1,
message3: data2,
email: email.value
};
emailjs.send('gmail', 'contact_form', templateParams, "user_uINuNBjAvZ4Re6NBn6W7K")
.then(function(response) {
console.log('SUCCESS!', response.status, response.text);
alert("Results Sent Successfully")
}, function(error) {
console.log('FAILED...', error);
});
email.value = ""
tbody.innerHTML = ""
result.textContent = 0
}
addBtn.addEventListener('click', click);
daily.addEventListener('click', () => ( value("daily") ))
weekly.addEventListener('click', () => ( value("weekly") ))
monthly.addEventListener('click', () => ( value("monthly") ))
tbody.addEventListener('click', deleteValue)
butSend.addEventListener("click", sendMail)