Skip to content

Commit

Permalink
feat: Add expire_at field to Reserved Domains
Browse files Browse the repository at this point in the history
- Add expire_at field to Reserved Domains form and permit it in controller
- Add expire_at column to Reserved Domains index table with status indicators
- Add expire date search filter using custom ransacker to ignore time component
- Update translations and labels
- Change "edit_pw" to "edit" in views and translations
  • Loading branch information
OlegPhenomenon committed Dec 20, 2024
1 parent a0c4fb1 commit 176b200
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/reserved_domains_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def reserved_checked_elements
end

def reserved_domain_params
params.require(:reserved_domain).permit(:name, :password)
params.require(:reserved_domain).permit(:name, :password, :expire_at)
end

def set_domain
Expand Down
4 changes: 4 additions & 0 deletions app/models/reserved_domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class ReservedDomain < ApplicationRecord

alias_attribute :registration_code, :password

ransacker :expire_date do
Arel.sql('DATE(expire_at)')
end

self.ignored_columns = %w[legacy_id]

MAX_DOMAIN_NAME_PER_REQUEST = 20
Expand Down
8 changes: 8 additions & 0 deletions app/views/admin/reserved_domains/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
<span class="help-block"><%= t '.password_hint' %></span>
</div>
</div>
<div class="form-group">
<div class="col-md-4 control-label">
<%= f.label :expire_at %>
</div>
<div class="col-md-7">
<%= f.text_field :expire_at, class: 'form-control js-datepicker', value: f.object.expire_at.present? ? l(f.object.expire_at, format: :short) : nil %>
</div>
</div>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/reserved_domains/edit.haml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
= render 'shared/title', name: t(:edit_pw)
= render 'shared/title', name: t(:edit)

= render 'form'
21 changes: 20 additions & 1 deletion app/views/admin/reserved_domains/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@
<%= 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 class="col-md-3">
<div class="form-group">
<%= f.label t(:expired_at) %>
<%= f.search_field :expire_date_eq,
value: params[:q][:expire_date_eq],
class: 'form-control js-datepicker',
placeholder: t(:expired_at) %>
</div>
</div>
</div>
<div class="row">
<div class="col-md-3">
Expand Down Expand Up @@ -76,6 +85,9 @@
<th class="col-xs-2">
<%= sort_link(@q, 'updated_at', t(:updated_at)) %>
</th>
<th class="col-xs-2">
<%= sort_link(@q, 'expire_at', t(:expire_at)) %>
</th>
<th class="col-xs-2">
<%= t(:actions) %>
</th>
Expand All @@ -100,7 +112,14 @@
<%= l(x.updated_at, format: :short) %>
</td>
<td>
<%= link_to(t(:edit_pw), edit_admin_reserved_domain_path(id: x.id), class: 'btn btn-primary btn-xs') %>
<% if x.expire_at.present? %>
<span class="label <%= x.expire_at < Date.today ? 'label-danger' : 'label-success' %>"><%= l(x.expire_at, format: :short) %></span>
<% else %>
<span class="label" style="background-color: #aaa; color: #fff;"><%= t(:not_set) %></span>
<% end %>
</td>
<td>
<%= link_to(t(:edit), edit_admin_reserved_domain_path(id: x.id), class: 'btn btn-primary btn-xs') %>
<%= link_to(t(:delete), delete_admin_reserved_domain_path(id: x.id), data: { confirm: t(:are_you_sure) }, class: 'btn btn-danger btn-xs') %>
</td>
</tr>
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,7 @@ en:
id: ID
created_at_from: 'Created at from'
created_at_until: 'Created at until'
expired_at: 'Expired at'
is_registrant: 'Is registrant'
force_delete_set_on_domain: 'Force delete set on domain %{domain_name}. Outzone date: %{outzone_date}. Purge date: %{purge_date}'
force_delete_auto_email: 'Force delete set on domain %{domain_name}. Outzone date: %{outzone_date}. Purge date: %{purge_date}. Invalid email: %{email}'
Expand Down

0 comments on commit 176b200

Please sign in to comment.