Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix paginating #121

Merged
merged 5 commits into from
Mar 13, 2015
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/resque/server/views/status.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<%= status_view :status_styles, :layout => false %>

<h1 class='wi'>Statuses: <%= @status.uuid %>/<%= @status.name %></h1>
<h1 class='wi'>Status <%= @status.uuid %></h1>
<p class='intro'>Viewing a specific job created with Resque::Plugins::Status. <a href="<%= u(:statuses) %>">Return to the list of statuses</a></p>

<div class="status-holder" rel="<%= @status.status %>" id="status_<%= @status.uuid %>">
<h2>Overwiev</h2>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sp

<div class="status-progress">
<div class="status-progress-bar status-<%= @status.status %>" style="width: <%= @status.pct_complete %>%;"></div>
<p><%= @status.pct_complete %>%</p>
</div>
<div class="status-message"><%= @status.message %></div>
<div class="status-time"><%= @status.time? ? @status.time : 'Not started' %></div>

<h2>Details</h2>
<div class="status-details">
<table>
<table class="vertically-top">
<thead>
<tr>
<th>Key</th>
Expand Down Expand Up @@ -81,7 +83,7 @@
time.setTime(value * 1000);
return time.toUTCString();
} else {
return JSON.stringify(value);
return JSON.stringify(value, null, " ");
}
}

Expand Down
6 changes: 6 additions & 0 deletions lib/resque/server/views/status_styles.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
z-index: 10;
color: #333;
}
table.vertically-top td {
vertical-align: text-top;
}
table.vertically-top tr {
border: 1px solid #ccc;
}

.status-holder {
background: #F7F7F7;
Expand Down
24 changes: 13 additions & 11 deletions lib/resque/server/views/statuses.erb
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<%= status_view :status_styles, :layout => false %>

<h1 class='wi'>Statuses</h1>

<%unless @statuses.empty?%>
<form method="POST" action="<%= u(:statuses) %>/clear" class='clear-failed'>
<input type='submit' name='' value='Clear Statuses' onclick='return confirm("Are you absolutely sure? This cannot be undone.");' />
</form>
<form method="POST" action="<%= u(:statuses) %>/clear/completed" class='clear-failed'>
<input type='submit' name='' value='Clear Completed Statuses' onclick='return confirm("Are you absolutely sure? This cannot be undone.");' />
</form>
<form method="POST" action="<%= u(:statuses) %>/clear/failed" class='clear-failed'>
<input type='submit' name='' value='Clear Failed Statuses' onclick='return confirm("Are you absolutely sure? This cannot be undone.");' />
</form>
<form method="POST" action="<%= u(:statuses) %>/clear" class='clear-failed'>
<input type='submit' name='' value='Clear Statuses' onclick='return confirm("Are you absolutely sure? This cannot be undone.");' />
</form>
<form method="POST" action="<%= u(:statuses) %>/clear/completed" class='clear-failed'>
<input type='submit' name='' value='Clear Completed Statuses' onclick='return confirm("Are you absolutely sure? This cannot be undone.");' />
</form>
<form method="POST" action="<%= u(:statuses) %>/clear/failed" class='clear-failed'>
<input type='submit' name='' value='Clear Failed Statuses' onclick='return confirm("Are you absolutely sure? This cannot be undone.");' />
</form>
<%end%>

<p class='intro'>These are recent jobs created with the Resque::Plugins::Status class</p>
<table>
<table class="vertically-top">
<tr>
<th>ID</th>
<th>Name</th>
Expand Down Expand Up @@ -46,7 +48,7 @@
</table>

<% unless @statuses.empty? %>
<%= partial :next_more, :start => @start, :size => @size %>
<%= partial :next_more, :start => @start, :size => @size, :per_page => per_page %>
<% end %>

<%= status_poll(@start) %>
Expand Down
14 changes: 9 additions & 5 deletions lib/resque/status_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ module Resque
module StatusServer

VIEW_PATH = File.join(File.dirname(__FILE__), 'server', 'views')
PER_PAGE = 50

def self.registered(app)

app.get '/statuses' do
@start = params[:start].to_i
@end = @start + (params[:per_page] || 50)
@end = @start + (params[:per_page] || per_page) - 1
@statuses = Resque::Plugins::Status::Hash.statuses(@start, @end)
@size = @statuses.size
@size = Resque::Plugins::Status::Hash.count
status_view(:statuses)
end

Expand Down Expand Up @@ -52,14 +53,17 @@ def self.registered(app)
@polling = true

@start = params[:start].to_i
@end = @start + (params[:per_page] || 50)
@end = @start + (params[:per_page] || per_page) - 1
@statuses = Resque::Plugins::Status::Hash.statuses(@start, @end)
@size = @statuses.size

@size = Resque::Plugins::Status::Hash.count
status_view(:statuses, {:layout => false})
end

app.helpers do
def per_page
PER_PAGE
end

def status_view(filename, options = {}, locals = {})
erb(File.read(File.join(::Resque::StatusServer::VIEW_PATH, "#{filename}.erb")), options, locals)
end
Expand Down