Remove deprecations from edit-category and add skeleton acceptance test

This commit is contained in:
Robin Ward 2015-05-15 11:03:27 -04:00
parent 764f9b42fe
commit 0362c50698
11 changed files with 89 additions and 63 deletions

View file

@ -17,7 +17,7 @@ export default DiscourseContainerView.extend({
tagName: 'button', tagName: 'button',
attributeBindings: ['style', 'title'], attributeBindings: ['style', 'title'],
classNames: ['colorpicker'].concat( isUsed ? ['used-color'] : ['unused-color'] ), classNames: ['colorpicker'].concat( isUsed ? ['used-color'] : ['unused-color'] ),
style: 'background-color: #' + color + ';', style: ('background-color: #' + color + ';').htmlSafe(),
title: isUsed ? I18n.t("category.already_used") : null, title: isUsed ? I18n.t("category.already_used") : null,
click: function() { click: function() {
self.set("value", color); self.set("value", color);

View file

@ -6,6 +6,10 @@ import { categoryBadgeHTML } from 'discourse/helpers/category-link';
export default ObjectController.extend(ModalFunctionality, { export default ObjectController.extend(ModalFunctionality, {
foregroundColors: ['FFFFFF', '000000'], foregroundColors: ['FFFFFF', '000000'],
categoryUploadUrl: '/category/uploads', categoryUploadUrl: '/category/uploads',
editingPermissions: false,
selectedTab: null,
saving: false,
deleting: false,
parentCategories: function() { parentCategories: function() {
return Discourse.Category.list().filter(function (c) { return Discourse.Category.list().filter(function (c) {
@ -15,31 +19,31 @@ export default ObjectController.extend(ModalFunctionality, {
// We can change the parent if there are no children // We can change the parent if there are no children
subCategories: function() { subCategories: function() {
if (Em.isEmpty(this.get('id'))) { return null; } if (Em.isEmpty(this.get('model.id'))) { return null; }
return Discourse.Category.list().filterBy('parent_category_id', this.get('id')); return Discourse.Category.list().filterBy('parent_category_id', this.get('model.id'));
}.property('model.id'), }.property('model.id'),
canSelectParentCategory: Em.computed.not('isUncategorizedCategory'), canSelectParentCategory: Em.computed.not('model.isUncategorizedCategory'),
onShow: function() { onShow() {
this.changeSize(); this.changeSize();
this.titleChanged(); this.titleChanged();
}, },
changeSize: function() { changeSize: function() {
if (this.present('description')) { if (this.present('model.description')) {
this.set('controllers.modal.modalClass', 'edit-category-modal full'); this.set('controllers.modal.modalClass', 'edit-category-modal full');
} else { } else {
this.set('controllers.modal.modalClass', 'edit-category-modal small'); this.set('controllers.modal.modalClass', 'edit-category-modal small');
} }
}.observes('description'), }.observes('model.description'),
title: function() { title: function() {
if (this.get('id')) { if (this.get('model.id')) {
return I18n.t("category.edit_long") + " : " + this.get('model.name'); return I18n.t("category.edit_long") + " : " + this.get('model.name');
} }
return I18n.t("category.create") + (this.get('model.name') ? (" : " + this.get('model.name')) : ''); return I18n.t("category.create") + (this.get('model.name') ? (" : " + this.get('model.name')) : '');
}.property('id', 'model.name'), }.property('model.id', 'model.name'),
titleChanged: function() { titleChanged: function() {
this.set('controllers.modal.title', this.get('title')); this.set('controllers.modal.title', this.get('title'));
@ -47,10 +51,10 @@ export default ObjectController.extend(ModalFunctionality, {
disabled: function() { disabled: function() {
if (this.get('saving') || this.get('deleting')) return true; if (this.get('saving') || this.get('deleting')) return true;
if (!this.get('name')) return true; if (!this.get('model.name')) return true;
if (!this.get('color')) return true; if (!this.get('model.color')) return true;
return false; return false;
}.property('saving', 'name', 'color', 'deleting'), }.property('saving', 'model.name', 'model.color', 'deleting'),
emailInEnabled: Discourse.computed.setting('email_in'), emailInEnabled: Discourse.computed.setting('email_in'),
@ -59,80 +63,82 @@ export default ObjectController.extend(ModalFunctionality, {
}.property('disabled', 'saving', 'deleting'), }.property('disabled', 'saving', 'deleting'),
colorStyle: function() { colorStyle: function() {
return "background-color: #" + (this.get('color')) + "; color: #" + (this.get('text_color')) + ";"; return "background-color: #" + this.get('model.color') + "; color: #" + this.get('model.text_color') + ";";
}.property('color', 'text_color'), }.property('model.color', 'model.text_color'),
categoryBadgePreview: function() { categoryBadgePreview: function() {
var c = Discourse.Category.create({ const model = this.get('model');
name: this.get('categoryName'), const c = Discourse.Category.create({
color: this.get('color'), name: model.get('categoryName'),
text_color: this.get('text_color'), color: model.get('color'),
parent_category_id: parseInt(this.get('parent_category_id'),10), text_color: model.get('text_color'),
read_restricted: this.get('model.read_restricted') parent_category_id: parseInt(model.get('parent_category_id'),10),
read_restricted: model.get('read_restricted')
}); });
return categoryBadgeHTML(c, {link: false}); return categoryBadgeHTML(c, {link: false});
}.property('parent_category_id', 'categoryName', 'color', 'text_color'), }.property('model.parent_category_id', 'model.categoryName', 'model.color', 'model.text_color'),
// background colors are available as a pipe-separated string // background colors are available as a pipe-separated string
backgroundColors: function() { backgroundColors: function() {
var categories = Discourse.Category.list(); const categories = Discourse.Category.list();
return Discourse.SiteSettings.category_colors.split("|").map(function(i) { return i.toUpperCase(); }).concat( return Discourse.SiteSettings.category_colors.split("|").map(function(i) { return i.toUpperCase(); }).concat(
categories.map(function(c) { return c.color.toUpperCase(); }) ).uniq(); categories.map(function(c) { return c.color.toUpperCase(); }) ).uniq();
}.property('Discourse.SiteSettings.category_colors'), }.property('Discourse.SiteSettings.category_colors'),
usedBackgroundColors: function() { usedBackgroundColors: function() {
var categories = Discourse.Category.list(); const categories = Discourse.Category.list();
var currentCat = this.get('model'); const currentCat = this.get('model');
return categories.map(function(c) { return categories.map(function(c) {
// If editing a category, don't include its color: // If editing a category, don't include its color:
return (currentCat.get('id') && currentCat.get('color').toUpperCase() === c.color.toUpperCase()) ? null : c.color.toUpperCase(); return (currentCat.get('id') && currentCat.get('color').toUpperCase() === c.color.toUpperCase()) ? null : c.color.toUpperCase();
}, this).compact(); }, this).compact();
}.property('id', 'color'), }.property('model.id', 'model.color'),
categoryName: function() { categoryName: function() {
var name = this.get('name') || ""; const name = this.get('name') || "";
return name.trim().length > 0 ? name : I18n.t("preview"); return name.trim().length > 0 ? name : I18n.t("preview");
}.property('name'), }.property('name'),
buttonTitle: function() { buttonTitle: function() {
if (this.get('saving')) return I18n.t("saving"); if (this.get('saving')) return I18n.t("saving");
if (this.get('isUncategorizedCategory')) return I18n.t("save"); if (this.get('model.isUncategorizedCategory')) return I18n.t("save");
return (this.get('id') ? I18n.t("category.save") : I18n.t("category.create")); return (this.get('model.id') ? I18n.t("category.save") : I18n.t("category.create"));
}.property('saving', 'id'), }.property('saving', 'model.id'),
deleteButtonTitle: function() { deleteButtonTitle: function() {
return I18n.t('category.delete'); return I18n.t('category.delete');
}.property(), }.property(),
showDescription: function() { showDescription: function() {
return !this.get('isUncategorizedCategory') && this.get('id'); return !this.get('model.isUncategorizedCategory') && this.get('model.id');
}.property('isUncategorizedCategory', 'id'), }.property('model.isUncategorizedCategory', 'model.id'),
showPositionInput: Discourse.computed.setting('fixed_category_positions'), showPositionInput: Discourse.computed.setting('fixed_category_positions'),
actions: { actions: {
showCategoryTopic: function() { showCategoryTopic() {
this.send('closeModal'); this.send('closeModal');
Discourse.URL.routeTo(this.get('topic_url')); Discourse.URL.routeTo(this.get('model.topic_url'));
return false; return false;
}, },
editPermissions: function(){ editPermissions() {
this.set('editingPermissions', true); this.set('editingPermissions', true);
}, },
addPermission: function(group, permission_id){ addPermission(group, id) {
this.get('model').addPermission({group_name: group + "", permission: Discourse.PermissionType.create({id: permission_id})}); this.get('model').addPermission({group_name: group + "",
permission: Discourse.PermissionType.create({id})});
}, },
removePermission: function(permission){ removePermission(permission) {
this.get('model').removePermission(permission); this.get('model').removePermission(permission);
}, },
saveCategory: function() { saveCategory() {
var self = this, const self = this,
model = this.get('model'), model = this.get('model'),
parentCategory = Discourse.Category.list().findBy('id', parseInt(model.get('parent_category_id'), 10)); parentCategory = Discourse.Category.list().findBy('id', parseInt(model.get('parent_category_id'), 10));
@ -155,8 +161,8 @@ export default ObjectController.extend(ModalFunctionality, {
}); });
}, },
deleteCategory: function() { deleteCategory() {
var self = this; const self = this;
this.set('deleting', true); this.set('deleting', true);
this.send('hideModal'); this.send('hideModal');

View file

@ -2,11 +2,11 @@
<section class='field'> <section class='field'>
<section class="field-item"> <section class="field-item">
<label>{{i18n 'category.name'}}</label> <label>{{i18n 'category.name'}}</label>
{{text-field value=name placeholderKey="category.name_placeholder" maxlength="50"}} {{text-field value=model.name placeholderKey="category.name_placeholder" maxlength="50"}}
</section> </section>
<section class="field-item"> <section class="field-item">
<label>{{i18n 'category.slug'}}</label> <label>{{i18n 'category.slug'}}</label>
{{text-field value=slug placeholderKey="category.slug_placeholder" maxlength="255"}} {{text-field value=model.slug placeholderKey="category.slug_placeholder" maxlength="255"}}
</section> </section>
</section> </section>
@ -19,7 +19,7 @@
{{/each}} {{/each}}
{{else}} {{else}}
<label>{{i18n 'category.parent'}}</label> <label>{{i18n 'category.parent'}}</label>
{{category-chooser valueAttribute="id" value=parent_category_id categories=parentCategories rootNone=true}} {{category-chooser valueAttribute="id" value=model.parent_category_id categories=parentCategories rootNone=true}}
{{/if}} {{/if}}
</section> </section>
{{/if}} {{/if}}
@ -27,12 +27,12 @@
{{#if showDescription}} {{#if showDescription}}
<section class='field'> <section class='field'>
<label>{{i18n 'category.description'}}</label> <label>{{i18n 'category.description'}}</label>
{{#if description}} {{#if model.description}}
{{{description}}} {{{model.description}}}
{{else}} {{else}}
{{i18n 'category.no_description'}} {{i18n 'category.no_description'}}
{{/if}} {{/if}}
{{#if topic_url}} {{#if model.topic_url}}
<br/> <br/>
{{d-button class="btn-small" action="showCategoryTopic" icon="pencil" label="category.change_in_category_topic"}} {{d-button class="btn-small" action="showCategoryTopic" icon="pencil" label="category.change_in_category_topic"}}
{{/if}} {{/if}}
@ -46,14 +46,14 @@
<div class='input-prepend input-append' style="margin-top: 10px;"> <div class='input-prepend input-append' style="margin-top: 10px;">
<span class='color-title'>{{i18n 'category.background_color'}}:</span> <span class='color-title'>{{i18n 'category.background_color'}}:</span>
<span class='add-on'>#</span>{{text-field value=color placeholderKey="category.color_placeholder" maxlength="6"}} <span class='add-on'>#</span>{{text-field value=model.color placeholderKey="category.color_placeholder" maxlength="6"}}
{{color-picker colors=backgroundColors usedColors=usedBackgroundColors value=color}} {{color-picker colors=backgroundColors usedColors=usedBackgroundColors value=model.color}}
</div> </div>
<div class='input-prepend input-append'> <div class='input-prepend input-append'>
<span class='color-title'>{{i18n 'category.foreground_color'}}:</span> <span class='color-title'>{{i18n 'category.foreground_color'}}:</span>
<span class='add-on'>#</span>{{text-field value=text_color placeholderKey="category.color_placeholder" maxlength="6"}} <span class='add-on'>#</span>{{text-field value=model.text_color placeholderKey="category.color_placeholder" maxlength="6"}}
{{color-picker colors=foregroundColors value=text_color}} {{color-picker colors=foregroundColors value=model.text_color}}
</div> </div>
</div> </div>
</section> </section>

View file

@ -1,9 +1,9 @@
<section class='field'> <section class='field'>
<label>{{i18n 'category.logo'}}</label> <label>{{i18n 'category.logo'}}</label>
{{image-uploader uploadUrl=categoryUploadUrl imageUrl=logo_url type="logo"}} {{image-uploader uploadUrl=categoryUploadUrl imageUrl=model.logo_url type="logo"}}
</section> </section>
<section class='field'> <section class='field'>
<label>{{i18n 'category.background_image'}}</label> <label>{{i18n 'category.background_image'}}</label>
{{image-uploader uploadUrl=categoryUploadUrl imageUrl=background_url type="background"}} {{image-uploader uploadUrl=categoryUploadUrl imageUrl=model.background_url type="background"}}
</section> </section>

View file

@ -1,6 +1,6 @@
<section class='field'> <section class='field'>
<ul class='permission-list'> <ul class='permission-list'>
{{#each p in permissions}} {{#each model.permissions as |p|}}
<li> <li>
<span class="name"><span class="badge-group">{{p.group_name}}</span></span> <span class="name"><span class="badge-group">{{p.group_name}}</span></span>
{{{i18n "category.can"}}} {{{i18n "category.can"}}}

View file

@ -1,13 +1,13 @@
<section class='field'> <section class='field'>
{{auto-close-form autoCloseTime=auto_close_hours {{auto-close-form autoCloseTime=model.auto_close_hours
autoCloseBasedOnLastPost=auto_close_based_on_last_post autoCloseBasedOnLastPost=model.auto_close_based_on_last_post
limited="true" }} limited="true" }}
</section> </section>
<section class='field'> <section class='field'>
<div class="allow-badges"> <div class="allow-badges">
<div> <div>
{{input type="checkbox" checked=allow_badges}} {{input type="checkbox" checked=model.allow_badges}}
{{i18n 'category.allow_badges_label'}} {{i18n 'category.allow_badges_label'}}
</div> </div>
</div> </div>

View file

@ -1,7 +1,7 @@
<div {{bind-attr class="loading:invisible"}}> <div>
<ul class="nav nav-pills"> <ul class="nav nav-pills">
{{edit-category-tab selectedTab=selectedTab tab="general"}} {{edit-category-tab selectedTab=selectedTab tab="general"}}
{{#unless isUncategorizedCategory}} {{#unless model.isUncategorizedCategory}}
{{edit-category-tab selectedTab=selectedTab tab="security"}} {{edit-category-tab selectedTab=selectedTab tab="security"}}
{{/unless}} {{/unless}}
{{edit-category-tab selectedTab=selectedTab tab="settings"}} {{edit-category-tab selectedTab=selectedTab tab="settings"}}
@ -16,11 +16,11 @@
<div class="modal-footer"> <div class="modal-footer">
<button class='btn btn-primary' {{bind-attr disabled="disabled"}} {{action "saveCategory"}}>{{buttonTitle}}</button> <button class='btn btn-primary' {{bind-attr disabled="disabled"}} {{action "saveCategory"}}>{{buttonTitle}}</button>
{{#if can_delete}} {{#if model.can_delete}}
<button class='btn btn-danger pull-right' {{bind-attr disabled="deleteDisabled"}} {{action "deleteCategory"}}><i class="fa fa-trash-o"></i>{{deleteButtonTitle}}</button> <button class='btn btn-danger pull-right' {{bind-attr disabled="deleteDisabled"}} {{action "deleteCategory"}}><i class="fa fa-trash-o"></i>{{deleteButtonTitle}}</button>
{{else}} {{else}}
<div class="cannot_delete_reason"> <div class="cannot_delete_reason">
{{{cannot_delete_reason}}} {{{model.cannot_delete_reason}}}
</div> </div>
{{/if}} {{/if}}
</div> </div>

View file

@ -19,7 +19,7 @@
{{/if}} {{/if}}
{{#if canEditCategory}} {{#if canEditCategory}}
{{d-button class="btn-default" action="editCategory" actionParam=category icon="wrench" label="category.edit_long"}} {{d-button class="btn-default edit-category" action="editCategory" actionParam=category icon="wrench" label="category.edit_long"}}
{{/if}} {{/if}}
<section class='category-heading'> <section class='category-heading'>

View file

@ -0,0 +1,17 @@
import { acceptance } from "helpers/qunit-helpers";
acceptance("Category Edit", { loggedIn: true });
test("Can edit a category", (assert) => {
visit("/c/bug");
click('.edit-category');
andThen(() => {
assert.ok(visible('#discourse-modal'), 'it pops up a modal');
});
click('a.close');
andThen(() => {
assert.ok(!visible('#discourse-modal'), 'it closes the modal');
});
});

View file

@ -0,0 +1,3 @@
export default {
"/c/1/show.json": {"category":{"id":1,"name":"bug","color":"e9dd00","text_color":"000000","slug":"bug","topic_count":2030,"post_count":13418,"description":"A bug report means something is broken, preventing normal/typical use of Discourse. Do be sure to search prior to submitting bugs. Include repro steps, and only describe one bug per topic please.","description_text":"A bug report means something is broken, preventing normal/typical use of Discourse. Do be sure to search prior to submitting bugs. Include repro steps, and only describe one bug per topic please.","topic_url":"/t/category-definition-for-bug/2","read_restricted":false,"permission":null,"notification_level":null,"logo_url":null,"background_url":null,"available_groups":["admins","discourse","everyone","moderators","staff","translators","trust_level_0","trust_level_1","trust_level_2","trust_level_3","trust_level_4"],"auto_close_hours":null,"auto_close_based_on_last_post":false,"group_permissions":[{"permission_type":1,"group_name":"everyone"}],"position":25,"cannot_delete_reason":"Can't delete this category because it has 2030 topics. Oldest topic is <a href=\"https://localhost:3000/t/when-a-new-post-appears-in-a-topic-the-bookmark-isn-t-updated/39\">When a new post appears in a topic, the bookmark isn't updated</a>.","allow_badges":true}}
};

File diff suppressed because one or more lines are too long