Project

General

Profile

« Previous | Next » 

Revision c1a8ccf1

Added by Daniel Lobato Garcia over 8 years ago

Fixes #10929 - Add removed widgets to dashboard

This commit allows users to re-add widgets. At this point it's only
possible to recover removed widgets by clicking on "Reset to default".

To do this I populate the 'Add widgets' list by getting a diff
between the current widgets and the available ones. The code calls any
available widget 'default_widget', so keep that in mind.

After removing a widget, we reload the page, which is fairly fast thanks
to turbolinks. This is so that we populate the 'Add widgets' list.

Clicking on the widget to add will trigger a POST call that will add the
widget to User.current.widgets and reload the page. The reason why I
need to reload the page is to get the data in the new widget, otherwise
we would load an empty widget. It's not optimal but turbolinks makes it
fast.

(cherry picked from commit 24fc15c59e0acb589ef46a8f60e8ce76e72fd8d2)

View differences:

test/functional/dashboard_controller_test.rb
require 'test_helper'
class DashboardControllerTest < ActionController::TestCase
test "should get index" do
test 'should get index' do
get :index, {}, set_session_user
assert_response :success
end
test 'create returns 404 if widget to add is not found' do
post :create, { :name => 'non-existent-widget' }, set_session_user
assert_response :not_found
end
test 'create adds widget to user if widget is valid' do
assert_difference('users(:admin).widgets.count', 1) do
post :create, { :name => 'Status table' }, set_session_user
end
assert_response :success
end
end

Also available in: Unified diff