ubah logic di eksekusi ANN agar ketika sudah diset di waktu tertentu maka otomatis akan mengirim pesan 1 ke topik tes/78220/topic/ANNeksekusi${kolamId} setiap waktu tersebut
Browse files- index.html +48 -25
index.html
CHANGED
|
@@ -1241,20 +1241,18 @@ margin-left: 5px;
|
|
| 1241 |
timeInput.type = 'time';
|
| 1242 |
timeInput.className = 'time-input';
|
| 1243 |
timeInput.id = `schedule-${i}-time`;
|
| 1244 |
-
|
| 1245 |
-
|
| 1246 |
-
|
| 1247 |
-
|
| 1248 |
-
|
| 1249 |
-
|
| 1250 |
-
|
| 1251 |
-
|
| 1252 |
-
|
| 1253 |
-
|
| 1254 |
-
}
|
| 1255 |
-
|
| 1256 |
-
|
| 1257 |
-
const wrapper = document.createElement('div');
|
| 1258 |
wrapper.className = 'flex flex-col gap-2';
|
| 1259 |
wrapper.appendChild(daySelect);
|
| 1260 |
wrapper.appendChild(timeInput);
|
|
@@ -1263,21 +1261,46 @@ margin-left: 5px;
|
|
| 1263 |
container.appendChild(wrapper);
|
| 1264 |
}
|
| 1265 |
}
|
| 1266 |
-
|
|
|
|
|
|
|
| 1267 |
function checkAndExecuteSchedule(day, time) {
|
| 1268 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1269 |
const days = ['minggu', 'senin', 'selasa', 'rabu', 'kamis', 'jumat', 'sabtu'];
|
| 1270 |
-
const
|
| 1271 |
-
const
|
|
|
|
|
|
|
|
|
|
| 1272 |
|
| 1273 |
-
|
| 1274 |
-
|
| 1275 |
-
|
| 1276 |
-
|
| 1277 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1278 |
}
|
| 1279 |
-
|
| 1280 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1281 |
function publish(topic, payload) {
|
| 1282 |
if (client.connected) {
|
| 1283 |
client.publish(topic, String(payload), publishOptions, (err) => {
|
|
|
|
| 1241 |
timeInput.type = 'time';
|
| 1242 |
timeInput.className = 'time-input';
|
| 1243 |
timeInput.id = `schedule-${i}-time`;
|
| 1244 |
+
const button = document.createElement('button');
|
| 1245 |
+
button.className = 'bg-blue-500 hover:bg-blue-600 text-white font-bold py-2 px-4 rounded';
|
| 1246 |
+
button.textContent = 'Set';
|
| 1247 |
+
button.onclick = function() {
|
| 1248 |
+
const day = daySelect.value;
|
| 1249 |
+
const time = timeInput.value;
|
| 1250 |
+
if (time) {
|
| 1251 |
+
// Setup automatic execution
|
| 1252 |
+
checkAndExecuteSchedule(day, time);
|
| 1253 |
+
}
|
| 1254 |
+
};
|
| 1255 |
+
const wrapper = document.createElement('div');
|
|
|
|
|
|
|
| 1256 |
wrapper.className = 'flex flex-col gap-2';
|
| 1257 |
wrapper.appendChild(daySelect);
|
| 1258 |
wrapper.appendChild(timeInput);
|
|
|
|
| 1261 |
container.appendChild(wrapper);
|
| 1262 |
}
|
| 1263 |
}
|
| 1264 |
+
// Store scheduled executions
|
| 1265 |
+
let scheduledExecutions = [];
|
| 1266 |
+
|
| 1267 |
function checkAndExecuteSchedule(day, time) {
|
| 1268 |
+
// Clear existing intervals
|
| 1269 |
+
scheduledExecutions.forEach(clearInterval);
|
| 1270 |
+
scheduledExecutions = [];
|
| 1271 |
+
|
| 1272 |
+
// Create new schedule
|
| 1273 |
const days = ['minggu', 'senin', 'selasa', 'rabu', 'kamis', 'jumat', 'sabtu'];
|
| 1274 |
+
const kolamId = document.getElementById('ann-kolam-select').value;
|
| 1275 |
+
const topic = `tes/78220/topic/ANNeksekusi${kolamId}`;
|
| 1276 |
+
|
| 1277 |
+
// Convert day to number (0=minggu, 1=senin, etc)
|
| 1278 |
+
const dayIndex = days.indexOf(day.toLowerCase());
|
| 1279 |
|
| 1280 |
+
// Set up interval to check every minute
|
| 1281 |
+
const intervalId = setInterval(() => {
|
| 1282 |
+
const now = new Date();
|
| 1283 |
+
// Convert to WIB (UTC+7)
|
| 1284 |
+
const wibTime = new Date(now.getTime() + (7 * 60 * 60 * 1000));
|
| 1285 |
+
|
| 1286 |
+
if (wibTime.getDay() === dayIndex &&
|
| 1287 |
+
wibTime.getHours() === parseInt(time.split(':')[0]) &&
|
| 1288 |
+
wibTime.getMinutes() === parseInt(time.split(':')[1])) {
|
| 1289 |
+
|
| 1290 |
+
publish(topic, '1');
|
| 1291 |
+
showNotification('safe', 'ANN Executed', `Jadwal ANN Kolam ${kolamId} telah dieksekusi otomatis`);
|
| 1292 |
+
}
|
| 1293 |
+
}, 60000); // Check every minute
|
| 1294 |
+
|
| 1295 |
+
scheduledExecutions.push(intervalId);
|
| 1296 |
+
showNotification('safe', 'Schedule Set', `ANN akan dieksekusi otomatis setiap ${day} pukul ${time}`);
|
| 1297 |
}
|
| 1298 |
+
|
| 1299 |
+
// Initialize with empty array
|
| 1300 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 1301 |
+
scheduledExecutions = [];
|
| 1302 |
+
});
|
| 1303 |
+
// ========== HELPER FUNCTIONS ==========
|
| 1304 |
function publish(topic, payload) {
|
| 1305 |
if (client.connected) {
|
| 1306 |
client.publish(topic, String(payload), publishOptions, (err) => {
|