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

Adjusted schedule ui to use the new rest service for rule preview #815

Merged
merged 3 commits into from
Apr 11, 2021
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
8 changes: 0 additions & 8 deletions bundles/org.openhab.ui/web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion bundles/org.openhab.ui/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
"framework7": "^5.7.12",
"framework7-icons": "^3.0.1",
"framework7-vue": "^5.7.12",
"later-again": "^0.1.1",
"leaflet": "^1.7.1",
"leaflet-providers": "^1.11.0",
"lodash": "^4.17.20",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@
</style>

<script>
import later from 'later-again'

export default {
components: {
'empty-state-placeholder': () => import('@/components/empty-state-placeholder.vue')
Expand Down Expand Up @@ -109,45 +107,22 @@ export default {
if (this.loading) return
this.loading = true
let occurrences = []
this.$oh.api.get('/rest/rules?tags=Schedule').then(data => {
this.rules = data.sort((a, b) => {
return a.name.localeCompare(b.name)
})

let start = new Date(), limit = new Date()
limit.setDate(start.getDate() + 31)

this.$oh.api.get('/rest/rules/schedule/simulations?from=' + start.toISOString() + '&until=' + limit.toISOString()).then(data => {
this.rules = data
this.initSearchbar = true
this.loading = false

// compute occurrences for rules
// map RulesExecutions per time
this.rules.forEach((rule) => {
rule.triggers.forEach((t) => {
if (t.type === 'timer.GenericCronTrigger') {
if (t.configuration && t.configuration.cronExpression) {
try {
const laterSchedule = later.cron(t.configuration.cronExpression, true)
const triggerNextOccurrences = later.schedule(laterSchedule).next(100)
occurrences.push(...triggerNextOccurrences.map((o) => {
return [o.toISOString(), rule]
}))
} catch (err) {
throw err
}
}
} else if (t.type === 'timer.TimeOfDayTrigger') {
if (t.configuration && t.configuration.time && t.configuration.time.match(/^\d\d:\d\d/)) {
for (let i = 0, d = new Date(); i < 31; i++) {
d.setUTCHours(t.configuration.time.split(':')[0], t.configuration.time.split(':')[1])
occurrences.push([d.toISOString().replace(), rule])
d.setDate(d.getDate() + 1)
}
}
}
})
occurrences.push([new Date(rule.date).toISOString(), rule.rule])
})

occurrences = occurrences.sort((o1, o2) => o1[0].localeCompare(o2[0]))
this.$set(this, 'calendar', {})

let start = new Date(), limit = new Date()
limit.setDate(start.getDate() + 31)
let day = start
// eslint-disable-next-line no-unmodified-loop-condition
while (day < limit) {
Expand All @@ -163,14 +138,6 @@ export default {
const dayOccurrences = occurrences.filter((o) => {
const occurrenceISODate = o[0].split('T')[0]
const rule = o[1]

// filter out the occurrences not satisfying common rule conditions modules
if (rule.conditions.some((c) => c.type === 'timer.DayOfWeekCondition' &&
c.configuration && Array.isArray(c.configuration.days) &&
c.configuration.days.indexOf(['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'][day.getDay()]) < 0)) {
return false
}

return occurrenceISODate === dayISODate
})
cal[year][month][dayofmonth] = dayOccurrences
Expand Down