Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/consul/consul
Browse files Browse the repository at this point in the history
  • Loading branch information
xuanxu committed Mar 8, 2016
2 parents 66eb201 + f6aaec9 commit 08f58c8
Show file tree
Hide file tree
Showing 34 changed files with 567 additions and 391 deletions.
7 changes: 6 additions & 1 deletion app/assets/stylesheets/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ a.delete {
}
}

.account-info, .login-as {
.account-info, .login-as, .info {
background-color: #e7e7e7;
border-radius: rem-calc(3);
font-size: rem-calc(16);
Expand All @@ -348,3 +348,8 @@ a.delete {
font-size: rem-calc(18);
}
}

.info p {
margin-bottom: 0;
}

23 changes: 15 additions & 8 deletions app/controllers/admin/spending_proposals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,26 @@ def index
end

def show
end

def edit
@admins = Administrator.includes(:user).all
@valuators = Valuator.includes(:user).all.order("users.username ASC")
@tags = ActsAsTaggableOn::Tag.spending_proposal_tags
end

def assign_admin
@spending_proposal.update(params.require(:spending_proposal).permit(:administrator_id))
render nothing: true
def update
if @spending_proposal.update(spending_proposal_params)
redirect_to admin_spending_proposal_path(@spending_proposal, anchor: 'classification'), notice: t("flash.actions.update.spending_proposal")
else
render :edit
end
end

def assign_valuators
params[:spending_proposal] ||= {}
params[:spending_proposal][:valuator_ids] ||= []
@spending_proposal.update(params.require(:spending_proposal).permit(valuator_ids: []))
end
private

def spending_proposal_params
params.require(:spending_proposal).permit(:administrator_id, :tag_list, valuator_ids: [])
end

end
19 changes: 17 additions & 2 deletions app/controllers/valuation/spending_proposals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ def index
end

def valuate
@spending_proposal.update_attributes(valuation_params)
redirect_to valuation_spending_proposal_path(@spending_proposal), notice: t('valuation.spending_proposals.notice.valuate')
if valid_price_params? && @spending_proposal.update(valuation_params)
redirect_to valuation_spending_proposal_path(@spending_proposal), notice: t('valuation.spending_proposals.notice.valuate')
else
render action: :edit
end
end

private
Expand All @@ -35,4 +38,16 @@ def restrict_access_to_assigned_items
raise ActionController::RoutingError.new('Not Found') unless current_user.administrator? || ValuationAssignment.exists?(spending_proposal_id: params[:id], valuator_id: current_user.valuator.id)
end

def valid_price_params?
if /\D/.match params[:spending_proposal][:price]
@spending_proposal.errors.add(:price, I18n.t('spending_proposals.wrong_price_format'))
end

if /\D/.match params[:spending_proposal][:price_first_year]
@spending_proposal.errors.add(:price_first_year, I18n.t('spending_proposals.wrong_price_format'))
end

@spending_proposal.errors.empty?
end

end
6 changes: 6 additions & 0 deletions app/helpers/spending_proposals_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module SpendingProposalsHelper

def spending_proposal_tags_select_options
ActsAsTaggableOn::Tag.spending_proposal_tags.pluck(:name)
end
end
2 changes: 1 addition & 1 deletion app/models/administrator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Administrator < ActiveRecord::Base
belongs_to :user, touch: true
delegate :name, :email, to: :user
delegate :name, :email, :name_and_email, to: :user

validates :user_id, presence: true, uniqueness: true
end
28 changes: 13 additions & 15 deletions app/models/spending_proposal.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class SpendingProposal < ActiveRecord::Base
include Measurable
include Sanitizable
include Taggable

apply_simple_captcha

Expand All @@ -18,13 +19,17 @@ class SpendingProposal < ActiveRecord::Base
validates :description, length: { maximum: SpendingProposal.description_max_length }
validates :terms_of_service, acceptance: { allow_nil: false }, on: :create

scope :valuation_open, -> { where(valuation_finished: false) }
scope :without_admin, -> { valuation_open.where(administrator_id: nil) }
scope :managed, -> { valuation_open.where(valuation_assignments_count: 0).where("administrator_id IS NOT ?", nil) }
scope :valuating, -> { valuation_open.where("valuation_assignments_count > 0 AND valuation_finished = ?", false) }
scope :valuation_finished, -> { where(valuation_finished: true) }
scope :valuation_open, -> { where(valuation_finished: false) }
scope :without_admin, -> { valuation_open.where(administrator_id: nil) }
scope :managed, -> { valuation_open.where(valuation_assignments_count: 0).where("administrator_id IS NOT ?", nil) }
scope :valuating, -> { valuation_open.where("valuation_assignments_count > 0 AND valuation_finished = ?", false) }
scope :valuation_finished, -> { where(valuation_finished: true) }

scope :for_render, -> { includes(:geozone, administrator: :user, valuators: :user) }
scope :by_admin, -> (admin) { where(administrator_id: admin.presence) }
scope :by_tag, -> (tag_name) { tagged_with(tag_name) }
scope :by_valuator, -> (valuator) { where("valuation_assignments.valuator_id = ?", valuator.presence).joins(:valuation_assignments) }

scope :for_render, -> { includes(:geozone, administrator: :user, valuators: :user) }

def description
super.try :html_safe
Expand All @@ -33,7 +38,8 @@ def description
def self.search(params, current_filter)
results = self
results = results.by_geozone(params[:geozone_id]) if params[:geozone_id].present?
results = results.by_administrator(params[:administrator_id]) if params[:administrator_id].present?
results = results.by_admin(params[:administrator_id]) if params[:administrator_id].present?
results = results.by_tag(params[:tag_name]) if params[:tag_name].present?
results = results.by_valuator(params[:valuator_id]) if params[:valuator_id].present?
results = results.send(current_filter) if current_filter.present?
results.for_render
Expand All @@ -47,14 +53,6 @@ def self.by_geozone(geozone)
end
end

def self.by_administrator(administrator)
where(administrator_id: administrator.presence)
end

def self.by_valuator(valuator)
joins(:valuation_assignments).includes(:valuators).where("valuation_assignments.valuator_id = ?", valuator.presence)
end

def feasibility
case feasible
when true
Expand Down
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ def send_oauth_confirmation_instructions
self.update(oauth_email: nil) if oauth_email.present?
end

def name_and_email
"#{name} (#{email})"
end

def save_requiring_finish_signup
self.update(registering_with_oauth: true)
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/valuator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Valuator < ActiveRecord::Base
belongs_to :user, touch: true
delegate :name, :email, to: :user
delegate :name, :email, :name_and_email, to: :user

has_many :valuation_assignments, dependent: :destroy
has_many :spending_proposals, through: :valuation_assignments
Expand Down
42 changes: 42 additions & 0 deletions app/views/admin/spending_proposals/_written_by_author.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<div class="callout primary float-right">
<%= t "admin.spending_proposals.show.heading", id: @spending_proposal.id %>
</div>

<br>
<h1 class="inline-block"><%= @spending_proposal.title %></h1>

<div class="row small-collapse info">
<div class="small-12 medium-4 column">
<p>
<strong><%= t("admin.spending_proposals.show.geozone") %>:</strong>
<%= geozone_name(@spending_proposal) %>
</p>
</div>

<div class="small-12 medium-4 column">
<p>
<strong><%= t("admin.spending_proposals.show.by") %>:</strong>
<%= link_to @spending_proposal.author.name, admin_user_path(@spending_proposal.author) %>
</p>
</div>

<div class="small-12 medium-4 column">
<p>
<strong><%= t("admin.spending_proposals.show.sent") %>:</strong>
<%= l @spending_proposal.created_at, format: :datetime %>
</p>
</div>

</div>

<% if @spending_proposal.association_name.present? %>
<p><strong><%= t("admin.spending_proposals.show.association_name") %>:</strong>
<%= @spending_proposal.association_name %>
</p>
<% end %>
<% if @spending_proposal.external_url.present? %>
<p><%= text_with_links @spending_proposal.external_url %>&nbsp;<i class="icon-external small"></i></p>
<% end %>
<%= safe_html_with_links @spending_proposal.description %>

This file was deleted.

40 changes: 40 additions & 0 deletions app/views/admin/spending_proposals/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<%= link_to admin_spending_proposals_path(@spending_proposal), class: 'back' do %>
<i class="icon-angle-left"></i> <%= t("admin.spending_proposals.show.back") %>
<% end %>
<%= render 'written_by_author' %>

<h2 id="form"><%= t("admin.spending_proposals.edit.classification") %></h2>

<%= form_for @spending_proposal, url: admin_spending_proposal_path(@spending_proposal) do |f| %>
<%= f.select(:administrator_id,
@admins.collect{ |a| [a.name_and_email, a.id ] },
{ include_blank: t("admin.spending_proposals.edit.undefined") },
class: "small-12 medium-6") %>
<%= f.label :valuator_ids, t("admin.spending_proposals.edit.assigned_valuators") %>
<%= f.collection_check_boxes :valuator_ids, @valuators, :id, :name_and_email do |b| %>
<%= b.label { b.check_box + b.text } %>
<% end %>
<%= f.label :tag_list, t("admin.spending_proposals.edit.tags") %>
<div class="tags">
<% @tags.each do |tag| %>
<a class="js-add-tag-link"><%= tag.name %></a>
<% end %>
</div>

<%= f.text_field :tag_list, value: @spending_proposal.tag_list.to_s,
label: false,
placeholder: t("admin.spending_proposals.edit.tags_placeholder"),
class: 'js-tag-list' %>

<p>
<%= f.submit(class: "button", value: t("admin.spending_proposals.edit.submit_button")) %>
</p>

<% end %>

<hr>
<%= render 'valuation/spending_proposals/written_by_valuators' %>
38 changes: 19 additions & 19 deletions app/views/admin/spending_proposals/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
<h2><%= t("admin.spending_proposals.index.title") %></h2>

<div class="row margin-top">
<div class="row margin">
<%= form_tag admin_spending_proposals_path, method: :get, enforce_utf8: false do %>
<div class="small-12 medium-4 column float-right">
<div class="small-12 medium-4 column">
<%= select_tag :administrator_id,
options_for_select(admin_select_options, params[:administrator_id]),
{ prompt: t("admin.spending_proposals.index.administrator_filter_all"),
label: false,
class: "js-submit-on-change" } %>
</div>
<div class="small-12 medium-4 column">
<%= select_tag :geozone_id,
options_for_select(geozone_select_options.unshift([t("geozones.none"), "all"]), params[:geozone_id]),
{ prompt: t("admin.spending_proposals.index.geozone_filter_all"),
label: false,
class: "js-submit-on-change" } %>
</div>
<div class="small-12 medium-4 column float-right">
<%= select_tag :administrator_id,
options_for_select(admin_select_options, params[:administrator_id]),
{ prompt: t("admin.spending_proposals.index.administrator_filter_all"),
label: false,
class: "js-submit-on-change" } %>
<div class="small-12 medium-4 column">
<%= select_tag :tag_name,
options_for_select(spending_proposal_tags_select_options, params[:tag_name]),
{ prompt: t("admin.spending_proposals.index.tags_filter_all"),
label: false,
class: "js-submit-on-change" } %>
</div>
<% end %>
</div>
Expand All @@ -25,7 +32,7 @@

<table>
<% @spending_proposals.each do |spending_proposal| %>
<tr id="<%= dom_id(spending_proposal) %>">
<tr id="<%= dom_id(spending_proposal) %>" class="spending_proposal">
<td>
<strong><%= spending_proposal.id %></strong>
</td>
Expand All @@ -34,23 +41,16 @@
</td>
<td class="small">
<% if spending_proposal.administrator.present? %>
<span title="<%= t('admin.spending_proposals.index.admin_assigned') %>"><%= spending_proposal.administrator.name %></span>
<span title="<%= t('admin.spending_proposals.index.assigned_admin') %>"><%= spending_proposal.administrator.name %></span>
<% else %>
<%= t("admin.spending_proposals.index.no_admin_assigned") %>
<% end %>
</td>
<td class="small">
<% case spending_proposal.valuators.size %>
<% when 0 %>
<% if spending_proposal.valuators.size == 0 %>
<%= t("admin.spending_proposals.index.no_valuators_assigned") %>
<% when 1 %>
<span title="<%= t('admin.spending_proposals.index.valuators_assigned', count: 1) %>">
<%= spending_proposal.valuators.first.name %>
</span>
<% else %>
<span title="<%= spending_proposal.valuators.map(&:name).join(', ') %>">
<%= t('admin.spending_proposals.index.valuators_assigned', count: spending_proposal.valuators.size) %>
</span>
<%= spending_proposal.valuators.collect(&:name).join(', ') %>
<% end %>
</td>
<td class="small">
Expand Down
Loading

0 comments on commit 08f58c8

Please sign in to comment.