Skip to content

Commit

Permalink
Merge pull request #48 from omnilord/master
Browse files Browse the repository at this point in the history
Resolve Issue #46 - Archive/Unarchive links
  • Loading branch information
nihonjinrxs authored Sep 23, 2018
2 parents f2e535d + 3a7c8a9 commit 3408842
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 21 deletions.
2 changes: 1 addition & 1 deletion app/views/distribution_points/archived.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
<%= link_to 'Add New Distribution Point', new_distribution_point_path, class: "button button-outline" %>
<%= link_to 'Download as CSV', archived_distribution_points_path(format: :csv), class: "button button-outline" %>

<%= render "shared/table", rows: @distribution_points, headers: @headers, columns: @columns, reverse_chron: false %>
<%= render "shared/archived_table", rows: @distribution_points, headers: @headers, columns: @columns, reverse_chron: false %>
10 changes: 5 additions & 5 deletions app/views/distribution_points/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<h1>Edit <%= @distribution_point.facility_name %></h1>
<% if admin? %>
<% if @distribution_point.active %>
<%= link_to 'Archive', archive_distribution_point_path(@distribution_point),
method: :post,
<% if @distribution_point.archived %>
<%= link_to 'Unarchive', unarchive_distribution_point_path(@distribution_point),
method: :delete,
data: { confirm: 'Are you sure?' },
class: 'button button-clear' %>
<% else %>
<%= link_to 'Reactivate', unarchive_distribution_point_path(@distribution_point),
method: :delete,
<%= link_to 'Archive', archive_distribution_point_path(@distribution_point),
method: :post,
data: { confirm: 'Are you sure?' },
class: 'button button-clear' %>
<% end %>
Expand Down
18 changes: 11 additions & 7 deletions app/views/distribution_points/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
<h1><%= @distribution_point.facility_name %></h1>


<%= link_to 'Update', [:edit, @distribution_point], class: 'button button-clear' %> |
<%= link_to 'Back', distribution_points_path, class: 'button button-clear' %>
<% if @distribution_point.archived %>
<%= link_to 'Back', archived_distribution_points_path, class: 'button button-clear' %>
<% else %>
<%= link_to 'Update', [:edit, @distribution_point], class: 'button button-clear' %> |
<%= link_to 'Back', distribution_points_path, class: 'button button-clear' %>
<% end %>
<% if admin? %> |
<% if @distribution_point.active %>
<%= link_to 'Archive', archive_distribution_point_path(@distribution_point),
method: :post,
<% if @distribution_point.archived %>
<%= link_to 'Unarchive', unarchive_distribution_point_path(@distribution_point),
method: :delete,
data: { confirm: 'Are you sure?' },
class: 'button button-clear' %>
<% else %>
<%= link_to 'Reactivate', unarchive_distribution_point_path(@distribution_point),
method: :delete,
<%= link_to 'Archive', archive_distribution_point_path(@distribution_point),
method: :post,
data: { confirm: 'Are you sure?' },
class: 'button button-clear' %>
<% end %>
Expand Down
54 changes: 54 additions & 0 deletions app/views/shared/_archived_table.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<table id="data-table" class="shared-table">
<thead>
<tr>
<th></th>
<% headers.each do |header| %>
<th><%= header %></th>
<% end %>
</tr>
</thead>

<tbody>
<% rows.each do |row| %>
<tr>
<td><%= link_to 'Show', row %> / <%= link_to 'Unarchive', [:unarchive, row],
method: :delete,
data: { confirm: 'Are you sure?' } %></td>
<% columns.each do |column| %>
<% value = row.send(column) %>
<% if value.acts_like?(:time) %>
<td data-order="<%= value.to_i %>">
<span title="<%= value %>"><%= time_ago_in_words(value) %> ago</span>
</td>
<% else %>
<td>
<%= truncate(value.to_s) %>
</td>
<% end %>
</td>
<% end %>
</tr>
<% end %>
</tbody>
</table>

<% unless reverse_chron %>
<script>
window.onload = function() {
document.dataTable = $('#data-table').DataTable({
"order": [[ 1, "desc" ]],
"stateSave": true
});
};
</script>
<% else %>
<script>
window.onload = function() {
document.dataTable = $('#data-table').DataTable({
"order": [[ 2, "asc" ]],
"stateSave": true
});
document.dataTable.order.fixed({ pre: [[ 2, "asc" ]] }).draw();
};
</script>
<% end %>
6 changes: 3 additions & 3 deletions app/views/shelters/archived.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
})
</script>

<%= link_to 'Add New Shelter', new_shelter_path, class: "button button-outline" %>
<%= link_to 'Download as CSV', archived_shelters_path(format: :csv), class: "button button-outline" %>
<%= link_to 'Add New Shelter', new_shelter_path, class: 'button button-outline' %>
<%= link_to 'Download as CSV', archived_shelters_path(format: :csv), class: 'button button-outline' %>

<%= render "shared/table", rows: @shelters, headers: @headers, columns: @columns, reverse_chron: false %>
<%= render 'shared/archived_table', rows: @shelters, headers: @headers, columns: @columns, reverse_chron: false %>
2 changes: 1 addition & 1 deletion app/views/shelters/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
data: { confirm: 'Are you sure?' },
class: 'button button-clear' %>
<% else %>
<%= link_to 'Reactivate', unarchive_shelter_path(@shelter),
<%= link_to 'Unarchive', unarchive_shelter_path(@shelter),
method: :delete,
data: { confirm: 'Are you sure?' },
class: 'button button-clear' %>
Expand Down
11 changes: 7 additions & 4 deletions app/views/shelters/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<h1><%= @shelter.shelter %></h1>


<%= link_to 'Update', [:edit, @shelter], class: 'button button-clear' %> |
<%= link_to 'Back', shelters_path, class: 'button button-clear' %>
<% if @shelter.active %>
<%= link_to 'Update', [:edit, @shelter], class: 'button button-clear' %> |
<%= link_to 'Back', shelters_path, class: 'button button-clear' %>
<% else %>
<%= link_to 'Back', archived_shelters_path, class: 'button button-clear' %>
<% end %>
<% if admin? %> |
<% if @shelter.active %>
<%= link_to 'Archive', archive_shelter_path(@shelter),
method: :post,
data: { confirm: 'Are you sure?' },
class: 'button button-clear' %>
<% else %>
<%= link_to 'Reactivate', unarchive_shelter_path(@shelter),
<%= link_to 'Unarchive', unarchive_shelter_path(@shelter),
method: :delete,
data: { confirm: 'Are you sure?' },
class: 'button button-clear' %>
Expand Down

0 comments on commit 3408842

Please sign in to comment.