diff --git a/app/assets/javascripts/discourse/components/category-drop.js.es6 b/app/assets/javascripts/discourse/components/category-drop.js.es6 index b05b9dcd77..527a4fb479 100644 --- a/app/assets/javascripts/discourse/components/category-drop.js.es6 +++ b/app/assets/javascripts/discourse/components/category-drop.js.es6 @@ -1,11 +1,5 @@ -/** - Renders a drop down for selecting a category +var get = Ember.get; - @class CategoryDropComponent - @extends Ember.Component - @namespace Discourse - @module Discourse -**/ export default Ember.Component.extend({ classNameBindings: ['category::no-category', 'categories:has-drop'], tagName: 'li', @@ -44,11 +38,20 @@ export default Ember.Component.extend({ badgeStyle: function() { var category = this.get('category'); + if (category) { - return Discourse.HTML.categoryStyle(category); - } else { - return "background-color: #eee; color: #333"; + var color = get(category, 'color'), + textColor = get(category, 'text_color'); + + if (color || textColor) { + var style = ""; + if (color) { style += "background-color: #" + color + "; "; } + if (textColor) { style += "color: #" + textColor + "; "; } + return style; + } } + + return "background-color: #eee; color: #333"; }.property('category'), clickEventName: function() { diff --git a/app/assets/javascripts/discourse/components/category-group.js.es6 b/app/assets/javascripts/discourse/components/category-group.js.es6 index 32434e74a9..14caa32bfe 100644 --- a/app/assets/javascripts/discourse/components/category-group.js.es6 +++ b/app/assets/javascripts/discourse/components/category-group.js.es6 @@ -1,3 +1,5 @@ +import { categoryBadgeHTML } from 'discourse/helpers/category-link'; + export default Ember.Component.extend({ _initializeAutocomplete: function(){ @@ -25,7 +27,7 @@ export default Ember.Component.extend({ }, template: template, transformComplete: function(category) { - return Discourse.HTML.categoryBadge(category, {allowUncategorized: true}); + return categoryBadgeHTML(category, {allowUncategorized: true}); } }); }.on('didInsertElement') diff --git a/app/assets/javascripts/discourse/controllers/edit-category.js.es6 b/app/assets/javascripts/discourse/controllers/edit-category.js.es6 index 443d3bcb7c..5928e97ea0 100644 --- a/app/assets/javascripts/discourse/controllers/edit-category.js.es6 +++ b/app/assets/javascripts/discourse/controllers/edit-category.js.es6 @@ -1,5 +1,6 @@ import ModalFunctionality from 'discourse/mixins/modal-functionality'; import ObjectController from 'discourse/controllers/object'; +import { categoryBadgeHTML } from 'discourse/helpers/category-link'; // Modal for editing / creating a category export default ObjectController.extend(ModalFunctionality, { @@ -69,7 +70,7 @@ export default ObjectController.extend(ModalFunctionality, { parent_category_id: parseInt(this.get('parent_category_id'),10), read_restricted: this.get('model.read_restricted') }); - return Discourse.HTML.categoryBadge(c, {showParent: true, link: false}); + return categoryBadgeHTML(c, {link: false}); }.property('parent_category_id', 'categoryName', 'color', 'text_color'), // background colors are available as a pipe-separated string diff --git a/app/assets/javascripts/discourse/controllers/history.js.es6 b/app/assets/javascripts/discourse/controllers/history.js.es6 index 2a00dc18d5..55302edc9c 100644 --- a/app/assets/javascripts/discourse/controllers/history.js.es6 +++ b/app/assets/javascripts/discourse/controllers/history.js.es6 @@ -1,5 +1,6 @@ import ModalFunctionality from 'discourse/mixins/modal-functionality'; import ObjectController from 'discourse/controllers/object'; +import { categoryBadgeHTML } from 'discourse/helpers/category-link'; // This controller handles displaying of history export default ObjectController.extend(ModalFunctionality, { @@ -22,14 +23,14 @@ export default ObjectController.extend(ModalFunctionality, { hide: function(postId, postVersion) { var self = this; - Discourse.Post.hideRevision(postId, postVersion).then(function (result) { + Discourse.Post.hideRevision(postId, postVersion).then(function () { self.refresh(postId, postVersion); }); }, show: function(postId, postVersion) { var self = this; - Discourse.Post.showRevision(postId, postVersion).then(function (result) { + Discourse.Post.showRevision(postId, postVersion).then(function () { self.refresh(postId, postVersion); }); }, @@ -68,7 +69,7 @@ export default ObjectController.extend(ModalFunctionality, { var changes = this.get("category_changes"); if (changes) { var category = Discourse.Category.findById(changes["previous"]); - return Discourse.HTML.categoryBadge(category, { allowUncategorized: true }); + return categoryBadgeHTML(category, { allowUncategorized: true }); } }.property("category_changes"), @@ -76,12 +77,12 @@ export default ObjectController.extend(ModalFunctionality, { var changes = this.get("category_changes"); if (changes) { var category = Discourse.Category.findById(changes["current"]); - return Discourse.HTML.categoryBadge(category, { allowUncategorized: true }); + return categoryBadgeHTML(category, { allowUncategorized: true }); } }.property("category_changes"), wiki_diff: function() { - var changes = this.get("wiki_changes") + var changes = this.get("wiki_changes"); if (changes) { return changes["current"] ? '' : @@ -93,7 +94,7 @@ export default ObjectController.extend(ModalFunctionality, { var moderator = Discourse.Site.currentProp('post_types.moderator_action'); var changes = this.get("post_type_changes"); if (changes) { - return changes["current"] == moderator ? + return changes["current"] === moderator ? '' : ''; } diff --git a/app/assets/javascripts/discourse/helpers/category-link.js.es6 b/app/assets/javascripts/discourse/helpers/category-link.js.es6 index 412a64df99..ea71350dfa 100644 --- a/app/assets/javascripts/discourse/helpers/category-link.js.es6 +++ b/app/assets/javascripts/discourse/helpers/category-link.js.es6 @@ -1,4 +1,63 @@ import registerUnbound from 'discourse/helpers/register-unbound'; +import { iconHTML } from 'discourse/helpers/fa-icon'; + +var get = Em.get, + escapeExpression = Handlebars.Utils.escapeExpression; + +function categoryStripe(tagName, category, extraClasses, href) { + if (!category) { return ""; } + + var color = Em.get(category, 'color'), + style = color ? "style='background-color: #" + color + ";'" : ""; + + return "<" + tagName + " class='badge-category-parent" + extraClasses + "' " + style + " href=\"" + href + "\">"; +} + +export function categoryBadgeHTML(category, opts) { + opts = opts || {}; + + if ((!category) || + (!opts.allowUncategorized && + Em.get(category, 'id') === Discourse.Site.currentProp("uncategorized_category_id") && + Discourse.SiteSettings.suppress_uncategorized_badge + ) + ) return ""; + + var description = get(category, 'description_text'), + restricted = get(category, 'read_restricted'), + url = Discourse.getURL("/c/") + Discourse.Category.slugFor(category), + href = (opts.link === false ? '' : url), + tagName = (opts.link === false || opts.link === "false" ? 'span' : 'a'), + extraClasses = (opts.extraClasses ? (' ' + opts.extraClasses) : ''); + + var html = ""; + + var parentCat = Discourse.Category.findById(category.get('parent_category_id')); + if (opts.hideParent) { parentCat = null; } + html += categoryStripe(tagName, parentCat, extraClasses, href); + + if (parentCat !== category) { + html += categoryStripe(tagName, category, extraClasses, href); + } + + var classNames = "badge-category clear-badge" + extraClasses; + if (restricted) { classNames += " restricted"; } + + html += "<" + tagName + ' href="' + href + '" ' + + 'data-drop-close="true" class="' + classNames + '"' + + (description ? 'title="' + escapeExpression(description) + '" ' : '') + + ">"; + + var name = escapeExpression(get(category, 'name')); + if (restricted) { + html += "
" + iconHTML('lock') + " " + name + "
"; + } else { + html += name; + } + html += ""; + + return "" + html + ""; +} export function categoryLinkHTML(category, options) { var categoryOptions = {}; @@ -9,12 +68,11 @@ export function categoryLinkHTML(category, options) { if (options) { if (options.allowUncategorized) { categoryOptions.allowUncategorized = true; } - if (options.showParent) { categoryOptions.showParent = true; } - if (options.onlyStripe) { categoryOptions.onlyStripe = true; } if (options.link !== undefined) { categoryOptions.link = options.link; } if (options.extraClasses) { categoryOptions.extraClasses = options.extraClasses; } + if (options.hideParent) { categoryOptions.hideParent = true; } } - return new Handlebars.SafeString(Discourse.HTML.categoryBadge(category, categoryOptions)); + return new Handlebars.SafeString(categoryBadgeHTML(category, categoryOptions)); } registerUnbound('category-link', categoryLinkHTML); diff --git a/app/assets/javascripts/discourse/lib/html.js b/app/assets/javascripts/discourse/lib/html.js index 8eb7a3be96..ccb807d6a8 100644 --- a/app/assets/javascripts/discourse/lib/html.js +++ b/app/assets/javascripts/discourse/lib/html.js @@ -1,11 +1,3 @@ -/** - Helpers to build HTML strings as well as custom fragments. - - @class HTML - @namespace Discourse - @module Discourse -**/ - var customizations = {}; Discourse.HTML = { @@ -15,9 +7,6 @@ Discourse.HTML = { using `setCustomHTML(key, html)`. This is used by a handlebars helper to find the HTML content it wants. It will also check the `PreloadStore` for any server side preloaded HTML. - - @method getCustomHTML - @param {String} key to lookup **/ getCustomHTML: function(key) { var c = customizations[key]; @@ -31,104 +20,9 @@ Discourse.HTML = { } }, - /** - Set a fragment of HTML by key. It can then be looked up with `getCustomHTML(key)`. - - @method setCustomHTML - @param {String} key to store the html - @param {String} html fragment to store - **/ + // Set a fragment of HTML by key. It can then be looked up with `getCustomHTML(key)`. setCustomHTML: function(key, html) { customizations[key] = html; - }, - - /** - Returns the CSS styles for a category - - @method categoryStyle - @param {Discourse.Category} category the category whose link we want - **/ - categoryStyle: function(category) { - var color = Em.get(category, 'color'), - textColor = Em.get(category, 'text_color'); - - if (!color && !textColor) { return; } - - // Add the custom style if we need to - var style = ""; - if (color) { style += "background-color: #" + color + "; "; } - if (textColor) { style += "color: #" + textColor + "; "; } - return style; - }, - - /** - Create a category badge - - @method categoryBadge - @param {Discourse.Category} category the category whose link we want - @param {Object} opts The options for the category link - @param {Boolean} opts.allowUncategorized Whether we allow rendering of the uncategorized category (default false) - @param {Boolean} opts.showParent Whether to visually show whether category is a sub-category (default false) - @param {Boolean} opts.link Whether this category badge should link to the category (default true) - @param {String} opts.extraClasses add this string to the class attribute of the badge - @returns {String} the html category badge - **/ - categoryBadge: function(category, opts) { - opts = opts || {}; - - if ((!category) || - (!opts.allowUncategorized && - Em.get(category, 'id') === Discourse.Site.currentProp("uncategorized_category_id") && - Discourse.SiteSettings.suppress_uncategorized_badge - ) - ) return ""; - - var name = Em.get(category, 'name'), - description = Em.get(category, 'description_text'), - restricted = Em.get(category, 'read_restricted'), - url = Discourse.getURL("/c/") + Discourse.Category.slugFor(category), - elem = (opts.link === false ? 'span' : 'a'), - extraClasses = (opts.extraClasses ? (' ' + opts.extraClasses) : ''), - html = "<" + elem + " href=\"" + (opts.link === false ? '' : url) + "\" ", - categoryStyle; - - // Parent stripe implies onlyStripe - if (opts.onlyStripe) { opts.showParent = true; } - - html += "data-drop-close=\"true\" class=\"badge-category" + (restricted ? ' restricted' : '' ) + - (opts.onlyStripe ? ' clear-badge' : '') + - extraClasses + "\" "; - name = Handlebars.Utils.escapeExpression(name); - - // Add description if we have it, without tags. Server has sanitized the description value. - if (description) html += "title=\"" + Handlebars.Utils.escapeExpression(description) + "\" "; - - if (!opts.onlyStripe) { - categoryStyle = Discourse.HTML.categoryStyle(category); - if (categoryStyle) { - html += "style=\"" + categoryStyle + "\" "; - } - } - - if (restricted) { - html += ">
" + name + "
"; - } else { - html += ">" + name + ""; - } - - if (opts.onlyStripe || (opts.showParent && category.get('parent_category_id'))) { - var parent = Discourse.Category.findById(category.get('parent_category_id')); - if (!parent) { parent = category; } - - categoryStyle = Discourse.HTML.categoryStyle(opts.onlyStripe ? category : parent) || ''; - html = "<" + elem + " class='badge-category-parent" + extraClasses + "' style=\"" + categoryStyle + - "\" href=\"" + (opts.link === false ? '' : url) + "\">" + - (Em.get(parent, 'read_restricted') ? " " : "") + - Em.get(parent, 'name') + "" + - html + ""; - } - - return html; } }; diff --git a/app/assets/javascripts/discourse/models/category.js b/app/assets/javascripts/discourse/models/category.js index 3f8bb6edb6..e7bc7dd6fa 100644 --- a/app/assets/javascripts/discourse/models/category.js +++ b/app/assets/javascripts/discourse/models/category.js @@ -232,6 +232,7 @@ Discourse.Category.reopenClass({ }, findById: function(id) { + if (!id) { return; } return Discourse.Category.idMap()[id]; }, diff --git a/app/assets/javascripts/discourse/templates/category-group-autocomplete.raw.hbs b/app/assets/javascripts/discourse/templates/category-group-autocomplete.raw.hbs index 5a3ec802d7..45533d2d7a 100644 --- a/app/assets/javascripts/discourse/templates/category-group-autocomplete.raw.hbs +++ b/app/assets/javascripts/discourse/templates/category-group-autocomplete.raw.hbs @@ -1,7 +1,7 @@
diff --git a/app/assets/javascripts/discourse/templates/components/category-drop.hbs b/app/assets/javascripts/discourse/templates/components/category-drop.hbs index 2f6481e77f..02a184e34b 100644 --- a/app/assets/javascripts/discourse/templates/components/category-drop.hbs +++ b/app/assets/javascripts/discourse/templates/components/category-drop.hbs @@ -1,27 +1,27 @@ {{#if category}} - + {{#if category.read_restricted}} - + {{fa-icon "lock"}} {{/if}} {{category.name}} {{else}} {{#if noSubcategories}} - {{i18n 'categories.no_subcategory'}} + {{i18n 'categories.no_subcategory'}} {{else}} - {{allCategoriesLabel}} + {{allCategoriesLabel}} {{/if}} {{/if}} {{#if categories}} - +
{{allCategoriesLabel}}
{{#if subCategory}} -
{{i18n 'categories.no_subcategory'}}
+
{{i18n 'categories.no_subcategory'}}
{{/if}} {{#if renderCategories}} - {{#each c in categories}}
{{category-link c allowUncategorized=true}}
{{/each}} + {{#each c in categories}}
{{category-link c allowUncategorized=true hideParent=subCategory}}
{{/each}} {{/if}}
{{/if}} diff --git a/app/assets/javascripts/discourse/templates/discovery/categories.hbs b/app/assets/javascripts/discourse/templates/discovery/categories.hbs index c3055c93b6..192cc7a77d 100644 --- a/app/assets/javascripts/discourse/templates/discovery/categories.hbs +++ b/app/assets/javascripts/discourse/templates/discovery/categories.hbs @@ -32,7 +32,7 @@ {{#if c.subcategories}}
{{#each s in c.subcategories}} - {{category-link s showParent="true" onlyStripe="true"}} + {{category-link s hideParent="true"}} {{#if s.unreadTopics}} {{unbound s.unreadTopics}} {{/if}} diff --git a/app/assets/javascripts/discourse/templates/header.hbs b/app/assets/javascripts/discourse/templates/header.hbs index 0cffe50fef..24aa48c715 100644 --- a/app/assets/javascripts/discourse/templates/header.hbs +++ b/app/assets/javascripts/discourse/templates/header.hbs @@ -113,9 +113,9 @@ {{/if}} {{#if topic.category.parentCategory}} - {{bound-category-link topic.category.parentCategory onlyStripe="true"}} + {{bound-category-link topic.category.parentCategory}} {{/if}} - {{bound-category-link topic.category onlyStripe="true"}} + {{bound-category-link topic.category hideParent=true}}
diff --git a/app/assets/javascripts/discourse/templates/list/category-column.raw.hbs b/app/assets/javascripts/discourse/templates/list/category-column.raw.hbs index 614f502ba2..10c175aac6 100644 --- a/app/assets/javascripts/discourse/templates/list/category-column.raw.hbs +++ b/app/assets/javascripts/discourse/templates/list/category-column.raw.hbs @@ -1 +1 @@ -{{category-link category showParent="true"}} +{{category-link category}} diff --git a/app/assets/javascripts/discourse/templates/mobile/components/basic-topic-list.hbs b/app/assets/javascripts/discourse/templates/mobile/components/basic-topic-list.hbs index 8f04d3a242..99aa9d66bf 100644 --- a/app/assets/javascripts/discourse/templates/mobile/components/basic-topic-list.hbs +++ b/app/assets/javascripts/discourse/templates/mobile/components/basic-topic-list.hbs @@ -32,7 +32,7 @@ {{#unless controller.hideCategory}}
- {{category-link t.category showParent="true"}} + {{category-link t.category}}
{{/unless}} {{#if controller.showParticipants}} diff --git a/app/assets/javascripts/discourse/templates/mobile/discovery/categories.hbs b/app/assets/javascripts/discourse/templates/mobile/discovery/categories.hbs index 2256ea394f..cbee5af14d 100644 --- a/app/assets/javascripts/discourse/templates/mobile/discovery/categories.hbs +++ b/app/assets/javascripts/discourse/templates/mobile/discovery/categories.hbs @@ -46,7 +46,7 @@
{{#each subcategory in c.subcategories}} - {{category-link subcategory showParent="true"}} + {{category-link subcategory}} {{/each}}
diff --git a/app/assets/javascripts/discourse/templates/mobile/list/topic_list_item.raw.hbs b/app/assets/javascripts/discourse/templates/mobile/list/topic_list_item.raw.hbs index 6f8fbbe5b8..f52e48ba43 100644 --- a/app/assets/javascripts/discourse/templates/mobile/list/topic_list_item.raw.hbs +++ b/app/assets/javascripts/discourse/templates/mobile/list/topic_list_item.raw.hbs @@ -11,7 +11,7 @@
{{#unless controller.hideCategory}}
- {{category-link content.category showParent="true"}} + {{category-link content.category}}
{{/unless}} diff --git a/app/assets/javascripts/discourse/templates/modal/edit-category-general.hbs b/app/assets/javascripts/discourse/templates/modal/edit-category-general.hbs index 7931c5ef57..2722479ed3 100644 --- a/app/assets/javascripts/discourse/templates/modal/edit-category-general.hbs +++ b/app/assets/javascripts/discourse/templates/modal/edit-category-general.hbs @@ -15,7 +15,7 @@ {{#if subCategories}} {{#each s in subCategories}} - {{category-badge s}} + {{category-badge s hideParent="true"}} {{/each}} {{else}} diff --git a/app/assets/javascripts/discourse/templates/site-map.hbs b/app/assets/javascripts/discourse/templates/site-map.hbs index 99c1e2c433..a1efed37ab 100644 --- a/app/assets/javascripts/discourse/templates/site-map.hbs +++ b/app/assets/javascripts/discourse/templates/site-map.hbs @@ -46,7 +46,7 @@ {{#each c in categories itemController='site-map-category'}}
  • - {{category-link c allowUncategorized="true" showParent="true"}} + {{category-link c allowUncategorized="true"}} {{#if c.unreadTotal}} {{c.unreadTotal}} diff --git a/app/assets/javascripts/discourse/templates/topic.hbs b/app/assets/javascripts/discourse/templates/topic.hbs index 8af8ac1953..878fa421e3 100644 --- a/app/assets/javascripts/discourse/templates/topic.hbs +++ b/app/assets/javascripts/discourse/templates/topic.hbs @@ -46,7 +46,7 @@ {{#if category.parentCategory}} {{bound-category-link category.parentCategory}} {{/if}} - {{bound-category-link category}} + {{bound-category-link category hideParent=true}} {{plugin-outlet "topic-category"}} {{/unless}} {{/if}} diff --git a/app/assets/javascripts/discourse/views/category-chooser.js.es6 b/app/assets/javascripts/discourse/views/category-chooser.js.es6 index 46a82d0128..f0e39a8a1d 100644 --- a/app/assets/javascripts/discourse/views/category-chooser.js.es6 +++ b/app/assets/javascripts/discourse/views/category-chooser.js.es6 @@ -1,6 +1,5 @@ import ComboboxView from 'discourse/views/combo-box'; - -var badgeHtml = Discourse.HTML.categoryBadge; +import { categoryBadgeHTML } from 'discourse/helpers/category-link'; export default ComboboxView.extend({ classNames: ['combobox category-combobox'], @@ -57,10 +56,10 @@ export default ComboboxView.extend({ } if (!category) return item.text; - var result = badgeHtml(category, {showParent: false, link: false, allowUncategorized: true}), + var result = categoryBadgeHTML(category, {link: false, allowUncategorized: true, hideParent: true}), parentCategoryId = category.get('parent_category_id'); if (parentCategoryId) { - result = badgeHtml(Discourse.Category.findById(parentCategoryId), {link: false}) + " " + result; + result = categoryBadgeHTML(Discourse.Category.findById(parentCategoryId), {link: false}) + " " + result; } result += " × " + category.get('topic_count') + ""; diff --git a/app/assets/javascripts/discourse/views/topic.js.es6 b/app/assets/javascripts/discourse/views/topic.js.es6 index 66e73adb49..f2213de9a1 100644 --- a/app/assets/javascripts/discourse/views/topic.js.es6 +++ b/app/assets/javascripts/discourse/views/topic.js.es6 @@ -1,5 +1,6 @@ import AddCategoryClass from 'discourse/mixins/add-category-class'; import { listenForViewEvent } from 'discourse/lib/app-events'; +import { categoryBadgeHTML } from 'discourse/helpers/category-link'; var TopicView = Discourse.View.extend(AddCategoryClass, Discourse.Scrolling, { templateName: 'topic', @@ -130,7 +131,7 @@ var TopicView = Discourse.View.extend(AddCategoryClass, Discourse.Scrolling, { } if (category) { - opts.catLink = Discourse.HTML.categoryBadge(category, {showParent: true}); + opts.catLink = categoryBadgeHTML(category); } else { opts.catLink = "" + I18n.t("topic.browse_all_categories") + ""; } diff --git a/app/assets/stylesheets/common/base/_topic-list.scss b/app/assets/stylesheets/common/base/_topic-list.scss index 751adbada0..54a6fd1b43 100644 --- a/app/assets/stylesheets/common/base/_topic-list.scss +++ b/app/assets/stylesheets/common/base/_topic-list.scss @@ -154,9 +154,9 @@ } .list-controls { - .home { - background-color: scale-color-diff(); + .category-dropdown-menu .home { color: $primary; + margin-left: 8px; } .badge-category { padding: 4px 10px; @@ -164,6 +164,10 @@ line-height: 24px; float: left; } + + .category-dropdown-menu .badge-category { + width: 100%; + } .category-dropdown-button { border-left: 1px solid rgba(0,0,0,0.15); font-size: 1.143em; @@ -223,18 +227,21 @@ ol.category-breadcrumb { background-color: $secondary; z-index: 100; + .cat { + margin-right: 20px; + } + + a.badge-category, a.badge-category-parent { + line-height: 19px; + overflow:hidden; + margin-bottom: 0; + } a.badge-category { font-size: 0.929em; font-weight: bold; float: none; - line-height: 19px; text-transform: none; - width: 100%; - min-width: 102px; - margin-right: 20px; - margin-bottom: 0; max-width:200px; - overflow:hidden; text-overflow:ellipsis; } } diff --git a/app/assets/stylesheets/common/components/badges.css.scss b/app/assets/stylesheets/common/components/badges.css.scss index 7549e5f563..0765de22a0 100644 --- a/app/assets/stylesheets/common/components/badges.css.scss +++ b/app/assets/stylesheets/common/components/badges.css.scss @@ -28,9 +28,9 @@ .badge-category { padding: 6px; - color: $secondary; + color: $primary; &[href] { - color: $secondary; + color: $primary; } } diff --git a/app/assets/stylesheets/desktop/user.scss b/app/assets/stylesheets/desktop/user.scss index 41e6923ab2..577612b09c 100644 --- a/app/assets/stylesheets/desktop/user.scss +++ b/app/assets/stylesheets/desktop/user.scss @@ -402,6 +402,9 @@ .user-stream { + .category { + margin-left: 3px; + } .excerpt { margin: 5px 0; font-size: 0.929em; diff --git a/app/helpers/user_notifications_helper.rb b/app/helpers/user_notifications_helper.rb index cb662043d5..c96da2c370 100644 --- a/app/helpers/user_notifications_helper.rb +++ b/app/helpers/user_notifications_helper.rb @@ -71,15 +71,8 @@ module UserNotificationsHelper category_url = "#{Discourse.base_url}#{category.url}" - if opts[:only_stripe] - result << " " - result << "#{category.name}" - else - if category.parent_category.present? - result << " " - end - result << "#{category.name}" - end + result << " " + result << "#{category.name}" result.html_safe end diff --git a/app/views/user_notifications/digest.html.erb b/app/views/user_notifications/digest.html.erb index 8545f198e6..833874de11 100644 --- a/app/views/user_notifications/digest.html.erb +++ b/app/views/user_notifications/digest.html.erb @@ -45,7 +45,7 @@
  • <%= link_to t.title, "#{Discourse.base_url}#{t.relative_url}" %> <%= t('user_notifications.digest.posts', count: t.posts_count) %> - <%= email_category(t.category, only_stripe: true) %> + <%= email_category(t.category) %>
  • <%- end -%> diff --git a/test/javascripts/lib/category-badge-test.js.es6 b/test/javascripts/lib/category-badge-test.js.es6 new file mode 100644 index 0000000000..22d76769a4 --- /dev/null +++ b/test/javascripts/lib/category-badge-test.js.es6 @@ -0,0 +1,41 @@ +module("categoryBadgeHTML"); + +import { categoryBadgeHTML } from "discourse/helpers/category-link"; + +test("categoryBadge without a category", function() { + blank(categoryBadgeHTML(), "it returns no HTML"); +}); + +test("Regular categoryBadge", function() { + var category = Discourse.Category.create({ + name: 'hello', + id: 123, + description_text: 'cool description', + color: 'ff0', + text_color: 'f00' + }), + tag = parseHTML(categoryBadgeHTML(category))[0]; + + equal(tag.name, 'span', 'it creates a `span` wrapper tag'); + equal(tag.attributes['class'], 'badge-wrapper', 'it has the correct class'); + + var label = tag.children[1]; + equal(label.attributes.title, 'cool description', 'it has the correct title'); + + equal(label.children[0].data, 'hello', 'it has the category name'); +}); + +test("undefined color", function() { + var noColor = Discourse.Category.create({ name: 'hello', id: 123 }), + tag = parseHTML(categoryBadgeHTML(noColor))[0]; + + blank(tag.attributes.style, "it has no color style because there are no colors"); +}); + +test("allowUncategorized", function() { + var uncategorized = Discourse.Category.create({name: 'uncategorized', id: 345}); + sandbox.stub(Discourse.Site, 'currentProp').withArgs('uncategorized_category_id').returns(345); + + blank(categoryBadgeHTML(uncategorized), "it doesn't return HTML for uncategorized by default"); + present(categoryBadgeHTML(uncategorized, {allowUncategorized: true}), "it returns HTML"); +}); diff --git a/test/javascripts/lib/html-test.js.es6 b/test/javascripts/lib/html-test.js.es6 index 57a4328f37..07ef2906a1 100644 --- a/test/javascripts/lib/html-test.js.es6 +++ b/test/javascripts/lib/html-test.js.es6 @@ -2,46 +2,6 @@ module("Discourse.HTML"); var html = Discourse.HTML; -test("categoryBadge without a category", function() { - blank(html.categoryBadge(), "it returns no HTML"); -}); - -test("Regular categoryBadge", function() { - var category = Discourse.Category.create({ - name: 'hello', - id: 123, - description_text: 'cool description', - color: 'ff0', - text_color: 'f00' - }), - tag = parseHTML(html.categoryBadge(category))[0]; - - equal(tag.name, 'a', 'it creates an `a` tag'); - equal(tag.attributes['class'], 'badge-category', 'it has the correct class'); - equal(tag.attributes.title, 'cool description', 'it has the correct title'); - - ok(tag.attributes.style.indexOf('#ff0') !== -1, "it has the color style"); - ok(tag.attributes.style.indexOf('#f00') !== -1, "it has the textColor style"); - - equal(tag.children[0].data, 'hello', 'it has the category name'); -}); - -test("undefined color", function() { - var noColor = Discourse.Category.create({ name: 'hello', id: 123 }), - tag = parseHTML(html.categoryBadge(noColor))[0]; - - blank(tag.attributes.style, "it has no color style because there are no colors"); -}); - -test("allowUncategorized", function() { - var uncategorized = Discourse.Category.create({name: 'uncategorized', id: 345}); - sandbox.stub(Discourse.Site, 'currentProp').withArgs('uncategorized_category_id').returns(345); - - blank(html.categoryBadge(uncategorized), "it doesn't return HTML for uncategorized by default"); - present(html.categoryBadge(uncategorized, {allowUncategorized: true}), "it returns HTML"); -}); - - test("customHTML", function() { blank(html.getCustomHTML('evil'), "there is no custom HTML for a key by default");