mirror of
https://github.com/dgtlmoon/changedetection.io.git
synced 2025-12-12 02:55:43 +00:00
New major functionality CONDITIONS - Compare values, check numbers within range, etc
Some checks failed
Build and push containers / metadata (push) Waiting to run
Build and push containers / build-push-containers (push) Waiting to run
Publish Python 🐍distribution 📦 to PyPI and TestPyPI / Build distribution 📦 (push) Waiting to run
Publish Python 🐍distribution 📦 to PyPI and TestPyPI / Test the built 📦 package works basically. (push) Blocked by required conditions
Publish Python 🐍distribution 📦 to PyPI and TestPyPI / Publish Python 🐍 distribution 📦 to PyPI (push) Blocked by required conditions
ChangeDetection.io App Test / lint-code (push) Waiting to run
ChangeDetection.io App Test / test-application-3-10 (push) Blocked by required conditions
ChangeDetection.io App Test / test-application-3-11 (push) Blocked by required conditions
ChangeDetection.io App Test / test-application-3-12 (push) Blocked by required conditions
ChangeDetection.io App Test / test-application-3-13 (push) Blocked by required conditions
ChangeDetection.io Container Build Test / test-container-build (push) Has been cancelled
Some checks failed
Build and push containers / metadata (push) Waiting to run
Build and push containers / build-push-containers (push) Waiting to run
Publish Python 🐍distribution 📦 to PyPI and TestPyPI / Build distribution 📦 (push) Waiting to run
Publish Python 🐍distribution 📦 to PyPI and TestPyPI / Test the built 📦 package works basically. (push) Blocked by required conditions
Publish Python 🐍distribution 📦 to PyPI and TestPyPI / Publish Python 🐍 distribution 📦 to PyPI (push) Blocked by required conditions
ChangeDetection.io App Test / lint-code (push) Waiting to run
ChangeDetection.io App Test / test-application-3-10 (push) Blocked by required conditions
ChangeDetection.io App Test / test-application-3-11 (push) Blocked by required conditions
ChangeDetection.io App Test / test-application-3-12 (push) Blocked by required conditions
ChangeDetection.io App Test / test-application-3-13 (push) Blocked by required conditions
ChangeDetection.io Container Build Test / test-container-build (push) Has been cancelled
This commit is contained in:
150
changedetectionio/static/js/conditions.js
Normal file
150
changedetectionio/static/js/conditions.js
Normal file
@@ -0,0 +1,150 @@
|
||||
$(document).ready(function () {
|
||||
// Function to set up button event handlers
|
||||
function setupButtonHandlers() {
|
||||
// Unbind existing handlers first to prevent duplicates
|
||||
$(".addRuleRow, .removeRuleRow, .verifyRuleRow").off("click");
|
||||
|
||||
// Add row button handler
|
||||
$(".addRuleRow").on("click", function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
let currentRow = $(this).closest("tr");
|
||||
|
||||
// Clone without events
|
||||
let newRow = currentRow.clone(false);
|
||||
|
||||
// Reset input values in the cloned row
|
||||
newRow.find("input").val("");
|
||||
newRow.find("select").prop("selectedIndex", 0);
|
||||
|
||||
// Insert the new row after the current one
|
||||
currentRow.after(newRow);
|
||||
|
||||
// Reindex all rows
|
||||
reindexRules();
|
||||
});
|
||||
|
||||
// Remove row button handler
|
||||
$(".removeRuleRow").on("click", function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
// Only remove if there's more than one row
|
||||
if ($("#rulesTable tbody tr").length > 1) {
|
||||
$(this).closest("tr").remove();
|
||||
reindexRules();
|
||||
}
|
||||
});
|
||||
|
||||
// Verify rule button handler
|
||||
$(".verifyRuleRow").on("click", function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
let row = $(this).closest("tr");
|
||||
let field = row.find("select[name$='field']").val();
|
||||
let operator = row.find("select[name$='operator']").val();
|
||||
let value = row.find("input[name$='value']").val();
|
||||
|
||||
// Validate that all fields are filled
|
||||
if (!field || field === "None" || !operator || operator === "None" || !value) {
|
||||
alert("Please fill in all fields (Field, Operator, and Value) before verifying.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Create a rule object
|
||||
const rule = {
|
||||
field: field,
|
||||
operator: operator,
|
||||
value: value
|
||||
};
|
||||
|
||||
// Show a spinner or some indication that verification is in progress
|
||||
const $button = $(this);
|
||||
const originalHTML = $button.html();
|
||||
$button.html("⌛").prop("disabled", true);
|
||||
|
||||
// Collect form data - similar to request_textpreview_update() in watch-settings.js
|
||||
let formData = new FormData();
|
||||
$('#edit-text-filter textarea, #edit-text-filter input').each(function() {
|
||||
const $element = $(this);
|
||||
const name = $element.attr('name');
|
||||
if (name) {
|
||||
if ($element.is(':checkbox')) {
|
||||
formData.append(name, $element.is(':checked') ? $element.val() : false);
|
||||
} else {
|
||||
formData.append(name, $element.val());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Also collect select values
|
||||
$('#edit-text-filter select').each(function() {
|
||||
const $element = $(this);
|
||||
const name = $element.attr('name');
|
||||
if (name) {
|
||||
formData.append(name, $element.val());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Send the request to verify the rule
|
||||
$.ajax({
|
||||
url: verify_condition_rule_url+"?"+ new URLSearchParams({ rule: JSON.stringify(rule) }).toString(),
|
||||
type: "POST",
|
||||
data: formData,
|
||||
processData: false, // Prevent jQuery from converting FormData to a string
|
||||
contentType: false, // Let the browser set the correct content type
|
||||
success: function (response) {
|
||||
if (response.status === "success") {
|
||||
if (response.result) {
|
||||
alert("✅ Condition PASSES verification against current snapshot!");
|
||||
} else {
|
||||
alert("❌ Condition FAILS verification against current snapshot.");
|
||||
}
|
||||
} else {
|
||||
alert("Error: " + response.message);
|
||||
}
|
||||
$button.html(originalHTML).prop("disabled", false);
|
||||
},
|
||||
error: function (xhr) {
|
||||
let errorMsg = "Error verifying condition.";
|
||||
if (xhr.responseJSON && xhr.responseJSON.message) {
|
||||
errorMsg = xhr.responseJSON.message;
|
||||
}
|
||||
alert(errorMsg);
|
||||
$button.html(originalHTML).prop("disabled", false);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Function to reindex form elements and re-setup event handlers
|
||||
function reindexRules() {
|
||||
// Unbind all button handlers first
|
||||
$(".addRuleRow, .removeRuleRow, .verifyRuleRow").off("click");
|
||||
|
||||
// Reindex all form elements
|
||||
$("#rulesTable tbody tr").each(function(index) {
|
||||
$(this).find("select, input").each(function() {
|
||||
let oldName = $(this).attr("name");
|
||||
let oldId = $(this).attr("id");
|
||||
|
||||
if (oldName) {
|
||||
let newName = oldName.replace(/\d+/, index);
|
||||
$(this).attr("name", newName);
|
||||
}
|
||||
|
||||
if (oldId) {
|
||||
let newId = oldId.replace(/\d+/, index);
|
||||
$(this).attr("id", newId);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Reattach event handlers after reindexing
|
||||
setupButtonHandlers();
|
||||
}
|
||||
|
||||
// Initial setup of button handlers
|
||||
setupButtonHandlers();
|
||||
});
|
||||
Reference in New Issue
Block a user