diff --git a/Gemfile b/Gemfile index 9a5d051..975cc50 100644 --- a/Gemfile +++ b/Gemfile @@ -8,11 +8,13 @@ gem 'pg', '>= 0.18', '< 2.0' gem 'puma', '~> 3.11' gem 'sass-rails', '~> 5.0' gem 'uglifier', '>= 1.3.0' +gem 'jquery-rails' gem 'coffee-rails', '~> 4.2' gem 'turbolinks', '~> 5' gem 'jbuilder', '~> 2.5' gem 'bootsnap', '>= 1.1.0', require: false gem 'activerecord-import' +gem 'kaminari' group :development, :test do gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] diff --git a/Gemfile.lock b/Gemfile.lock index a5b5a1d..f9d5bbf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -87,6 +87,22 @@ GEM io-like (0.3.0) jbuilder (2.9.1) activesupport (>= 4.2.0) + jquery-rails (4.3.5) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) + kaminari (1.1.1) + activesupport (>= 4.1.0) + kaminari-actionview (= 1.1.1) + kaminari-activerecord (= 1.1.1) + kaminari-core (= 1.1.1) + kaminari-actionview (1.1.1) + actionview + kaminari-core (= 1.1.1) + kaminari-activerecord (1.1.1) + activerecord + kaminari-core (= 1.1.1) + kaminari-core (1.1.1) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -204,6 +220,8 @@ DEPENDENCIES chromedriver-helper coffee-rails (~> 4.2) jbuilder (~> 2.5) + jquery-rails + kaminari listen (>= 3.0.5, < 3.2) pg (>= 0.18, < 2.0) pry diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 82e6f0f..de6a7de 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -10,6 +10,7 @@ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details // about supported directives. // +//= require jquery //= require rails-ujs //= require activestorage //= require turbolinks diff --git a/app/assets/javascripts/mushrooms.coffee b/app/assets/javascripts/mushrooms.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/mushrooms.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index d05ea0f..0959a46 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -13,3 +13,38 @@ *= require_tree . *= require_self */ + +.body-container { + padding: 20px; + padding-right: 50px; +} + +.table-container, .filters { + height: 100vh; + overflow: scroll; +} + +thead th, .title { + position: sticky; + top: 0; +} + +th, td { + padding: 8px 16px; +} + +th, .title { + background:#eee; +} + +.title { + padding: 15px; +} + +.select-wrapper { + padding-top: 15px; +} + +label { + font-size: 1.5em !important; +} diff --git a/app/assets/stylesheets/mushrooms.scss b/app/assets/stylesheets/mushrooms.scss new file mode 100644 index 0000000..326df7f --- /dev/null +++ b/app/assets/stylesheets/mushrooms.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the mushrooms controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/mushrooms_controller.rb b/app/controllers/mushrooms_controller.rb new file mode 100644 index 0000000..3766922 --- /dev/null +++ b/app/controllers/mushrooms_controller.rb @@ -0,0 +1,10 @@ +class MushroomsController < ApplicationController + + def index + @mushrooms = [] + + if params[:filter].present? + @mushrooms = FilterMushroom.new(params[:filter], params[:page]).run + end + end +end diff --git a/app/helpers/mushrooms_helper.rb b/app/helpers/mushrooms_helper.rb new file mode 100644 index 0000000..4b3efde --- /dev/null +++ b/app/helpers/mushrooms_helper.rb @@ -0,0 +1,16 @@ +module MushroomsHelper + include MushroomAttributesInfo + + def mushroom_attributes_values(key) + MUSHROOM_ATTRIBUTES[key].values + end + + def filter_selected?(key, value) + if params[:filter].blank? + '' + elsif params[:filter][key]&.include?(value) + 'selected' + else + end + end +end diff --git a/db/mushroom_attributes_info.rb b/app/models/concerns/mushroom_attributes_info.rb similarity index 100% rename from db/mushroom_attributes_info.rb rename to app/models/concerns/mushroom_attributes_info.rb diff --git a/app/services/filter_mushroom.rb b/app/services/filter_mushroom.rb new file mode 100644 index 0000000..8944911 --- /dev/null +++ b/app/services/filter_mushroom.rb @@ -0,0 +1,60 @@ +class FilterMushroom + attr_reader :page + + def initialize(filter_params, page) + @page = page + @mushroom_class = filter_params[:mushroom_class] + @cap_shape = filter_params[:cap_shape] + @cap_surface = filter_params[:cap_surface] + @cap_color = filter_params[:cap_color] + @bruises = filter_params[:bruises] + @odor = filter_params[:odor] + @gill_attachment = filter_params[:gill_attachment] + @gill_spacing = filter_params[:gill_spacing] + @gill_size = filter_params[:gill_size] + @gill_color = filter_params[:gill_color] + @stalk_shape = filter_params[:stalk_shape] + @stalk_root = filter_params[:stalk_root] + @stalk_surface_above_ring = filter_params[:stalk_surface_above_ring] + @stalk_surface_below_ring = filter_params[:stalk_surface_below_ring] + @stalk_color_above_ring = filter_params[:stalk_color_above_ring] + @stalk_color_below_ring = filter_params[:stalk_color_below_ring] + @veil_type = filter_params[:veil_type] + @veil_color = filter_params[:veil_color] + @ring_number = filter_params[:ring_number] + @ring_type = filter_params[:ring_type] + @spore_print_color = filter_params[:spore_print_color] + @population = filter_params[:population] + @habitat = filter_params[:habitat] + end + + def run + query = Mushroom.all + + query = query.where(mushroom_class: @mushroom_class) if @mushroom_class.present? + query = query.where(cap_shape: @cap_shape) if @cap_shape.present? + query = query.where(cap_surface: @cap_surface) if @cap_surface.present? + query = query.where(cap_color: @cap_color) if @cap_color.present? + query = query.where(bruises: @bruises) if @bruises.present? + query = query.where(odor: @odor) if @odor.present? + query = query.where(gill_attachment: @gill_attachment) if @gill_attachment.present? + query = query.where(gill_spacing: @gill_spacing) if @gill_spacing.present? + query = query.where(gill_size: @gill_size) if @gill_size.present? + query = query.where(gill_color: @gill_color) if @gill_color.present? + query = query.where(stalk_shape: @stalk_shape) if @stalk_shape.present? + query = query.where(stalk_root: @stalk_root) if @stalk_root.present? + query = query.where(stalk_surface_above_ring: @stalk_surface_above_ring) if @stalk_surface_above_ring.present? + query = query.where(stalk_surface_below_ring: @stalk_surface_below_ring) if @stalk_surface_below_ring.present? + query = query.where(stalk_color_above_ring: @stalk_color_above_ring) if @stalk_color_above_ring.present? + query = query.where(stalk_color_below_ring: @stalk_color_below_ring) if @stalk_color_below_ring.present? + query = query.where(veil_type: @veil_type) if @veil_type.present? + query = query.where(veil_color: @veil_color) if @veil_color.present? + query = query.where(ring_number: @ring_number) if @ring_number.present? + query = query.where(ring_type: @ring_type) if @ring_type.present? + query = query.where(spore_print_color: @spore_print_color) if @spore_print_color.present? + query = query.where(population: @population) if @population.present? + query = query.where(habitat: @habitat) if @habitat.present? + + query.page(page) + end +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index ffeef56..d104f74 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,15 +1,22 @@
+# | +Class | +Cap Shape | +Cap Surface | +Cap Color | +Bruises | +Odor | +Gill Attachment | +Gill Spacing | +Gill Size | +Gill Color | +Stalk Shape | +Stalk Root | +Stalk Surface Above Ring | +Stalk Surface Below Ring | +Stalk Color Above Ring | +Stalk Color Below Ring | +Veil Type | +Veil Color | +Ring Number | +Ring Type | +Spore Print Color | +Population | +Habitat | +
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
<%= row_count %> | +<%= mushroom.mushroom_class %> | +<%= mushroom.cap_shape %> | +<%= mushroom.cap_surface %> | +<%= mushroom.cap_color %> | +<%= mushroom.bruises %> | +<%= mushroom.odor %> | +<%= mushroom.gill_attachment %> | +<%= mushroom.gill_spacing %> | +<%= mushroom.gill_size %> | +<%= mushroom.gill_color %> | +<%= mushroom.stalk_shape %> | +<%= mushroom.stalk_root %> | +<%= mushroom.stalk_surface_above_ring %> | +<%= mushroom.stalk_surface_below_ring %> | +<%= mushroom.stalk_color_above_ring %> | +<%= mushroom.stalk_color_below_ring %> | +<%= mushroom.veil_type %> | +<%= mushroom.veil_color %> | +<%= mushroom.ring_number %> | +<%= mushroom.ring_type %> | +<%= mushroom.spore_print_color %> | +<%= mushroom.population %> | +<%= mushroom.habitat %> | +