Skip to content

Commit

Permalink
Merge pull request #2058 from mamhoff/preview-page-link
Browse files Browse the repository at this point in the history
Convert "Visit page" button to "Link to new tab"
  • Loading branch information
tvdeyen authored Mar 30, 2021
2 parents 793d324 + 4e6ee4c commit 9ec35e5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 44 deletions.
9 changes: 0 additions & 9 deletions app/controllers/alchemy/admin/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,6 @@ def unlock
end
end

def visit
@page.unlock!
redirect_to show_page_url(
urlname: @page.urlname,
locale: prefix_locale? ? @page.language_code : nil,
host: @page.site.host == "*" ? request.host : @page.site.host,
)
end

# Sets the page public and updates the published_at attribute that is used as cache_key
#
def publish
Expand Down
29 changes: 19 additions & 10 deletions app/views/alchemy/admin/pages/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,26 @@
</div>
<% unless @page.layoutpage? %>
<div class="button_with_label">
<%= form_tag alchemy.visit_admin_page_path(@page), id: 'visit_page_form' do %>
<%= button_tag class: 'icon_button', disabled: !@page.public? do %>
<% if @page.public? %>
<%= link_to show_page_url(
urlname: @page.urlname,
locale: prefix_locale? ? @page.language_code : nil,
host: @page.site.host == "*" ? request.host : @page.site.host,
),
title: Alchemy.t("Visit page"),
data: { turbolinks: false },
target: "_blank",
class: 'icon_button' do %>
<%= render_icon('external-link-alt') %>
<% end %>
<label>
<% if @page.public? %>
<%= Alchemy.t("Visit page") %>
<% else %>
<%= Alchemy.t(:cannot_visit_unpublic_page) %>
<% end %>
</label>
<label><%= Alchemy.t("Visit page") %></label>
<% else %>
<%= content_tag "a",
title: Alchemy.t(:cannot_visit_unpublic_page),
class: 'disabled icon_button' do %>
<%= render_icon('external-link-alt') %>
<% end %>
<label><%= Alchemy.t(:cannot_visit_unpublic_page) %></label>
<% end %>
</div>
<% end %>
Expand Down Expand Up @@ -140,7 +149,7 @@
<script type="text/javascript" charset="utf-8">

$(function() {
$('#unlock_page_form, #visit_page_form, #publish_page_form').on('submit', function(event) {
$('#unlock_page_form, #publish_page_form').on('submit', function(event) {
var not_dirty = Alchemy.checkPageDirtyness(this);
if (!not_dirty) Alchemy.pleaseWaitOverlay(false);
return not_dirty;
Expand Down
1 change: 0 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
post :unlock
post :publish
post :fold
post :visit
get :configure
get :preview
get :info
Expand Down
24 changes: 0 additions & 24 deletions spec/requests/alchemy/admin/pages_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -633,30 +633,6 @@ module Alchemy
end
end

describe "#visit" do
subject do
post visit_admin_page_path(page)
end

let(:page) { create(:alchemy_page, urlname: "home", site: site) }

context "when the pages site is a catch-all" do
let(:site) { create(:alchemy_site, host: "*") }

it "should redirect to the page path" do
is_expected.to redirect_to("/home")
end
end

context "when pages site is a real host" do
let(:site) { create(:alchemy_site, host: "reallygoodsite.com") }

it "should redirect to the page path on that host" do
is_expected.to redirect_to("http://reallygoodsite.com/home")
end
end
end

describe "#fold" do
let(:page) { create(:alchemy_page) }

Expand Down

0 comments on commit 9ec35e5

Please sign in to comment.