Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 7 additions & 2 deletions app/models/dash_kit/dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ def block_layout_kind
end

def layout_data
KsBlocks.layout_data(roomed_blocks, kind: block_layout_kind, grid: declared_grid, offered: block_layout_offered)
.merge(version: KsBlocks.version_of(blocks))
room_blocks_from_their_types!
KsBlocks.layout_data(blocks, kind: block_layout_kind, grid: declared_grid, offered: block_layout_offered)
end

def room_blocks_from_their_types!
roomed = roomed_blocks
update!(blocks: roomed) unless roomed == blocks
end

def add_built_widget(definition, x: nil, y: nil)
Expand Down
24 changes: 23 additions & 1 deletion test/dash_kit/dashboard_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,28 @@ def test_a_dashboard_keeps_a_block_added_to_its_layout
config.register(:restated) { |d| d.widget :on_deck, label: "On Deck", partial: "widgets/home/on_deck", width: 3, height: 1 }
end

assert_equal KsBlocks.version_of(dashboard.reload.blocks), dashboard.layout_data[:version]
drawn = dashboard.layout_data

assert_equal KsBlocks.version_of(dashboard.reload.blocks), drawn[:version]
end

test "a move is accepted at the sizes the dashboard is drawn at, not the sizes it once stored" do
DashKit.reset_registry!
DashKit.configure do |config|
config.register(:shrunk) do |d|
d.widget :one, label: "One", partial: "widgets/home/on_deck", width: 3, height: 1
d.widget :two, label: "Two", partial: "widgets/home/tasks", width: 3, height: 1
end
end
dashboard = DashKit::Dashboard.create!(owner: @account, name: "Shrunk", dashboard_type: "shrunk")
dashboard.update!(blocks: [
{ "id" => "a", "type" => "one", "x" => 0, "y" => 0, "w" => 3, "h" => 4 },
{ "id" => "b", "type" => "two", "x" => 0, "y" => 4, "w" => 3, "h" => 4 }
])
dashboard.layout_data

dashboard.place_blocks([ { "id" => "a", "x" => 0, "y" => 1 }, { "id" => "b", "x" => 0, "y" => 0 } ])

assert_equal [ [ "b", 0 ], [ "a", 1 ] ], dashboard.reload.blocks.sort_by { |block| block["y"] }.map { |block| block.values_at("id", "y") }
end
end
Loading