diff --git a/app/controllers/results_controller.rb b/app/controllers/results_controller.rb index c953ce15a..a5491ed3d 100644 --- a/app/controllers/results_controller.rb +++ b/app/controllers/results_controller.rb @@ -9,8 +9,13 @@ class ResultsController < ApplicationController respond_to do |format| format.json do # API endpoint + @results = @my_module.results + + apply_sort! + apply_filters! + render( - json: apply_sort(@my_module.results), + json: @results, formats: :json ) end @@ -74,7 +79,6 @@ class ResultsController < ApplicationController end def update_asset_view_mode - html = '' ActiveRecord::Base.transaction do @result.assets_view_mode = params[:assets_view_mode] @result.save!(touch: false) @@ -115,23 +119,34 @@ class ResultsController < ApplicationController params.require(:result).permit(:name) end - def apply_sort(results) + def apply_sort! case params[:sort] when 'updated_at_asc' - results.order(updated_at: :asc) + @results = @results.order(updated_at: :asc) when 'updated_at_desc' - results.order(updated_at: :desc) + @results = @results.order(updated_at: :desc) when 'created_at_asc' - results.order(created_at: :asc) + @results = @results.order(created_at: :asc) when 'created_at_desc' - results.order(created_at: :desc) + @results = @results.order(created_at: :desc) when 'name_asc' - results.order(name: :asc) + @results = @results.order(name: :asc) when 'name_desc' - results.order(name: :desc) + @results = @results.order(name: :desc) end end + def apply_filters! + if params[:query].present? + @results = @results.search(current_user, params[:archived] == 'true', params[:query], params[:page] || 1) + end + + @results = @results.where('created_at >= ?', params[:created_at_from]) if params[:created_at_from] + @results = @results.where('created_at <= ?', params[:created_at_to]) if params[:created_at_to] + @results = @results.where('updated_at >= ?', params[:updated_at_from]) if params[:updated_at_from] + @results = @results.where('updated_at <= ?', params[:updated_at_to]) if params[:updated_at_to] + end + def load_my_module @my_module = MyModule.readable_by_user(current_user).find(params[:my_module_id]) end diff --git a/app/javascript/vue/results/results.vue b/app/javascript/vue/results/results.vue index 58ff39d71..888b2f84f 100644 --- a/app/javascript/vue/results/results.vue +++ b/app/javascript/vue/results/results.vue @@ -1,6 +1,13 @@ -import '../../../../vendor/assets/javascripts/bootstrap-datetimepicker'; diff --git a/app/javascript/vue/shared/filters/inputs/checkbox_filter.vue b/app/javascript/vue/shared/filters/inputs/checkbox_filter.vue new file mode 100644 index 000000000..d4d6f8d79 --- /dev/null +++ b/app/javascript/vue/shared/filters/inputs/checkbox_filter.vue @@ -0,0 +1,14 @@ + + + diff --git a/app/javascript/vue/shared/filters/inputs/date_range_filter.vue b/app/javascript/vue/shared/filters/inputs/date_range_filter.vue new file mode 100644 index 000000000..1b20709b6 --- /dev/null +++ b/app/javascript/vue/shared/filters/inputs/date_range_filter.vue @@ -0,0 +1,52 @@ + + + diff --git a/app/javascript/vue/shared/filters/inputs/select_filter.vue b/app/javascript/vue/shared/filters/inputs/select_filter.vue new file mode 100644 index 000000000..8d52a523f --- /dev/null +++ b/app/javascript/vue/shared/filters/inputs/select_filter.vue @@ -0,0 +1,15 @@ + + + diff --git a/app/javascript/vue/shared/filters/inputs/text_filter.vue b/app/javascript/vue/shared/filters/inputs/text_filter.vue new file mode 100644 index 000000000..d2a1158f8 --- /dev/null +++ b/app/javascript/vue/shared/filters/inputs/text_filter.vue @@ -0,0 +1,28 @@ + + + diff --git a/config/locales/en.yml b/config/locales/en.yml index 52dedfcb2..a3f7f4714 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1265,6 +1265,14 @@ en: created_at_desc: "Created last" name_asc: "Name A to Z" name_desc: "Name Z to A" + filters: + query: + label: 'Contains text' + placeholder: 'Enter search terms' + created_at: + label: 'Created date' + updated_at: + label: 'Updated date' options: comment_title: "Comments" no_comments: "No comments" @@ -3710,6 +3718,8 @@ en: Added: 'Added' by: 'by' name: 'name' + From: 'From' + To: 'To' marvinjs: new_sketch: "New Chemical Drawing"