Skip to content

Commit

Permalink
Merge branch 'staging' into issue-1685
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio Dessi committed Mar 3, 2020
2 parents 63b3337 + 2c6033f commit dd46830
Show file tree
Hide file tree
Showing 692 changed files with 7,513 additions and 5,412 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ gem "scenic"
gem "secure_headers"
gem "tzinfo" # For validation of user selected timezone names
gem "valid_url"
# gem "farady", "~> 1.0.0"
gem "kaminari"

group :development, :test do
gem "climate_control"
Expand Down
46 changes: 30 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ GEM
amq-protocol (2.3.0)
bcrypt (3.1.13)
builder (3.2.4)
bunny (2.14.3)
bunny (2.14.4)
amq-protocol (~> 2.3, >= 2.3.0)
case_transform (0.2)
activesupport
Expand All @@ -82,9 +82,9 @@ GEM
simplecov
url
coderay (1.1.2)
concurrent-ruby (1.1.5)
concurrent-ruby (1.1.6)
crass (1.0.6)
database_cleaner (1.7.0)
database_cleaner (1.8.3)
declarative (0.0.10)
declarative-option (0.1.0)
delayed_job (4.1.8)
Expand All @@ -100,7 +100,7 @@ GEM
warden (~> 1.2.3)
diff-lcs (1.3)
digest-crc (0.4.1)
discard (1.1.0)
discard (1.2.0)
activerecord (>= 4.2, < 7)
docile (1.3.2)
erubi (1.9.0)
Expand All @@ -109,7 +109,7 @@ GEM
factory_bot_rails (5.1.1)
factory_bot (~> 5.1.0)
railties (>= 4.2.0)
faker (2.10.1)
faker (2.10.2)
i18n (>= 1.6, < 2)
faraday (0.15.4)
multipart-post (>= 1.2, < 3)
Expand All @@ -119,18 +119,20 @@ GEM
railties (>= 3.2, < 6.1)
globalid (0.4.2)
activesupport (>= 4.2.0)
google-api-client (0.36.4)
google-api-client (0.37.1)
addressable (~> 2.5, >= 2.5.1)
googleauth (~> 0.9)
httpclient (>= 2.8.1, < 3.0)
mini_mime (~> 1.0)
representable (~> 3.0)
retriable (>= 2.0, < 4.0)
signet (~> 0.12)
google-cloud-core (1.4.1)
google-cloud-core (1.5.0)
google-cloud-env (~> 1.0)
google-cloud-errors (~> 1.0)
google-cloud-env (1.3.0)
faraday (~> 0.11)
google-cloud-errors (1.0.0)
google-cloud-storage (1.25.1)
addressable (~> 2.5)
digest-crc (~> 0.4)
Expand All @@ -153,6 +155,18 @@ GEM
json (2.3.0)
jsonapi-renderer (0.2.2)
jwt (2.2.1)
kaminari (1.2.0)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.0)
kaminari-activerecord (= 1.2.0)
kaminari-core (= 1.2.0)
kaminari-actionview (1.2.0)
actionview
kaminari-core (= 1.2.0)
kaminari-activerecord (1.2.0)
activerecord
kaminari-core (= 1.2.0)
kaminari-core (1.2.0)
loofah (2.4.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
Expand All @@ -162,7 +176,7 @@ GEM
mimemagic (~> 0.3.2)
memoist (0.16.2)
method_source (0.9.2)
mimemagic (0.3.3)
mimemagic (0.3.4)
mini_mime (1.0.2)
mini_portile2 (2.4.0)
minitest (5.14.0)
Expand All @@ -171,7 +185,7 @@ GEM
mutations (0.9.0)
activesupport
nio4r (2.5.2)
nokogiri (1.10.7)
nokogiri (1.10.8)
mini_portile2 (~> 2.4.0)
orm_adapter (0.5.0)
os (1.0.1)
Expand All @@ -190,7 +204,7 @@ GEM
faraday_middleware (~> 0.13.0)
hashie (~> 3.6)
multi_json (~> 1.13.1)
rack (2.1.1)
rack (2.2.2)
rack-attack (6.2.2)
rack (>= 1.0, < 3)
rack-cors (1.1.1)
Expand Down Expand Up @@ -240,7 +254,7 @@ GEM
actionpack (>= 5.0)
railties (>= 5.0)
retriable (3.1.2)
rollbar (2.23.2)
rollbar (2.24.0)
rspec (3.9.0)
rspec-core (~> 3.9.0)
rspec-expectations (~> 3.9.0)
Expand All @@ -264,7 +278,7 @@ GEM
rspec-support (3.9.2)
rspec_junit_formatter (0.4.1)
rspec-core (>= 2, < 4, != 2.12.0)
scenic (1.5.1)
scenic (1.5.2)
activerecord (>= 4.0.0)
railties (>= 4.0.0)
secure_headers (6.3.0)
Expand All @@ -273,11 +287,10 @@ GEM
faraday (~> 0.9)
jwt (>= 1.5, < 3.0)
multi_json (~> 1.10)
simplecov (0.17.1)
simplecov (0.18.5)
docile (~> 1.1)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
simplecov-html (~> 0.11)
simplecov-html (0.12.1)
sprockets (4.0.0)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
Expand Down Expand Up @@ -320,6 +333,7 @@ DEPENDENCIES
google-cloud-storage (~> 1.11)
hashdiff
jwt
kaminari
mutations
passenger
pg
Expand Down
10 changes: 10 additions & 0 deletions app/controllers/api/abstract_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ def default_serializer_options
{ root: false, user: current_user }
end

def maybe_paginate(collection)
page = params[:page]
per = params[:per]

if page && per
render json: collection.page(page).per(per)
else
render json: collection
end
end
private

def clean_expired_farm_events
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/alerts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Api
class AlertsController < Api::AbstractController
def index
render json: current_device.alerts
maybe_paginate current_device.alerts
end

def destroy
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/farm_events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class FarmEventsController < Api::AbstractController
before_action :clean_expired_farm_events, only: [:index]

def index
render json: current_device.farm_events
maybe_paginate current_device.farm_events
end

def show
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/farmware_envs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def create
end

def index
render json: farmware_envs
maybe_paginate farmware_envs
end

def show
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/farmware_installations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Api
class FarmwareInstallationsController < Api::AbstractController
def index
render json: farmware_installations
maybe_paginate farmware_installations
end

def show
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/peripherals_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Api
class PeripheralsController < Api::AbstractController
def index
render json: current_device.peripherals
maybe_paginate current_device.peripherals
end

def show
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/pin_bindings_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Api
class PinBindingsController < Api::AbstractController
def index
render json: pin_bindings
maybe_paginate pin_bindings
end

def show
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/plant_templates_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Api
class PlantTemplatesController < Api::AbstractController
def index
render json: current_device.plant_templates
maybe_paginate current_device.plant_templates
end

def create
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/point_groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class PointGroupsController < Api::AbstractController
before_action :clean_expired_farm_events, only: [:destroy]

def index
render json: your_point_groups
maybe_paginate your_point_groups
end

def show
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/points_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def index
.where("discarded_at < ?", Time.now - HARD_DELETE_AFTER)
.destroy_all

render json: points(params.fetch(:filter) { "kept" })
maybe_paginate points(params.fetch(:filter) { "kept" })
end

def show
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/regimens_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class RegimensController < Api::AbstractController
before_action :clean_expired_farm_events, only: [:destroy]

def index
render json: your_regimens
maybe_paginate your_regimens
end

def show
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/saved_gardens_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Api
class SavedGardensController < Api::AbstractController
def index
render json: current_device.saved_gardens
maybe_paginate current_device.saved_gardens
end

def create
Expand Down
24 changes: 20 additions & 4 deletions app/controllers/api/sensor_readings_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
module Api
class SensorReadingsController < Api::AbstractController
LIMIT = 5000
before_action :clean_old

def create
mutate SensorReadings::Create.run(raw_json, device: current_device)
mutate SensorReadings::Create.run(raw_json, device: current_device)
end

def index
render json: readings
maybe_paginate(readings)
end

def show
Expand All @@ -17,10 +20,23 @@ def destroy
render json: ""
end

private
private

def clean_old
if current_device.sensor_readings.count > LIMIT
current_device
.sensor_readings
.where
.not(id: readings.pluck(:id))
.delete_all
end
end

def readings
SensorReading.where(device: current_device)
@readings ||= SensorReading
.where(device: current_device)
.order(created_at: :desc)
.limit(LIMIT)
end

def reading
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/sensors_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Api
class SensorsController < Api::AbstractController
def index
render json: current_device.sensors
maybe_paginate current_device.sensors
end

def show
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/tools_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Api
class ToolsController < Api::AbstractController

def index
render json: tools
maybe_paginate tools
end

def show
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/webcam_feeds_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def create
end

def index
render json: webcams
maybe_paginate webcams
end

def show
Expand Down
7 changes: 4 additions & 3 deletions app/models/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,10 @@ def help_customer
end

TOO_MANY_CONNECTIONS =
"Your device is " +
"reconnecting to the server too often. Please " +
"see https://developer.farm.bot/docs/connectivity-issues"
"Your device is reconnecting to the server too often. " +
"This may be a sign of local network issues. " +
"Please review the documentation provided at " +
"https://software.farm.bot/docs/connecting-farmbot-to-the-internet"
def self.connection_warning(username)
device_id = username.split("_").last.to_i || 0
device = self.find_by(id: device_id)
Expand Down
2 changes: 1 addition & 1 deletion app/models/in_use_point.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class InUsePoint < ApplicationRecord
DEFAULT_NAME = "point"
FANCY_NAMES = {
GenericPointer.name => DEFAULT_NAME,
ToolSlot.name => "tool slot",
ToolSlot.name => "slot",
Plant.name => "plant",
}

Expand Down
2 changes: 1 addition & 1 deletion app/models/point_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class PointGroup < ApplicationRecord
BAD_SORT = "%{value} is not valid. Valid options are: " +
SORT_TYPES.map(&:inspect).join(", ")
DEFAULT_CRITERIA = {
day: { op: "<", days: 0 },
day: { op: "<", days_ago: 0 },
string_eq: {},
number_eq: {},
number_lt: {},
Expand Down
2 changes: 1 addition & 1 deletion app/models/tool_slot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ToolSlot < Point
MIN_PULLOUT = PULLOUT_DIRECTIONS.min
PULLOUT_ERR = "must be a value between #{MIN_PULLOUT} and #{MAX_PULLOUT}. "\
"%{value} is not valid."
IN_USE = "already in use by another tool slot. "\
IN_USE = "already in use by another slot. "\
"Please un-assign the tool from its current slot"\
" before reassigning."

Expand Down
2 changes: 2 additions & 0 deletions app/mutations/devices/create_seed_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ class CreateSeedData < Mutations::Command
"genesis_1.2" => Devices::Seeders::GenesisOneTwo,
"genesis_1.3" => Devices::Seeders::GenesisOneThree,
"genesis_1.4" => Devices::Seeders::GenesisOneFour,
"genesis_1.5" => Devices::Seeders::GenesisOneFive,
"genesis_xl_1.4" => Devices::Seeders::GenesisXlOneFour,
"genesis_xl_1.5" => Devices::Seeders::GenesisXlOneFive,

"demo_account" => Devices::Seeders::DemoAccountSeeder,
"none" => Devices::Seeders::None,
Expand Down
Loading

0 comments on commit dd46830

Please sign in to comment.