mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-08 06:04:35 +08:00
Move frontend global constats javascript out of asset pipeline, to enable properly accessing ENV [SCI-11495]
This commit is contained in:
parent
7306f6652c
commit
bff5a6586a
7 changed files with 47 additions and 27 deletions
|
@ -1,24 +0,0 @@
|
|||
const GLOBAL_CONSTANTS = {
|
||||
NAME_TRUNCATION_LENGTH: <%= Constants::NAME_TRUNCATION_LENGTH %>,
|
||||
NAME_MAX_LENGTH: <%= Constants::NAME_MAX_LENGTH %>,
|
||||
NAME_MIN_LENGTH: <%= Constants::NAME_MIN_LENGTH %>,
|
||||
TEXT_MAX_LENGTH: <%= Constants::TEXT_MAX_LENGTH %>,
|
||||
TABLE_CARD_MIN_WIDTH: 340, <%# pixels %>
|
||||
TABLE_CARD_GAP: 16, <%# pixels %>
|
||||
FILENAME_TRUNCATION_LENGTH: <%= Constants::FILENAME_TRUNCATION_LENGTH %>,
|
||||
FILE_MAX_SIZE_MB: parseInt($('meta[name="max-file-size"]').attr('content'), 10),
|
||||
IS_SAFARI: /^((?!chrome|android).)*safari/i.test(navigator.userAgent),
|
||||
REPOSITORY_LIST_ITEMS_PER_COLUMN: <%= Constants::REPOSITORY_LIST_ITEMS_PER_COLUMN %>,
|
||||
REPOSITORY_CHECKLIST_ITEMS_PER_COLUMN: <%= Constants::REPOSITORY_CHECKLIST_ITEMS_PER_COLUMN %>,
|
||||
REPOSITORY_STOCK_UNIT_ITEMS_PER_COLUMN: <%= Constants::REPOSITORY_STOCK_UNIT_ITEMS_PER_COLUMN %>,
|
||||
HAS_UNSAVED_DATA_CLASS_NAME: 'has-unsaved-data',
|
||||
DEFAULT_ELEMENTS_PER_PAGE: <%= Constants::DEFAULT_ELEMENTS_PER_PAGE %>,
|
||||
FILENAME_MAX_LENGTH: <%= Constants::FILENAME_MAX_LENGTH %>,
|
||||
FAST_STATUS_POLLING_INTERVAL: <%= Constants::FAST_STATUS_POLLING_INTERVAL %>,
|
||||
SLOW_STATUS_POLLING_INTERVAL: <%= Constants::SLOW_STATUS_POLLING_INTERVAL %>,
|
||||
ASSET_POLLING_INTERVAL: <%= Constants::ASSET_POLLING_INTERVAL %>,
|
||||
ASSET_SYNC_URL: '<%= Constants::ASSET_SYNC_URL %>',
|
||||
GLOBAL_SEARCH_PREVIEW_LIMIT: <%= Constants::GLOBAL_SEARCH_PREVIEW_LIMIT %>,
|
||||
SEARCH_LIMIT: <%= Constants::SEARCH_LIMIT %>,
|
||||
SCINOTE_EDIT_RESTRICTED_EXTENSIONS: <%= Constants::SCINOTE_EDIT_RESTRICTED_EXTENSIONS %>
|
||||
};
|
38
app/controllers/global_constants_controller.rb
Normal file
38
app/controllers/global_constants_controller.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class GlobalConstantsController < ApplicationController
|
||||
before_action :load_global_constants
|
||||
skip_before_action :authenticate_user!, only: :index
|
||||
skip_before_action :verify_authenticity_token, only: :index
|
||||
|
||||
def index; end
|
||||
|
||||
private
|
||||
|
||||
def load_global_constants
|
||||
@global_constants = {
|
||||
NAME_TRUNCATION_LENGTH: Constants::NAME_TRUNCATION_LENGTH,
|
||||
NAME_MAX_LENGTH: Constants::NAME_MAX_LENGTH,
|
||||
NAME_MIN_LENGTH: Constants::NAME_MIN_LENGTH,
|
||||
TEXT_MAX_LENGTH: Constants::TEXT_MAX_LENGTH,
|
||||
TABLE_CARD_MIN_WIDTH: 340,
|
||||
TABLE_CARD_GAP: 16,
|
||||
FILENAME_TRUNCATION_LENGTH: Constants::FILENAME_TRUNCATION_LENGTH,
|
||||
FILE_MAX_SIZE_MB: Rails.configuration.x.file_max_size_mb,
|
||||
REPOSITORY_LIST_ITEMS_PER_COLUMN: Constants::REPOSITORY_LIST_ITEMS_PER_COLUMN,
|
||||
REPOSITORY_CHECKLIST_ITEMS_PER_COLUMN: Constants::REPOSITORY_CHECKLIST_ITEMS_PER_COLUMN,
|
||||
REPOSITORY_STOCK_UNIT_ITEMS_PER_COLUMN: Constants::REPOSITORY_STOCK_UNIT_ITEMS_PER_COLUMN,
|
||||
HAS_UNSAVED_DATA_CLASS_NAME: 'has-unsaved-data',
|
||||
DEFAULT_ELEMENTS_PER_PAGE: Constants::DEFAULT_ELEMENTS_PER_PAGE,
|
||||
FILENAME_MAX_LENGTH: Constants::FILENAME_MAX_LENGTH,
|
||||
FAST_STATUS_POLLING_INTERVAL: Constants::FAST_STATUS_POLLING_INTERVAL,
|
||||
SLOW_STATUS_POLLING_INTERVAL: Constants::SLOW_STATUS_POLLING_INTERVAL,
|
||||
ASSET_POLLING_INTERVAL: Constants::ASSET_POLLING_INTERVAL,
|
||||
ASSET_SYNC_URL: Constants::ASSET_SYNC_URL,
|
||||
GLOBAL_SEARCH_PREVIEW_LIMIT: Constants::GLOBAL_SEARCH_PREVIEW_LIMIT,
|
||||
SEARCH_LIMIT: Constants::SEARCH_LIMIT,
|
||||
SCINOTE_EDIT_RESTRICTED_EXTENSIONS: Constants::SCINOTE_EDIT_RESTRICTED_EXTENSIONS,
|
||||
SCINOTE_EDIT_LATEST_JSON_URL: Constants::SCINOTE_EDIT_LATEST_JSON_URL
|
||||
}
|
||||
end
|
||||
end
|
1
app/views/global_constants/index.js.erb
Normal file
1
app/views/global_constants/index.js.erb
Normal file
|
@ -0,0 +1 @@
|
|||
const GLOBAL_CONSTANTS = <%= @global_constants.to_json.html_safe %>;
|
|
@ -5,7 +5,6 @@
|
|||
<meta data-hook="head-js">
|
||||
<title><%=t "head.title", title: (yield :head_title) %></title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
|
||||
<meta name="max-file-size" content="<%= Rails.configuration.x.file_max_size_mb %>">
|
||||
<meta name="tiny-mce-assets-url" content="<%= tiny_mce_assets_path %>">
|
||||
<% if user_signed_in? %>
|
||||
<meta name="expiration-url" content="<%= users_expire_in_path %>">
|
||||
|
@ -18,6 +17,8 @@
|
|||
<% if ::NewRelic::Agent.instance.started? %>
|
||||
<%= ::NewRelic::Agent.browser_timing_header(controller.request.content_security_policy_nonce) %>
|
||||
<% end %>
|
||||
<script src="<%= global_constants_path %>"></script>
|
||||
|
||||
<%= javascript_include_tag 'jquery_bundle' %>
|
||||
<%= javascript_include_tag 'application_pack' %>
|
||||
|
||||
|
@ -79,7 +80,6 @@
|
|||
data-datetime-picker-format-vue="<%= datetime_picker_format_date_only_vue %>"
|
||||
<% end %>
|
||||
>
|
||||
|
||||
<span style="display: none;" data-hook="body-js"></span>
|
||||
<span style="display: none;" data-hook="application-body-html"></span>
|
||||
|
||||
|
@ -140,6 +140,5 @@
|
|||
|
||||
<%= javascript_include_tag 'prism' %>
|
||||
<%= javascript_include_tag "vue_components_repository_item_sidebar" %>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
<meta data-hook="head-js">
|
||||
<title><%=t "head.title", title: (yield :head_title) %></title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
|
||||
<script src="<%= global_constants_path %>"></script>
|
||||
|
||||
<%= stylesheet_link_tag "tailwind", "data-turbo-track": "reload" %>
|
||||
<%= stylesheet_link_tag 'bootstrap_pack', media: 'all' %>
|
||||
<%= stylesheet_link_tag 'application', media: 'all' %>
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
<style media="all">
|
||||
html, body { height: 100%; min-height: 100%; }
|
||||
</style>
|
||||
<script src="<%= global_constants_path %>"></script>
|
||||
|
||||
<%= stylesheet_link_tag "tailwind", "data-turbo-track": "reload" %>
|
||||
<%= stylesheet_link_tag 'bootstrap_pack', media: 'all' %>
|
||||
<%= stylesheet_link_tag 'application_pack_styles', media: 'all' %>
|
||||
|
|
|
@ -7,6 +7,8 @@ Rails.application.routes.draw do
|
|||
get 'api/health', to: 'api/api#health', as: 'api_health'
|
||||
get 'api/status', to: 'api/api#status', as: 'api_status'
|
||||
|
||||
get '/global_constants', to: 'global_constants#index', as: 'global_constants'
|
||||
|
||||
post 'access_tokens/revoke', to: 'doorkeeper/access_tokens#revoke'
|
||||
|
||||
# Addons
|
||||
|
|
Loading…
Add table
Reference in a new issue