Skip to content

Commit

Permalink
rationalizes query parameter names to match field names
Browse files Browse the repository at this point in the history
  • Loading branch information
smirolo committed Dec 27, 2023
1 parent 0da54e4 commit 39554a9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
11 changes: 5 additions & 6 deletions saas/api/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class MetricsMixin(DateRangeContextMixin, ProviderMixin):
"""
Base class for metrics APIs
"""
period_type_param = 'period'
nb_periods_param = 'num_periods'
period_type_param = 'period_type'
nb_periods_param = 'nb_periods'
serializer_class = MetricsSerializer

@extend_schema(parameters=[QueryParamPeriodSerializer])
Expand All @@ -63,7 +63,6 @@ def get(self, request, *args, **kwargs):
nb_periods = query_serializer.validated_data.get(self.nb_periods_param)
period_type = query_serializer.validated_data.get(
self.period_type_param, humanize.MONTHLY)
print("XXX [MetricsMixin] query_serializer.validated_data=%s" % str(query_serializer.validated_data))

date_periods = convert_dates_to_utc(
generate_periods(period_type, nb_periods=nb_periods,
Expand All @@ -87,7 +86,7 @@ class BalancesAPIView(MetricsMixin, GenericAPIView):
The date from which trailing balances are computed can be specified
by the `ends_at` query parameter. The type of periods (hourly, daily,
weekly, monthly, yearly) to aggregate balances over, and the number of
periods to return can be specificed by `period` and `num_periods`
periods to return can be specificed by `period_type` and `nb_periods`
respectively.
The API is typically used within an HTML
Expand Down Expand Up @@ -447,7 +446,7 @@ class CustomerMetricAPIView(MetricsMixin, GenericAPIView):
The date from which trailing balances are computed can be specified
by the `ends_at` query parameter. The type of periods (hourly, daily,
weekly, monthly, yearly) to aggregate balances over, and the number of
periods to return can be specificed by `period` and `num_periods`
periods to return can be specificed by `period_type` and `nb_periods`
respectively.
The API is typically used within an HTML
Expand Down Expand Up @@ -667,7 +666,7 @@ class PlanMetricAPIView(MetricsMixin, GenericAPIView):
The date from which trailing balances are computed can be specified
by the `ends_at` query parameter. The type of periods (hourly, daily,
weekly, monthly, yearly) to aggregate balances over, and the number of
periods to return can be specificed by `period` and `num_periods`
periods to return can be specificed by `period_type` and `nb_periods`
respectively.
The API is typically used within an HTML
Expand Down
4 changes: 2 additions & 2 deletions saas/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1458,11 +1458,11 @@ class QueryParamPeriodSerializer(NoModelSerializer):
ends_at = serializers.CharField(required=False,
help_text=_("Data/time for the end of the period (in ISO format)"))

period = EnumField(choices=Plan.INTERVAL_CHOICES, required=False,
period_type = EnumField(choices=Plan.INTERVAL_CHOICES, required=False,
help_text=_("Natural period length"\
" (hourly, daily, weekly, monthly, yearly). Defaults to monthly."))

num_periods = serializers.IntegerField(
nb_periods = serializers.IntegerField(
required=False,
min_value=1,
max_value=100,
Expand Down
14 changes: 7 additions & 7 deletions saas/static/js/djaodjin-saas-vue.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021, DjaoDjin inc.
// Copyright (c) 2023, DjaoDjin inc.
// All rights reserved.
// BSD 2-Clause license

Expand Down Expand Up @@ -348,7 +348,7 @@ var timezoneMixin = {
},
methods: {
// Used to be filters but Vue3 will not allow it.
asPeriodHeading: function(datetime, periodType, tzString) {
asPeriodHeading: function(atTime, periodType, tzString) {
var datetime = null;
if( typeof atTime === 'string' ) {
datetime = new Date(atTime);
Expand Down Expand Up @@ -1620,7 +1620,7 @@ Vue.component('metrics-charts', {
params: {
ends_at: this.datetimeOrNow(
this.$dateRange ? this.$dateRange.ends_at : null),
period: "monthly"
period_type: "monthly"
},
}
return data;
Expand All @@ -1630,7 +1630,7 @@ Vue.component('metrics-charts', {
var vm = this;
var params = {
ends_at: vm.params.ends_at,
period: vm.params.period,
period_type: vm.params.period_type,
};
if( vm.timezone ) {
params["timezone"] = vm.timezone;
Expand Down Expand Up @@ -1750,12 +1750,12 @@ Vue.component('metrics-charts', {
this.get();
}
},
period: {
periodType: {
get: function() {
return this.params.period;
return this.params.period_type;
},
set: function(newVal) {
this.$set(this.params, 'period', newVal);
this.$set(this.params, 'period_type', newVal);
this.get();
}
},
Expand Down
6 changes: 3 additions & 3 deletions saas/templates/saas/metrics/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
<option value="local">Local</option>
<option value="utc">UTC</option>
</select>
<select name="period"
<select name="period_type"
ng-model="period"
ng-change="prepareCurrentTabData(ends_at, timezone, period)"
v-model="period"
v-model="periodType"
@change="prepareCurrentTabData">
<option value="hourly">Hourly</option>
<option value="daily">Daily</option>
Expand Down Expand Up @@ -58,7 +58,7 @@
<td></td>
<th ng-repeat="col in table.data[0].values"
v-for="col in table.data[0].values">
[[ asPeriodHeading(col[0], params.period, '{{organization.default_timezone}}') ]]
[[ asPeriodHeading(col[0], params.period_type, '{{organization.default_timezone}}') ]]
</th>
</tr>
<tr ng-prop-id="row.slug"
Expand Down

0 comments on commit 39554a9

Please sign in to comment.