-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Paperworks are now searchable by date_min and date_max, #38
- Loading branch information
Showing
24 changed files
with
551 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Place all the behaviors and hooks related to the matching controller here. | ||
// All this logic will automatically be available in application.js. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* | ||
Place all the styles related to the matching controller here. | ||
They will automatically be included in application.css. | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
require 'billit_representers/representers/paperwork_collection_representer' | ||
class PaperworksController < ApplicationController | ||
respond_to :json, :xml | ||
# GET /paperworks | ||
# GET /paperworks.json | ||
def index | ||
@paperworks = Paperwork.all | ||
|
||
respond_to do |format| | ||
format.html # index.html.erb | ||
format.json { render json: @paperworks } | ||
end | ||
end | ||
|
||
# GET /paperworks/1 | ||
# GET /paperworks/1.json | ||
def show | ||
@paperwork = Paperwork.find(params[:id]) | ||
|
||
respond_to do |format| | ||
format.html # show.html.erb | ||
format.json { render json: @paperwork } | ||
end | ||
end | ||
|
||
# GET /paperworks/new | ||
# GET /paperworks/new.json | ||
def new | ||
@paperwork = Paperwork.new | ||
|
||
respond_to do |format| | ||
format.html # new.html.erb | ||
format.json { render json: @paperwork } | ||
end | ||
end | ||
|
||
# GET /paperworks/1/edit | ||
def edit | ||
@paperwork = Paperwork.find(params[:id]) | ||
end | ||
|
||
# POST /paperworks | ||
# POST /paperworks.json | ||
def create | ||
@paperwork = Paperwork.new(params[:paperwork]) | ||
|
||
respond_to do |format| | ||
if @paperwork.save | ||
format.html { redirect_to @paperwork, notice: 'Paperwork was successfully created.' } | ||
format.json { render json: @paperwork, status: :created, location: @paperwork } | ||
else | ||
format.html { render action: "new" } | ||
format.json { render json: @paperwork.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PUT /paperworks/1 | ||
# PUT /paperworks/1.json | ||
def update | ||
@paperwork = Paperwork.find(params[:id]) | ||
|
||
respond_to do |format| | ||
if @paperwork.update_attributes(params[:paperwork]) | ||
format.html { redirect_to @paperwork, notice: 'Paperwork was successfully updated.' } | ||
format.json { head :no_content } | ||
else | ||
format.html { render action: "edit" } | ||
format.json { render json: @paperwork.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /paperworks/1 | ||
# DELETE /paperworks/1.json | ||
def destroy | ||
@paperwork = Paperwork.find(params[:id]) | ||
@paperwork.destroy | ||
|
||
respond_to do |format| | ||
format.html { redirect_to paperworks_url } | ||
format.json { head :no_content } | ||
end | ||
end | ||
|
||
# GET paperworks/search.json?q=search_string | ||
def search | ||
require 'will_paginate/array' | ||
# Sunspot.remove_all(Paperwork) # descomentar para reindexar, | ||
# Sunspot.index!(Paperwork.all) # en caso de cambio en modelo | ||
search = search_for(params) | ||
# @paperwork = search.results | ||
puts "params" | ||
puts params | ||
puts "/params" | ||
@paperworks = search.results | ||
@paperworks.extend(Billit::PaperworkCollectionRepresenter) | ||
respond_with @paperworks.to_json(params), represent_with: Billit::PaperworkCollectionRepresenter | ||
# @paperwork.extend(Billit::BillCollectionPageRepresenter) | ||
#respond_with @paperwork.to_json(params)#, represent_with: Billit::BillCollectionPageRepresenter | ||
end | ||
|
||
def filter_conditions(conditions) | ||
@mongoid_attribute_names = ["_id", "created_at"] #FIX should probably have a greater scope | ||
@search_attribute_names = ["q", "bill_id", "law_text"] | ||
@range_field_types = [DateTime] | ||
@range_modifier_min = "_min" | ||
@range_modifier_max = "_max" | ||
|
||
bill_range_fields = Paperwork.fields.dup | ||
@range_field_types.each do |type| | ||
bill_range_fields.reject! {|field_name, metadata| metadata.options[:type]!= type} | ||
end | ||
bill_range_attributes = bill_range_fields.keys | ||
|
||
bill_public_attributes = Paperwork.attribute_names - @mongoid_attribute_names | ||
|
||
equivalence_attributes = bill_public_attributes + @search_attribute_names | ||
range_attributes_min = bill_range_attributes.map {|attribute| attribute + @range_modifier_min} | ||
range_attributes_max = bill_range_attributes.map {|attribute| attribute + @range_modifier_max} | ||
|
||
filtered_conditions = {} | ||
equivalence_conditions = {} | ||
range_conditions_min = {} | ||
range_conditions_max = {} | ||
conditions.each do |key, value| | ||
next if value.nil?() || value == "" | ||
if equivalence_attributes.include?(key) | ||
equivalence_conditions[key] = value | ||
elsif range_attributes_min.include?(key) | ||
range_conditions_min[key.gsub(@range_modifier_min, "")] = value | ||
elsif range_attributes_max.include?(key) | ||
range_conditions_max[key.gsub(@range_modifier_max, "")] = value | ||
end | ||
end | ||
|
||
return {equivalence_conditions: equivalence_conditions,\ | ||
range_conditions_min: range_conditions_min, range_conditions_max: range_conditions_max} | ||
end | ||
|
||
def search_for(conditions) | ||
filtered_conditions = filter_conditions(conditions) | ||
|
||
search = Sunspot.search(Paperwork) do | ||
# FIX the equivalence conditions settings should be in a conf file | ||
# search over all fields | ||
if filtered_conditions[:equivalence_conditions].key?("q") | ||
fulltext filtered_conditions[:equivalence_conditions]["q"] do | ||
# boost_fields :tags => 3.0 | ||
# boost_fields :subject_areas => 2.9 | ||
# boost_fields :title => 2.5 | ||
# boost_fields :abstract => 2.0 | ||
end | ||
filtered_conditions[:equivalence_conditions].delete("q") | ||
end | ||
# search over bill identifiers, both uid and short uid | ||
if filtered_conditions[:equivalence_conditions].key?("bill_id") | ||
text_fields do | ||
any_of do | ||
with(:uid, filtered_conditions[:equivalence_conditions]["bill_id"]) | ||
with(:short_uid, filtered_conditions[:equivalence_conditions]["bill_id"]) | ||
end | ||
end | ||
filtered_conditions[:equivalence_conditions].delete("bill_id") | ||
end | ||
#search over specific fields | ||
text_fields do | ||
all_of do | ||
filtered_conditions[:equivalence_conditions].each do |key, value| | ||
any_of do | ||
value.split("|").each do |term| | ||
with(key, term) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
all_of do | ||
#range_conditions_min might be asdf_min instead of asdf | ||
filtered_conditions[:range_conditions_min].each do |key, value| | ||
with(key).greater_than(value) | ||
end | ||
filtered_conditions[:range_conditions_max].each do |key, value| | ||
with(key).less_than(value) | ||
end | ||
end | ||
|
||
paginate page:conditions[:page], per_page:conditions[:per_page] | ||
end | ||
search | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module Billit::PaperworksHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
class Billit::Directive | ||
class Directive | ||
include Mongoid::Document | ||
include Mongoid::Timestamps | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
class Billit::Document | ||
class Document | ||
include Mongoid::Document | ||
include Mongoid::Timestamps | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
class Billit::Priority | ||
class Priority | ||
include Mongoid::Document | ||
include Mongoid::Timestamps | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
class Billit::Remark | ||
class Remark | ||
include Mongoid::Document | ||
include Mongoid::Timestamps | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
class Billit::Report | ||
class Report | ||
include Mongoid::Document | ||
include Mongoid::Timestamps | ||
|
||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
= form_for @billit_paperwork do |f| | ||
- if @billit_paperwork.errors.any? | ||
#error_explanation | ||
%h2= "#{pluralize(@billit_paperwork.errors.count, "error")} prohibited this billit_paperwork from being saved:" | ||
%ul | ||
- @billit_paperwork.errors.full_messages.each do |msg| | ||
%li= msg | ||
|
||
.field | ||
= f.label :session | ||
= f.text_field :session | ||
.field | ||
= f.label :date | ||
= f.datetime_select :date | ||
.field | ||
= f.label :description | ||
= f.text_field :description | ||
.field | ||
= f.label :stage | ||
= f.text_field :stage | ||
.field | ||
= f.label :chamber | ||
= f.text_field :chamber | ||
.actions | ||
= f.submit 'Save' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
%h1 Editing billit_paperwork | ||
|
||
= render 'form' | ||
|
||
= link_to 'Show', @billit_paperwork | ||
\| | ||
= link_to 'Back', billit_paperworks_path |
Oops, something went wrong.