Skip to content

Commit

Permalink
Add admin pages for subscription inspection
Browse files Browse the repository at this point in the history
  • Loading branch information
mihar committed Feb 21, 2018
1 parent 859e261 commit 32738ba
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
24 changes: 24 additions & 0 deletions app/controllers/admin/subscriptions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# frozen_string_literal: true

class Admin::SubscriptionsController < Admin::AdminController
def index
@subscriptions = Subscription.all
if params[:active]
@subscriptions = @subscriptions.active
elsif params[:inactive]
@subscriptions = @subscriptions.inactive
elsif params[:yearly]
@subscriptions = @subscriptions.active.yearly
elsif params[:per_issue]
@subscriptions = @subscriptions.active.per_issue
elsif params[:free]
@subscriptions = @subscriptions.free
elsif params[:without_order_form]
@subscriptions = @subscriptions.active.without_order_form
elsif params[:rewards]
@subscriptions = @subscriptions.active.rewards
elsif params[:ending_last_year]
@subscriptions = @subscriptions.where(Subscription.arel_table[:end].not_eq(nil).and(Subscription.arel_table[:end].lt(Date.today.beginning_of_year)).and(Subscription.arel_table[:end].gteq(1.year.ago.beginning_of_year)))
end

@subscriptions = @subscriptions.order(end: :desc, quantity: :desc).page(params[:page])
end

def show
respond_with resource
end
Expand Down
63 changes: 63 additions & 0 deletions app/views/admin/subscriptions/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<h2>
Naročnine
<small><%= conditional_filtering_link "Aktivne", param: :active %> | </small>
<small><%= conditional_filtering_link "Potekle", param: :inactive %> | </small>
<small><%= conditional_filtering_link "Potekle v #{1.year.ago.year}", param: :ending_last_year %> | </small>
<small><%= conditional_filtering_link "Brezplačne", param: :free %> | </small>
<small><%= conditional_filtering_link "Nagradne", param: :rewards %> | </small>
<small><%= conditional_filtering_link "Brez naročilnice", param: :without_order_form %></small>
</h2>

<table class="table rowlinks">
<thead>
<tr>
<th>ID</th>
<th>Naročnik</th>
<th>Pričetek</th>
<th>Konec</th>
<th>Darilo?</th>
<th>Kol.</th>
<th>Plan</th>
</tr>
</thead>
<tbody>
<% @subscriptions.each do |subscription| %>
<tr>
<td>
<%= link_to "", admin_subscription_path(subscription) %>
<%= subscription.id %>
</td>
<td>
<%= subscription.customer %>
</td>
<td>
<span class="label label-success">
<%=l subscription.start %>
</span>
</td>
<td>
<% if subscription.end? %>
<span class="label label-danger">
<%=l subscription.end %>
</span>
<% end %>
</td>
<td>
<% if subscription.is_reward? %>
<span class="label label-warning">
<i class="glyphicon glyphicon-gift"></i>
</span>
<% end %>
</td>
<td>
<%= subscription.quantity %>
</td>
<td>
<%= subscription.plan %>
</td>
</tr>
<% end %>
</tbody>
</table>

<%= paginate @subscriptions %>

0 comments on commit 32738ba

Please sign in to comment.