forked from OSC/ondemand
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
# The controller to add new pages with layouts and widgets based on configuration. | ||
# | ||
# It uses a page_code coming from the URL to determine which layout to use. | ||
# If the page_code does not match a configuration object, an error message is displayed. | ||
class CustomPagesController < ApplicationController | ||
def index | ||
page_code = params[:page_code] | ||
@page_layout = @user_configuration.custom_pages.fetch(page_code.to_sym, {}) | ||
flash.now[:alert] = t('dashboard.custom_pages.invalid', page: page_code) if @page_layout.blank? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<%= javascript_include_tag 'dashboard', nonce: true %> | ||
|
||
<%- @page_layout.fetch(:rows, []).each do |row| -%> | ||
<div class="row"> | ||
<%- row.fetch(:columns, []).each do |col| -%> | ||
<div class='<%= "col-md-#{col.fetch(:width, "12")}" %>'> | ||
<%- Array(col.fetch(:widgets, [])).each do |widget| -%> | ||
<%= render_widget(widget.to_s) %> | ||
<%- end -%> | ||
</div> | ||
<%- end -%> | ||
</div> | ||
<%- end -%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
apps/dashboard/test/controllers/custom_pages_controller_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require "test_helper" | ||
|
||
class CustomPagesControllerTest < ActiveSupport::TestCase | ||
|
||
test "index should set flash message if page_code configuration is not found" do | ||
target = CustomPagesController.new | ||
target.instance_variable_set(:@user_configuration, stub("user_configuration", {custom_pages: {}})) | ||
target.stubs(:params).returns({page_code: "not_found_page"}) | ||
flash = ActionDispatch::Request.empty.flash | ||
target.stubs(:flash).returns(flash) | ||
target.expects(:t).with("dashboard.custom_pages.invalid", {:page => "not_found_page"}) | ||
|
||
target.index | ||
end | ||
|
||
test "index should not set flash message if page_code configuration is found" do | ||
page_config = { | ||
rows: [] | ||
} | ||
target = CustomPagesController.new | ||
target.instance_variable_set(:@user_configuration, stub("user_configuration", {custom_pages: {test_page: page_config}})) | ||
target.stubs(:params).returns({page_code: "test_page"}) | ||
target.expects(:flash).times(0) | ||
|
||
target.index | ||
end | ||
|
||
end |
1 change: 1 addition & 0 deletions
1
apps/dashboard/test/fixtures/config/views/widgets/_custom_pages_test.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h3>Custom Pages Test Widget</h3> |
37 changes: 37 additions & 0 deletions
37
apps/dashboard/test/integration/custom_pages_integration_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require 'test_helper' | ||
|
||
class CustomPagesIntegrationTest < ActionDispatch::IntegrationTest | ||
|
||
test "should render configured page layout" do | ||
stub_user_configuration({ | ||
custom_pages: { | ||
docs: { | ||
rows: [ | ||
{columns: [ | ||
{ | ||
widgets: 'custom_pages_test' | ||
} | ||
]}, | ||
{columns: [ | ||
{ | ||
width: 8, | ||
widgets: 'custom_pages_test' | ||
} | ||
]} | ||
] | ||
} | ||
} | ||
}) | ||
|
||
get custom_pages_path(page_code: "docs") | ||
|
||
assert :success | ||
assert_select 'div.row', 2 | ||
assert_select 'div.row > div.col-md-12', 1 | ||
assert_select 'div.row > div.col-md-12 > h3', text: "Custom Pages Test Widget" | ||
assert_select 'div.row > div.col-md-8', 1 | ||
assert_select 'div.row > div.col-md-8 > h3', text: "Custom Pages Test Widget" | ||
end | ||
|
||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters