Commit 2706cff1 authored by Vildravn's avatar Vildravn
Browse files

Merge branch '5-no-data-fix' into 'beta'

Resolve "Fix issue with displaying the widget if there's missing data"

See merge request !4
parents 34779ff7 a92f815c
......@@ -19,7 +19,7 @@
*/
const colors = {
bg: new Color('#1C1C1C'),
header: new Color('#FFFFFF'),
textWhite: new Color('#FFFFFF'),
textYellow: new Color('#FFD100'),
textGrey: new Color('#BBBBBB'),
faction: {
......@@ -35,7 +35,7 @@ const colors = {
const textStyles = {
header: {
font: new Font('HelveticaNeue-Bold', 12),
color: colors.header
color: colors.textWhite
},
line: {
font: new Font('HelveticaNeue', 12),
......@@ -44,6 +44,10 @@ const textStyles = {
lineBold: {
font: new Font('HelveticaNeue-Bold', 9),
color: colors.textGrey
},
lineWhite: {
font: new Font('HelveticaNeue', 12),
color: colors.textWhite
}
}
......@@ -58,7 +62,8 @@ const slBosses = {
}
// -----------------------------
const REGION = (args.widgetParameter.toUpperCase() == 'US' ? 'US' : 'EU');
let REGION = args.widgetParameter || 'EU';
REGION = (REGION.toUpperCase() == 'US' ? 'US' : 'EU');
const cheerio = importModule('cheerio');
let $ = undefined;
......@@ -97,7 +102,7 @@ async function createWidget(size) {
let whData = await fetchData("https://www.wowhead.com", "loadString");
$ = cheerio.load(whData);
let data = undefined;
let data = null;
whData = undefined;
delete (whData);
......@@ -122,19 +127,24 @@ async function createWidget(size) {
await buildAffixDisplay(rightColumn, data);
rightColumn.addSpacer(20);
data = await parseTextGroup(`#${REGION}-group-epiceliteworldsl`, `.tiw-region[data-region="${REGION}"]`);
await buildTextDisplay(rightColumn, "world boss", data, slBosses[data[0]]);
const bossLink = (data ? slBosses[data[0]] : null);
await buildTextDisplay(rightColumn, "world boss", data, bossLink);
$ = undefined;
delete ($);
} else {
const text = widget.addText('The widget is not configured correctly.');
text.textColor = textStyles.header.color;
text.font = textStyles.header.font;
text.textColor = textStyles.lineWhite.color;
text.font = textStyles.lineWhite.font;
}
} else {
const text = widget.addText(`${size} widget is currently not supported.`);
text.textColor = textStyles.header.color;
text.font = textStyles.header.font;
const contentStack = widget.addStack();
contentStack.layoutHorizontally();
contentStack.addSpacer();
const text = contentStack.addText(`${size} widget is currently not supported.`);
text.textColor = textStyles.lineWhite.color;
text.font = textStyles.lineWhite.font;
contentStack.addSpacer();
}
return widget;
......@@ -142,10 +152,12 @@ async function createWidget(size) {
async function buildAffixDisplay(parent, affixes) {
const levels = ["2+", "4+", "7+", "10+"];
for (let i = 0; i < affixes.length; i++) {
let affix = affixes[i];
if (affixes) {
for (let i = 0; i < affixes.length; i++) {
let affix = affixes[i];
affix.text = levels[i];
affix.text = levels[i];
}
}
await buildImageDisplay(parent, "mythic+ affixes", affixes);
......@@ -160,6 +172,13 @@ async function buildTextDisplay(parent, heading, data, url) {
header.textColor = textStyles.header.color;
header.font = textStyles.header.font;
if (!data) {
const line = contentStack.addText('No data');
line.textColor = textStyles.lineWhite.color;
line.font = textStyles.lineWhite.font;
return;
}
for (const item of data) {
const line = contentStack.addText(item);
line.textColor = textStyles.line.color;
......@@ -175,6 +194,13 @@ async function buildImageDisplay(parent, heading, data) {
header.textColor = textStyles.header.color;
header.font = textStyles.header.font;
if (!data) {
const line = contentStack.addText('No data');
line.textColor = textStyles.lineWhite.color;
line.font = textStyles.lineWhite.font;
return;
}
const horizontalStack = contentStack.addStack();
horizontalStack.layoutHorizontally();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment