Update cycle count regularly
This commit is contained in:
parent
fffdccc7b8
commit
b7dbc597d8
@ -10,11 +10,9 @@ import (
|
|||||||
|
|
||||||
func declareQuotesRoutes(cfg *config.Config, router *gin.RouterGroup) {
|
func declareQuotesRoutes(cfg *config.Config, router *gin.RouterGroup) {
|
||||||
router.GET("/quoteoftheday", func(c *gin.Context) {
|
router.GET("/quoteoftheday", func(c *gin.Context) {
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
router.GET("/quotes", func(c *gin.Context) {
|
router.GET("/quotes", func(c *gin.Context) {
|
||||||
|
|
||||||
})
|
})
|
||||||
router.POST("/quotes", func(c *gin.Context) {
|
router.POST("/quotes", func(c *gin.Context) {
|
||||||
|
|
||||||
|
@ -57,8 +57,9 @@ func GetNextAlarm(db *LevelDBStorage) (*time.Time, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
now := time.Now()
|
||||||
for _, alarm := range alarmsSingle {
|
for _, alarm := range alarmsSingle {
|
||||||
if closestAlarm == nil || closestAlarm.After(alarm.Time) {
|
if closestAlarm == nil || (closestAlarm.After(alarm.Time) && alarm.Time.After(now)) {
|
||||||
closestAlarm = &alarm.Time
|
closestAlarm = &alarm.Time
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
35
ui/src/components/CycleCounter.svelte
Normal file
35
ui/src/components/CycleCounter.svelte
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<script>
|
||||||
|
import { createEventDispatcher, onMount, onDestroy } from 'svelte';
|
||||||
|
|
||||||
|
export let begins = null;
|
||||||
|
export let ends;
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
let interval;
|
||||||
|
onMount(() => {
|
||||||
|
if (!begins) {
|
||||||
|
interval = setInterval(() => {
|
||||||
|
begins = new Date();
|
||||||
|
if (begins > ends) {
|
||||||
|
dispatch("reload")
|
||||||
|
}
|
||||||
|
}, 15000);
|
||||||
|
begins = new Date();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
onDestroy(() => {
|
||||||
|
if (interval) {
|
||||||
|
clearInterval(interval);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export { className as class };
|
||||||
|
let className = 'text-muted';
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if begins && ends}
|
||||||
|
<span class="{className}">
|
||||||
|
(dans {Math.trunc((ends.getTime()-begins.getTime())/5400000)} cycles + {Math.trunc(((ends.getTime()-begins.getTime())%5400000)/60000)} min)
|
||||||
|
</span>
|
||||||
|
{/if}
|
@ -4,6 +4,7 @@
|
|||||||
Icon,
|
Icon,
|
||||||
} from 'sveltestrap';
|
} from 'sveltestrap';
|
||||||
|
|
||||||
|
import CycleCounter from '../components/CycleCounter.svelte';
|
||||||
import DateFormat from '../components/DateFormat.svelte';
|
import DateFormat from '../components/DateFormat.svelte';
|
||||||
import { getNextAlarm, newNCyclesAlarm } from '../lib/alarmsingle';
|
import { getNextAlarm, newNCyclesAlarm } from '../lib/alarmsingle';
|
||||||
import { alarmsSingle } from '../stores/alarmsingle';
|
import { alarmsSingle } from '../stores/alarmsingle';
|
||||||
@ -11,11 +12,13 @@
|
|||||||
|
|
||||||
let nextAlarmP = getNextAlarm();
|
let nextAlarmP = getNextAlarm();
|
||||||
|
|
||||||
function newCyclesAlarm(ncycles) {
|
function reloadNextAlarm() {
|
||||||
newNCyclesAlarm(ncycles).then(() => {
|
|
||||||
nextAlarmP = getNextAlarm();
|
nextAlarmP = getNextAlarm();
|
||||||
alarmsSingle.clear();
|
alarmsSingle.clear();
|
||||||
})
|
}
|
||||||
|
|
||||||
|
function newCyclesAlarm(ncycles) {
|
||||||
|
newNCyclesAlarm(ncycles).then(reloadNextAlarm);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -44,12 +47,12 @@
|
|||||||
aujourd'hui à
|
aujourd'hui à
|
||||||
<DateFormat date={nextalarm} timeStyle="long" />
|
<DateFormat date={nextalarm} timeStyle="long" />
|
||||||
<br class="d-block d-md-none" />
|
<br class="d-block d-md-none" />
|
||||||
<span class="text-muted">(dans {Math.trunc((nextalarm.getTime()-Date.now())/5400000)} cycles + {Math.trunc(((nextalarm.getTime()-Date.now())%5400000)/60000)} min)</span>
|
<CycleCounter ends={nextalarm} on:reload={reloadNextAlarm} />
|
||||||
{:else if nextalarm.getDay() == new Date(Date.now() + 86400000).getDay() && nextalarm.getMonth() == new Date(Date.now() + 86400000).getMonth() && nextalarm.getFullYear() == new Date(Date.now() + 86400000).getFullYear()}
|
{:else if nextalarm.getDay() == new Date(Date.now() + 86400000).getDay() && nextalarm.getMonth() == new Date(Date.now() + 86400000).getMonth() && nextalarm.getFullYear() == new Date(Date.now() + 86400000).getFullYear()}
|
||||||
demain à
|
demain à
|
||||||
<DateFormat date={nextalarm} timeStyle="long" />
|
<DateFormat date={nextalarm} timeStyle="long" />
|
||||||
<br class="d-block d-md-none" />
|
<br class="d-block d-md-none" />
|
||||||
<span class="text-muted">(dans {Math.trunc((nextalarm.getTime()-Date.now())/5400000)} cycles + {Math.trunc(((nextalarm.getTime()-Date.now())%5400000)/60000)} min)</span>
|
<CycleCounter ends={nextalarm} on:reload={reloadNextAlarm} />
|
||||||
{:else if nextalarm.getTime() < Date.now() + 604800000}
|
{:else if nextalarm.getTime() < Date.now() + 604800000}
|
||||||
<span title={nextalarm}>{nextalarm.toLocaleString('default', {weekday: 'long'})}</span>
|
<span title={nextalarm}>{nextalarm.toLocaleString('default', {weekday: 'long'})}</span>
|
||||||
à
|
à
|
||||||
|
Loading…
x
Reference in New Issue
Block a user