Skip to content

Commit

Permalink
Use new data.json format
Browse files Browse the repository at this point in the history
  • Loading branch information
imlayered authored Nov 2, 2024
1 parent 64f4d44 commit b0bef8c
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ document.addEventListener("DOMContentLoaded", () => {
return response.json();
})
.then((data) => {
updateAnnouncementBar(data.sections.announcementBar, data.announcement);
if (data.sections.announcementBar)
updateAnnouncementBar(data.announcement);
updateOverallStatus(
data.services,
data.RandomOperationalMessage,
Expand Down Expand Up @@ -144,9 +145,9 @@ function displayErrorMessage() {
`;
}

function updateAnnouncementBar(isEnabled, announcement) {
function updateAnnouncementBar(announcement) {
const announcementBar = document.getElementById("announcement-bar");
if (isEnabled && announcement && announcement.text) {
if (announcement && announcement.text) {
announcementBar.textContent = announcement.text;
announcementBar.style.display = "block";
} else {
Expand All @@ -161,8 +162,8 @@ function updateOverallStatus(services, RandomOperationalMessage, data) {
if (data.OverallStatus && data.OverallStatus !== "NoOverride") {
overallStatus = data.OverallStatus;
} else {
const allStatuses = Object.values(services).flatMap((group) =>
Object.values(group)
const allStatuses = services.flatMap(category =>
category.services.map(service => service.status)
);
if (allStatuses.some((status) => status === "Maintenance")) {
overallStatus = "Maintenance";
Expand Down Expand Up @@ -205,7 +206,7 @@ function updateOverallStatus(services, RandomOperationalMessage, data) {
statusText =
successMessages[Math.floor(Math.random() * successMessages.length)];
} else {
statusText = "All systems operational";
statusText = "All systems are operational";
}
statusIcon = "✓";
} else {
Expand Down Expand Up @@ -233,7 +234,10 @@ function updateServices(services) {
const servicesContainer = document.getElementById("services");
servicesContainer.innerHTML = "<h2>Services</h2>";

Object.entries(services).forEach(([groupName, serviceGroup]) => {
services.forEach((category) => {
const groupName = category.categoryName;
const serviceGroup = category.services;

const groupElement = document.createElement("div");
groupElement.className = "service-group";

Expand All @@ -250,7 +254,10 @@ function updateServices(services) {
const serviceList = document.createElement("div");
serviceList.className = "service-list";

Object.entries(serviceGroup).forEach(([serviceName, status]) => {
serviceGroup.forEach((service) => {
const serviceName = service.serviceName;
const status = service.status;

const serviceItem = document.createElement("div");
serviceItem.className = "service-item";

Expand Down Expand Up @@ -348,7 +355,7 @@ function createAlertElement(item, className) {
}

function calculateGroupStatus(serviceGroup) {
const statuses = Object.values(serviceGroup);
const statuses = serviceGroup.map(service => service.status);
if (statuses.every((status) => status === "Operational")) {
return "Operational";
} else if (statuses.some((status) => status === "Maintenance")) {
Expand Down

0 comments on commit b0bef8c

Please sign in to comment.