From 62616f7527e3556b6ca5096c763601c1fe13ff17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Wed, 31 May 2023 20:31:23 -0700 Subject: [PATCH 1/2] Added YoHours button to recurring schedule fields Fields that accept opening_hours syntax are now standard text fields with the addition of a button that links out to YoHours. The user can use this button to compose a value or visualize an existing value. --- data/core.yaml | 1 + modules/presets/index.js | 6 ++++++ modules/ui/fields/index.js | 2 ++ modules/ui/fields/input.js | 27 ++++++++++++++++++++++++++- 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/data/core.yaml b/data/core.yaml index 37e18ea696..d35f75a925 100644 --- a/data/core.yaml +++ b/data/core.yaml @@ -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 diff --git a/modules/presets/index.js b/modules/presets/index.js index 2caf97549f..3e70be9e56 100644 --- a/modules/presets/index.js +++ b/modules/presets/index.js @@ -66,6 +66,12 @@ 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 => { + vals[3][id].type = 'schedule'; + }); + _this.merge({ categories: vals[0], defaults: vals[1], diff --git a/modules/ui/fields/index.js b/modules/ui/fields/index.js index ba5cb0c344..bd6f4fcba0 100644 --- a/modules/ui/fields/index.js +++ b/modules/ui/fields/index.js @@ -34,6 +34,7 @@ import { uiFieldEmail, uiFieldIdentifier, uiFieldNumber, + uiFieldSchedule, uiFieldTel, uiFieldText, uiFieldUrl @@ -79,6 +80,7 @@ export var uiFields = { onewayCheck: uiFieldOnewayCheck, radio: uiFieldRadio, restrictions: uiFieldRestrictions, + schedule: uiFieldSchedule, semiCombo: uiFieldSemiCombo, structureRadio: uiFieldStructureRadio, tel: uiFieldTel, diff --git a/modules/ui/fields/input.js b/modules/ui/fields/input.js index aa8d552251..08a1e16745 100644 --- a/modules/ui/fields/input.js +++ b/modules/ui/fields/input.js @@ -18,12 +18,14 @@ export { uiFieldText as uiFieldEmail, uiFieldText as uiFieldIdentifier, uiFieldText as uiFieldNumber, + uiFieldText as uiFieldSchedule, 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}'; export function uiFieldText(field, context) { var dispatch = d3_dispatch('change'); @@ -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'); @@ -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; } @@ -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); } From df4e533030c774728bd3fa69ae795b5345250632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Wed, 31 May 2023 21:08:07 -0700 Subject: [PATCH 2/2] Only manipulate types of fields that exist --- modules/presets/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/presets/index.js b/modules/presets/index.js index 3e70be9e56..3fe6760956 100644 --- a/modules/presets/index.js +++ b/modules/presets/index.js @@ -69,7 +69,9 @@ export function presetIndex() { // https://github.com/ideditor/schema-builder/issues/100 const scheduleFields = ['opening_hours', 'opening_hours/covid19', 'service_times', 'collection_times']; scheduleFields.forEach(id => { - vals[3][id].type = 'schedule'; + if (id in vals[3]) { + vals[3][id].type = 'schedule'; + } }); _this.merge({