Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to configure preset time ranges #313

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 2.3.1 (unreleased)

- Improved column names for uploads
- Allow to configure time range selector preset ranges

## 2.3.0 (2020-11-16)

Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,15 @@ Use `{start_time}` and `{end_time}` for time ranges. [Example](https://blazer.do
SELECT * FROM ratings WHERE rated_at >= {start_time} AND rated_at <= {end_time}
```

You can configure the available preset ranges in the time range selector in `blazer.yml`. The default configuration, if none is provided, is:

```yaml
timepicker_ranges:
- ["Today", 0, 0]
- ["Last 7 Days", 6, 0]
- ["Last 30 Days", 29, 0]
```

### Smart Variables

[Example](https://blazer.dokkuapp.com/queries/1-smart-variable)
Expand Down
11 changes: 6 additions & 5 deletions app/views/blazer/_variables.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,14 @@
$("#end_time").val(toDate(end).endOf("day").utc().format())
}

var datepickerRanges = <%=raw Blazer.timepicker_ranges %>;

$("#reportrange").daterangepicker(
{
ranges: {
"Today": [dateStr(), dateStr()],
"Last 7 Days": [dateStr(6), dateStr()],
"Last 30 Days": [dateStr(29), dateStr()]
},
ranges: datepickerRanges.reduce(function(map, range) {
map[range[0]] = [dateStr(range[1]), dateStr(range[2])];
return map;
}, {}),
locale: {
format: format
},
Expand Down
4 changes: 4 additions & 0 deletions lib/blazer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ def self.data_sources
end
end

def self.timepicker_ranges
settings["timepicker_ranges"] || [["Today", 0, 0], ["Last 7 Days", 6, 0], ["Last 30 Days", 29, 0]]
end

def self.extract_vars(statement)
# strip commented out lines
# and regex {1} or {1,2}
Expand Down