MCPcopy Create free account
hub / github.com/Necriso/ScriptableWidgets / createWidget

Function createWidget

guenstigsteTankstelleAT.js:76–146  ·  view source on GitHub ↗
(data, fuelType)

Source from the content-addressed store, hash-verified

74}
75
76async function createWidget(data, fuelType) {
77 let list = createList(data);
78 const stations = data;
79 const attr = stations.filter(stations => stations.prices.length !== 0);
80
81 attr.sort(function (a, b) {
82 return a['prices'][0]['amount'] > b['prices'][0]['amount'];
83 });
84
85 for (let i = 0; i < 3; i++) {
86 if (attr[i]) {
87 if (i === 0) {
88 let stationPrice = list.addText(formatValue(attr[i]['prices'][0]['amount']))
89 stationPrice.font = new Font('Menlo', 25)
90 stationPrice.centerAlignText()
91 stationPrice.textColor = textColor
92
93 let stationName = list.addText(attr[i]['name'])
94 stationName.font = Font.boldSystemFont(12)
95 stationName.textColor = textColor
96 stationName.centerAlignText()
97
98 let station = list.addText(attr[i].location.address)
99 station.font = Font.lightSystemFont(12)
100 station.centerAlignText()
101 station.textColor = textColor
102
103 list.addSpacer(7)
104 } else if (i === 1) {
105 let stationStack1 = list.addStack()
106 let price1 = stationStack1.addText(formatValue(attr[i]['prices'][0]['amount']))
107 price1.font = new Font('Menlo', 10)
108 price1.textColor = greyTextColor
109
110 stationStack1.addSpacer(3)
111 let addressStack1 = stationStack1.addStack()
112 addressStack1.layoutVertically()
113
114 let station1 = addressStack1.addText(attr[i]['name'])
115 station1.font = Font.regularSystemFont(10)
116 station1.textColor = greyTextColor
117
118 let address1 = addressStack1.addText(attr[i].location.address)
119 address1.font = Font.regularSystemFont(10)
120 address1.textColor = greyTextColor
121
122 list.addSpacer(2)
123 } else if (i === 2) {
124 let stationStack2 = list.addStack()
125 let price2 = stationStack2.addText(formatValue(attr[i]['prices'][0]['amount']))
126 price2.font = new Font('Menlo', 10)
127 price2.textColor = greyTextColor
128
129 stationStack2.addSpacer(3)
130
131 let addressStack2 = stationStack2.addStack()
132 addressStack2.layoutVertically()
133

Callers 1

Calls 2

createListFunction · 0.70
formatValueFunction · 0.70

Tested by

no test coverage detected