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

Sitemap Editor: Extend chart period config for ISO8601 #2186

Merged
merged 4 commits into from
Nov 26, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,9 @@
<f7-list-input v-if="supports('refresh')" label="Refresh interval" type="number" :value="widget.config.refresh" @input="updateParameter('refresh', $event)" clear-button />
<f7-list-input v-if="supports('encoding')" label="Encoding" type="text" :value="widget.config.encoding" @input="updateParameter('encoding', $event)" clear-button />
<f7-list-input v-if="supports('service')" label="Service" type="text" :value="widget.config.service" @input="updateParameter('service', $event)" clear-button />
<f7-list-item v-if="supports('period')" title="Period" smart-select :smart-select-params="{openIn: 'popover', closeOnSelect: true}">
<select name="periods" required :value="widget.config.period" @change="updateParameter('period', $event)">
<option v-for="def in periodDefs" :key="def.key" :value="def.key">
{{ def.value }}
</option>
</select>
</f7-list-item>
<f7-list-input v-if="supports('period')" label="Period" type="text"
placeholder="PnYnMnDTnHnMnS" validate pattern="^P(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(\d+H)?(\d+M)?(\d+S)?)?$|^\d*[YMWDh]$"
:value="widget.config.period" @input="updateParameter('period', $event)" clear-button />
<f7-list-input v-if="supports('height')" label="Height" type="number" :value="widget.config.height" @input="updateParameter('height', $event)" clear-button />
<f7-list-input v-if="supports('sendFrequency')" label="Frequency" type="number" :value="widget.config.sendFrequency" @input="updateParameter('sendFrequency', $event)" clear-button />
<f7-list-input v-if="supports('minValue')" label="Minimum" type="number" :value="widget.config.minValue" @input="updateParameter('minValue', $event)" clear-button />
Expand Down Expand Up @@ -97,21 +93,6 @@ export default {
Input: ['inputHint'],
Default: ['height']
},
periodDefs: [
{ key: 'h', value: 'Hour' },
{ key: '4h', value: '4 Hours' },
{ key: '8h', value: '8 Hours' },
{ key: '12h', value: '12 Hours' },
{ key: 'D', value: 'Day' },
{ key: '2D', value: '2 Days' },
{ key: '3D', value: '3 Days' },
{ key: 'W', value: 'Week' },
{ key: '2W', value: '2 Weeks' },
{ key: 'M', value: 'Month' },
{ key: '2M', value: '2 Months' },
{ key: '4M', value: '4 Months' },
{ key: 'Y', value: 'Year' }
],
inputHintDefs: [
{ key: 'text', value: 'Text' },
{ key: 'number', value: 'Number' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ describe('SitemapEdit', () => {
lastDialogConfig = null
wrapper.vm.selectWidget([wrapper.vm.sitemap.slots.widgets[0], wrapper.vm.sitemap])
await wrapper.vm.$nextTick()
localVue.set(wrapper.vm.selectedWidget.config, 'period', '5h')
localVue.set(wrapper.vm.selectedWidget.config, 'period', '5d')
wrapper.vm.validateWidgets()
expect(lastDialogConfig).toBeTruthy()
expect(lastDialogConfig.content).toMatch(/Chart widget Chart Test, invalid period configured: 5h/)
expect(lastDialogConfig.content).toMatch(/Chart widget Chart Test, invalid period configured: 5d/)

// configure a period for the Chart and check that there are no validation errors anymore
lastDialogConfig = null
Expand All @@ -199,6 +199,14 @@ describe('SitemapEdit', () => {
localVue.set(wrapper.vm.selectedWidget.config, 'period', '4h')
wrapper.vm.validateWidgets()
expect(lastDialogConfig).toBeFalsy()

// configure an ISO-8601 period for the Chart and check that there are no validation errors
lastDialogConfig = null
wrapper.vm.selectWidget([wrapper.vm.sitemap.slots.widgets[0], wrapper.vm.sitemap])
await wrapper.vm.$nextTick()
localVue.set(wrapper.vm.selectedWidget.config, 'period', 'P10M2W1DT12H30M')
wrapper.vm.validateWidgets()
expect(lastDialogConfig).toBeFalsy()
})

it('validates step is positive', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ export default {
}
})
widgetList.filter(widget => widget.component === 'Chart').forEach(widget => {
if (!(widget.config && widget.config.period && ['h', '4h', '8h', '12h', 'D', '2D', '3D', 'W', '2W', 'M', '2M', '4M', 'Y'].includes(widget.config.period))) {
if (!(widget.config && widget.config.period && /^P(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(\d+H)?(\d+M)?(\d+S)?)?$|^\d*[YMWDh]$/.test(widget.config.period))) {
let label = widget.config && widget.config.label ? widget.config.label : 'without label'
validationWarnings.push(widget.component + ' widget ' + label + ', invalid period configured: ' + widget.config.period)
}
Expand Down