Skip to content

Commit 563a567

Browse files
authored
Merge pull request #423 from fablabbcn/monolith-final-snagging
Monolith final snagging
2 parents c88963b + be66f8d commit 563a567

39 files changed

Lines changed: 294 additions & 78 deletions

app/assets/stylesheets/application.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@
3131
@import "components/reading";
3232
@import "components/devices_typeahead";
3333
@import "components/extra_info";
34+
@import "components/blurable";

app/assets/stylesheets/bootstrap_variables.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ $green: #00E597;
3333
$teal: #2CB5AE;
3434
$yellow: #FFC100;
3535

36+
$darker-yellow: #CC9900;
37+
3638
$primary: $yellow;
3739
$info: $purple;
3840

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.blurable {
2+
position: relative;
3+
.blurable-inner {
4+
filter: blur(0.25rem);
5+
}
6+
.blurable-cta-container {
7+
position: absolute;
8+
top: 0;
9+
left: 0;
10+
bottom: 0;
11+
right: 0;
12+
display: flex;
13+
align-items: center;
14+
.blurable-cta {
15+
display: block;
16+
background-color: $yellow;
17+
color: $black;
18+
padding: 0.5rem 1rem;
19+
margin: 0 auto;
20+
width: fit-content;
21+
border-radius: 1rem;
22+
filter: drop-shadow(5px 5px 5px rgba(0, 0, 0, 0.5));
23+
font-weight: 600;
24+
border: 1px solid #1c1c1c;
25+
text-transform: uppercase;
26+
font-family: "Kanit";
27+
text-decoration: none;
28+
&:hover, &:active {
29+
text-decoration: underline;
30+
}
31+
}
32+
}
33+
}

app/assets/stylesheets/global.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,16 @@ a.subtle-link {
318318
fill: $green;
319319
}
320320

321+
&.partially-online {
322+
color: $yellow;
323+
fill: $yellow;
324+
}
325+
326+
.darker &.partially-online {
327+
color: $darker-yellow;
328+
fill: $darker-yellow;
329+
}
330+
321331
&.offline {
322332
color: $red;
323333
fill: $red;

app/controllers/ui/experiments_controller.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,29 @@ def authorize_experiment!(action, alert)
131131
end
132132

133133
def experiment_params
134-
params.require(:experiment).permit(
134+
new_params = params.require(:experiment).permit(
135135
:name,
136136
:description,
137137
:is_test,
138138
:starts_at,
139139
:ends_at,
140-
{ :device_ids => [] },
141-
).transform_values {|v| v.blank? ? nil : v }
140+
{ device_ids: [] }
141+
).transform_values { |v| v.blank? ? nil : v }
142+
new_params[:starts_at] = parse_local_time(new_params[:starts_at])
143+
new_params[:ends_at] = parse_local_time(new_params[:ends_at])
144+
new_params
142145
end
143146

144147
def owner_name(capitalize=true)
145148
owner = @experiment&.owner || current_user
146149
helpers.possessive(owner, current_user, capitalize: capitalize, third_person: true)
147150
end
151+
152+
def parse_local_time(time)
153+
tz = current_user&.time_zone || ActiveSupport::TimeZone["Etc/UTC"]
154+
time && tz.rfc3339(time)
155+
rescue ArgumentError
156+
time
157+
end
148158
end
149159
end

app/controllers/ui/users_controller.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def create
4747
:email,
4848
:password,
4949
:password_confirmation,
50+
:preferred_time_zone,
5051
:ts_and_cs,
5152
))
5253
if @user.valid?
@@ -121,7 +122,8 @@ def user_params
121122
:password_confirmation,
122123
:city,
123124
:country_code,
124-
:url
125+
:url,
126+
:preferred_time_zone
125127
)
126128
end
127129

app/controllers/v0/readings_controller.rb

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,15 @@ def index
1111
check_missing_params("rollup", "sensor_key||sensor_id") # sensor_key or sensor_id
1212
return unless check_date_param_format("from")
1313
return unless check_date_param_format("to")
14-
render json: Kairos.query(params)
14+
data = Kairos.query(params)
15+
if params["localtimes"] == "1"
16+
render json: convert_to_local_times(data)
17+
else
18+
render json: data
19+
end
1520
end
1621

22+
1723
def create
1824
check_missing_params("data")
1925
@device = Device.includes(:components).find(params[:id])
@@ -36,13 +42,12 @@ def create
3642
end
3743

3844
def legacy_create
39-
4045
if request.headers['X-SmartCitizenData']
4146
storer = RawStorer.new
4247
JSON.parse(request.headers['X-SmartCitizenData']).each do |raw_reading|
4348
mac = request.headers['X-SmartCitizenMacADDR']
4449
version = request.headers['X-SmartCitizenVersion']
45-
ip = (request.headers['X-SmartCitizenIP'] || request.remote_ip)
50+
ip = request.headers['X-SmartCitizenIP'] || request.remote_ip
4651
storer.store(raw_reading,mac,version,ip)
4752
end
4853
end
@@ -65,5 +70,18 @@ def csv_archive
6570
end
6671
end
6772

73+
74+
private
75+
76+
def convert_to_local_times(data)
77+
tz = current_user&.time_zone || ActiveSupport::TimeZone["Etc/UTC"]
78+
from = tz.at(data["from"])
79+
to = tz.at(data["to"])
80+
readings = data["readings"].map {|reading|
81+
[tz.at(reading[0]), reading[1]]
82+
}
83+
data.merge({ from: from, to: to, readings: readings })
84+
end
85+
6886
end
6987
end

app/helpers/application_helper.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ def show_svg(path)
44
raw file.read
55
end
66
end
7+
78
def flash_class(level)
89
case level.to_sym
910
when :success then "alert alert-success"
@@ -13,6 +14,19 @@ def flash_class(level)
1314
end
1415
end
1516

17+
def device_collection_status_class(container)
18+
if container.all_devices_online?
19+
"online"
20+
elsif container.all_devices_offline?
21+
"offline"
22+
else
23+
"partially-online"
24+
end
25+
end
26+
27+
def local_time_zone
28+
current_user&.time_zone || ActiveSupport::TimeZone["Etc/UTC"]
29+
end
1630

1731
def sc_nav_button_to(legend, path, opts={})
1832
button_class = opts[:dark_buttons] ? "btn-dark" : "btn-secondary"

app/javascript/application.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {setupMapLocationPickers} from "components/map_location_picker";
77
import {setupReadings} from "components/reading";
88
import {setupDevicesTypeahead} from "components/devices_typeahead";
99
import {setupExtraInfos} from "components/extra_info";
10+
import {setupAutoFillTimeZone} from "components/auto_fill_time_zone";
11+
import {setupBlurables} from "components/blurable";
1012

1113
export default function setupApplication() {
1214
$(function() {
@@ -21,5 +23,7 @@ export default function setupApplication() {
2123
setupExtraInfos();
2224
setupDevicesTypeahead();
2325
setupReadings();
26+
setupAutoFillTimeZone();
27+
setupBlurables();
2428
});
2529
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as $ from "jquery";
2+
3+
export function setupAutoFillTimeZone() {
4+
const tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
5+
$(".auto_fill_time_zone").val(tz);
6+
}

0 commit comments

Comments
 (0)