-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Artur Beljajev
committed
Feb 5, 2017
1 parent
2a42b55
commit 9eb60e4
Showing
35 changed files
with
795 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,5 @@ | |
// @import bootstrap-datepicker3 | ||
@import admin/admin | ||
@import admin/bootstrap-dialog-fix | ||
@import admin/disputes | ||
|
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,18 @@ | ||
.admin-disputes-index-page .disputes { | ||
td:nth-child(1) { | ||
width: 25%; | ||
} | ||
|
||
td:nth-child(2) { | ||
width: 25%; | ||
} | ||
|
||
td:nth-child(3) { | ||
width: 25%; | ||
} | ||
|
||
td:nth-child(4) { | ||
text-align: center; | ||
width: 25%; | ||
} | ||
} |
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,5 @@ | ||
module Admin | ||
class BaseController < AdminController | ||
|
||
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,53 @@ | ||
module Admin | ||
class DisputesController < BaseController | ||
load_and_authorize_resource | ||
|
||
def index | ||
@disputes = @disputes.includes(:domain).latest_on_top | ||
end | ||
|
||
def new | ||
@dispute = Dispute.new | ||
end | ||
|
||
def create | ||
@dispute = Dispute.new(dispute_params) | ||
created = @dispute.save | ||
|
||
if created | ||
flash[:notice] = t('.created') | ||
redirect_to admin_disputes_path | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
def edit | ||
end | ||
|
||
def update | ||
updated = @dispute.update(dispute_params) | ||
|
||
if updated | ||
flash[:notice] = t('.updated') | ||
redirect_to admin_disputes_path | ||
else | ||
render :edit | ||
end | ||
end | ||
|
||
def destroy | ||
if @dispute.destroy | ||
flash[:notice] = t('.deleted') | ||
end | ||
|
||
redirect_to admin_disputes_path | ||
end | ||
|
||
private | ||
|
||
def dispute_params | ||
params.require(:dispute).permit(:domain_name, :expire_date, :password) | ||
end | ||
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
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,26 @@ | ||
class Dispute < ActiveRecord::Base | ||
belongs_to :domain, required: true | ||
|
||
validates :expire_date, :password, presence: true | ||
validates :domain, uniqueness: true | ||
validate :validate_expire_date_past | ||
|
||
alias_attribute :create_time, :created_at | ||
|
||
delegate :name, to: :domain, prefix: true, allow_nil: true | ||
|
||
def self.latest_on_top | ||
order(create_time: :desc) | ||
end | ||
|
||
def domain_name=(value) | ||
self.domain = Domain.find_by(name: value) | ||
end | ||
|
||
private | ||
|
||
def validate_expire_date_past | ||
return if expire_date.nil? | ||
errors.add(:expire_date, :past) if expire_date.past? | ||
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
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,12 @@ | ||
<tr class="dispute"> | ||
<td><%= dispute.domain_name %></td> | ||
<td><%= l dispute.created_at %></td> | ||
<td><%= l dispute.expire_date %></td> | ||
<td> | ||
<%= link_to t('.edit_btn'), edit_admin_dispute_path(dispute), class: 'btn btn-primary btn-xs' %> | ||
<%= link_to t('.delete_btn'), admin_dispute_path(dispute), | ||
method: :delete, | ||
data: { confirm: t('.delete_btn_confirm') }, | ||
class: 'btn btn-danger btn-xs' %> | ||
</td> | ||
</tr> |
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,37 @@ | ||
<%= form_for [:admin, dispute], html: { class: 'form-horizontal' }, auto_html5_validation: false do |f| %> | ||
<%= render 'form_errors', target: dispute %> | ||
|
||
<div class="form-group"> | ||
<%= f.label :domain, class: 'col-sm-2 control-label', for: nil %> | ||
|
||
<div class="col-sm-4"> | ||
<%= f.text_field :domain_name, class: 'form-control', autofocus: true, required: true, | ||
placeholder: 'example.com' %> | ||
</div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<%= f.label :expire_date, class: 'col-sm-2 control-label' %> | ||
|
||
<div class="col-sm-4"> | ||
<%= f.text_field :expire_date, class: 'form-control datepicker', required: true, | ||
pattern: '[0-9]{4}-[0-9]{2}-[0-9]{2}', | ||
placeholder: Time.zone.today.to_s %> | ||
</div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<%= f.label :password, class: 'col-sm-2 control-label' %> | ||
|
||
<div class="col-sm-4"> | ||
<%= f.text_field :password, class: 'form-control' %> | ||
</div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<div class="col-sm-offset-2 col-sm-2"> | ||
<%= f.submit t(".#{dispute.new_record? ? 'create' : 'update'}_btn"), class: 'btn btn-success', | ||
name: nil %> | ||
</div> | ||
</div> | ||
<% 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,10 @@ | ||
<ol class="breadcrumb"> | ||
<%= link_to t('admin.disputes.index.title'), admin_disputes_path %> | ||
</ol> | ||
|
||
|
||
<div class="page-header"> | ||
<h1><%= t '.title' %></h1> | ||
</div> | ||
|
||
<%= render 'form', dispute: @dispute %> |
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,30 @@ | ||
<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_dispute_path, class: 'btn btn-primary' %> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<% if @disputes.present? %> | ||
<table class="table table-hover table-bordered disputes"> | ||
<thead> | ||
<tr> | ||
<th><%= Domain.model_name.human %></th> | ||
<th><%= Dispute.human_attribute_name :created_at %></th> | ||
<th><%= Dispute.human_attribute_name :expire_date %></th> | ||
<th></th> | ||
</tr> | ||
</thead> | ||
|
||
<tbody> | ||
<%= render @disputes %> | ||
</tbody> | ||
</table> | ||
<% else %> | ||
<div class="alert alert-info"><%= t '.not_found' %></div> | ||
<% 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,9 @@ | ||
<ol class="breadcrumb"> | ||
<%= link_to t('admin.disputes.index.title'), admin_disputes_path %> | ||
</ol> | ||
|
||
<div class="page-header"> | ||
<h1><%= t '.title' %></h1> | ||
</div> | ||
|
||
<%= render 'form', dispute: @dispute %> |
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,11 @@ | ||
<% if target.errors.any? %> | ||
<div class="alert alert-danger"> | ||
<p><%= pluralize(target.errors.count, 'error') %> prohibited this <%= target.model_name.human.downcase %> from being saved:</p> | ||
|
||
<ul> | ||
<% target.errors.full_messages.each do |message| %> | ||
<li><%= message %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% 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,43 @@ | ||
en: | ||
admin: | ||
disputes: | ||
index: | ||
new_btn: New dispute | ||
title: Disputes | ||
not_found: No dispute found | ||
|
||
new: | ||
title: New dispute | ||
|
||
edit: | ||
title: Edit dispute | ||
|
||
create: | ||
created: Dispute has been successfully created | ||
|
||
update: | ||
updated: Dispute has been successfully updated | ||
|
||
destroy: | ||
deleted: Dispute has been successfully deleted | ||
|
||
dispute: | ||
edit_btn: Edit | ||
delete_btn: Delete | ||
delete_btn_confirm: Are you sure you want to delete dispute? | ||
|
||
form: | ||
create_btn: Create dispute | ||
update_btn: Update dispute | ||
|
||
activerecord: | ||
attributes: | ||
dispute: | ||
expire_date: Date of expiry | ||
|
||
errors: | ||
models: | ||
dispute: | ||
attributes: | ||
expire_date: | ||
past: cannot be in the past |
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,12 @@ | ||
class CreateDisputes < ActiveRecord::Migration | ||
def change | ||
create_table :disputes do |t| | ||
t.integer :domain_id, index: true | ||
t.string :password | ||
t.datetime :expire_time | ||
t.datetime :created_at | ||
end | ||
|
||
add_foreign_key :disputes, :domains | ||
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,6 @@ | ||
class ChangeDisputeExpireTime < ActiveRecord::Migration | ||
def change | ||
change_column :disputes, :expire_time, :date | ||
rename_column :disputes, :expire_time, :expire_date | ||
end | ||
end |
6 changes: 6 additions & 0 deletions
6
db/migrate/20170205135240_add_domain_id_unique_index_to_disputes.rb
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,6 @@ | ||
class AddDomainIdUniqueIndexToDisputes < ActiveRecord::Migration | ||
def change | ||
remove_index :disputes, :domain_id | ||
add_index :disputes, :domain_id, unique: true | ||
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
Oops, something went wrong.