Skip to content

Commit

Permalink
Add Version Filter to UI
Browse files Browse the repository at this point in the history
Signed-off-by: Musilah <[email protected]>
  • Loading branch information
Musilah committed Aug 6, 2023
1 parent 37b6eb1 commit 658d305
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 23 deletions.
1 change: 1 addition & 0 deletions api/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func retrieveSummaryEndpoint(svc callhome.Service) endpoint.Endpoint {
Countries: summary.Countries,
Cities: summary.Cities,
Services: summary.Services,
Mf_Versions: summary.Mf_Versions,

This comment has been minimized.

Copy link
@drasko

drasko Aug 6, 2023

Contributor

It is not idiomatic to use underscore in variable names. Probably it should be something like MFVer or MFVersion

TotalDeployments: summary.TotalDeployments,
}, nil
}
Expand Down
1 change: 1 addition & 0 deletions api/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type telemetrySummaryRes struct {
Countries []callhome.CountrySummary `json:"countries,omitempty"`
Cities []string `json:"cities,omitempty"`
Services []string `json:"services,omitempty"`
Mf_Versions []string `json:"mf_version,omitempty"`

This comment has been minimized.

Copy link
@drasko

drasko Aug 6, 2023

Contributor

Why is JSON mf_version field unmarshalled in to something that is versions, i.e. plural, i.e. string array. If it is array in the JSON, why over there is not called also mf_versions (plural)? This inconsistency is confusing.

This comment has been minimized.

Copy link
@Musilah

Musilah Aug 7, 2023

Contributor

That was a slight mistake. Lemme correct the error.

TotalDeployments int `json:"total_deployments,omitempty"`
}

Expand Down
40 changes: 21 additions & 19 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,26 +94,28 @@ func (ts *telemetryService) ServeUI(ctx context.Context, filters TelemetryFilter
to = filters.To.Format(time.DateOnly)
}
data := struct {
Countries string
Cities string
FilterCountries []CountrySummary
FilterCities []string
FilterServices []string
NoDeployments int
NoCountries int
MapData string
From string
To string
Countries string
Cities string
FilterCountries []CountrySummary
FilterCities []string
FilterServices []string
FilterMf_Versions []string
NoDeployments int
NoCountries int
MapData string
From string
To string
}{
Countries: string(countries),
FilterCountries: unfilteredSummary.Countries,
FilterCities: unfilteredSummary.Cities,
FilterServices: unfilteredSummary.Services,
NoDeployments: summary.TotalDeployments,
NoCountries: len(summary.Countries),
MapData: string(pg),
From: from,
To: to,
Countries: string(countries),
FilterCountries: unfilteredSummary.Countries,
FilterCities: unfilteredSummary.Cities,
FilterServices: unfilteredSummary.Services,
FilterMf_Versions: unfilteredSummary.Mf_Versions,
NoDeployments: summary.TotalDeployments,
NoCountries: len(summary.Countries),
MapData: string(pg),
From: from,
To: to,
}

var res bytes.Buffer
Expand Down
1 change: 1 addition & 0 deletions telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type TelemetrySummary struct {
Countries []CountrySummary `json:"countries,omitempty"`
Cities []string `json:"cities,omitempty"`
Services []string `json:"services,omitempty"`
Mf_Versions []string `json:"mf_version,omitempty"`
TotalDeployments int `json:"total_deployments,omitempty"`
}

Expand Down
14 changes: 14 additions & 0 deletions timescale/timescale.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,20 @@ func (r repo) RetrieveSummary(ctx context.Context, filters callhome.TelemetryFil
}
summary.Services = append(summary.Services, val)
}

q3 := fmt.Sprintf(`select distinct mf_version from telemetry %s;`, filterQuery)
mf_versionRows, err := r.db.NamedQuery(q3, params)
if err != nil {
return callhome.TelemetrySummary{}, err
}
defer mf_versionRows.Close()
for mf_versionRows.Next() {
var val string
if err := mf_versionRows.Scan(&val); err != nil {
return callhome.TelemetrySummary{}, err
}
summary.Mf_Versions = append(summary.Mf_Versions, val)
}
return summary, nil
}

Expand Down
5 changes: 3 additions & 2 deletions web/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ body {
.btn {
margin-left: 20px;
margin-right: 20px;
padding: 5px 20px;
padding: 10px 20px;
text-align: center;
line-height: 10px;
line-height: 10px;
margin-top: 10px;
}

#map {
Expand Down
7 changes: 5 additions & 2 deletions web/template/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ <h1 class="modal-title fs-5" id="applyFiltersLabel">Apply Filters</h1>
<label for="version-filter" class="form-label">Version</label>
<select id="version-filter" class="form-select">
<option value="">Select a Version</option>

{{range $i, $mf_version := .FilterMf_Versions}}
<option value="{{$mf_version}}">{{$mf_version}}</option>
{{end}}
</select>
<label for="service-filter" class="form-label">Service</label>
<select id="service-filter" class="form-select">
Expand Down Expand Up @@ -96,6 +98,7 @@ <h1 class="modal-title fs-5" id="applyFiltersLabel">Apply Filters</h1>
var selectedCountry = document.getElementById('country-filter').value;
var selectedCity = document.getElementById('city-filter').value;
var selectedService = document.getElementById('service-filter').value;
var selectedMf_Version = document.getElementById('version-filter').value;

var fromDate = fromDateInput ? new Date(fromDateInput) : null;
var toDate = toDateInput ? new Date(toDateInput) : null;
Expand All @@ -112,7 +115,7 @@ <h1 class="modal-title fs-5" id="applyFiltersLabel">Apply Filters</h1>
var fromDate = fromDateInput ? new Date(fromDateInput).toISOString() : '';
var toDate = toDateInput ? new Date(toDateInput).toISOString() : '';

var url = `/?from=${encodeURIComponent(fromDate)}&to=${encodeURIComponent(toDate)}&country=${encodeURIComponent(selectedCountry)}&city=${encodeURIComponent(selectedCity)}&service=${encodeURIComponent(selectedService)}`;
var url = `/?from=${encodeURIComponent(fromDate)}&to=${encodeURIComponent(toDate)}&country=${encodeURIComponent(selectedCountry)}&city=${encodeURIComponent(selectedCity)}&service=${encodeURIComponent(selectedService)}&mf_version=${encodeURIComponent(selectedMf_Version)}`;
window.location.href = url;
}

Expand Down

0 comments on commit 658d305

Please sign in to comment.