Skip to content

Commit

Permalink
Minor submitter widget fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-hank committed Oct 1, 2021
1 parent beb7a07 commit 260cf06
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 16 deletions.
7 changes: 6 additions & 1 deletion app/assets/javascripts/widgets/submitter.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@ var LumenSubmitterWidget = (function () {
if (this.dom_element) {
this.iframe = document.createElement('iframe');
this.iframe.src = this.SERVICE_URL;
this.iframe.style.cssText = 'border: none; margin: 0; padding: 0; width:100%;';
this.dom_element.appendChild(this.iframe);

// This will max the iframe size
iFrameResize({ log: false }, this.iframe)
iFrameResize({
log: false,
warningTimeout: 0,
checkOrigin: false
}, this.iframe)
}
}
};
Expand Down
1 change: 0 additions & 1 deletion app/assets/stylesheets/application.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
@import 'layouts/application';
@import 'layouts/home';
@import 'layouts/sessions';
@import 'layouts/submitter_widget';

// Views
@import 'home/index';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.submitter_widget_notices {
/* @HACK:FIXME Firefox has problems with rendering an iframe */
width: calc(100% - 1px);
background-color: #ffffff;

section.main.app {
background-color: #ffffff;
Expand Down
16 changes: 10 additions & 6 deletions app/controllers/submitter_widget_notices_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ def create
end

@notice = NoticeBuilder.new(
get_notice_type(params), notice_params, current_user
get_notice_type(params), notice_params, submitter_widget_user
).build

@notice.review_required = true

if @notice.valid?
@notice.save
@notice.mark_for_review
flash.notice = 'Notice created! Thank you, it will be reviewed and published on the Lumen database website.'
else
Rails.logger.warn "Could not create notice with params: #{params}"
Expand All @@ -46,7 +47,7 @@ def create

def build_entity_notice_roles(model_class)
model_class::DEFAULT_ENTITY_NOTICE_ROLES.each do |role|
next if %w[sender recipient].include?(role)
next if %w[submitter recipient].include?(role)

@notice.entity_notice_roles.build(name: role).build_entity(
kind: default_kind_based_on_role(role)
Expand All @@ -55,8 +56,7 @@ def build_entity_notice_roles(model_class)
end

def allowed_to_submit?
widget_public_key &&
User.find_by_widget_public_key(widget_public_key.to_s)
widget_public_key && submitter_widget_user
end

def authorized_to_create?
Expand All @@ -70,6 +70,10 @@ def widget_public_key
end

def redirect_to_new_form
redirect_to new_submitter_widget_notice_path(type: params[:notice][:type], widget_public_key: @widget_public_key)
redirect_to new_submitter_widget_notice_path(widget_public_key: @widget_public_key)
end

def submitter_widget_user
User.find_by_widget_public_key(widget_public_key.to_s)
end
end
12 changes: 11 additions & 1 deletion app/views/layouts/submitter_widget.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@
<meta name="ROBOTS" content="NOODP" />
<title><%= yield(:title) %></title>
<%= render 'shared/head' -%>
<%= stylesheet_link_tag 'submitter_widget', :media => 'all' %>
<%= stylesheet_link_tag :submitter_widget, :media => 'all' %>
<script>
window.paceOptions = {
startOnPageLoad: false
}

window.onbeforeunload = function () {
Pace.stop()
Pace.bar.render()
}
</script>
</head>
<body class="<%= body_class %>">
<%= render 'flashes' -%>
Expand Down
4 changes: 2 additions & 2 deletions app/views/mailers/api_submitter_request_approved.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ Hi,

your submitter plugin access request has been approved.

Your plugin private key is: <%= @user.authentication_token %>
Your plugin private key is: <%= @user.widget_public_key %>

You can use it to configure the plugin. Integration documentation of the plugin is located here: <%= root_url %>/api_submitter_documentation.
You can use it to configure the plugin. Integration documentation of the plugin is located here: <%= Chill::Application.config.site_host %>/api_submitter_documentation.

Thank you,
Lumen Database team
2 changes: 0 additions & 2 deletions app/views/notices/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@
<section class="notice-new">
<%= render form_partial_for(@notice), notice: @notice %>
</section>

<%= javascript_include_tag('iframe-resizer-server.min') %>
2 changes: 0 additions & 2 deletions app/views/notices/select_type.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,3 @@
<% end %>
</section>
</div>

<%= javascript_include_tag('iframe-resizer-server.min') %>
8 changes: 8 additions & 0 deletions app/views/notices/submitter_widget/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@
</section>

<%= javascript_include_tag('iframe-resizer-server.min') %>
<%= javascript_include_tag('pace.min') %>
<%= stylesheet_link_tag('pace', :media => 'all') %>

<script>
document.querySelector('form').addEventListener('submit', function(e){
parentIFrame.scrollToOffset(0, -20);
});
</script>
2 changes: 2 additions & 0 deletions app/views/notices/submitter_widget/select_type.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@
</div>

<%= javascript_include_tag('iframe-resizer-server.min') %>
<%= javascript_include_tag('pace.min') %>
<%= stylesheet_link_tag('pace', :media => 'all') %>
9 changes: 8 additions & 1 deletion config/initializers/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,11 @@
# folder are already added.
# Rails.application.config.assets.precompile += %w( admin.js admin.css )
Rails.application.config.assets.non_digest_named_assets = ['widgets/*.js']
Rails.application.config.assets.precompile += %w[widgets/submitter.js iframe-resizer-server.min iframe-resizer-client.min]
Rails.application.config.assets.precompile += %w[
widgets/submitter.js
iframe-resizer-server.min
iframe-resizer-client.min
submitter_widget.css
pace.min.js
pace.css
]
6 changes: 6 additions & 0 deletions vendor/assets/javascripts/pace.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions vendor/assets/stylesheets/pace.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
.pace {
-webkit-pointer-events: none;
pointer-events: none;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
-webkit-transition: -webkit-opacity 0.5s;
transition: opacity 0.5s;
opacity: 0;
}

.pace .pace-activity {
display: block;
position: fixed;
z-index: 777777;
top: 0;
right: 0;
width: 100%;
height: 100%;
background: rgba(0,0,0,0.8);
-webkit-transition: -webkit-opacity 0.5s;
transition: opacity 0.5s;
pointer-events: none;
}

.pace.pace-active {
opacity: 1;
-webkit-transition: -webkit-opacity 0.5s;
transition: opacity 0.5s;
}

.pace .pace-activity::before,
.pace .pace-activity::after {
-moz-box-sizing: border-box;
box-sizing: border-box;
position: absolute;
top: 100px;
left: 50%;
display: block;
border: 5px solid #fff;
border-radius: 50%;
content: '';
}

.pace .pace-activity::before {
margin-top: -40px;
margin-left: -40px;
width: 80px;
height: 80px;
border-right-color: rgba(0, 0, 0, .2);
border-left-color: rgba(0, 0, 0, .2);
-webkit-animation: pace-theme-corner-indicator-spin 3s linear infinite;
animation: pace-theme-corner-indicator-spin 3s linear infinite;
}

.pace .pace-activity::after {
margin-top: -20px;
margin-left: -20px;
width: 40px;
height: 40px;
border-top-color: rgba(0, 0, 0, .2);
border-bottom-color: rgba(0, 0, 0, .2);
-webkit-animation: pace-theme-corner-indicator-spin 1s linear infinite;
animation: pace-theme-corner-indicator-spin 1s linear infinite;
}

@-webkit-keyframes pace-theme-corner-indicator-spin {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(359deg); }
}
@keyframes pace-theme-corner-indicator-spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(359deg); }
}

0 comments on commit 260cf06

Please sign in to comment.