diff --git a/TODO b/TODO index dd21f01..12c6d7c 100644 --- a/TODO +++ b/TODO @@ -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. diff --git a/app/assets/javascripts/changes_updates.js.coffee b/app/assets/javascripts/changes_updates.js.coffee new file mode 100644 index 0000000..12f3d87 --- /dev/null +++ b/app/assets/javascripts/changes_updates.js.coffee @@ -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() diff --git a/app/assets/javascripts/reload_changes.js.coffee b/app/assets/javascripts/reload_changes.js.coffee deleted file mode 100644 index 0e4a4a8..0000000 --- a/app/assets/javascripts/reload_changes.js.coffee +++ /dev/null @@ -1,5 +0,0 @@ -$ -> - if $('h1').html() == 'Changes' - setTimeout(-> - location.reload() - , 120 * 1000) diff --git a/app/controllers/admin/versions_controller.rb b/app/controllers/admin/versions_controller.rb index c9a16c9..8dd32f6 100644 --- a/app/controllers/admin/versions_controller.rb +++ b/app/controllers/admin/versions_controller.rb @@ -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 diff --git a/app/views/admin/versions/_modal.html.haml b/app/views/admin/versions/_modal.html.haml index 1cfb348..081e745 100644 --- a/app/views/admin/versions/_modal.html.haml +++ b/app/views/admin/versions/_modal.html.haml @@ -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' diff --git a/app/views/admin/versions/_version.html.haml b/app/views/admin/versions/_version.html.haml index ac4e8b9..24da880 100644 --- a/app/views/admin/versions/_version.html.haml +++ b/app/views/admin/versions/_version.html.haml @@ -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 diff --git a/app/views/admin/versions/index.html.haml b/app/views/admin/versions/index.html.haml index b215cee..9835da5 100644 --- a/app/views/admin/versions/index.html.haml +++ b/app/views/admin/versions/index.html.haml @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 34d4021..83dc714 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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