Skip to content

Commit 2bb9e36

Browse files
committed
feat: ✨ announcements.js file will handle creating the html 4 everything
1 parent bd4d407 commit 2bb9e36

File tree

1 file changed

+130
-68
lines changed

1 file changed

+130
-68
lines changed

scripts/others/announcements.js

+130-68
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,147 @@
1-
//state will be either "update" or "announcements"
2-
//when "update" is passed it will know there user needs to update
1+
// To change what branch the announcements.json is fetched from, enter branch name between "SODA-for-SPARC/" and "/scripts" in the url below
2+
// state will be either "update" or "announcements"
33
const checkForAnnouncements = async (state) => {
4-
const url = `https://raw.githubusercontent.com/fairdataihub/SODA-for-SPARC/announcements-launch-fix/scripts/meta/announcements.json?timestamp=${new Date().getTime()}`;
4+
const url = `https://raw.githubusercontent.com/fairdataihub/SODA-for-SPARC/staging/scripts/meta/announcements.json?timestamp=${new Date().getTime()}`;
55

66
const axiosInstance = axios.create({
77
baseURL: url,
88
timeout: 0,
99
});
1010

1111
try {
12-
//retrieve the announcements from the SODA repo (announcements.json)
12+
// Retrieve the platform, app version, and request the announcement
13+
let platform = String(os.platform);
14+
let appVersion = String(app.getVersion());
1315
let result = await axiosInstance.get();
1416
let res = result.data;
1517
console.log("Announcements result: ", res);
1618

17-
let platform = String(os.platform);
19+
// Prepare the platform name for the announcement
20+
if (platform === "darwin") {
21+
platform = "Mac";
22+
} else if (platform === "win32") {
23+
platform = "Windows";
24+
} else {
25+
platform = "Linux";
26+
}
1827

19-
for (var key of Object.keys(res)) {
20-
//app version should latest version to receive announcement
21-
if (appVersion === key) {
22-
if (Object.keys(res[key]).includes(platform)) {
23-
//check for platform
24-
if (res[key][platform]["show"] === true) {
25-
//if platform found then use that object to create announcement
26-
if (state === "announcements") {
27-
await Swal.fire({
28-
title: res[key][platform]["title"],
29-
html: `<p>${res[key][platform]["message"]}</p>`,
30-
icon: res[key][platform]["type"],
31-
heightAuto: false,
32-
backdrop: "rgba(0,0,0, 0.4)",
33-
confirmButtonText: "Okay",
34-
allowOutsideClick: false,
35-
allowEscapeKey: false,
36-
didOpen: () => {
37-
let swal_alert = document.getElementsByClassName("swal2-popup")[0];
38-
swal_alert.style.width = "40rem";
39-
},
40-
});
41-
}
42-
}
43-
} else {
44-
if (Object.keys(res[key]).includes("all")) {
45-
//check if all is in json structure
46-
//announcements for all OS's
47-
Swal.fire({
48-
title: res[key]["all"]["title"],
49-
html: `<p>${res[key]["all"]["message"]}</p>`,
50-
icon: res[key]["all"]["type"],
51-
heightAuto: false,
52-
backdrop: "rgba(0,0,0, 0.4)",
53-
confirmButtonText: "Okay",
54-
allowOutsideClick: false,
55-
allowEscapeKey: false,
56-
didOpen: () => {
57-
let swal_alert = document.getElementsByClassName("swal2-popup")[0];
58-
swal_alert.style.width = "40rem";
59-
},
60-
});
61-
}
62-
}
63-
} else {
64-
//app version is not up to date
65-
if (state === "update") {
66-
Swal.fire({
67-
title: res["older"]["all"]["title"],
68-
html: `<p>${res[key]["all"]["message"]}</p>`,
69-
icon: res[key]["all"]["type"],
70-
heightAuto: false,
71-
backdrop: "rgba(0,0,0, 0.4)",
72-
confirmButtonText: "Okay",
73-
allowOutsideClick: false,
74-
allowEscapeKey: false,
75-
didOpen: () => {
76-
let swal_alert = document.getElementsByClassName("swal2-popup")[0];
77-
swal_alert.style.width = "40rem";
78-
},
79-
});
80-
}
81-
}
28+
if (appVersion in res && state === "announcements") {
29+
console.log(res[appVersion]);
30+
console.log("version match");
31+
let features = res[appVersion]["announcements"]["features"];
32+
let bugFixes = res[appVersion]["announcements"]["bug-fixes"];
33+
let htmlMessage = `
34+
<div style="text-align: justify; overflow-y: auto; max-height: 350px;">
35+
<div style="margin-bottom: 1rem;">
36+
<label style="font-weight: 700; font-size: 17px;">Feature Additions:<br></label>
37+
${features.map((feature) => {
38+
console.log(feature);
39+
return `<li style="margin: .5rem 0 .5rem 0;">${feature}</li>`;
40+
}).join("")}
41+
42+
<label style="font-weight: 700; font-size: 17px;">Bug Fixes:<br></label>
43+
${bugFixes.map((bugfix) => {
44+
return `<li style="margin: .5rem 0 .5rem 0;">${bugfix}</li>`;
45+
}).join("")}
46+
</div>
47+
</div>
48+
`;
49+
50+
await Swal.fire({
51+
title: `Welcome to SODA for SPARC ${appVersion} for ${platform}`,
52+
html: htmlMessage,
53+
icon: "info",
54+
heightAuto: false,
55+
backdrop: "rgba(0,0,0, 0.4)",
56+
confirmButtonText: "Okay",
57+
allowOutsideClick: false,
58+
allowEscapeKey: false,
59+
didOpen: () => {
60+
let swal_alert = document.getElementsByClassName("swal2-popup")[0];
61+
swal_alert.style.width = "60rem";
62+
},
63+
});
64+
} else if (state === "update") {
65+
await Swal.fire({
66+
title: `SODA for SPARC ${appVersion} is out of date`,
67+
html: `<p>Please update to the latest version of SODA for SPARC for the best experience.</p>`,
68+
icon: "info",
69+
heightAuto: false,
70+
backdrop: "rgba(0,0,0, 0.4)",
71+
confirmButtonText: "Okay",
72+
allowOutsideClick: false,
73+
allowEscapeKey: false,
74+
didOpen: () => {
75+
let swal_alert = document.getElementsByClassName("swal2-popup")[0];
76+
swal_alert.style.width = "40rem";
77+
},
78+
});
8279
}
80+
81+
// for (var key of Object.keys(res)) {
82+
// //app version should latest version to receive announcement
83+
// if (appVersion === key) {
84+
// if (Object.keys(res[key]).includes(platform)) {
85+
// //check for platform
86+
// if (res[key][platform]["show"] === true) {
87+
// //if platform found then use that object to create announcement
88+
// if (state === "announcements") {
89+
// await Swal.fire({
90+
// title: res[key][platform]["title"],
91+
// html: `<p>${res[key][platform]["message"]}</p>`,
92+
// icon: res[key][platform]["type"],
93+
// heightAuto: false,
94+
// backdrop: "rgba(0,0,0, 0.4)",
95+
// confirmButtonText: "Okay",
96+
// allowOutsideClick: false,
97+
// allowEscapeKey: false,
98+
// didOpen: () => {
99+
// let swal_alert = document.getElementsByClassName("swal2-popup")[0];
100+
// swal_alert.style.width = "40rem";
101+
// },
102+
// });
103+
// }
104+
// }
105+
// } else {
106+
// if (Object.keys(res[key]).includes("all")) {
107+
// //check if all is in json structure
108+
// //announcements for all OS's
109+
// Swal.fire({
110+
// title: res[key]["all"]["title"],
111+
// html: `<p>${res[key]["all"]["message"]}</p>`,
112+
// icon: res[key]["all"]["type"],
113+
// heightAuto: false,
114+
// backdrop: "rgba(0,0,0, 0.4)",
115+
// confirmButtonText: "Okay",
116+
// allowOutsideClick: false,
117+
// allowEscapeKey: false,
118+
// didOpen: () => {
119+
// let swal_alert = document.getElementsByClassName("swal2-popup")[0];
120+
// swal_alert.style.width = "40rem";
121+
// },
122+
// });
123+
// }
124+
// }
125+
// } else {
126+
// //app version is not up to date
127+
// if (state === "update") {
128+
// Swal.fire({
129+
// title: res["older"]["all"]["title"],
130+
// html: `<p>${res[key]["all"]["message"]}</p>`,
131+
// icon: res[key]["all"]["type"],
132+
// heightAuto: false,
133+
// backdrop: "rgba(0,0,0, 0.4)",
134+
// confirmButtonText: "Okay",
135+
// allowOutsideClick: false,
136+
// allowEscapeKey: false,
137+
// didOpen: () => {
138+
// let swal_alert = document.getElementsByClassName("swal2-popup")[0];
139+
// swal_alert.style.width = "40rem";
140+
// },
141+
// });
142+
// }
143+
// }
144+
// }
83145
} catch (error) {
84146
console.error(error);
85147
}

0 commit comments

Comments
 (0)