Add closed disputed sections to disputes view

This commit is contained in:
Karl Erik Õunapuu 2020-04-27 10:56:27 +03:00
parent c3497ab46f
commit 42946dfa15
4 changed files with 202 additions and 74 deletions

View file

@ -8,10 +8,16 @@ module Admin
# GET /admin/disputes
def index
params[:q] ||= {}
disputes = Dispute.all.order(:domain_name)
disputes = Dispute.active.all.order(:domain_name)
@q = disputes.search(params[:q])
@disputes = @q.result.page(params[:page])
@disputes = @disputes.per(params[:results_per_page]) if params[:results_per_page].to_i.positive?
closed_disputes = Dispute.closed.order(:domain_name)
@closed_q = closed_disputes.search(params[:closed_q])
@closed_disputes = @closed_q.result.page(params[:closed_page])
@closed_disputes = @closed_disputes.per(params[:results_per_page]) if params[:results_per_page].to_i.positive?
end
# GET /admin/disputes/1

View file

@ -2,10 +2,10 @@
class Dispute < ApplicationRecord
validates :domain_name, :password, :starts_at, :expires_at, presence: true
validates_uniqueness_of :domain_name, case_sensitive: true
before_validation :fill_empty_passwords
before_validation :set_expiry_date
validate :validate_domain_name
validate :validate_domain_name_format
validate :validate_domain_name_period_uniqueness
with_options on: :admin do
validate :validate_start_date
@ -15,7 +15,7 @@ class Dispute < ApplicationRecord
after_destroy :remove_data
scope :expired, -> { where('expires_at < ?', Time.zone.today) }
scope :active, -> { where('expires_at > ? AND closed = 0', Time.zone.today) }
scope :active, -> { where('expires_at > ? AND closed = false', Time.zone.today) }
scope :closed, -> { where(closed: true) }
alias_attribute :name, :domain_name
@ -78,7 +78,7 @@ class Dispute < ApplicationRecord
errors.add(:starts_at, :past) if starts_at.past?
end
def validate_domain_name
def validate_domain_name_format
return unless domain_name
zone = domain_name.split('.').last
@ -86,4 +86,13 @@ class Dispute < ApplicationRecord
errors.add(:domain_name, :unsupported_zone) unless supported_zone
end
def validate_domain_name_period_uniqueness
return unless new_record?
existing_dispute = Dispute.unscoped.where(domain_name: domain_name, closed: false).where('expires_at > ?', starts_at)
return unless existing_dispute.any?
errors.add(:base, 'Dispute already exists for this domain at given timeframe')
end
end

View file

@ -1,69 +0,0 @@
- content_for :actions do
= link_to(t('.new_btn'), new_admin_dispute_path, class: 'btn btn-primary')
= render 'shared/title', name: t('.title')
.row
.col-md-12
= search_form_for [:admin, @q], html: { style: 'margin-bottom: 0;', class: 'js-form', autocomplete: 'off' } do |f|
.row
.col-md-3
.form-group
= f.label :name
= f.search_field :name_matches, value: params[:q][:name_matches], class: 'form-control', placeholder: t(:name)
.col-md-3
.form-group
= f.label t(:created_at_from)
= f.search_field :created_at_gteq, value: params[:q][:created_at_gteq], class: 'form-control js-datepicker', placeholder: t(:created_at_from)
.col-md-3
.form-group
= f.label t(:created_at_until)
= f.search_field :created_at_lteq, value: params[:q][:created_at_lteq], class: 'form-control js-datepicker', placeholder: t(:created_at_until)
.row
.col-md-3
.form-group
= label_tag t(:results_per_page)
= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page)
.col-md-3{style: 'padding-top: 25px;'}
%button.btn.btn-primary
&nbsp;
%span.glyphicon.glyphicon-search
&nbsp;
= link_to(t('.reset_btn'), admin_disputes_path, class: 'btn btn-default')
%hr
.row
.col-md-12
.table-responsive
%table.table.table-hover.table-bordered.table-condensed
%thead
%tr
%th{class: 'col-xs-2'}
= sort_link(@q, 'name')
%th{class: 'col-xs-2'}
= sort_link(@q, 'password')
%th{class: 'col-xs-2'}
= sort_link(@q, 'starts_at')
%th{class: 'col-xs-2'}
= sort_link(@q, 'expires_at')
%th{class: 'col-xs-2'}
= sort_link(@q, 'comment')
%th{class: 'col-xs-2'}
= t(:actions)
%tbody
- @disputes.each do |x|
%tr
%td= x.domain_name
%td= x.password
%td= x.starts_at
%td= x.expires_at
%td= x.comment
%td
= link_to(t(:edit), edit_admin_dispute_path(id: x.id),
class: 'btn btn-primary btn-xs')
= link_to(t(:delete), delete_admin_dispute_path(id: x.id),
data: { confirm: t(:are_you_sure) }, class: 'btn btn-danger btn-xs')
.row
.col-md-6
= paginate @disputes
.col-md-6.text-right
.pagination
= t(:result_count, count: @disputes.total_count)

