-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from omnilord/trashcan
Adding functionality to view trashed items and restore them when needed.
- Loading branch information
Showing
14 changed files
with
349 additions
and
96 deletions.
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
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,28 @@ | ||
class TrashController < ApplicationController | ||
before_action :authenticate_admin!, only: [:destroy] | ||
before_action :set_trash, only: [:show, :destroy] | ||
|
||
def index | ||
@trash = Trash.all | ||
end | ||
|
||
def show | ||
@columns = @resource.class::ColumnNames | ||
@headers = @resource.class::HeaderNames | ||
end | ||
|
||
def destroy | ||
if resource = @trash.restore! | ||
redirect_to resource | ||
else | ||
redirect_to trash_path, notice: "Could not restore '#{@resource.name}' (#{@trash.trashable_type}/#{@trash.trashable_id})." | ||
end | ||
end | ||
|
||
private | ||
|
||
def set_trash | ||
@trash = Trash.find(params[:id]) | ||
@resource = @trash.resource | ||
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 |
---|---|---|
|
@@ -58,6 +58,10 @@ def self.to_csv | |
end | ||
end | ||
|
||
def name | ||
facility_name | ||
end | ||
|
||
def outdated? | ||
updated_at < 4.hours.ago | ||
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 |
---|---|---|
|
@@ -78,6 +78,10 @@ def self.to_csv | |
end | ||
end | ||
|
||
def name | ||
shelter | ||
end | ||
|
||
def outdated? | ||
updated_at < 4.hours.ago | ||
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
22 changes: 22 additions & 0 deletions
22
app/views/distribution_points/_distribution_point.html.erb
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,22 @@ | ||
<h1><%= resource.facility_name %></h1> | ||
|
||
<%= content_for :resource_command_list %> | ||
|
||
<div class="row"> | ||
<div class="column"> | ||
<%= render 'shared/show', record: resource, headers: @headers, columns: @columns %> | ||
</div> | ||
<div class="column"> | ||
<div id="map" style="height: 300px; width: 100%"></div> | ||
<script> | ||
$(window).ready(function(){ | ||
simpleMap({ | ||
selector: "#map", | ||
name: "<%= j resource.facility_name %>", | ||
lat: <%= resource.latitude || 0 %>, | ||
lng: <%= resource.longitude || 0 %> | ||
}) | ||
}) | ||
</script> | ||
</div> | ||
</div> |
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 |
---|---|---|
@@ -1,50 +1,32 @@ | ||
<h1><%= @distribution_point.facility_name %></h1> | ||
|
||
|
||
<% 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? %> | | ||
<% content_for :resource_command_list do %> | ||
<% if @distribution_point.archived %> | ||
<%= link_to 'Unarchive', unarchive_distribution_point_path(@distribution_point), | ||
method: :delete, | ||
data: { confirm: 'Are you sure?' }, | ||
class: 'button button-clear' %> | ||
<%= link_to 'Back', archived_distribution_points_path, class: 'button button-clear' %> | ||
<% else %> | ||
<%= link_to 'Archive', archive_distribution_point_path(@distribution_point), | ||
<%= link_to 'Update', edit_distribution_point_path(@distribution_point), class: 'button button-clear' %> | | ||
<%= link_to 'Back', distribution_points_path, class: 'button button-clear' %> | ||
<% end %> | ||
<% if admin? %> | | ||
<% 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 'Archive', archive_distribution_point_path(@distribution_point), | ||
method: :post, | ||
data: { confirm: 'Are you sure?' }, | ||
class: 'button button-clear' %> | ||
<% end %> | | ||
<%= link_to 'Delete', @distribution_point, | ||
method: :delete, | ||
data: { confirm: 'Are you sure?' }, | ||
class: 'button button-clear' %> | ||
<% end %> | ||
<% if user_signed_in? && @distribution_point.outdated? %> | | ||
<%= link_to 'Mark Current', mark_current_distribution_point_path(@distribution_point), | ||
method: :post, | ||
data: { confirm: 'Are you sure?' }, | ||
class: 'button button-clear' %> | ||
<% end %> | | ||
<%= link_to 'Delete', @distribution_point, | ||
method: :delete, | ||
data: { confirm: 'Are you sure?' }, | ||
class: 'button button-clear' %> | ||
<% end %> | ||
<% if user_signed_in? && @distribution_point.outdated? %> | | ||
<%= link_to 'Mark Current', mark_current_distribution_point_path(@distribution_point), | ||
method: :post, | ||
class: 'button button-clear' %> | ||
<% end %> | ||
<% end %> | ||
|
||
<div class="row"> | ||
<div class="column"> | ||
<%= render 'shared/show', record: @distribution_point, headers: @headers, columns: @columns %> | ||
</div> | ||
<div class="column"> | ||
<div id="map" style="height: 300px; width: 100%"></div> | ||
<script> | ||
$(window).ready(function(){ | ||
simpleMap({ | ||
selector: "#map", | ||
name: "<%= j @distribution_point.facility_name %>", | ||
lat: <%= @distribution_point.latitude || 0 %>, | ||
lng: <%= @distribution_point.longitude || 0 %> | ||
}) | ||
}) | ||
</script> | ||
</div> | ||
</div> | ||
<%= render @distribution_point, resource: @distribution_point %> |
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,22 @@ | ||
<h1><%= resource.name %></h1> | ||
|
||
<%= content_for :resource_command_list %> | ||
|
||
<div class="row"> | ||
<div class="column"> | ||
<%= render 'shared/show', record: resource, headers: headers, columns: columns %> | ||
</div> | ||
<div class="column"> | ||
<div id="map" style="height: 300px; width: 100%"></div> | ||
<script> | ||
$(window).ready(function(){ | ||
simpleMap({ | ||
selector: "#map", | ||
name: "<%= j resource.name %>", | ||
lat: <%= resource.latitude || 0 %>, | ||
lng: <%= resource.longitude || 0 %> | ||
}) | ||
}) | ||
</script> | ||
</div> | ||
</div> |
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 |
---|---|---|
@@ -1,49 +1,34 @@ | ||
<h1><%= @shelter.shelter %></h1> | ||
|
||
<% 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? %> | | ||
<% content_for :resource_command_list do %> | ||
<% if @shelter.active %> | ||
<%= link_to 'Archive', archive_shelter_path(@shelter), | ||
method: :post, | ||
data: { confirm: 'Are you sure?' }, | ||
class: 'button button-clear' %> | ||
<%= link_to 'Update', [:edit, @shelter], class: 'button button-clear' %> | | ||
<%= link_to 'Back', shelters_path, class: 'button button-clear' %> | ||
<% else %> | ||
<%= link_to 'Unarchive', unarchive_shelter_path(@shelter), | ||
method: :delete, | ||
data: { confirm: 'Are you sure?' }, | ||
class: 'button button-clear' %> | ||
<% end %> | | ||
<%= link_to 'Delete', @shelter, | ||
method: :delete, | ||
data: { confirm: 'Are you sure?' }, | ||
<%= 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 'Unarchive', unarchive_shelter_path(@shelter), | ||
method: :delete, | ||
data: { confirm: 'Are you sure?' }, | ||
class: 'button button-clear' %> | ||
<% end %> | | ||
<%= link_to 'Delete', @shelter, | ||
method: :delete, | ||
data: { confirm: 'Are you sure?' }, | ||
class: 'button button-clear' %> | ||
<% end %> | ||
<% if user_signed_in? && @shelter.outdated? %> | | ||
<%= link_to 'Mark Current', mark_current_shelter_path(@shelter), | ||
method: :post, | ||
class: 'button button-clear' %> | ||
<% end %> | ||
<% if user_signed_in? && @shelter.outdated? %> | | ||
<%= link_to 'Mark Current', mark_current_shelter_path(@shelter), | ||
method: :post, | ||
class: 'button button-clear' %> | ||
<% end %> | ||
<% end %> | ||
|
||
<div class="row"> | ||
<div class="column"> | ||
<%= render 'shared/show', record: @shelter, headers: @headers, columns: @columns %> | ||
</div> | ||
<div class="column"> | ||
<div id="map" style="height: 300px; width: 100%"></div> | ||
<script> | ||
$(window).ready(function(){ | ||
simpleMap({ | ||
selector: "#map", | ||
name: "<%= j @shelter.shelter %>", | ||
lat: <%= @shelter.latitude || 0 %>, | ||
lng: <%= @shelter.longitude || 0 %> | ||
}) | ||
}) | ||
</script> | ||
</div> | ||
</div> | ||
<%= render @shelter, resource: @shelter, | ||
headers: @headers, | ||
columns: @columns %> |
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 @@ | ||
<h1>Trashed Records</h1> | ||
|
||
|
||
<table id="data-table"> | ||
<thead> | ||
<tr> | ||
<th></th> | ||
<th>Type/ID</th> | ||
<th>Record Name</th> | ||
<th>Deleted At</th> | ||
<th>Deleted By</th> | ||
<th>Reason</th> | ||
</tr> | ||
</thead> | ||
|
||
<tbody> | ||
<% @trash.each do |row| %> | ||
<tr> | ||
<td class="controlsColumn"> | ||
<%= link_to 'Show', row, class: 'button button-clear' %> | ||
<% if admin? %> | ||
<br/> | ||
<%= link_to 'Restore', row, | ||
method: :delete, | ||
data: { confirm: 'Are you sure?' }, | ||
class: 'button button-clear' %> | ||
<% end %> | ||
</td> | ||
<td><%= "#{row.trashable_type}/#{row.trashable_id}" %></td> | ||
<td><%= sanitize(row.resource.name) %></td> | ||
<td><%= time_ago_in_words(row.created_at) %> ago</td> | ||
<td><%= row.user&.email %></td> | ||
<td><%= sanitize(row.reason) %></td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
|
||
<script> | ||
window.onload = function() { | ||
$('#data-table').DataTable(); | ||
}; | ||
</script> |
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 @@ | ||
<% content_for :resource_command_list do %> | ||
<%= link_to 'Restore', trash_path(@trash), | ||
method: :delete, | ||
data: { confirm: 'Are you sure?' }, | ||
class: 'button button-clear' %> | ||
<% end %> | ||
<%= render @resource, resource: @resource, | ||
headers: @headers, | ||
columns: @columns %> |
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.