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

Add YoHours button to recurring schedule fields #9678

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions data/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ en:
copy: copy
view_on: view on {domain}
visit_website: visit website
edit_in: edit in {tool}
favorite: favorite
list: list
text: text
Expand Down
8 changes: 8 additions & 0 deletions modules/presets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ export function presetIndex() {
fileFetcher.get('preset_fields')
])
.then(vals => {
// https://github.com/ideditor/schema-builder/issues/100
const scheduleFields = ['opening_hours', 'opening_hours/covid19', 'service_times', 'collection_times'];
scheduleFields.forEach(id => {
if (id in vals[3]) {
vals[3][id].type = 'schedule';
}
});

_this.merge({
categories: vals[0],
defaults: vals[1],
Expand Down
2 changes: 2 additions & 0 deletions modules/ui/fields/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
uiFieldEmail,
uiFieldIdentifier,
uiFieldNumber,
uiFieldSchedule,
uiFieldTel,
uiFieldText,
uiFieldUrl
Expand Down Expand Up @@ -79,6 +80,7 @@ export var uiFields = {
onewayCheck: uiFieldOnewayCheck,
radio: uiFieldRadio,
restrictions: uiFieldRestrictions,
schedule: uiFieldSchedule,
semiCombo: uiFieldSemiCombo,
structureRadio: uiFieldStructureRadio,
tel: uiFieldTel,
Expand Down
27 changes: 26 additions & 1 deletion modules/ui/fields/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ export {
uiFieldText as uiFieldEmail,
uiFieldText as uiFieldIdentifier,
uiFieldText as uiFieldNumber,
uiFieldText as uiFieldSchedule,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it would be nice to keep the dropdown button for some common values like 24/7 that YoHours doesn’t support. But the combo field doesn’t support an external link button as far as I know.

uiFieldText as uiFieldTel,
uiFieldText as uiFieldUrl,
likelyRawNumberFormat
};

const likelyRawNumberFormat = /^-?(0\.\d*|\d*\.\d{0,2}(\d{4,})?|\d{4,}\.\d{3})$/;
const yoHoursURLFormat = 'https://projets.pavie.info/yohours/?oh={value}';
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spellcheck action on GitHub Actions doesn’t like this URL because French words sometimes look like misspelled English words. 😉


export function uiFieldText(field, context) {
var dispatch = d3_dispatch('change');
Expand Down Expand Up @@ -196,6 +198,26 @@ export function uiFieldText(field, context) {
}
})
.merge(outlinkButton);
} else if (field.type === 'schedule') {

input.attr('type', 'text');

outlinkButton = wrap.selectAll('.foreign-id-permalink')
.data([0]);

outlinkButton.enter()
.append('button')
.call(svgIcon('#iD-icon-out-link'))
.attr('class', 'form-field-button foreign-id-permalink')
.attr('title', () => t('icons.edit_in', { tool: 'YoHours' }))
.on('click', function(d3_event) {
d3_event.preventDefault();

var value = validIdentifierValueForLink();
var url = yoHoursURLFormat.replace(/{value}/, encodeURIComponent(value || ''));
window.open(url, '_blank');
})
.merge(outlinkButton);
} else if (field.type === 'url') {
input.attr('type', 'text');

Expand Down Expand Up @@ -377,6 +399,9 @@ export function uiFieldText(field, context) {
if (field.type === 'identifier' && field.pattern) {
return value && value.match(new RegExp(field.pattern))[0];
}
if (field.type === 'schedule') {
return value;
}
return null;
}

Expand Down Expand Up @@ -520,7 +545,7 @@ export function uiFieldText(field, context) {
if (field.type === 'date') updateDateField();

if (outlinkButton && !outlinkButton.empty()) {
var disabled = !validIdentifierValueForLink();
var disabled = !validIdentifierValueForLink() && field.type !== 'schedule';
outlinkButton.classed('disabled', disabled);
}

Expand Down