(data, brand)
| 87 | } |
| 88 | |
| 89 | async function createWidget(data, brand) { |
| 90 | |
| 91 | const list = new ListWidget() |
| 92 | list.setPadding(0, 4, 1, 4) |
| 93 | |
| 94 | const gradient = new LinearGradient() |
| 95 | gradient.locations = [0, 1] |
| 96 | gradient.colors = [ |
| 97 | backColor, |
| 98 | backColor2 |
| 99 | ] |
| 100 | list.backgroundGradient = gradient |
| 101 | |
| 102 | if (data.error) { |
| 103 | let errorMessage = list.addText('No station in selected radius found. Please set a greater radius in widget parameters') |
| 104 | errorMessage.font = Font.boldSystemFont(12) |
| 105 | errorMessage.textColor = textColor |
| 106 | return list |
| 107 | } |
| 108 | |
| 109 | const stations = data.stations; |
| 110 | let selectedStations |
| 111 | |
| 112 | if (brand) { |
| 113 | selectedStations = stations.filter(stations => stations['brand'].toLowerCase() === brand.toLowerCase()); |
| 114 | } else { |
| 115 | selectedStations = stations |
| 116 | } |
| 117 | |
| 118 | const attr = selectedStations[0] |
| 119 | |
| 120 | let open = '🔴' |
| 121 | if (attr.isOpen) { |
| 122 | open = '🟢' |
| 123 | } |
| 124 | |
| 125 | let firstLineStack = list.addStack() |
| 126 | |
| 127 | let stationName = firstLineStack.addText(attr.brand) |
| 128 | stationName.font = Font.boldSystemFont(15) |
| 129 | stationName.textColor = textColor |
| 130 | |
| 131 | firstLineStack.addSpacer() |
| 132 | let stationOpen = firstLineStack.addText(open) |
| 133 | stationOpen.font = Font.mediumSystemFont(10) |
| 134 | stationOpen.rightAlignText() |
| 135 | |
| 136 | list.addSpacer(5) |
| 137 | |
| 138 | let dieselStack = list.addStack() |
| 139 | let dieselLabel = dieselStack.addText("Diesel:") |
| 140 | dieselLabel.font = Font.boldSystemFont(12) |
| 141 | dieselLabel.textColor = textColor |
| 142 | |
| 143 | dieselStack.addSpacer() |
| 144 | let dieselPrice = dieselStack.addText(formatValue(attr.diesel)) |
| 145 | dieselPrice.font = new Font('Menlo', 12) |
| 146 | dieselPrice.textColor = textColor |
no test coverage detected