Skip to content

Commit

Permalink
WIP: Fix/access request from implementation feedback (#17)
Browse files Browse the repository at this point in the history
* [Refactor][xs]: Code formatting

* [From][xl]: Access request form API implementation

* [UI][xl]:Response list/view/delete  UI implementation and other improvement

* [Email][s]: Email text updated

* [BugFix][xs]: checkbox selection bug fix

* [Fix][xs]: Bug fix and consent required

* [actions][xs]: Call to action buttons

* [fix][xs]: bug fix

* [fix][xs]: Explicit limit specified on upload

* [improve][xs]: improve title

* [captcha][xs]: captcha added for bot blocking

* [Improve][xs]: label fixes

* [Improve][xs]: Consent focus when it's not checked

* [Email][xs]: Date format change

* [update][s]: Full name, postal updated to first, surname & country respectively

* [update][s]: 2 questions column removed

* [update][s]: Feedbacks implemented #datopian/ubdc-clientshared-tracker#22

* [deploy][s]: Captcha Implemented, Reviews Implemented

* [Fix][xs]: Checkbox not so reactive bug fix

---------

Co-authored-by: Sagar Ghimire <[email protected]>
  • Loading branch information
sneha-sharma12 and sagargg committed Nov 10, 2023
1 parent fb295df commit bcd907e
Show file tree
Hide file tree
Showing 22 changed files with 1,038 additions and 61 deletions.
57 changes: 57 additions & 0 deletions ckanext/ubdc/assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -7131,6 +7131,11 @@ button.close {
overflow: hidden;
}

input[type=checkbox][name=contactConsent]:focus,
input[type=checkbox][name=consentName]:focus {
outline: 1px solid lightblue;
}

.beta-message {
background: #d5580d;
color: #fff;
Expand Down Expand Up @@ -11379,6 +11384,58 @@ br.line-height2 {
color: #843534;
}

.access-request-response {
position: relative;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 4px;
margin-bottom: 15px;
}
.access-request-response .response {
margin: 0;
font-size: 16px;
padding: 10px 20px;
color: #777;
background-color: #f7f7f7;
border-bottom: 1px solid #eee;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
}
.access-request-response p {
padding: 20px;
}

.checkboxes label {
display: flex;
font-weight: 400;
}
.checkboxes label input {
margin: 0;
margin-right: 8px;
}
.checkboxes label::after {
content: "";
display: block;
clear: both;
}

.radio-group label {
display: flex;
}
.radio-group label input {
margin: 0;
margin-right: 8px;
}

.access-request-container {
display: flex;
justify-content: flex-end;
margin: 10px;
}
.access-request-container a {
font-size: 14px;
}

.input-group .form-control {
z-index: 0;
}
Expand Down
47 changes: 47 additions & 0 deletions ckanext/ubdc/assets/js/access_request.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
ckan.module("data-service-request-form", function (jQuery) {
return {
initialize: function () {
var message = this._('There are unsaved modifications to this form');

$.proxyAll(this, /_on/);

this.el.incompleteFormWarning(message);

// Disable the submit button on form submit, to prevent multiple
// consecutive form submissions.

this.el.on('submit', this._onSubmit);

this.el.find('.checkboxes label').click(function (event) {
event.stopPropagation();
var checkbox = $(this).find('input');
checkbox.prop('checked', !checkbox.prop('checked'));
});

this.el.find('.checkboxes label input').click(function (event) {
event.stopPropagation();
});
},
_onSubmit: function () {
// The button is not disabled immediately so that its value can be sent
// the first time the form is submitted, because the "save" field is
// used in the backend.

var consent = this.el.find('input[name="consent"]')
var contactConsent = this.el.find('input[name="contactConsent"]')
if (!consent.prop('checked')) {
consent.focus();
this.el.preventDefault()
}

if (!contactConsent.prop('checked')) {
contactConsent.focus();
this.el.preventDefault()
}

setTimeout(function () {
this.el.find('button[name="save"]').attr('disabled', true);
}.bind(this), 0);
}
};
});
35 changes: 35 additions & 0 deletions ckanext/ubdc/assets/js/reCaptcha.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
ckan.module('reCaptcha', function (jQuery) {
return {
options: {
sitekey: null,
},
initialize: function () {
var recaptcha = document.createElement('script');
recaptcha.src = 'https://www.google.com/recaptcha/api.js?render=' + this.options.sitekey;
recaptcha.async = true;
recaptcha.defer = true;
document.body.appendChild(recaptcha);
$.proxyAll(this, /_on/);

// onClick event
this.el.on('click', this._onClick);

// hidden input field with the token
this.el.before('<input type="hidden" name="g-recaptcha-response" value="">');

},
_onClick: function (event) {
event.preventDefault();
var module = this;
grecaptcha.ready(function (module) {
return function () {
grecaptcha.execute(module.options.sitekey, { action: 'submit' }).then(function (token) {
jQuery('input[name="g-recaptcha-response"]').val(token);
jQuery('#data-service-access-request')[0].reportValidity()
module.el.closest('form').submit();
});
};
}(module));
}
};
});
2 changes: 2 additions & 0 deletions ckanext/ubdc/assets/webassets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ ubdc-cc-js:
output: ckanext-ubdc/%(version)s-ubdc-cc.js
contents:
- js/civic_cookies.js
- js/access_request.js
- js/reCaptcha.js
- js/beta_message.js

ubdc-css:
Expand Down
75 changes: 45 additions & 30 deletions ckanext/ubdc/helpers.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,71 @@

from ckan import model
from ckan.logic import get_action
import ckan.plugins.toolkit as tk
from ckanext.ubdc import view


def popular_datasets(limit=3):
"""Return a list of the most popular datasets."""
context = {'model': model, 'session': model.Session}
data_dict = {'sort': 'views_recent desc', 'rows': limit}
return get_action('package_search')(context, data_dict)['results']
context = {"model": model, "session": model.Session}
data_dict = {"sort": "views_recent desc", "rows": limit}
return get_action("package_search")(context, data_dict)["results"]


def resources_count():
"""Return the total number of resources."""
context = {'model': model, 'session': model.Session}
data_dict = {'query': 'name:'}
return get_action('resource_search')(context, data_dict)['count']
context = {"model": model, "session": model.Session}
data_dict = {"query": "name:"}
return get_action("resource_search")(context, data_dict)["count"]


def tags_count():
"""Return the total number of tags."""
context = {'model': model, 'session': model.Session}
return {'count': len(get_action('tag_list')(context, {})) }
context = {"model": model, "session": model.Session}
return {"count": len(get_action("tag_list")(context, {}))}


def get_gtm_id():
"""Return the Google Tag Manager ID."""
return tk.config.get('ls', '')
return tk.config.get("ls", "")


def get_cookie_control_config():
cookie_control_config = {}

api_key = tk.config.get("ckanext.ubdc.cc.api_key", "")
cookie_control_config["api_key"] = api_key

cookie_control_config = {}
license_type = tk.config.get("ckanext.ubdc.cc.license_type", "COMMUNITY")
cookie_control_config["license_type"] = license_type

api_key = tk.config.get(
'ckanext.ubdc.cc.api_key', '')
cookie_control_config['api_key'] = api_key
popup_position = tk.config.get("ckanext.ubdc.cc.popup_position", "LEFT")
cookie_control_config["popup_position"] = popup_position

license_type = tk.config.get(
'ckanext.ubdc.cc.license_type', 'COMMUNITY')
cookie_control_config['license_type'] = license_type
theme_color = tk.config.get("ckanext.ubdc.cc.theme_color", "DARK")
cookie_control_config["theme_color"] = theme_color

popup_position = tk.config.get(
'ckanext.ubdc.cc.popup_position', 'LEFT')
cookie_control_config['popup_position'] = popup_position
initial_state = tk.config.get("ckanext.ubdc.cc.initial_state", "OPEN")
cookie_control_config["initial_state"] = initial_state

theme_color = tk.config.get(
'ckanext.ubdc.cc.theme_color', 'DARK')
cookie_control_config['theme_color'] = theme_color
gtm_id = tk.config.get("googleanalytics.measurement_id", "")
cookie_control_config["gtm_id"] = gtm_id.replace("G-", "_ga_")

initial_state = tk.config.get(
'ckanext.ubdc.cc.initial_state', 'OPEN')
cookie_control_config['initial_state'] = initial_state
return cookie_control_config

gtm_id = tk.config.get(
'googleanalytics.measurement_id', '')
cookie_control_config['gtm_id'] = gtm_id.replace('G-', '_ga_')

return cookie_control_config
def get_field_to_question(value):
get_field_to_question = {
"first_name": "First Name",
"surname": "Surname",
"organization": "Organisation / Institution",
"email": "Email Address",
"telephone": "Telephone Number",
"country": "Country",
"summary_of_project": "Summary of your project or intended use of UBDC data and/or services",
"project_funding": "The UBDC does not provide project funding itself, but our collections and services can be used in projects funded from other sources. Are you applying for funding for this project or work?",
"funding_information": "If yes, please provide additional information (e.g. deadline) and/or a link to the Funding Call.",
"wish_to_use_data": "Please select all data from the UBDC collections you wish to use.",
"document_url": "Optional supporting documentation upload (PDF or DOC only).",
"created": "Date of submission",
}
return get_field_to_question.get(value, value)
Loading

0 comments on commit bcd907e

Please sign in to comment.