Skip to content

Commit

Permalink
Replace text-angular editor with trix editor in fields for shop messa…
Browse files Browse the repository at this point in the history
…ges and about fields for enterprises and enterprise groups
  • Loading branch information
cillian committed Aug 9, 2024
1 parent 8ab1cbe commit b0567f7
Show file tree
Hide file tree
Showing 73 changed files with 123 additions and 2,739 deletions.
6 changes: 1 addition & 5 deletions app/assets/javascripts/admin/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
//= require angular
//= require angular-resource
//= require angular-animate
//= require angular-sanitize
//= require angularjs-file-upload
//= require ../shared/ng-infinite-scroll.min.js
//= require ../shared/ng-tags-input.min.js
Expand Down Expand Up @@ -61,11 +62,6 @@
//= require ./variant_overrides/variant_overrides

// text, dates and translations
//= require textAngular-rangy.min.js
// This replaces angular-sanitize. We should include only one.
// https://github.com/textAngular/textAngular#where-to-get-it
//= require textAngular-sanitize.min.js
//= require textAngular.min.js
//= require i18n/translations
//= require darkswarm/i18n.translate.js

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
angular.module("admin.enterprise_groups", ["admin.side_menu", "admin.users", "textAngular"])
angular.module("admin.enterprise_groups", ["admin.side_menu", "admin.users", "ngSanitize"])
14 changes: 0 additions & 14 deletions app/assets/javascripts/admin/enterprises/enterprises.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,10 @@ angular.module("admin.enterprises", [
"admin.utils",
"admin.shippingMethods",
"admin.users",
"textAngular",
"admin.side_menu",
"admin.taxons",
'admin.indexUtils',
'admin.tagRules',
'admin.dropdown',
'ngSanitize']
)
# For more options: https://github.com/textAngular/textAngular/blob/master/src/textAngularSetup.js
.config [
'$provide', ($provide) ->
$provide.decorator 'taTranslations', [
'$delegate'
(taTranslations) ->
taTranslations.insertLink = {
tooltip: t('admin.enterprises.form.shop_preferences.shopfront_message_link_tooltip'),
dialogPrompt: t('admin.enterprises.form.shop_preferences.shopfront_message_link_prompt')
}
taTranslations
]
]
2 changes: 1 addition & 1 deletion app/assets/javascripts/admin/products/products.js.coffee
Original file line number Diff line number Diff line change
@@ -1 +1 @@
angular.module("admin.products", ["textAngular", "admin.utils", "OFNShared"])
angular.module("admin.products", ["ngSanitize", "admin.utils", "OFNShared"])

This file was deleted.

This file was deleted.

12 changes: 10 additions & 2 deletions app/models/enterprise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,20 @@ def self.distinct_count

# Remove any unsupported HTML.
def long_description
HtmlSanitizer.sanitize(super)
HtmlSanitizer.sanitize_and_enforce_link_target_blank(super)
end

# Remove any unsupported HTML.
def long_description=(html)
super(HtmlSanitizer.sanitize(html))
super(HtmlSanitizer.sanitize_and_enforce_link_target_blank(html))
end

def preferred_shopfront_message=(html)
self.prefers_shopfront_message = HtmlSanitizer.sanitize_and_enforce_link_target_blank(html)
end

def preferred_shopfront_closed_message=(html)
self.prefers_shopfront_closed_message = HtmlSanitizer.sanitize_and_enforce_link_target_blank(html)

Check warning on line 267 in app/models/enterprise.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Line is too long. [102/100] Raw Output: app/models/enterprise.rb:267:101: C: Layout/LineLength: Line is too long. [102/100]
end

def contact
Expand Down
4 changes: 2 additions & 2 deletions app/models/enterprise_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ def to_param

# Remove any unsupported HTML.
def long_description
HtmlSanitizer.sanitize(super)
HtmlSanitizer.sanitize_and_enforce_link_target_blank(super)
end

# Remove any unsupported HTML.
def long_description=(html)
super(HtmlSanitizer.sanitize(html))
super(HtmlSanitizer.sanitize_and_enforce_link_target_blank(html))
end

private
Expand Down
12 changes: 12 additions & 0 deletions app/services/html_sanitizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,16 @@ def self.sanitize(html)
html, tags: ALLOWED_TAGS, attributes: (ALLOWED_ATTRIBUTES + ALLOWED_TRIX_DATA_ATTRIBUTES)
)
end

def self.sanitize_and_enforce_link_target_blank(html)
sanitize(enforce_link_target_blank(html))
end

def self.enforce_link_target_blank(html)
return if html.nil?

Nokogiri::HTML::DocumentFragment.parse(html).tap do |document|
document.css("a").each { |link| link["target"] = "_blank" }
end.to_s
end
end
5 changes: 2 additions & 3 deletions app/views/admin/enterprise_groups/_form_about.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
%fieldset.alpha.no-border-bottom#about_panel{ data: { "tabs-and-panels-target": "panel" } }
%legend= t('.about')
= f.field_container :long_description do
%text-angular{'id' => 'enterprise_group_long_description', 'name' => 'enterprise_group[long_description]', 'class' => 'text-angular', "textangular-links-target-blank" => true,
'ta-toolbar' => "[['h1','h2','h3','h4','p'],['bold','italics','underline','clear'],['insertLink']]"}
!= @enterprise_group[:long_description]
= f.hidden_field :long_description, id: "enterprise_group_long_description", value: @enterprise_group.long_description
%trix-editor{ input: "enterprise_group_long_description", "data-controller": "trixeditor" }
13 changes: 3 additions & 10 deletions app/views/admin/enterprises/form/_about_us.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@
.omega.eight.columns
= f.text_field :description, maxlength: 255, placeholder: t('.desc_short_placeholder')
.row
.alpha.three.columns
.alpha.eleven.columns
= f.label :long_description, t('.desc_long')
.omega.eight.columns
-# textAngular toolbar options, add to the ta-toolbar array below and separate into groups with extra ],[ if needed:
-# ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'pre', 'quote'],
-# ['bold', 'italics', 'underline', 'strikeThrough', 'ul', 'ol', 'redo', 'undo', 'clear'],
-# ['justifyLeft','justifyCenter','justifyRight','indent','outdent'],
-# ['html', 'insertImage', 'insertLink', 'insertVideo']
%text-angular{'ng-model' => 'Enterprise.long_description', 'id' => 'enterprise_long_description', 'name' => 'enterprise[long_description]', 'class' => 'text-angular', "textangular-links-target-blank" => true,
'ta-toolbar' => "[['h1','h2','h3','h4','p'],['bold','italics','underline','clear'],['insertLink']]",
'placeholder' => t('.desc_long_placeholder')}
= f.hidden_field :long_description, id: "enterprise_long_description", value: @enterprise.long_description
%trix-editor{ input: "enterprise_long_description", "data-controller": "trixeditor" }
16 changes: 6 additions & 10 deletions app/views/admin/enterprises/form/_shop_preferences.html.haml
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
.row
.three.columns.alpha
.eleven.columns.alpha
= f.label "enterprise_preferred_shopfront_message", t('.shopfront_message')
.eight.columns.omega
%text-angular{'ng-model' => 'Enterprise.preferred_shopfront_message', 'id' => 'enterprise_preferred_shopfront_message', 'name' => 'enterprise[preferred_shopfront_message]', 'class' => 'text-angular textangular-strip', 'ta-paste' => "stripFormatting($html)", "textangular-links-target-blank" => true,
'ta-toolbar' => "[['h1','h2','h3','h4','p'],['bold','italics','underline','clear'],['insertLink']]",
'placeholder' => t('.shopfront_message_placeholder')}
= f.hidden_field :preferred_shopfront_message, id: "enterprise_preferred_shopfront_message", value: @enterprise.preferred_shopfront_message
%trix-editor{ input: "enterprise_preferred_shopfront_message", "data-controller": "trixeditor", placeholder: t('.shopfront_message_placeholder') }
.row
.three.columns.alpha
.eleven.columns.alpha
= f.label "enterprise_preferred_shopfront_closed_message", t('.shopfront_closed_message')
.eight.columns.omega
%text-angular{'ng-model' => 'Enterprise.preferred_shopfront_closed_message', 'id' => 'enterprise_preferred_shopfront_closed_message', 'name' => 'enterprise[preferred_shopfront_closed_message]', 'class' => 'text-angular textangular-strip', 'ta-paste' => "stripFormatting($html)", "textangular-links-target-blank" => true,
'ta-toolbar' => "[['h1','h2','h3','h4','p'],['bold','italics','underline','clear'],['insertLink']]",
'placeholder' => t('.shopfront_closed_message_placeholder')}
= f.hidden_field :preferred_shopfront_closed_message, id: "enterprise_preferred_shopfront_closed_message", value: @enterprise.preferred_shopfront_closed_message
%trix-editor{ input: "enterprise_preferred_shopfront_closed_message", "data-controller": "trixeditor", placeholder: t('.shopfront_closed_message_placeholder') }
.row
.text-normal
Expand Down
2 changes: 0 additions & 2 deletions app/webpacker/css/admin/all.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
@import "~jquery-ui/themes/base/resizable";
@import "vendor/assets/stylesheets/jquery-ui-theme";
@import "~jquery-ui/themes/base/dialog";
@import "../shared/textAngular";
@import "../shared/ng-tags-input.min";
@import "vendor/assets/stylesheets/select2.css.scss";
@import "~flatpickr/dist/flatpickr";
Expand Down Expand Up @@ -72,7 +71,6 @@
@import "components/todo";
@import "components/tooltip";
@import "components/wizard_progress";
@import "components/text-angular";

@import "pages/enterprise_form";
@import "pages/subscription_form";
Expand Down
43 changes: 0 additions & 43 deletions app/webpacker/css/admin/components/text-angular.scss

This file was deleted.

6 changes: 5 additions & 1 deletion app/webpacker/css/admin/trix.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
trix-toolbar .trix-button-row {
flex-wrap: wrap;
}

trix-toolbar [data-trix-button-group="file-tools"] {
display: none;
}
Expand All @@ -11,7 +15,7 @@ trix-editor {
color: #222;

a {
color: #f27052; // Equivalent to text-angular a
color: #f27052;
}

@include trix-styles;
Expand Down
2 changes: 0 additions & 2 deletions app/webpacker/css/admin_v3/all.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
@import "~jquery-ui/themes/base/resizable";
@import "vendor/assets/stylesheets/jquery-ui-theme";
@import "~jquery-ui/themes/base/dialog";
@import "../shared/textAngular";
@import "../shared/ng-tags-input.min";
@import "vendor/assets/stylesheets/select2.css.scss";
@import "~flatpickr/dist/flatpickr";
Expand Down Expand Up @@ -76,7 +75,6 @@
@import "../admin/components/todo";
@import "../admin/components/tooltip";
@import "../admin/components/wizard_progress";
@import "components/text-angular"; // admin_v3

@import "../admin/pages/enterprise_form";
@import "../admin/pages/subscription_form";
Expand Down
43 changes: 0 additions & 43 deletions app/webpacker/css/admin_v3/components/text-angular.scss

This file was deleted.

Loading

0 comments on commit b0567f7

Please sign in to comment.