From 9e9e4a4da454fe23c595d6bab48b5ddd4280b8a6 Mon Sep 17 00:00:00 2001 From: Mohammed Minhajuddin <68331751+minhajuddin2510@users.noreply.github.com> Date: Fri, 2 May 2025 14:45:58 -0400 Subject: [PATCH 1/6] added popover for DRUF --- .../assets/js/scheming-suggestions.js | 241 ++++++++++ ckanext/scheming/assets/resource.config | 1 + ckanext/scheming/assets/styles/scheming.css | 444 ++++++++++++++++++ ckanext/scheming/assets/webassets.yml | 9 + ckanext/scheming/helpers.py | 80 ++++ ckanext/scheming/suggestion_test_schema.yaml | 110 +++++ .../scheming/form_snippets/markdown.html | 34 +- .../scheming/form_snippets/select.html | 22 +- .../scheming/form_snippets/text.html | 32 +- .../scheming/snippets/suggestion_button.html | 60 +++ .../scheming/snippets/suggestions_asset.html | 1 + 11 files changed, 1022 insertions(+), 12 deletions(-) create mode 100644 ckanext/scheming/assets/js/scheming-suggestions.js create mode 100644 ckanext/scheming/suggestion_test_schema.yaml create mode 100644 ckanext/scheming/templates/scheming/snippets/suggestion_button.html create mode 100644 ckanext/scheming/templates/scheming/snippets/suggestions_asset.html diff --git a/ckanext/scheming/assets/js/scheming-suggestions.js b/ckanext/scheming/assets/js/scheming-suggestions.js new file mode 100644 index 000000000..95aff8133 --- /dev/null +++ b/ckanext/scheming/assets/js/scheming-suggestions.js @@ -0,0 +1,241 @@ +ckan.module('scheming-suggestions', function($) { + return { + initialize: function() { + console.log("Initializing scheming-suggestions module"); + + var el = this.el; + var content = $(el).attr('data-content'); + + var $popoverDiv = $(''); + $popoverDiv.html(content); + $('body').append($popoverDiv); + + $(el).closest('.control-group').addClass('has-suggestion'); + + $popoverDiv.find('.suggestion-apply-btn').each(function() { + var isValid = $(this).data('is-valid') !== 'false'; + if (!isValid) { + $(this).addClass('suggestion-apply-btn-disabled'); + } + }); + + $(el).on('click', function(e) { + e.preventDefault(); + e.stopPropagation(); + + $('.custom-suggestion-popover').hide(); + + var buttonPos = $(el).offset(); + var parentWidth = $(window).width(); + var popoverWidth = Math.min(350, parentWidth - 40); + + var leftPos = buttonPos.left; + if (leftPos + popoverWidth > parentWidth - 20) { + leftPos = Math.max(20, parentWidth - popoverWidth - 20); + } + + $popoverDiv.css({ + position: 'absolute', + top: buttonPos.top + $(el).outerHeight() + 10, + left: leftPos, + maxWidth: popoverWidth + 'px', + zIndex: 1000 + }); + + $popoverDiv.toggle(); + }); + + // Close popover when clicking outside + $(document).on('click', function(e) { + if (!$(e.target).closest('.suggestion-btn').length && + !$(e.target).closest('.custom-suggestion-popover').length) { + $popoverDiv.hide(); + } + }); + + // Handle formula toggle button + $popoverDiv.on('click', '.formula-toggle-btn', function(e) { + e.preventDefault(); + e.stopPropagation(); + + var $formulaSection = $(this).closest('.suggestion-popover-content').find('.suggestion-formula'); + var $toggleIcon = $(this).find('.formula-toggle-icon'); + var $toggleText = $(this).find('.formula-toggle-text'); + + if ($formulaSection.is(':visible')) { + // Hide formula + $formulaSection.slideUp(200); + $toggleIcon.html('▼'); // Down arrow + $toggleText.text('Show formula'); + $(this).removeClass('formula-toggle-active'); + } else { + // Show formula + $formulaSection.slideDown(200); + $toggleIcon.html('▲'); // Up arrow + $toggleText.text('Hide formula'); + $(this).addClass('formula-toggle-active'); + } + }); + + // Handle copy formula button + $popoverDiv.on('click', '.copy-formula-btn', function(e) { + e.preventDefault(); + e.stopPropagation(); + + var formula = $(this).data('formula'); + var $copyBtn = $(this); + + // Create a temp textarea to copy from + var $temp = $("