Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Commit

Permalink
Better updating of versions#index.
Browse files Browse the repository at this point in the history
  • Loading branch information
nning committed Apr 14, 2014
1 parent 07b023f commit 7dbb9b7
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 11 deletions.
1 change: 0 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
is thrown (see test/unit/mailbox_test.rb:57):
SQLite3::ConstraintException: UNIQUE constraint failed: relocations.mailbox_id: INSERT INTO "relocations" ("created_at", "mailbox_id", "old_domain", "old_username", "updated_at") VALUES (?, ?, ?, ?, ?)
* Relocation daemon.
* Make auto-refresh in changes index configurable.
24 changes: 24 additions & 0 deletions app/assets/javascripts/changes_updates.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
update = ->
table = $('table.changes')
o = table.find('tr.version:first')

uri = table.data('uri') + '?since=' + o.data('id')

$.get uri, (data) ->
unless data == ' '
table.find('tbody').prepend(data)

n = table.find('tr.version:first')
n.hide()
n.fadeIn()

table.find('tr.version:last').remove()

enqueue()

enqueue = ->
setTimeout update, 10000

$ ->
if $('table.changes').length && !document.URL.contains('?page=')
enqueue()
5 changes: 0 additions & 5 deletions app/assets/javascripts/reload_changes.js.coffee

This file was deleted.

7 changes: 7 additions & 0 deletions app/controllers/admin/versions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@ def revert
redirect_to [:admin, :versions], flash: { error: "Impossible to revert #{@version.event}." }
end
end

# Return versions since an id rendered as HTML.
def updates
since = params[:since].to_i || 0
@versions = Version.where('id > ?', since).order('created_at desc')
render @versions
end
end
2 changes: 1 addition & 1 deletion app/views/admin/versions/_modal.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
= summarize_changes version.object_changes
.modal-footer
- if ['update', 'destroy'].include? version.event
= link_to 'Revert', [:admin, :revert, version], class: 'btn btn-danger', method: :post
= link_to 'Revert', [:revert, :admin, version], class: 'btn btn-danger', method: :post
= button_tag 'Close', class: 'btn btn-default', :'data-dismiss' => 'modal'
2 changes: 1 addition & 1 deletion app/views/admin/versions/_version.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%tr
%tr{class: 'version', :'data-id' => version.id}
%td= icon_for_event version.event
%td= version.item_type
%td= link_to_object version
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/versions/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.page-header
%h1 Changes

%table.table.table-striped
%table.table.table-striped.changes{:'data-uri' => updates_admin_versions_path}
%thead
%th Action
%th Type
Expand Down
6 changes: 4 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
resources :mailboxes, except: :show
resources :permissions, except: :show
end
resources :versions, only: :index
post 'versions/:id/revert' => 'versions#revert', as: 'revert_version'
resources :versions, only: :index do
get 'updates', on: :collection
post 'revert', on: :member
end
post 'search' => 'searches#search'
end

Expand Down

0 comments on commit 7dbb9b7

Please sign in to comment.