Skip to content

Commit

Permalink
Add logic for component
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtrussler committed Jan 17, 2024
1 parent fdca15b commit af251c3
Showing 1 changed file with 27 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ window.GOVUK = window.GOVUK || {}
window.GOVUK.Modules = window.GOVUK.Modules || {};

(function (Modules) {
function LayoutFooter ($module) {
function StatusPageAlert ($module) {
this.$module = $module
this.items = {}
this.incidentCurrent = []
Expand All @@ -11,9 +11,6 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
this.maintenanceFuture = []
this.maintenancePast = []
// this.xmlString = fetch("file:///status.xml")

// console.log(this.xmlString)

this.xmlString = `<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
Expand All @@ -34,16 +31,19 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
</rss>`;
}

LayoutFooter.prototype.init = function () {
console.log('LayoutFooter init!')
StatusPageAlert.prototype.init = function () {
console.log('StatusPageAlert init!!')

var parser = new DOMParser();
var xmlDoc = parser.parseFromString(this.xmlString, "text/xml");
this.items = xmlDoc.querySelectorAll("item");

console.log('xmlDoc: ', xmlDoc)

this.items = xmlDoc.documentElement.querySelectorAll("item");
this.itemsCategorise()
}

LayoutFooter.prototype.itemsCategorise = function() {
StatusPageAlert.prototype.itemsCategorise = function() {
var now = new Date();

this.items.forEach((item) => {
Expand Down Expand Up @@ -73,47 +73,30 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
this.addAlert()
}

LayoutFooter.prototype.addAlert = function() {
var status = 0
var href = document.location.href
var alertLocation = document.querySelector('#status-page-alert')
StatusPageAlert.prototype.addAlert = function() {
var alertLocation = this.$module
var alertMessages = alertLocation.querySelectorAll('.alert-message')

// Demo
if (href.includes('?')) {
status = document.location.href.split('?')[1].split('=')[1]

if (status == '4') {
alertMessages[3].style.display = "block"
} else if (status == '2') {
alertMessages[1].style.display = "block"
} else if (status == '3') {
alertMessages[2].style.display = "block"
} else if (status == '1') {
alertMessages[0].style.display = "block"
}
} else {
if (this.maintenanceFuture.length > 0 && (this.maintenanceCurrent.length > 0 || this.incidentCurrent.length > 0)) {
alertMessages[3].style.display = "block"
} else if (this.maintenanceCurrent.length > 0 || this.incidentCurrent.length > 0) {
alertMessages[1].style.display = "block"
} else if (this.maintenanceFuture.length > 0 && this.maintenanceCurrent.length == 0 && this.incidentCurrent.length == 0) {
var start = new Date(this.maintenanceFuture[0].querySelector('pubDate').textContent)
var end = new Date(this.maintenanceFuture[0].querySelector('maintenanceEndDate').textContent)
if (this.maintenanceFuture.length > 0 && (this.maintenanceCurrent.length > 0 || this.incidentCurrent.length > 0)) {
alertMessages[3].style.display = "block"
} else if (this.maintenanceCurrent.length > 0 || this.incidentCurrent.length > 0) {
alertMessages[1].style.display = "block"
} else if (this.maintenanceFuture.length > 0 && this.maintenanceCurrent.length == 0 && this.incidentCurrent.length == 0) {
var start = new Date(this.maintenanceFuture[0].querySelector('pubDate').textContent)
var end = new Date(this.maintenanceFuture[0].querySelector('maintenanceEndDate').textContent)

var startDate = start.toLocaleDateString('en-GB')
var endDate = end.toLocaleDateString('en-GB')
var startTime = start.toLocaleTimeString('en-GB')
var endTime = end.toLocaleTimeString('en-GB')
var startDate = start.toLocaleDateString('en-GB')
var endDate = end.toLocaleDateString('en-GB')
var startTime = start.toLocaleTimeString('en-GB')
var endTime = end.toLocaleTimeString('en-GB')

alertMessages[2].querySelector('.startDateTime').textContent = `${startDate} at ${startTime}`
alertMessages[2].querySelector('.startEndTime').textContent = `${endDate} at ${endTime}`
alertMessages[2].style.display = "block"
} else {
alertMessages[0].style.display = "block"
}
alertMessages[2].querySelector('.startDateTime').textContent = `${startDate} at ${startTime}`
alertMessages[2].querySelector('.startEndTime').textContent = `${endDate} at ${endTime}`
alertMessages[2].style.display = "block"
} else {
alertMessages[0].style.display = "block"
}
}

Modules.LayoutFooter = LayoutFooter
Modules.StatusPageAlert = StatusPageAlert
})(window.GOVUK.Modules)

0 comments on commit af251c3

Please sign in to comment.