-
-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate clock to system widget (#977)
Signed-off-by: Hubert Nusser <hubsif@gmx.de>
- Loading branch information
Showing
8 changed files
with
176 additions
and
55 deletions.
There are no files selected for viewing
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,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) | ||
--> |
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
31 changes: 1 addition & 30 deletions
31
bundles/org.openhab.ui/web/src/assets/definitions/widgets/system/clock.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
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>') | ||
] |
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
33 changes: 33 additions & 0 deletions
33
bundles/org.openhab.ui/web/src/components/widgets/system/oh-clock.vue
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,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> |