Skip to content
Snippets Groups Projects
Verified Commit d98f5363 authored by Marc Hanisch's avatar Marc Hanisch
Browse files

sorts with the help of the DateComparator

parent 9a791e1f
No related branches found
No related tags found
2 merge requests!104Load and save Generic Device Actions,!93Actions UI for devices
......@@ -389,6 +389,7 @@ import { Contact } from '@/models/Contact'
import { DeviceProperty } from '@/models/DeviceProperty'
import { IAction } from '@/models/Action'
import { GenericAction } from '@/models/GenericAction'
import { DateComparator, isDateCompareable } from '@/modelUtils/Compareables'
const toUtcDate = (dt: DateTime) => {
return dt.toUTC().toFormat('yyyy-MM-dd TT')
......@@ -621,28 +622,21 @@ export default class DeviceActionsPage extends Vue {
deviceMountAction1,
deviceUnmountAction1
]
// Todo: sort all actions by date descending
await Promise.all([this.fetchGenericActions()])
// sort the actions descending
// sort the actions
const comparator = new DateComparator()
this.actions.sort((i: IAction, j: IAction): number => {
if (!('beginDate' in i) && !('beginDate' in j)) {
return 0
if (isDateCompareable(i) && isDateCompareable(j)) {
// multiply result with -1 to get descending order
return comparator.compare(i, j) * -1
}
if (('beginDate' in i) && ('beginDate' in j)) {
if ((i as IAction & { beginDate: DateTime }).beginDate < (j as IAction & { beginDate: DateTime }).beginDate) {
return 1
}
if ((i as IAction & { beginDate: DateTime }).beginDate > (j as IAction & { beginDate: DateTime }).beginDate) {
return -1
}
return 0
if (isDateCompareable(i)) {
return 1
}
if (!('beginDate' in i) && ('beginDate' in j)) {
if (isDateCompareable(j)) {
return -1
}
if (('beginDate' in i) && !('beginDate' in j)) {
return 1
}
return 0
})
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment