From 6858348b50babe203e1d9be42e4fbe4d06feadf2 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Fri, 7 May 2021 15:27:46 +0800 Subject: [PATCH 1/2] Upgrade Bootstrap 5 --- README.md | 4 +- .../profile_card_component.html.erb | 10 +- app/controllers/replies_controller.rb | 2 +- app/helpers/application_helper.rb | 4 +- app/helpers/likes_helper.rb | 2 +- app/helpers/topics_helper.rb | 2 +- app/helpers/users_helper.rb | 4 +- app/javascript/admin/index.scss | 11 +- app/javascript/front/app.js | 3 - app/javascript/front/editor.js | 74 ++- app/javascript/front/emoji-modal.js | 79 ++- app/javascript/front/index.scss | 9 +- app/javascript/front/notifier.js | 44 +- app/javascript/front/toc.js | 4 +- app/javascript/front/users.scss | 6 +- app/javascript/homeland/_vars.scss | 21 +- app/javascript/homeland/dark-mode.scss | 16 +- app/javascript/homeland/index.js | 15 +- app/javascript/homeland/index.scss | 116 +++- app/views/admin/applications/index.html.erb | 37 +- app/views/admin/applications/show.html.erb | 4 +- app/views/admin/comments/index.html.erb | 22 +- app/views/admin/dashboards/index.html.erb | 32 +- app/views/admin/locations/index.html.erb | 17 +- app/views/admin/nodes/_form.html.erb | 6 +- app/views/admin/nodes/index.html.erb | 25 +- app/views/admin/photos/index.html.erb | 19 +- app/views/admin/plugins/index.html.erb | 6 +- app/views/admin/plugins/new.html.erb | 4 +- app/views/admin/plugins/show.html.erb | 2 +- app/views/admin/replies/edit.html.erb | 6 +- app/views/admin/replies/index.html.erb | 51 +- app/views/admin/site_configs/_form.html.erb | 6 +- app/views/admin/topics/_form.html.erb | 6 +- app/views/admin/topics/edit.html.erb | 6 +- app/views/admin/topics/index.html.erb | 68 +- app/views/admin/users/_form.html.erb | 104 ++- app/views/admin/users/_user.html.erb | 21 +- app/views/admin/users/edit.html.erb | 24 +- app/views/admin/users/index.html.erb | 20 +- app/views/devise/registrations/new.html.erb | 2 +- app/views/devise/sessions/new.html.erb | 4 +- .../doorkeeper/applications/_form.html.erb | 20 +- .../doorkeeper/applications/index.html.erb | 4 +- app/views/layouts/application.html.erb | 16 +- app/views/layouts/mailer.html.erb | 110 ++-- app/views/layouts/simple.html.erb | 6 +- app/views/notifications/_team_invite.html.erb | 2 +- .../notifications/index.html.erb | 2 +- app/views/replies/edit.html.erb | 9 +- app/views/settings/account.html.erb | 24 +- app/views/settings/password.html.erb | 6 +- app/views/settings/profile.html.erb | 10 +- app/views/settings/reward.html.erb | 22 +- app/views/settings/show.html.erb | 53 +- app/views/shared/_captcha_input.html.erb | 4 +- app/views/shared/_editor_help_block.html.erb | 44 +- app/views/shared/_editor_toolbar.html.erb | 12 +- app/views/shared/_error_messages.html.erb | 8 +- app/views/shared/_usernav.html.erb | 8 +- app/views/team_users/_form.html.erb | 22 +- app/views/team_users/edit.html.erb | 10 +- app/views/team_users/index.html.erb | 4 +- app/views/team_users/new.html.erb | 12 +- app/views/team_users/show.html.erb | 3 +- app/views/teams/edit.html.erb | 8 +- app/views/topics/_ban.html.erb | 40 +- app/views/topics/_buttons.html.erb | 3 +- app/views/topics/_form.html.erb | 18 +- app/views/topics/_menu.html.erb | 8 +- app/views/topics/_node_info.html.erb | 2 +- app/views/topics/_topic_sidebar.html.erb | 6 +- app/views/users/_menu.html.erb | 2 +- app/views/users/_reward.html.erb | 2 +- app/views/users/_sidebar.html.erb | 10 +- config/initializers/bootstrap_form.rb | 37 ++ config/locales/views.en.yml | 2 +- config/locales/views.zh-CN.yml | 2 +- lib/assets/javascripts/jquery.fluidbox.min.js | 219 ++++++- .../javascripts/jquery.infinitescroll.min.js | 604 +++++++++++++++++- lib/templates/erb/scaffold/show.html.erb | 14 +- package.json | 9 +- test/helpers/application_helper_test.rb | 2 +- test/helpers/likes_helper_test.rb | 2 +- test/helpers/users_helper_test.rb | 4 +- test/lib/markdown_test.rb | 2 +- yarn.lock | 50 +- 87 files changed, 1613 insertions(+), 762 deletions(-) create mode 100644 config/initializers/bootstrap_form.rb diff --git a/README.md b/README.md index a3fcf4a8ef..9c334c1ffd 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@

- +

Open source discussion website.

开源的论坛/社区网站系统,基于 Ruby China 发展而来。

- +

diff --git a/app/components/profile_card_component.html.erb b/app/components/profile_card_component.html.erb index e06779c23a..3b0eb57d44 100644 --- a/app/components/profile_card_component.html.erb +++ b/app/components/profile_card_component.html.erb @@ -1,9 +1,9 @@
-
+
<%= user_avatar_tag(user, :md) %>
-
+
<%= link_to user, class: "name-box" do %>
<%= user.name %> @@ -17,7 +17,7 @@ <% if user.tagline.present? %>
<%= user.tagline %>
<% end %> -
+
<% end %> <% if !owner? user %> -
+
<%= follow_user_tag(user) %>
<% end %> -
\ No newline at end of file +
diff --git a/app/controllers/replies_controller.rb b/app/controllers/replies_controller.rb index 8d2c8da872..248dba2f21 100644 --- a/app/controllers/replies_controller.rb +++ b/app/controllers/replies_controller.rb @@ -15,7 +15,7 @@ def create current_user.read_topic(@topic) @msg = t("replies.created_successfully") else - @msg = @reply.errors.full_messages.join("
") + @msg = @reply.errors.full_messages.join("
") end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index ce62cc54fe..5a1fc6e681 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -16,7 +16,7 @@ def sanitize_markdown(html) def notice_message flash_messages = [] - close_html = %() + close_html = %() flash.each do |type, message| type = :success if type.to_sym == :notice @@ -154,7 +154,7 @@ def form_group(form, field, opts = {}, &block) opts[:class] += " has-error" if has_errors content_tag :div, class: opts[:class] do - concat form.label field, class: "control-label" if opts[:label] != false + concat form.label field, class: "form-label" if opts[:label] != false concat capture(&block) concat errors_for(form, field) end diff --git a/app/helpers/likes_helper.rb b/app/helpers/likes_helper.rb index 57e2d5283d..7fabcb2e7c 100644 --- a/app/helpers/likes_helper.rb +++ b/app/helpers/likes_helper.rb @@ -6,7 +6,7 @@ module LikesHelper # params # - likeable - Like target # - :cache - when true, will not check current user is liked, directly return no like status for cache. - # - :class - Add class for link, for example: "btn btn-default" + # - :class - Add class for link, for example: "btn btn-secondary" def likeable_tag(likeable, opts = {}) return "" if likeable.blank? diff --git a/app/helpers/topics_helper.rb b/app/helpers/topics_helper.rb index 843fde9a99..82da137cb0 100644 --- a/app/helpers/topics_helper.rb +++ b/app/helpers/topics_helper.rb @@ -50,7 +50,7 @@ def topic_excellent_tag(topic) def topic_close_tag(topic) return "" unless topic.closed? - content_tag(:i, "", title: t("topics.closed_tooltip"), class: "fa fa-check-circle", data: {toggle: "tooltip"}) + content_tag(:i, "", title: t("topics.closed_tooltip"), class: "fa fa-check-circle", "data-bs-toggle": "tooltip") end def render_node_name(node) diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 2f656a95d8..0ceb755ae7 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -72,7 +72,7 @@ def block_node_tag(node) return "" if node.blank? blocked = current_user.block_node?(node) - class_names = "btn btn-default button-block-node" + class_names = "btn btn-secondary button-block-node" if blocked link_to icon_tag("eye-slash", label: t("common.unblock_node")), "#", "data-id" => node.id, :class => "#{class_names} active" @@ -87,7 +87,7 @@ def block_user_tag(user) return "" if current_user.id == user.id blocked = current_user.block_user?(user) - class_names = "button-block-user btn btn-default btn-block" + class_names = "button-block-user btn btn-secondary btn-block" if blocked link_to icon_tag("eye-slash", label: t("common.unblock_user")), "#", "data-id" => user.login, :class => "#{class_names} active" diff --git a/app/javascript/admin/index.scss b/app/javascript/admin/index.scss index b618cd76b6..d4011b6d86 100644 --- a/app/javascript/admin/index.scss +++ b/app/javascript/admin/index.scss @@ -88,8 +88,13 @@ pre { margin-bottom: 15px; .form-inline { - .form-group { - margin-right: 10px; + @extend .d-grid; + @extend .gap-2; + @extend .d-sm-block; + @extend .d-md-flex; + + .form-control { + width: auto; } } } @@ -115,7 +120,7 @@ table { .badge { color: var(--gray); border-radius: 12px; - border: 1px solid var(--btn-default-border-color); + border: 1px solid var(--btn-secondary-border-color); font-size: 12px; font-weight: normal; } diff --git a/app/javascript/front/app.js b/app/javascript/front/app.js index b302cc4f74..336f44b5de 100644 --- a/app/javascript/front/app.js +++ b/app/javascript/front/app.js @@ -40,9 +40,6 @@ const AppView = Backbone.View.extend({ initComponents() { $("abbr.timeago").timeago(); - $(".alert").alert(); - $(".dropdown-toggle").dropdown(); - $('[data-toggle="tooltip"]').tooltip(); // Bind Ctrl+Enter for submit $(".cell_comments_new textarea").unbind("keydown"); diff --git a/app/javascript/front/editor.js b/app/javascript/front/editor.js index cede9037f7..63cf095937 100644 --- a/app/javascript/front/editor.js +++ b/app/javascript/front/editor.js @@ -1,10 +1,10 @@ window.Editor = Backbone.View.extend({ - el: '.editor-toolbar', + el: ".editor-toolbar", events: { "click #editor-upload-image": "browseUpload", "click .insert-codes a": "appendCodesFromHint", - "click .pickup-emoji": "pickupEmoji" + "click .pickup-emoji": "pickupEmoji", }, initialize(opts) { @@ -16,23 +16,23 @@ window.Editor = Backbone.View.extend({ let dropzone; const self = this; const editor = $("textarea.topic-editor"); - editor.wrap("
"); + editor.wrap('
'); - const editor_dropzone = $('.topic-editor-dropzone'); - editor_dropzone.on('paste', event => { + const editor_dropzone = $(".topic-editor-dropzone"); + editor_dropzone.on("paste", (event) => { return self.handlePaste(event); }); - return dropzone = editor_dropzone.dropzone({ + return (dropzone = editor_dropzone.dropzone({ url: "/photos", dictDefaultMessage: "", clickable: true, paramName: "file", maxFilesize: 20, uploadMultiple: false, - acceptedFiles: 'image/*', + acceptedFiles: "image/*", headers: { - "X-CSRF-Token": $("meta[name=\"csrf-token\"]").attr("content") + "X-CSRF-Token": $('meta[name="csrf-token"]').attr("content"), }, previewContainer: false, processing() { @@ -53,20 +53,20 @@ window.Editor = Backbone.View.extend({ self.appendImageFromUpload(res.url); }, error(temp, msg) { - if (typeof msg === "string") { // from client side + if (typeof msg === "string") { + // from client side App.alert(msg); - } else { // from server side - App.alert(msg.message) + } else { + // from server side + App.alert(msg.message); } }, - totaluploadprogress(num) { - }, - sending() { - }, + totaluploadprogress(num) {}, + sending() {}, queuecomplete() { self.restoreUploaderStatus(); - } - }); + }, + })); }, uploadFile(item, filename) { @@ -74,7 +74,7 @@ window.Editor = Backbone.View.extend({ const formData = new FormData(); formData.append("file", item, filename); return $.ajax({ - url: '/photos', + url: "/photos", type: "POST", data: formData, dataType: "JSON", @@ -93,7 +93,7 @@ window.Editor = Backbone.View.extend({ }, complete() { return self.restoreUploaderStatus(); - } + }, }); }, @@ -123,12 +123,12 @@ window.Editor = Backbone.View.extend({ browseUpload(e) { $(".topic-editor").focus(); - $('.topic-editor-dropzone').click(); + $(".topic-editor-dropzone").click(); return false; }, showUploading() { - const btn = $("#editor-upload-image") + const btn = $("#editor-upload-image"); btn.addClass("active"); }, @@ -144,16 +144,17 @@ window.Editor = Backbone.View.extend({ // 往编辑器里面的光标前插入两个空白字符 insertSpaces(e) { - this.insertString(' '); + this.insertString(" "); return false; }, // 往编辑器里面插入代码模版 appendCodesFromHint(e) { - const link = $(e.currentTarget); - const language = link.data("lang"); + const link = e.currentTarget; + const language = link.getAttribute("data-lang"); + const txtBox = $(".topic-editor"); - const caret_pos = txtBox.caret('pos'); + const caret_pos = txtBox.caret("pos"); let prefix_break = ""; if (txtBox.val().length > 0) { prefix_break = "\n"; @@ -161,10 +162,15 @@ window.Editor = Backbone.View.extend({ const src_merged = `${prefix_break}\`\`\`${language}\n\n\`\`\`\n`; const source = txtBox.val(); const before_text = source.slice(0, caret_pos); - txtBox.val(before_text + src_merged + source.slice(caret_pos + 1, source.count)); - txtBox.caret('pos', (caret_pos + src_merged.length) - 5); + txtBox.val( + before_text + src_merged + source.slice(caret_pos + 1, source.count) + ); + txtBox.caret("pos", caret_pos + src_merged.length - 5); txtBox.focus(); - txtBox.trigger('click'); + txtBox.trigger("click"); + + // click body to dismiss dropdown + document.querySelector("body").click(); return false; }, @@ -172,28 +178,28 @@ window.Editor = Backbone.View.extend({ const $target = $(".topic-editor"); const start = $target[0].selectionStart; const end = $target[0].selectionEnd; - $target.val($target.val().substring(0, start) + str + $target.val().substring(end)); - $target[0].selectionStart = ($target[0].selectionEnd = start + str.length); + $target.val( + $target.val().substring(0, start) + str + $target.val().substring(end) + ); + $target[0].selectionStart = $target[0].selectionEnd = start + str.length; return $target.focus(); }, initComponents() { // 绑定文本框 tab 按键事件 $("textarea.topic-editor").unbind("keydown.tab"); - $("textarea.topic-editor").bind("keydown.tab", "tab", el => { + $("textarea.topic-editor").bind("keydown.tab", "tab", (el) => { return this.insertSpaces(el); }); return $("textarea.topic-editor").autogrow(); }, - pickupEmoji() { if (!window._emojiModal) { window._emojiModal = new EmojiModalView(); } window._emojiModal.show(); return false; - } + }, }); - diff --git a/app/javascript/front/emoji-modal.js b/app/javascript/front/emoji-modal.js index 7fb3975ae4..dcffa7ad70 100644 --- a/app/javascript/front/emoji-modal.js +++ b/app/javascript/front/emoji-modal.js @@ -1,14 +1,14 @@ -import { EMOJI_LIST, EMOJI_GROUPS } from './emoji-data'; +import { EMOJI_LIST, EMOJI_GROUPS } from "./emoji-data"; window.EmojiModalView = Backbone.View.extend({ - className: 'emoji-modal modal', + className: "emoji-modal modal", panels: {}, events: { "click .tab-pane a.emoji": "insertCode", "mouseover .tab-pane a.emoji": "preview", - "click .nav-tabs li a": "changePanel" + "click .nav-tabs li a": "changePanel", }, initialize() { @@ -18,7 +18,7 @@ window.EmojiModalView = Backbone.View.extend({ diff --git a/app/views/settings/account.html.erb b/app/views/settings/account.html.erb index e772a9a350..024e22562b 100644 --- a/app/views/settings/account.html.erb +++ b/app/views/settings/account.html.erb @@ -1,15 +1,13 @@
<%= render 'menu' %> -
- <% if !Setting.sso_enabled? && @user.authorizations.any? %>
<%= t("users.bind_another_account") %>
- -
    - <% @user.authorizations.each do |authorizaion| %> -
  • - <%= Homeland::Utils.omniauth_name(authorizaion.provider) %> - <%= link_to(raw(''), auth_unbind_setting_path(authorizaion.provider), rel: "twitsy", title: ("users.click_to_unbind"), method: 'delete' )%> -
  • - <% end %> -
+
+
+ <% @user.authorizations.each do |authorizaion| %> + <%= link_to auth_unbind_setting_path(authorizaion.provider), class: "btn btn-outline-warning", title: ("users.click_to_unbind"), method: 'delete' do %> + + <%= Homeland::Utils.omniauth_name(authorizaion.provider) %> + <% end %> + <% end %> +
+
<% end %>
diff --git a/app/views/settings/password.html.erb b/app/views/settings/password.html.erb index 41ef072a55..c60907e419 100644 --- a/app/views/settings/password.html.erb +++ b/app/views/settings/password.html.erb @@ -1,15 +1,13 @@
<%= render 'menu' %> -
<%= t("users.need_login_again_after_password_updated_html") %>
-
<%= form_for @user, url: setting_path, method: :put do |f| %> <%= render "shared/error_messages", target: @user %> - +
<%= f.label :current_password %> <%= f.password_field :current_password, class: "form-control" %> @@ -18,12 +16,10 @@ <%= f.label :password %> <%= f.password_field :password, class: "form-control" %>
-
<%= f.label :password_confirmation %> <%= f.password_field :password_confirmation, class: "form-control" %>
-
<%= f.submit t("users.update_password"), class: "btn btn-primary", 'data-disable-with' => t("common.saving") %>
diff --git a/app/views/settings/profile.html.erb b/app/views/settings/profile.html.erb index e73976b0d0..615702b775 100644 --- a/app/views/settings/profile.html.erb +++ b/app/views/settings/profile.html.erb @@ -5,7 +5,7 @@
<%= form_for @user, url: setting_path, method: :put, html: { enctype: "multipart/form-data" } do |f| %> <%= render "shared/error_messages", target: @user %> - + <% if Setting.has_profile_field? :location %>
<%= f.label :location %> @@ -22,7 +22,7 @@
<%= f.label :github %>
- https://github.com/ + https://github.com/ <%= f.text_field :github, class: "form-control" %>
@@ -31,7 +31,7 @@
<%= f.label :twitter %>
- https://twitter.com/ + https://twitter.com/ <%= f.text_field :twitter, class: "form-control" %>
@@ -48,10 +48,10 @@ field_prefix = Profile.contact_field_prefix(field) %>
- + <% if field_prefix %>
- <%= field_prefix %> + <%= field_prefix %> <% end %> <% if field_prefix %>
diff --git a/app/views/settings/reward.html.erb b/app/views/settings/reward.html.erb index 7223ed6e0e..77fdf77374 100644 --- a/app/views/settings/reward.html.erb +++ b/app/views/settings/reward.html.erb @@ -1,6 +1,5 @@
<%= render 'menu' %> -
@@ -8,30 +7,27 @@
<%= form_for @user, url: setting_path, method: :put, html: { enctype: "multipart/form-data" } do |f| %> <%= render "shared/error_messages", target: @user %> - - + <% User::REWARD_FIELDS.each do |field| %>
- +
<% if field == :alipay %> - 打开支付宝客户端:右上角 “+” -> 我要收款 -> 设定金额 -> 保存二维码图片 + 打开支付宝客户端:右上角 “+” -> 我要收款 -> 设定金额 -> 保存二维码图片 <% elsif field == :wechat %> - 打开微信手机客户端:右上角 “+” -> 收付款 -> 我要收款 -> 保存二维码图片 + 打开微信手机客户端:右上角 “+” -> 收付款 -> 我要收款 -> 保存二维码图片 <% end %>
- <% if @user.reward_field(field) %> -
-
- +
+
+ +
-
<% end %> <% end %> -
@@ -50,6 +46,6 @@
-
+
diff --git a/app/views/settings/show.html.erb b/app/views/settings/show.html.erb index 5a9144769c..ac60cb7399 100644 --- a/app/views/settings/show.html.erb +++ b/app/views/settings/show.html.erb @@ -1,6 +1,5 @@
<%= render 'menu' %> -
@@ -11,40 +10,34 @@
<% if Setting.allow_change_login? %>
- + <%= f.text_field :login, style: "width: 200px", class: "form-control", placeholder: t("activerecord.attributes.user.login") %>
- <% end %> - -
- - <%= f.text_field :name, style: "width: 200px", class: "form-control", placeholder: t("activerecord.attributes.user.name") %> -
- -
- - <%= f.file_field :avatar, class: "form-control" %> -
- + <% end %> +
+ + <%= f.text_field :name, style: "width: 200px", class: "form-control", placeholder: t("activerecord.attributes.user.name") %> +
+
+ + <%= f.file_field :avatar, class: "form-control" %> +
+
+ + <%= f.text_field :email, disabled: @user.email_locked?, class: "form-control", placeholder: "Email" %> +
+
+ +
+ <% if Setting.has_profile_field? :tagline %>
- - <%= f.text_field :email, disabled: @user.email_locked?, class: "form-control", placeholder: "Email" %> -
- -
- + <%= f.label :tagline %> + <%= f.text_field :tagline, class: "form-control" %>
- - <% if Setting.has_profile_field? :tagline %> -
- <%= f.label :tagline %> - <%= f.text_field :tagline, class: "form-control" %> -
- <% end %> + <% end %>
-
<%= t("activerecord.attributes.user.theme") %>
diff --git a/app/views/shared/_captcha_input.html.erb b/app/views/shared/_captcha_input.html.erb index 5036c2bad2..3c263b7ce3 100644 --- a/app/views/shared/_captcha_input.html.erb +++ b/app/views/shared/_captcha_input.html.erb @@ -3,10 +3,10 @@ <%= recaptcha_tags site_key: Setting.recaptcha_key %> <% else %> <%= rucaptcha_input_tag(class: 'form-control', placeholder: t('common.captcha')) %> -
+ <% end %> -<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/shared/_editor_help_block.html.erb b/app/views/shared/_editor_help_block.html.erb index 849e303ab4..e48e02a1ae 100644 --- a/app/views/shared/_editor_help_block.html.erb +++ b/app/views/shared/_editor_help_block.html.erb @@ -1,34 +1,32 @@
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持表情,见 Emoji cheat sheet
  • -
  • 按 “M” 键查看更多 帮助
  • +
  • 按 “M” 键查看更多 帮助
  • 注意单词拼写,以及中英文排版,参考此页 -
- -