View file

@ -0,0 +1,182 @@
<% content_for :actions do %>
<%= link_to(t('.new_btn'), new_admin_dispute_path, class: 'btn btn-primary') %>
<% end %>
<%= render 'shared/title', name: t('.title') %>
<div class="row">
<div class="col-md-12">
<%= search_form_for [:admin, @q], html: { style: 'margin-bottom: 0;', class: 'js-form', autocomplete: 'off' } do |f| %>
<div class="row">
<div class="col-md-3">
<div class="form-group">
<%= f.label :name %>
<%= f.search_field :name_matches, value: params[:q][:name_matches], class: 'form-control', placeholder: t(:name) %>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<%= f.label t(:created_at_from) %>
<%= f.search_field :created_at_gteq, value: params[:q][:created_at_gteq], class: 'form-control js-datepicker', placeholder: t(:created_at_from) %>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<%= f.label t(:created_at_until) %>
<%= f.search_field :created_at_lteq, value: params[:q][:created_at_lteq], class: 'form-control js-datepicker', placeholder: t(:created_at_until) %>
</div>
</div>
</div>
<div class="row">
<div class="col-md-3">
<div class="form-group">
<%= label_tag t(:results_per_page) %>
<%= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page) %>
</div>
</div>
<div class="col-md-3" style="padding-top: 25px;">
<button class="btn btn-primary">
&nbsp;
<span class="glyphicon glyphicon-search"></span>
&nbsp;
</button>
<%= link_to(t('.reset_btn'), admin_disputes_path, class: 'btn btn-default') %>
</div>
</div>
<% end %>
</div>
</div>
<hr />
<p>Active disputes</p>
<div class="row">
<div class="col-md-12">
<div class="table-responsive">
<table class="table table-hover table-bordered table-condensed">
<thead>
<tr>
<th class="col-xs-2">
<%= sort_link(@q, 'name') %>
</th>
<th class="col-xs-2">
<%= sort_link(@q, 'password') %>
</th>
<th class="col-xs-2">
<%= sort_link(@q, 'starts_at') %>
</th>
<th class="col-xs-2">
<%= sort_link(@q, 'expires_at') %>
</th>
<th class="col-xs-2">
<%= sort_link(@q, 'comment') %>
</th>
<th class="col-xs-2">
<%= t(:actions) %>
</th>
</tr>
</thead>
<tbody>
<% @disputes.each do |x| %>
<tr>
<td>
<%= x.domain_name %>
</td>
<td>
<%= x.password %>
</td>
<td>
<%= x.starts_at %>
</td>
<td>
<%= x.expires_at %>
</td>
<td>
<%= x.comment %>
</td>
<td>
<%= link_to t(:edit), edit_admin_dispute_path(id: x.id),
class: 'btn btn-primary btn-xs' %>
<%= link_to t(:delete), delete_admin_dispute_path(id: x.id),
data: { confirm: t(:are_you_sure) }, class: 'btn btn-danger btn-xs' %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<%= paginate @disputes %>
</div>
<div class="col-md-6 text-right">
<div class="pagination">
<%= t(:result_count, count: @disputes.total_count) %>
</div>
</div>
</div>
<hr />
<p>Expired / Closed disputes</p>
<div class="row">
<div class="col-md-12">
<div class="table-responsive">
<table class="table table-hover table-bordered table-condensed">
<thead>
<tr>
<th class="col-xs-2">
<%= sort_link(@q, 'name') %>
</th>
<th class="col-xs-2">
<%= sort_link(@q, 'password') %>
</th>
<th class="col-xs-2">
<%= sort_link(@q, 'starts_at') %>
</th>
<th class="col-xs-2">
<%= sort_link(@q, 'expires_at') %>
</th>
<th class="col-xs-2">
<%= sort_link(@q, 'comment') %>
</th>
<th class="col-xs-2">
<%= t(:actions) %>
</th>
</tr>
</thead>
<tbody>
<% @closed_disputes.each do |x| %>
<tr>
<td>
<%= x.domain_name %>
</td>
<td>
<%= x.password %>
</td>
<td>
<%= x.starts_at %>
</td>
<td>
<%= x.expires_at %>
</td>
<td>
<%= x.comment %>
</td>
<td>
<%= link_to t(:delete), delete_admin_dispute_path(id: x.id),
data: { confirm: t(:are_you_sure) }, class: 'btn btn-danger btn-xs' %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<%= paginate @closed_disputes %>
</div>
<div class="col-md-6 text-right">
<div class="pagination">
<%= t(:result_count, count: @closed_disputes.total_count) %>
</div>
</div>
</div>