Commit 8322cf53 authored by Stan Hu's avatar Stan Hu

Geo: Fix handling of nil/zero values in admin screen

If data were not available, the admin page would often show "null"
everywhere. This MR also makes it possible to enable JavaScript on
the feature spec.
parent 9ac714cb
...@@ -8,6 +8,7 @@ const unknownClass = 'geo-node-unknown'; ...@@ -8,6 +8,7 @@ const unknownClass = 'geo-node-unknown';
const healthyIcon = 'fa-check'; const healthyIcon = 'fa-check';
const unhealthyIcon = 'fa-times'; const unhealthyIcon = 'fa-times';
const unknownIcon = 'fa-times'; const unknownIcon = 'fa-times';
const notAvailable = 'Not Available';
class GeoNodeStatus { class GeoNodeStatus {
constructor(el) { constructor(el) {
...@@ -49,7 +50,19 @@ class GeoNodeStatus { ...@@ -49,7 +50,19 @@ class GeoNodeStatus {
} }
static formatCountAndPercentage(count, total, percentage) { static formatCountAndPercentage(count, total, percentage) {
return `${gl.text.addDelimiter(count)}/${gl.text.addDelimiter(total)} (${percentage})`; if (count !== null || total != null) {
return `${gl.text.addDelimiter(count)}/${gl.text.addDelimiter(total)} (${percentage})`;
}
return notAvailable;
}
static formatCount(count) {
if (count !== null) {
gl.text.addDelimiter(count);
}
return notAvailable;
} }
getStatus() { getStatus() {
...@@ -73,21 +86,21 @@ class GeoNodeStatus { ...@@ -73,21 +86,21 @@ class GeoNodeStatus {
status.repositories_count, status.repositories_count,
status.repositories_synced_in_percentage); status.repositories_synced_in_percentage);
const repoFailedText = gl.text.addDelimiter(status.repositories_failed_count); const repoFailedText = GeoNodeStatus.formatCount(status.repositories_failed_count);
const lfsText = GeoNodeStatus.formatCountAndPercentage( const lfsText = GeoNodeStatus.formatCountAndPercentage(
status.lfs_objects_synced_count, status.lfs_objects_synced_count,
status.lfs_objects_count, status.lfs_objects_count,
status.lfs_objects_synced_in_percentage); status.lfs_objects_synced_in_percentage);
const lfsFailedText = gl.text.addDelimiter(status.lfs_objects_failed_count); const lfsFailedText = GeoNodeStatus.formatCount(status.lfs_objects_failed_count);
const attachmentText = GeoNodeStatus.formatCountAndPercentage( const attachmentText = GeoNodeStatus.formatCountAndPercentage(
status.attachments_synced_count, status.attachments_synced_count,
status.attachments_count, status.attachments_count,
status.attachments_synced_in_percentage); status.attachments_synced_in_percentage);
const attachmentFailedText = gl.text.addDelimiter(status.attachments_failed_count); const attachmentFailedText = GeoNodeStatus.formatCount(status.attachments_failed_count);
this.$repositoriesSynced.text(repoText); this.$repositoriesSynced.text(repoText);
this.$repositoriesFailed.text(repoFailedText); this.$repositoriesFailed.text(repoFailedText);
...@@ -96,14 +109,14 @@ class GeoNodeStatus { ...@@ -96,14 +109,14 @@ class GeoNodeStatus {
this.$attachmentsSynced.text(attachmentText); this.$attachmentsSynced.text(attachmentText);
this.$attachmentsFailed.text(attachmentFailedText); this.$attachmentsFailed.text(attachmentFailedText);
let eventDate = 'N/A'; let eventDate = notAvailable;
let cursorDate = 'N/A'; let cursorDate = notAvailable;
if (status.last_event_timestamp !== null) { if (status.last_event_timestamp !== null && status.last_event_timestamp > 0) {
eventDate = gl.utils.formatDate(new Date(status.last_event_timestamp * 1000)); eventDate = gl.utils.formatDate(new Date(status.last_event_timestamp * 1000));
} }
if (status.cursor_last_event_timestamp !== null) { if (status.cursor_last_event_timestamp !== null && status.cursor_last_event_timestamp > 0) {
cursorDate = gl.utils.formatDate(new Date(status.cursor_last_event_timestamp * 1000)); cursorDate = gl.utils.formatDate(new Date(status.cursor_last_event_timestamp * 1000));
} }
......
...@@ -132,7 +132,7 @@ class GeoNodeStatus < ActiveRecord::Base ...@@ -132,7 +132,7 @@ class GeoNodeStatus < ActiveRecord::Base
private private
def sync_percentage(total, synced) def sync_percentage(total, synced)
return 0 if total.zero? return 0 if !total.present? || total.zero?
(synced.to_f / total.to_f) * 100.0 (synced.to_f / total.to_f) * 100.0
end end
......
...@@ -218,6 +218,12 @@ describe GeoNodeStatus, :geo do ...@@ -218,6 +218,12 @@ describe GeoNodeStatus, :geo do
expect(subject.repositories_synced_in_percentage).to eq(0) expect(subject.repositories_synced_in_percentage).to eq(0)
end end
it 'returns 0 when project count is unknown' do
allow(subject).to receive(:repositories_count).and_return(nil)
expect(subject.repositories_synced_in_percentage).to eq(0)
end
it 'returns the right percentage with no group restrictions' do it 'returns the right percentage with no group restrictions' do
create(:geo_project_registry, :synced, project: project_1) create(:geo_project_registry, :synced, project: project_1)
......
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