Skip to content

Commit

Permalink
Issues 126/cet time (#129)
Browse files Browse the repository at this point in the history
Issues 126/cet time

#126
and a few changes by #123

Reviewed-by: Anton Sidelnikov
Reviewed-by: Ilia Bakhterev
  • Loading branch information
bakhterets authored Aug 28, 2024
1 parent 39a3fb7 commit dadc8a6
Show file tree
Hide file tree
Showing 12 changed files with 263 additions and 211 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ classDiagram
class IncidentStatuses{
-int incident_id
+date time
+enum status [scheduled, investigating, identified, watching, fixed]
+enum status [investigating, identified, watching, fixed]
+string text
-int user_id
Expand Down
2 changes: 1 addition & 1 deletion app/default_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class DefaultConfiguration:
}

MAINTENANCE_STATUSES = {
"scheduled": "Maintenance scheduled",
"in progress": "Maintenance is in progress",
"modified": "Maintenance time window has been modified",
"completed": "Maintenance is successfully completed",
Expand All @@ -57,6 +56,7 @@ class DefaultConfiguration:
INCIDENT_STATUSES = {
"analyzing": "Analyzing incident (problem not known yet)",
"fixing": "Fixing incident (problem identified, working on fix)",
"impact changed": "Impact changed (incident impact has been changed)",
"observing": "Observing fix (fix deployed, watching recovery)",
"resolved": "Incident Resolved (service is fully available. Done)",
}
Expand Down
26 changes: 26 additions & 0 deletions app/static/js/datetime_labels.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const formatDateTimeWithTimeZone = (date) => {
if (isNaN(date.getTime())) return 'Invalid Date';

const options = {
year: 'numeric',
month: 'short',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
timeZoneName: 'short',
hour12: false,
};

const localDateTime = new Intl.DateTimeFormat('en-GB', options).format(date);
return localDateTime.replace(/(\d{2})\/(\d{2})\/(\d{4}), (\d{2}:\d{2}) (.+)/, '$3-$2-$1 $4 $5');
};

const updateDateLabels = () => {
document.querySelectorAll('.datetime').forEach((element) => {
const dateTimeStr = element.textContent;
const dateTimeUTC = new Date(dateTimeStr);
element.textContent = formatDateTimeWithTimeZone(dateTimeUTC);
});
};

updateDateLabels();
56 changes: 56 additions & 0 deletions app/static/js/incident_datelabels.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const updateDateLabel = (selectElement) => {
const selectedValue = selectElement ? selectElement.value : '';
const updateDateLabelElement = document.getElementById('updateDateLabelElement');
const updateDateDiv = document.getElementById('updateDateDiv');
const updateMessageDiv = document.getElementById('updateMessageDiv');

if (updateDateLabelElement && updateDateDiv && updateMessageDiv) {
switch (selectedValue) {
case 'reopened':
updateMessageDiv.style.display = 'block';
updateDateDiv.style.display = 'none';
break;
default:
updateDateLabelElement.innerText = 'Updated at:';
updateDateDiv.style.display = 'block';
updateMessageDiv.style.display = 'block';
break;
case 'Choose status..':
updateDateLabelElement.innerText = 'Updated at:';
updateDateDiv.style.display = 'block';
updateMessageDiv.style.display = 'block';
break;
}
}
};

const updateMaintenanceFields = (selectElement) => {
const selectedValue = selectElement ? selectElement.value : '';
const updateDateLabelElement = document.getElementById('updateDateLabelElement');
const updateDateDiv = document.getElementById('updateDateDiv');
const maintenanceStartDiv = document.getElementById('maintenanceStartDiv');
const maintenanceEndDiv = document.getElementById('maintenanceEndDiv');
const updateMessageDiv = document.getElementById('updateMessageDiv');


if (maintenanceStartDiv && maintenanceEndDiv && updateMessageDiv) {
switch (selectedValue) {
case 'modified':
maintenanceStartDiv.style.display = 'block';
maintenanceEndDiv.style.display = 'block';
updateDateDiv.style.display = 'none';
break;
case 'completed':
maintenanceEndDiv.style.display = 'none';
maintenanceStartDiv.style.display = 'none';
updateDateDiv.style.display = 'block';
break;
default:
maintenanceStartDiv.style.display = 'none';
maintenanceEndDiv.style.display = 'none';
updateDateDiv.style.display = 'block';
updateDateLabelElement.innerText = 'Updated at:';
break;
}
}
};
19 changes: 19 additions & 0 deletions app/static/js/timezone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
document.addEventListener('DOMContentLoaded', () => {
const timezoneField = document.getElementById('timezone');
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC';
if (timezoneField) {
timezoneField.value = timezone;

}

const date = new Date();
const timezoneName = new Intl.DateTimeFormat('en-GB', {
timeZone: timezone,
timeZoneName: 'short'
}).formatToParts(date).find(part => part.type === 'timeZoneName').value;

const timezoneInfoElements = document.querySelectorAll('.timezone-info');
timezoneInfoElements.forEach(element => {
element.textContent = `${timezoneName}`;
});
});
90 changes: 35 additions & 55 deletions app/web/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class IncidentUpdateForm(FlaskForm):
)
update_impact = SelectField("Incident Impact")
update_status = SelectField("Update Status")
update_date = DateTimeField("Next Update by", format='%Y-%m-%dT%H:%M')
update_date = DateTimeField("Updated at:", format='%Y-%m-%dT%H:%M')
timezone = StringField("Timezone", validators=[validators.DataRequired()])
submit = SubmitField("Submit")

Expand Down Expand Up @@ -73,56 +73,26 @@ def validate_update_date(self, field):
upd_date_form = None
raise validators.ValidationError("Update date cannot be empty")

# if self.update_status.data == "resolved":
# if upd_date_form > naive_utcnow():
# raise validators.ValidationError(
# "End date cannot be in the future"
# )
# if upd_date_form < self._start_date:
# raise validators.ValidationError(
# "End date cannot be before the start date"
# )
# for timestamp in self._updates_ts:
# if upd_date_form <= timestamp:
# raise validators.ValidationError(
# "End date cannot be before any "
# "other status-update timestamp or equal"
# )
# elif self.update_status.data == "changed":
# if upd_date_form > naive_utcnow():
# raise validators.ValidationError(
# "End date cannot be in the future"
# )
# if upd_date_form < self._start_date:
# raise validators.ValidationError(
# "End date cannot be before the start date"
# )
# for timestamp in self._updates_ts:
# if upd_date_form <= timestamp:
# raise validators.ValidationError(
# "End date cannot be before any "
# "other status-update timestamp or equal"
# )
if self.update_status.data in [
"analyzing",
"fixing",
"observing",
"in progress",
"impact changed",
"resolved",
"changed",
]:
if upd_date_form > naive_utcnow():
raise validators.ValidationError(
"Update date cannot be in the future"
"The date cannot be in the future"
)
if upd_date_form < self._start_date:
raise validators.ValidationError(
"End date cannot be before the start date"
"The date cannot be before the start date"
)
for timestamp in self._updates_ts:
if upd_date_form <= timestamp:
raise validators.ValidationError(
"End date cannot be before any "
"The date cannot be before any "
"other status-update timestamp or equal"
)

Expand All @@ -144,9 +114,9 @@ class MaintenanceUpdateForm(FlaskForm):
)
update_impact = SelectField("Incident Impact")
update_status = SelectField("Update Status")
start_date = DateTimeField("Start date", format='%Y-%m-%dT%H:%M')
end_date = DateTimeField("End date", format='%Y-%m-%dT%H:%M')
update_date = DateTimeField("Next Update by", format='%Y-%m-%dT%H:%M')
start_date = DateTimeField("Start date:", format='%Y-%m-%dT%H:%M')
end_date = DateTimeField("End date:", format='%Y-%m-%dT%H:%M')
update_date = DateTimeField("Updated at:", format='%Y-%m-%dT%H:%M')
timezone = StringField("Timezone", validators=[validators.DataRequired()])
submit = SubmitField("Submit")

