-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
409 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,39 @@ | ||
/** | ||
* A hack script to properly load CKAN modules on an AJAX loaded HTML | ||
*/ | ||
ckan.module("tour-htmx", function ($) { | ||
return { | ||
initialize: function () { | ||
$.proxyAll(this, /_on/); | ||
console.log('loaded'); | ||
document.addEventListener('htmx:beforeRequest', this._onHTMXbeforeRequest); | ||
document.addEventListener('htmx:afterSettle', this._onHTMXafterSettle); | ||
document.addEventListener('htmx:pushedIntoHistory', this._onHTMXpushedIntoHistory); | ||
}, | ||
|
||
_onHTMXbeforeRequest: function (e) { | ||
$(e.detail.target).find("[data-module]").unbind() | ||
|
||
for (const [key, _] of Object.entries(ckan.module.instances)) { | ||
ckan.module.instances[key] = null; | ||
} | ||
}, | ||
|
||
_onHTMXafterSettle: function (e) { | ||
const doNotInitialize = ["tour-htmx"] | ||
|
||
if (e.detail.pathInfo.requestPath === "/admin_panel/config/tour/add_step") { | ||
var newStep = $(".tour-steps__steps .tour-step").last(); | ||
|
||
newStep.find("[data-module]").each(function (_, element) { | ||
const moduleName = $(element).attr("data-module"); | ||
|
||
if (!doNotInitialize.includes(moduleName)) { | ||
ckan.module.initializeElement(element); | ||
} | ||
}) | ||
} | ||
|
||
}, | ||
}; | ||
}); |
3 changes: 1 addition & 2 deletions
3
ckanext/tour/assets/js/init-tour.js → ckanext/tour/assets/js/tour-init.js
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,73 @@ | ||
/** | ||
* A script to manage multiple steps fieldsets | ||
*/ | ||
ckan.module("tour-steps", function ($) { | ||
return { | ||
initialize: function () { | ||
$.proxyAll(this, /_on/); | ||
var self = this; | ||
|
||
// this vars | ||
this.addStepBtn = $(".add-step"); | ||
|
||
// add event listeners | ||
$(document).on('click', '.add-step', this._onAddStep); | ||
$(document).on('click', '.remove-step', this._onRemoveStep); | ||
|
||
// HTMX events | ||
document.body.addEventListener('htmx:afterSwap', function (e) { | ||
let requestPath = e.detail.pathInfo.requestPath; | ||
|
||
if (requestPath === "/admin_panel/config/tour/add_step") { | ||
self._toggleRemoveBtns(); | ||
self._updateLastStepId(); | ||
} | ||
}); | ||
|
||
this._toggleRemoveBtns(); | ||
this._updateLastStepId(); | ||
}, | ||
|
||
_onAddStep: function (e) { | ||
// | ||
}, | ||
|
||
/** | ||
* Triggered on remove step | ||
* | ||
* @param {event} e | ||
*/ | ||
_onRemoveStep: function (e) { | ||
e.preventDefault(); | ||
|
||
var stepId = $(e.target).closest(".tour-step").data("stepId"); | ||
|
||
$(`#step_${stepId}`).remove(); | ||
|
||
this._toggleRemoveBtns(); | ||
this._updateLastStepId(); | ||
}, | ||
|
||
/** | ||
* Should be at least 1 step for a tour. Disable remove step button if | ||
* only 1 left. | ||
*/ | ||
_toggleRemoveBtns: function () { | ||
var steps = $(".tour-steps__steps .tour-step"); | ||
$(".remove-step").toggleClass("disabled", steps.length == 1) | ||
}, | ||
|
||
/** | ||
* Update the stepId we are sending to a server when adding a new step | ||
*/ | ||
_updateLastStepId: function () { | ||
var steps = $(".tour-steps__steps .tour-step"); | ||
|
||
this.addStepBtn.attr("hx-vals", JSON.stringify({ | ||
stepId: steps.last().data("step-id") + 1 | ||
})) | ||
|
||
|
||
} | ||
}; | ||
}); |
Large diffs are not rendered by default.
Oops, something went wrong.
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,9 +1,13 @@ | ||
from ckanext.tour.model import TourStep | ||
|
||
def tour_hello(): | ||
return "Hello, tour!" | ||
|
||
|
||
def get_helpers(): | ||
return { | ||
"tour_hello": tour_hello, | ||
} | ||
def tour_get_position_options(): | ||
return [ | ||
{"value": step, "text": step} | ||
for step in ( | ||
TourStep.Position.bottom, | ||
TourStep.Position.top, | ||
TourStep.Position.right, | ||
TourStep.Position.left, | ||
) | ||
] |
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
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
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,65 @@ | ||
{% extends 'admin_panel/base.html' %} | ||
|
||
{% import 'macros/form.html' as form %} | ||
|
||
{% block breadcrumb_content %} | ||
<li>{% link_for _("Tour add"), named_route='tour.add' %}</li> | ||
{% endblock breadcrumb_content %} | ||
|
||
{% block ap_content %} | ||
<h1>{{ _("Tour add") }}</h1> | ||
|
||
<h1>Tour add form:</h1> | ||
<form action="{{ h.url_for("tour.add") }}" method="POST"> | ||
{% call form.input("title", label=_("Tour title"), value=data.title, attrs={'required': 1, 'class': 'form-control'}) %} | ||
{{ form.info(_("A tour title to explain what is it for")) }} | ||
{% endcall %} | ||
|
||
{% call form.input("anchor", label=_("Query anchor"), value=data.anchor) %} | ||
{{ form.info(_('An anchor element query that will trigger the tour. Could be a tooltip, button or any HTML element.', classes=['info-help-tight'])) }} | ||
{% endcall %} | ||
|
||
{% call form.input("page", label=_("Page anchor"), value=data.page) %} | ||
{{ form.info(_('Optional. A path to a page, where tour will be applied. Note, that a page tour will be triggered automatically.', classes=['info-help-tight'])) }} | ||
{% endcall %} | ||
|
||
<h3>{{ _("Tour steps:") }}</h3> | ||
|
||
<div | ||
class="tour-steps" | ||
data-module="tour-steps tour-htmx"> | ||
|
||
<div class="tour-steps__steps"> | ||
{% for step in data.steps %} | ||
{% snippet 'tour/tour_step.html', step=step %} | ||
{% else %} | ||
{% snippet 'tour/tour_step.html', step={} %} | ||
{% endfor %} | ||
</div> | ||
|
||
<div class="form-actions js-form-wrapper form-wrapper"> | ||
<button | ||
class="add-step btn btn-success" | ||
hx-trigger="click" | ||
hx-post="{{ h.url_for('tour.add_step') }}" | ||
hx-vals='' | ||
hx-swap="beforeend" | ||
hx-target=".tour-steps__steps" | ||
> | ||
{{ _("Add step") }} | ||
<i class="fa fa-plus"></i> | ||
</button> | ||
</div> | ||
</div> | ||
|
||
<div class="form-actions js-form-wrapper form-wrapper"> | ||
<button class="btn btn-primary" type="submit">{{ _("Create tour") }}</button> | ||
</div> | ||
</form> | ||
{% endblock ap_content %} | ||
|
||
{% block scripts %} | ||
{{ super() }} | ||
|
||
{% asset 'tour/tour-htmx' %} | ||
{% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{% from 'macros/form/input.html' import input %} | ||
{% from 'macros/form/checkbox.html' import checkbox %} | ||
|
||
{# | ||
Builds a file upload for input | ||
|
||
Example | ||
{% import 'macros/form.html' as form %} | ||
{{ form.image_upload(data, errors, is_upload_enabled=true) }} | ||
|
||
#} | ||
{% macro image_upload(data, errors, field_url='image_url', field_upload='image_upload', field_clear='clear_upload', | ||
is_url=false, is_upload=false, is_upload_enabled=false, placeholder=false, | ||
url_label='', upload_label='', field_name='image_url') %} | ||
{% set placeholder = placeholder if placeholder else _('http://example.com/my-image.jpg') %} | ||
{% set url_label = url_label or _('Image URL') %} | ||
{% set upload_label = upload_label or _('Image') %} | ||
{% set previous_upload = data['previous_upload'] %} | ||
|
||
{% if field_url == 'url' and field_upload == 'upload' %} | ||
{# backwards compatibility for old resource forms that still call the `forms.image_upload()` macro, eg ckanext-scheming #} | ||
{% snippet 'package/snippets/resource_upload_field.html', | ||
data=data, | ||
errors=errors, | ||
is_url=is_url, | ||
is_upload=is_upload, | ||
is_upload_enabled=is_upload_enabled, | ||
url_label=url_label, | ||
upload_label=upload_label, | ||
placeholder=placeholder %} | ||
{% else %} | ||
{% if is_upload_enabled %} | ||
<div class="image-upload" | ||
data-module="image-upload" | ||
data-module-is_url="{{ 'true' if is_url else 'false' }}" | ||
data-module-is_upload="{{ 'true' if is_upload else 'false' }}" | ||
data-module-field_url="{{ field_url }}" | ||
data-module-field_upload="{{ field_upload }}" | ||
data-module-field_clear="{{ field_clear }}" | ||
data-module-upload_label="{{ upload_label }}" | ||
data-module-field_name="{{ field_name }}" | ||
data-module-previous_upload="{{ 'true' if previous_upload else 'false' }}"> | ||
{% endif %} | ||
|
||
|
||
{{ input(field_url, label=url_label, id='field-image-url', type='url', placeholder=placeholder, value=data.get(field_url), error=errors.get(field_url), classes=['control-full']) }} | ||
|
||
|
||
{% if is_upload_enabled %} | ||
{{ input(field_upload, label=upload_label, id='field-image-upload', type='file', placeholder='', value='', error='', classes=['control-full']) }} | ||
{% if is_upload %} | ||
{{ checkbox(field_clear, label=_('Clear Upload'), id='field-clear-upload', value='true', error='', classes=['control-full']) }} | ||
{% endif %} | ||
{% endif %} | ||
|
||
{% if is_upload_enabled %}</div>{% endif %} | ||
{% endif %} | ||
|
||
{% endmacro %} |
Oops, something went wrong.