Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

187 refactor notification module #193

Merged
merged 17 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Entirety/.env.EXAMPLE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Application Load
ENTITIES_LOAD=True
DEVICES_LOAD=True
NOTIFICATIONS_LOAD=True
SUBSCRIPTIONS_LOAD=True
SEMANTICS_LOAD=True

# Database
Expand Down
2 changes: 1 addition & 1 deletion app/Entirety/projects/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def get_context_data(self, **kwargs):

context["entities_load"] = apps.is_installed("entities")
context["devices_load"] = apps.is_installed("devices")
context["notifications_load"] = apps.is_installed("subscriptions")
context["subscriptions_load"] = apps.is_installed("subscriptions")
context["semantics_load"] = apps.is_installed("semantics")
# TODO change the tag if data model module
context["smart_datamodels_load"] = apps.is_installed(
Expand Down
162 changes: 162 additions & 0 deletions app/Entirety/static/js/subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,165 @@ function removeEntity(event) {
});
}
}

function showMqttSection() {
var mqtt = document.getElementById('mqtt');
var mqttCustom = document.getElementById('mqttCustom');
var http = document.getElementById('http');
var httpCustom = document.getElementById('httpCustom');

// Show only MQTT section
mqtt.classList.remove('d-none');
mqtt.classList.add('d-block');

// Hide HTTP and other sections
http.classList.add('d-none');
http.classList.remove('d-block');
httpCustom.classList.add('d-none');
httpCustom.classList.remove('d-block');
mqttCustom.classList.add('d-none');
mqttCustom.classList.remove('d-block');

// Enable only MQTT inputs
mqtt.querySelectorAll('input, select, textarea').forEach(function (input) {
input.disabled = false;
});
mqttCustom.querySelectorAll('input, select, textarea').forEach(function (input) {
input.disabled = true;
});
http.querySelectorAll('input, select, textarea').forEach(function (input) {
input.disabled = true;
});
httpCustom.querySelectorAll('input, select, textarea').forEach(function (input) {
input.disabled = true;
});
}

function showMqttCustomSection() {
var mqtt = document.getElementById('mqtt');
var mqttCustom = document.getElementById('mqttCustom');
var http = document.getElementById('http');
var httpCustom = document.getElementById('httpCustom');

// Show only MQTT Custom section
mqttCustom.classList.remove('d-none');
mqttCustom.classList.add('d-block');

// Hide other sections
mqtt.classList.add('d-none');
mqtt.classList.remove('d-block');
http.classList.add('d-none');
http.classList.remove('d-block');
httpCustom.classList.add('d-none');
httpCustom.classList.remove('d-block');

// Enable only MQTT Custom inputs
mqtt.querySelectorAll('input, select, textarea').forEach(function (input) {
input.disabled = true;
});
mqttCustom.querySelectorAll('input, select, textarea').forEach(function (input) {
input.disabled = false;
});
http.querySelectorAll('input, select, textarea').forEach(function (input) {
input.disabled = true;
});
httpCustom.querySelectorAll('input, select, textarea').forEach(function (input) {
input.disabled = true;
});
}

function showHttpSection() {
var mqtt = document.getElementById('mqtt');
var mqttCustom = document.getElementById('mqttCustom');
var http = document.getElementById('http');
var httpCustom = document.getElementById('httpCustom');

// Show only HTTP section
http.classList.remove('d-none');
http.classList.add('d-block');

// Hide other sections
mqtt.classList.add('d-none');
mqtt.classList.remove('d-block');
mqttCustom.classList.add('d-none');
mqttCustom.classList.remove('d-block');
httpCustom.classList.add('d-none');
httpCustom.classList.remove('d-block');

// Enable only HTTP inputs
http.querySelectorAll('input, select, textarea').forEach(function (input) {
input.disabled = false;
});
mqtt.querySelectorAll('input, select, textarea').forEach(function (input) {
input.disabled = true;
});
mqttCustom.querySelectorAll('input, select, textarea').forEach(function (input) {
input.disabled = true;
});
httpCustom.querySelectorAll('input, select, textarea').forEach(function (input) {
input.disabled = true;
});
}

function showHttpCustomSection() {
var mqtt = document.getElementById('mqtt');
var mqttCustom = document.getElementById('mqttCustom');
var http = document.getElementById('http');
var httpCustom = document.getElementById('httpCustom');

// Show only HTTP Custom section
httpCustom.classList.remove('d-none');
httpCustom.classList.add('d-block');

// Hide other sections
mqtt.classList.add('d-none');
mqtt.classList.remove('d-block');
mqttCustom.classList.add('d-none');
mqttCustom.classList.remove('d-block');
http.classList.add('d-none');
http.classList.remove('d-block');

// Enable only HTTP Custom inputs
httpCustom.querySelectorAll('input, select, textarea').forEach(function (input) {
input.disabled = false;
});
mqtt.querySelectorAll('input, select, textarea').forEach(function (input) {
input.disabled = true;
});
mqttCustom.querySelectorAll('input, select, textarea').forEach(function (input) {
input.disabled = true;
});
http.querySelectorAll('input, select, textarea').forEach(function (input) {
input.disabled = true;
});
}

function handleEndpointTypeChange(endpointType) {
if (endpointType.value === 'mqtt') {
showMqttSection();
} else if (endpointType.value === 'mqttCustom') {
showMqttCustomSection();
} else if (endpointType.value === 'http') {
showHttpSection();
} else if (endpointType.value === 'httpCustom') {
showHttpCustomSection();
}
}

document.addEventListener('DOMContentLoaded', function () {
var endpointType = document.getElementById('id_endpoint_type');

// Run appropriate function on page load
handleEndpointTypeChange(endpointType);

// Attach change event listener to dropdown
endpointType.addEventListener('change', function () {
handleEndpointTypeChange(this);
});
});

// Handle back/forward navigation using the pageshow event
window.addEventListener('pageshow', function () {
var endpointType = document.getElementById('id_endpoint_type');
handleEndpointTypeChange(endpointType);
});
Loading