mirror of
https://github.com/ThisIsBenny/iOS-Widgets.git
synced 2025-06-07 05:57:41 +00:00
add SortBy option
This commit is contained in:
parent
e82defda15
commit
11b36a7151
1 changed files with 17 additions and 1 deletions
|
@ -8,6 +8,7 @@ Version 1.2.0
|
||||||
Changelog:
|
Changelog:
|
||||||
v1.2.0
|
v1.2.0
|
||||||
- Large Widget: write percentage to the bar and show total numbers
|
- Large Widget: write percentage to the bar and show total numbers
|
||||||
|
- Allow to change sorting my add a field namen into sortBy variable
|
||||||
v1.1.1
|
v1.1.1
|
||||||
- Cache path changed
|
- Cache path changed
|
||||||
- Allow force Update of the data
|
- Allow force Update of the data
|
||||||
|
@ -31,6 +32,10 @@ Changelog:
|
||||||
// How many minutes should the cache be valid
|
// How many minutes should the cache be valid
|
||||||
let cacheMinutes = 4 * 60
|
let cacheMinutes = 4 * 60
|
||||||
|
|
||||||
|
// enter the name of the field which shoul be used for sorting in the large widget list.
|
||||||
|
// e.g. 'quote' or 'vaccinated'. Default: State name
|
||||||
|
const sortBy = ''
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
////////////////////////// Dev Settings ////////////////////////
|
////////////////////////// Dev Settings ////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -263,7 +268,18 @@ if (config.widgetFamily === 'large') {
|
||||||
const stack = widget.addStack()
|
const stack = widget.addStack()
|
||||||
stack.layoutVertically()
|
stack.layoutVertically()
|
||||||
stack.spacing = spacing
|
stack.spacing = spacing
|
||||||
for (const [key, value] of Object.entries(result.states).sort((a, b) => a[0].localeCompare(b[0]))) {
|
|
||||||
|
let list = Object.entries(result.states)
|
||||||
|
|
||||||
|
list = list.sort((a, b) => {
|
||||||
|
if(sortBy && a[1][sortBy] !== undefined && b[1][sortBy] !== undefined) {
|
||||||
|
return a[1][sortBy] > b[1][sortBy]
|
||||||
|
} else {
|
||||||
|
return a[0].localeCompare(b[0])
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
for (const [key, value] of list) {
|
||||||
const row = stack.addStack()
|
const row = stack.addStack()
|
||||||
row.layoutHorizontally()
|
row.layoutHorizontally()
|
||||||
const stateText = row.addText(key)
|
const stateText = row.addText(key)
|
||||||
|
|
Loading…
Add table
Reference in a new issue