-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
banners now configuable in admin interface
- Loading branch information
Thomas Hanke
committed
Jan 30, 2025
1 parent
8f4a8f2
commit e0db305
Showing
10 changed files
with
348 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,65 @@ | ||
ckan.module("matolabtheme-module", function ($, _) { | ||
"use strict"; | ||
return { | ||
options: { | ||
debug: false, | ||
}, | ||
initialize: function () { | ||
console.log("Initialized Counter Animation for element: ", this.el); | ||
'use strict'; | ||
|
||
const updateCounter = (counter, targetValue) => { | ||
counter.innerText = "0"; // Start the counter from 0 | ||
counter.setAttribute("data-target", targetValue); // Update data-target attribute | ||
ckan.module('matolabtheme-module', function ($) { | ||
return { | ||
initialize: function () { | ||
console.log('matolabtheme-module initialized!'); | ||
console.log('Element:', this.el); | ||
|
||
const duration = +counter.getAttribute("data-duration") * 1000; | ||
const increment = targetValue / (duration / 10); | ||
let count = 0; | ||
const updateCounter = (counter, targetValue) => { | ||
counter.innerText = '0'; // Start the counter from 0 | ||
counter.setAttribute('data-target', targetValue); // Update data-target attribute | ||
|
||
const animate = () => { | ||
count += increment; | ||
const duration = +counter.getAttribute('data-duration') * 1000; | ||
const increment = targetValue / (duration / 10); | ||
let count = 0; | ||
|
||
if (count >= targetValue) { | ||
counter.innerText = targetValue; // Final value | ||
} else { | ||
counter.innerText = Math.ceil(count); // Animated value | ||
requestAnimationFrame(animate); | ||
} | ||
}; | ||
const animate = () => { | ||
count += increment; | ||
|
||
requestAnimationFrame(animate); | ||
}; | ||
if (count >= targetValue) { | ||
counter.innerText = targetValue; // Final value | ||
} else { | ||
counter.innerText = Math.ceil(count); // Animated value | ||
requestAnimationFrame(animate); | ||
} | ||
}; | ||
|
||
const fetchAndAnimateCounter = async () => { | ||
const apiUrl = this.el.get(0).getAttribute("data-api-url"); // Fetch the API URL from the parent element | ||
if (!apiUrl) { | ||
console.error("No API URL specified for counter:", this.el); | ||
return; | ||
} | ||
requestAnimationFrame(animate); | ||
}; | ||
|
||
try { | ||
const response = await $.getJSON(apiUrl); | ||
let datasetCount = 0; // Count of datasets | ||
let totalResources = 0; // Sum of all resources | ||
const organizations = new Set(); // To store unique organizations | ||
let orgCount = 0; // Sum of organisations | ||
const fetchAndAnimateCounter = async () => { | ||
const apiUrl = this.el.get(0).getAttribute('data-api-url'); | ||
if (!apiUrl) { | ||
console.error('No API URL specified for counter:', this.el); | ||
return; | ||
} | ||
|
||
// Check if the response is successful and contains results | ||
if (response && typeof response === 'object'){ | ||
datasetCount = response.pkg_count; // Count of datasets | ||
try { | ||
const response = await $.getJSON(apiUrl); | ||
let datasetCount = 0; | ||
let totalResources = 0; | ||
let orgCount = 0; | ||
|
||
// Calculate total resources using num_resources property | ||
totalResources=response.res_count; | ||
orgCount=response.org_count; | ||
} else { | ||
console.error("Invalid API response structure:", response); | ||
} | ||
if (response && response.success && response.result) { | ||
const result = response.result; | ||
// Count datasets, resources, and organizations | ||
datasetCount = result.pkg_count || 0; // `pkg_count` for datasets | ||
totalResources = result.res_count || 0; // `res_count` for resources | ||
orgCount = result.org_count || 0; // `org_count` for organizations | ||
} else { | ||
console.error('Invalid API response structure:', response); | ||
} | ||
|
||
// Update and animate the counters independently | ||
updateCounter(document.getElementById("dataset_counter"), datasetCount); // For datasets | ||
updateCounter(document.getElementById("resource_counter"), totalResources); // For resources | ||
updateCounter(document.getElementById("orgs_counter"), orgCount); // For unique organizations | ||
} catch (error) { | ||
console.error(`API request to ${apiUrl} failed:`, error); | ||
} | ||
}; | ||
updateCounter(document.getElementById('dataset_counter'), datasetCount); | ||
updateCounter(document.getElementById('resource_counter'), totalResources); | ||
updateCounter(document.getElementById('orgs_counter'), orgCount); | ||
} catch (error) { | ||
console.error(`API request to ${apiUrl} failed:`, error); | ||
} | ||
}; | ||
|
||
// Fetch and animate the counters | ||
fetchAndAnimateCounter(); // Call the function to fetch and animate counters | ||
|
||
// Animate individual counters (if needed) | ||
const counters = this.el.get(0).querySelectorAll(".theme-counter"); | ||
counters.forEach(counter => { | ||
updateCounter(counter, 0); // Initialize counters to 0 | ||
}); | ||
}, | ||
}; | ||
}); | ||
fetchAndAnimateCounter(); | ||
}, | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,27 @@ | ||
$(document).ready(function () { | ||
// Attach keypress listener to all forms | ||
let hoveredForm = null; | ||
|
||
// Track which form the mouse is currently over | ||
$(document).on('mouseenter', 'form', function () { | ||
hoveredForm = $(this); | ||
}); | ||
|
||
$(document).on('mouseleave', 'form', function () { | ||
hoveredForm = null; | ||
}); | ||
|
||
// Listen for Shift + Enter keypress | ||
$(document).on('keydown', function (event) { | ||
if (event.shiftKey && event.key === 'Enter') { | ||
event.preventDefault(); // Prevent any default behavior | ||
// Find the submit button across the entire page or near the current active element | ||
const button = $(event.target).closest('form').find('.form-actions button[type="submit"]').first(); | ||
event.preventDefault(); // Prevent default behavior | ||
|
||
// Find the submit button in the hovered form (or the focused form) | ||
const form = hoveredForm || $(event.target).closest('form'); | ||
const button = form.find('.form-actions button[type="submit"]').last(); | ||
|
||
if (button.length) { | ||
button.click(); // Trigger the button's click event | ||
} | ||
button.click(); // Trigger the button's click event | ||
} | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{% ckan_extends %} | ||
{% block admin_form_help %} | ||
{{super()}} | ||
{{data}} | ||
<p><strong>Banner Config:</strong> You can change the banners for top and bottom here </p> | ||
{% link_for _('Banner Config'), named_route='matolabtheme.banner_config', class_='btn btn-secondary', icon='upload' %} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.