Refactor prices

#475
This commit is contained in:
Artur Beljajev 2017-04-26 00:51:06 +03:00
parent 5fdc1938af
commit 5a533e09bf
44 changed files with 1027 additions and 375 deletions

View file

@ -0,0 +1,60 @@
<%= form_for [:admin, price], html: { class: 'form-horizontal' } do |f| %>
<%= render 'form_errors', target: price %>
<div class="form-group">
<%= f.label :zone_id, class: 'col-sm-2 control-label' %>
<div class="col-sm-3">
<%= f.collection_select :zone_id, zones, :id, :origin, {}, class: 'form-control', required: true %>
</div>
</div>
<div class="form-group">
<%= f.label :operation_category, class: 'col-sm-2 control-label' %>
<div class="col-sm-3">
<%= f.select :operation_category, operation_categories, {}, class: 'form-control', required: true %>
</div>
</div>
<div class="form-group">
<%= f.label :duration, class: 'col-sm-2 control-label' %>
<div class="col-sm-3">
<%= f.select :duration, durations, {}, class: 'form-control', required: true %>
</div>
</div>
<div class="form-group">
<%= f.label :price, class: 'col-sm-2 control-label' %>
<div class="col-sm-3">
<div class="input-group">
<%= f.money_field :price, class: 'form-control', required: true %>
<div class="input-group-addon"><%= Money::default_currency.symbol %></div>
</div>
</div>
</div>
<div class="form-group">
<%= f.label :valid_from, class: 'col-sm-2 control-label' %>
<div class="col-sm-6">
<div class="input-group">
<%= f.text_field :valid_from, value: f.object.valid_from.try(:to_s, :dshort),
class: 'form-control datepicker' %>
<span class="input-group-addon">-</span>
<%= f.text_field :valid_to, value: f.object.valid_to.try(:to_s, :dshort),
class: 'form-control datepicker' %>
</div>
</div>
</div>
<hr>
<div class="row">
<div class="col-md-8 text-right">
<%= f.submit t(".#{f.object.new_record? ? 'create' : 'update'}_btn"), class: 'btn btn-success', name: nil %>
</div>
</div>
<% end %>

View file

@ -0,0 +1,15 @@
<tr>
<td><%= price.zone_name %></td>
<td><%= price.duration %></td>
<td><%= price.operation_category %></td>
<td><%= currency(price.price) %></td>
<td><%= l(price.valid_from, format: :ydate) %></td>
<td><%= l(price.valid_to, format: :ydate) %></td>
<td>
<%= link_to t('.edit_btn'), edit_admin_price_path(price), class: 'btn btn-xs btn-primary' %>
<%= link_to(t('.delete_btn'), admin_price_path(price),
method: :delete,
data: { confirm: t('.delete_btn_confirm') },
class: 'btn btn-xs btn-danger') %>
</td>
</tr>

View file

@ -0,0 +1,20 @@
<ol class="breadcrumb">
<li><%= link_to t('admin.billing.prices.index.title'), admin_prices_path %></li>
</ol>
<div class="page-header">
<h1><%= t '.title' %></h1>
</div>
<% if @price.persisted? && @price.errors.none? %>
<div class="alert alert-info">
<% active_price = ::Billing::Price.price_for(@price.zone, @price.operation_category, @price.duration) %>
<% if active_price %>
<%= t('active_price_for_this_operation_is', price: "#{active_price.price.amount.to_s} EUR") %>
<% else %>
<%= t('active_price_missing_for_this_operation') %>
<% end %>
</div>
<% end %>
<%= render 'form', price: @price %>

View file

@ -0,0 +1,41 @@
<div class="page-header">
<div class="row">
<div class="col-sm-10">
<h1><%= t '.title' %></h1>
</div>
<div class="col-sm-2 text-right">
<%= link_to t('.new_btn'), new_admin_price_path, class: 'btn btn-primary' %>
</div>
</div>
</div>
<% if @prices.present? %>
<table class="table table-hover table-bordered table-wrapped">
<thead>
<tr>
<th><%= sort_link(@q, 'zone_id', DNS::Zone.model_name.human) %></th>
<th><%= sort_link(@q, 'duration', ::Billing::Price.human_attribute_name(:duration)) %></th>
<th><%= sort_link(@q, 'operation_category', ::Billing::Price.human_attribute_name(:operation)) %></th>
<th><%= sort_link(@q, 'price', t(:price)) %></th>
<th><%= sort_link(@q, 'valid_from', t(:valid_from)) %></th>
<th><%= sort_link(@q, 'valid_to', t(:valid_to)) %></th>
<th></th>
</tr>
</thead>
<tbody>
<% @prices.each do |price| %>
<%= render 'price', price: price %>
<% end %>
</tbody>
</table>
<div class="row">
<div class="col-md-12">
<%= paginate @prices %>
</div>
</div>
<% else %>
<div class="alert alert-info"><%= t '.not_found' %></div>
<% end %>

View file

@ -0,0 +1,9 @@
<ol class="breadcrumb">
<li><%= link_to t('admin.billing.prices.index.title'), admin_prices_path %></li>
</ol>
<div class="page-header">
<h1><%= t '.title' %></h1>
</div>
<%= render 'form', price: @price %>