Skip to content

Commit

Permalink
Migrate clock to system widget (#977)
Browse files Browse the repository at this point in the history
Signed-off-by: Hubert Nusser <hubsif@gmx.de>
  • Loading branch information
hubsif committed Mar 26, 2021
1 parent 45b67da commit 093ea4b
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 55 deletions.
1 change: 1 addition & 0 deletions bundles/org.openhab.ui/doc/components/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ source: https://github.com/openhab/openhab-webui/edit/main/bundles/org.openhab.u
|--------|------|-------------|
| [`oh-button`](./oh-button.html) | [Button](./oh-button.html) | Button performing an action |
| [`oh-chart`](./oh-chart.html) | [Chart](./oh-chart.html) | Visualize series of data |
| [`oh-clock`](./oh-clock.html) | [Digital Clock](./oh-clock.html) | Display a digital clock |
| [`oh-colorpicker`](./oh-colorpicker.html) | [Colorpicker](./oh-colorpicker.html) | Control to pick a color |
| [`oh-gauge`](./oh-gauge.html) | [Gauge](./oh-gauge.html) | Circular or semi-circular read-only gauge |
| [`oh-icon`](./oh-icon.html) | [Icon](./oh-icon.html) | Display an openHAB icon |
Expand Down
91 changes: 91 additions & 0 deletions bundles/org.openhab.ui/doc/components/oh-clock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
title: oh-clock - Digital Clock
component: oh-clock
label: Digital Clock
description: Display a digital clock
source: https://github.com/openhab/openhab-webui/edit/main/bundles/org.openhab.ui/doc/components/oh-clock.md
prev: /docs/ui/components/
---

# oh-clock - Digital Clock

<!-- Put a screenshot here if relevant:
![](./images/oh-clock/header.jpg)
-->

[[toc]]

<!-- Note: you can overwrite the definition-provided description and add your own intro/additional sections instead -->
<!-- DO NOT REMOVE the following comments if you intend to keep the definition-provided description -->
<!-- GENERATED componentDescription -->
Display a digital clock
<!-- GENERATED /componentDescription -->

## Configuration

<!-- DO NOT REMOVE the following comments -->
<!-- GENERATED props -->
### General
<div class="props">
<PropGroup label="General">
<PropBlock type="TEXT" name="format" label="Date Format">
<PropDescription>
Date format, see <a class="external text-color-blue" target="_blank" href="https://day.js.org/docs/en/display/format">dayjs docs</a>
</PropDescription>
</PropBlock>
</PropGroup>
</div>


<!-- GENERATED /props -->

<!-- If applicable describe how properties are forwarded to a underlying component from Framework7, ECharts, etc.:
### Inherited Properties
-->

<!-- If applicable describe the slots recognized by the component and what they represent:
### Slots
#### `default`
The contents of the oh-clock.
-->

<!-- Add as many examples as desired - put the YAML in a details container when it becomes too long (~150/200+ lines):
## Examples
### Example 1
![](./images/oh-clock/example1.jpg)
```yaml
component: oh-clock
config:
prop1: value1
prop2: value2
```
### Example 2
![](./images/oh-clock/example2.jpg)
::: details YAML
```yaml
component: oh-clock
config:
prop1: value1
prop2: value2
slots
```
:::
-->

<!-- Try to clean up URLs to the forum (https://community.openhab.org/t/<threadID>[/<postID>] should suffice)
## Community Resources
- [Community Post 1](https://community.openhab.org/t/12345)
- [Community Post 2](https://community.openhab.org/t/23456)
-->
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,38 @@ export const OhWebFrameCardDefinition = () => new WidgetDefinition('oh-webframe-
.paramGroup(pg('webframe', 'Web Frame'), WebFrameParameters())

// OhClockCard
import ClockParameters from '../system/clock.js'
export const OhClockCardDefinition = () => new WidgetDefinition('oh-clock-card', 'Digital Clock Card', 'Display a digital clock in a card')
.paramGroup(CardParameterGroup(), CardParameters())
.paramGroup(pg('clock', 'Clock'), ClockParameters())
.paramGroup(pg('clock', 'Clock'), [
pt('timeFormat', 'Time Format', 'Time format, see <a class="external text-color-blue" target="_blank" href="https://day.js.org/docs/en/display/format">dayjs docs</a>').o([
{ value: 'LTS', label: 'Localized time including seconds (\'LTS\', e.g. \'8:02:18 PM\')' },
{ value: 'LT', label: 'Localized time (\'LT\'. e.g. \'8:02 PM\')' },
{ value: 'HH:mm:ss', label: 'Current time (\'HH:mm:ss\')' }
], false),
pt('background', 'Background style', 'Background style (in CSS "background" attribute format)'),
pt('timeFontSize', 'Time Font Size', 'Time font size (e.g. "34px")'),
pt('timeFontWeight', 'Time Font Weight', 'Time font weight (e.g. "normal" or "bold")'),
pb('showDate', 'Show the date', 'Show the current date in addition to the time'),
pt('dateFormat', 'Date Format', 'Date format, see <a class="external text-color-blue" target="_blank" href="https://day.js.org/docs/en/display/format">dayjs docs</a>').o([
{ value: 'LL', label: 'Localized long date (\'LL\', e.g. \'August 16, 2018\')' },
{ value: 'L', label: 'Localized short date (\'L\', e.g. \'08/16/2018\')' },
{ value: 'MM/DD/YYYY', label: 'Current date (\'MM/DD/YYYY\')' }
], false).v((value, configuration, configDescription, parameters) => {
return configuration.showDate === true
}),
pt('datePos', 'Date Position', 'Where to show the date').o([
{ value: 'above', label: 'Above time' },
{ value: 'below', label: 'Below time' }
]).v((value, configuration, configDescription, parameters) => {
return configuration.showDate === true
}),
pt('dateFontSize', 'Date Font Size', 'Date font size (e.g. "34px")')
.v((value, configuration, configDescription, parameters) => {
return configuration.showDate === true
}),
pt('dateFontWeight', 'Date Font Weight', 'Date font weight (e.g. "normal" or "bold")')
.v((value, configuration, configDescription, parameters) => {
return configuration.showDate === true
})
])
.paramGroup(actionGroup(null, 'Action to perform when the clock is clicked'), actionParams())
Original file line number Diff line number Diff line change
@@ -1,34 +1,5 @@
import { pb, pt } from '../helpers.js'

export default () => [
pt('timeFormat', 'Time Format', 'Time format, see <a class="external text-color-blue" target="_blank" href="https://day.js.org/docs/en/display/format">dayjs docs</a>').o([
{ value: 'LTS', label: 'Localized time including seconds (\'LTS\', e.g. \'8:02:18 PM\')' },
{ value: 'LT', label: 'Localized time (\'LT\'. e.g. \'8:02 PM\')' },
{ value: 'HH:mm:ss', label: 'Current time (\'HH:mm:ss\')' }
], false),
pt('background', 'Background style', 'Background style (in CSS "background" attribute format)'),
pt('timeFontSize', 'Time Font Size', 'Time font size (e.g. "34px")'),
pt('timeFontWeight', 'Time Font Weight', 'Time font weight (e.g. "normal" or "bold")'),
pb('showDate', 'Show the date', 'Show the current date in addition to the time'),
pt('dateFormat', 'Date Format', 'Date format, see <a class="external text-color-blue" target="_blank" href="https://day.js.org/docs/en/display/format">dayjs docs</a>').o([
{ value: 'LL', label: 'Localized long date (\'LL\', e.g. \'August 16, 2018\')' },
{ value: 'L', label: 'Localized short date (\'L\', e.g. \'08/16/2018\')' },
{ value: 'MM/DD/YYYY', label: 'Current date (\'MM/DD/YYYY\')' }
], false).v((value, configuration, configDescription, parameters) => {
return configuration.showDate === true
}),
pt('datePos', 'Date Position', 'Where to show the date').o([
{ value: 'above', label: 'Above time' },
{ value: 'below', label: 'Below time' }
]).v((value, configuration, configDescription, parameters) => {
return configuration.showDate === true
}),
pt('dateFontSize', 'Date Font Size', 'Date font size (e.g. "34px")')
.v((value, configuration, configDescription, parameters) => {
return configuration.showDate === true
}),
pt('dateFontWeight', 'Date Font Weight', 'Date font weight (e.g. "normal" or "bold")')
.v((value, configuration, configDescription, parameters) => {
return configuration.showDate === true
})
pt('format', 'Date Format', 'Date format, see <a class="external text-color-blue" target="_blank" href="https://day.js.org/docs/en/display/format">dayjs docs</a>')
]
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,7 @@ export const OhWebFrameDefinition = () => new WidgetDefinition('oh-webframe', 'W
import RepeaterParameters from './repeater.js'
export const OhRepeaterDefinition = () => new WidgetDefinition('oh-repeater', 'Repeater', 'Iterate over an array and repeat the children components in the default slot')
.params(RepeaterParameters())

import ClockParameters from './clock.js'
export const OhClockDefinition = () => new WidgetDefinition('oh-clock', 'Digital Clock', 'Display a digital clock')
.params(ClockParameters())
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
</f7-card-header>
<f7-card-content @click.native="performAction" class="clock-card-content text-align-center">
<f7-row v-if="config.showDate && config.datePos !== 'below'">
<f7-col :style="{ 'font-size': config.dateFontSize || '1vw', 'font-weight': config.dateFontWeight || 'normal' }" v-text="date" />
<f7-col>
<oh-clock :context="{ component: 'oh-clock', config: {} }" :style="{ 'font-size': config.dateFontSize || '1vw', 'font-weight': config.dateFontWeight || 'normal' }" :format="config.dateFormat" />
</f7-col>
</f7-row>
<f7-row>
<f7-col :style="{ 'font-size': config.timeFontSize || '2vw', 'font-weight': config.timeFontWeight || 'normal' }" v-text="time" />
<f7-col>
<oh-clock :context="{ component: 'oh-clock', config: {} }" :style="{ 'font-size': config.timeFontSize || '2vw', 'font-weight': config.timeFontWeight || 'normal' }" :format="config.timeFormat" />
</f7-col>
</f7-row>
<f7-row v-if="config.showDate && config.datePos === 'below'">
<f7-col :style="{ 'font-size': config.dateFontSize || '1vw', 'font-weight': config.dateFontWeight || 'normal' }" v-text="date" />
<f7-col>
<oh-clock :context="{ component: 'oh-clock', config: {} }" :style="{ 'font-size': config.dateFontSize || '1vw', 'font-weight': config.dateFontWeight || 'normal' }" :format="config.dateFormat" />
</f7-col>
</f7-row>
</f7-card-content>
<f7-card-footer v-if="config.footer">
Expand All @@ -21,32 +27,16 @@
</template>

<script>
import dayjs from 'dayjs'
import mixin from '../widget-mixin'
import { actionsMixin } from '../widget-actions'
import OhClock from '../system/oh-clock.vue'
import { OhClockCardDefinition } from '@/assets/definitions/widgets/standard/cards'
export default {
data () {
return {
time: '',
date: ''
}
},
mixins: [mixin, actionsMixin],
widget: OhClockCardDefinition,
methods: {
updateTime () {
this.time = dayjs().format(this.config.timeFormat || 'LTS')
this.date = dayjs().format(this.config.dateFormat || 'LL')
}
},
mounted () {
this.updateTime()
this.timer = setInterval(this.updateTime, 1000)
components: {
OhClock
},
beforeDestroy () {
clearInterval(this.timer)
}
widget: OhClockCardDefinition
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ export { default as OhTrend } from './oh-trend.vue'
export { default as OhWebframe } from './oh-webframe.vue'
export { default as OhRepeater } from './oh-repeater.vue'
export { default as OhChart } from './oh-chart.vue'
export { default as OhClock } from './oh-clock.vue'
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<template>
<div :class="config.class" :style="config.style" v-text="date" />
</template>

<script>
import dayjs from 'dayjs'
import mixin from '../widget-mixin'
import { actionsMixin } from '../widget-actions'
import { OhClockDefinition } from '@/assets/definitions/widgets/system'
export default {
mixins: [mixin, actionsMixin],
props: ['format'],
widget: OhClockDefinition,
data () {
return {
date: ''
}
},
methods: {
updateTime () {
this.date = dayjs().format(this.format || this.config.format || 'LTS')
}
},
mounted () {
this.updateTime()
this.timer = setInterval(this.updateTime, 1000)
},
beforeDestroy () {
clearInterval(this.timer)
}
}
</script>

0 comments on commit 093ea4b

Please sign in to comment.