Expand All @@ -171,10 +141,23 @@ def validate_incident_start(self, field):

def validate_update_date(self, field):
if field.data is None:
if self.update_status.data in ["modified", "completed"]:
if (
self.update_status.data == "completed"
and naive_utcnow() > self._start_date
):
field.errors[:] = []
raise validators.StopValidation()
elif (
self.update_status.data == "completed"
and naive_utcnow() > self._start_date
):
raise validators.ValidationError(
"The date cannot be earlier than the start date"
)
if field.data is None:
if self.update_status.data == "modified":
field.errors[:] = []
raise validators.StopValidation()

if field.data is not None:
upd_date_form = naive_from_dttz(
self.update_date.data,
Expand All @@ -184,27 +167,24 @@ def validate_update_date(self, field):
upd_date_form = None
raise validators.ValidationError("Update date cannot be empty")

if self.update_status.data in [
"scheduled",
"in progress",
]:
if field.data is not None and self.update_status.data == "completed":
if upd_date_form < self._start_date:
raise validators.ValidationError(
"The date cannot be earlier than the start date"
)
if self.update_status.data == "in progress":
if upd_date_form > naive_utcnow():
raise validators.ValidationError(
"Update date cannot be in the future"
)
if upd_date_form < self._start_date:
if self._updates_ts:
raise validators.ValidationError(
"End date cannot be before the start date"
"This maintenance already has a status update, "
"no statuses should be present."
)
for timestamp in self._updates_ts:
if upd_date_form <= timestamp:
raise validators.ValidationError(
"End date cannot be before any "
"other status-update timestamp or equal"
)
if upd_date_form > self._end_date:
raise validators.ValidationError(
"The update date cannot be later than the end date"
"Update date cannot be later than the end date"
)

def validate_start_date(self, field):
Expand Down Expand Up @@ -258,12 +238,12 @@ def validate_end_date(self, field):
)
if end_date_form < start_date_form:
raise validators.ValidationError(
"End date cannot be before start date"
"End date cannot be earlier than the start date"
)
for timestamp in self._updates_ts:
if end_date_form < timestamp:
raise validators.ValidationError(
"End date cannot be before any update timestamp"
"End date cannot be earlier than any update timestamp"
)


Expand Down
Loading

0 comments on commit dadc8a6

Please sign in to comment.