From 960d64930cacdc695e50fcf4d8dcb428a091641b Mon Sep 17 00:00:00 2001 From: Wojciech Zawistowski Date: Tue, 13 May 2014 08:53:11 -0400 Subject: [PATCH] Wiki Post --- .../discourse/controllers/history.js.es6 | 15 +++++ .../discourse/controllers/topic_controller.js | 4 ++ .../javascripts/discourse/models/post.js | 21 +++++- .../templates/modal/history.js.handlebars | 5 ++ .../discourse/templates/post.js.handlebars | 3 + .../discourse/views/post_menu_view.js | 51 ++++++++++++--- .../javascripts/discourse/views/post_view.js | 6 ++ .../stylesheets/common/base/history.scss | 3 + .../stylesheets/desktop/topic-post.scss | 44 ++++++++++++- app/assets/stylesheets/mobile/discourse.scss | 4 ++ app/assets/stylesheets/mobile/topic-post.scss | 50 +++++++++++++- app/controllers/posts_controller.rb | 11 ++++ app/models/post.rb | 2 +- app/models/post_revision.rb | 13 +++- app/serializers/post_revision_serializer.rb | 3 +- app/serializers/post_serializer.rb | 3 +- config/locales/client.en.yml | 3 + config/locales/server.en.yml | 2 + config/routes.rb | 1 + config/site_settings.yml | 5 +- .../20140408061512_add_wiki_to_posts.rb | 5 ++ lib/guardian/post_guardian.rb | 22 ++++++- spec/components/guardian_spec.rb | 65 +++++++++++++++++++ spec/controllers/posts_controller_spec.rb | 39 +++++++++++ spec/models/post_revision_spec.rb | 8 +++ .../fixtures/site_settings_fixtures.js | 2 +- 26 files changed, 371 insertions(+), 19 deletions(-) create mode 100644 db/migrate/20140408061512_add_wiki_to_posts.rb diff --git a/app/assets/javascripts/discourse/controllers/history.js.es6 b/app/assets/javascripts/discourse/controllers/history.js.es6 index 9e458cde97d..6f43cff99d7 100644 --- a/app/assets/javascripts/discourse/controllers/history.js.es6 +++ b/app/assets/javascripts/discourse/controllers/history.js.es6 @@ -60,6 +60,21 @@ export default Discourse.ObjectController.extend(Discourse.ModalFunctionality, { }.property("viewMode", "category_changes"), + wiki_diff: function() { + var viewMode = this.get("viewMode"); + var changes = this.get("wiki_changes"); + if (changes === null) { return; } + + if (viewMode === "inline") { + var diff = changes["current_wiki"] ? '' : ''; + return "
" + diff + "
"; + } else { + var prev = changes["previous_wiki"] ? '' : " "; + var curr = changes["current_wiki"] ? '' : ''; + return "
" + prev + "
" + curr + "
"; + } + }.property("viewMode", "wiki_changes"), + title_diff: function() { var viewMode = this.get("viewMode"); if(viewMode === "side_by_side_markdown") { diff --git a/app/assets/javascripts/discourse/controllers/topic_controller.js b/app/assets/javascripts/discourse/controllers/topic_controller.js index da9a63c7345..467956224e3 100644 --- a/app/assets/javascripts/discourse/controllers/topic_controller.js +++ b/app/assets/javascripts/discourse/controllers/topic_controller.js @@ -243,6 +243,10 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected }).finally(function() { self.set('loadingExpanded', false); }); + }, + + toggleWiki: function(post) { + post.toggleProperty('wiki'); } }, diff --git a/app/assets/javascripts/discourse/models/post.js b/app/assets/javascripts/discourse/models/post.js index 7517a0e9589..40acf44a244 100644 --- a/app/assets/javascripts/discourse/models/post.js +++ b/app/assets/javascripts/discourse/models/post.js @@ -80,6 +80,25 @@ Discourse.Post = Discourse.Model.extend({ }.observes('bookmarked'), + wikiChanged: function() { + var self = this; + + Discourse.ajax('/posts/' + this.get('id') + '/wiki', { + type: 'PUT', + data: { + wiki: this.get('wiki') ? true : false + } + }).then(function() { + self.incrementProperty('version'); + }, function(error) { + if (error && error.responseText) { + bootbox.alert($.parseJSON(error.responseText).errors[0]); + } else { + bootbox.alert(I18n.t('generic_error')); + } + }); + }.observes('wiki'), + internalLinks: function() { if (this.blank('link_counts')) return null; return this.get('link_counts').filterProperty('internal').filterProperty('title'); @@ -439,5 +458,3 @@ Discourse.Post.reopenClass({ } }); - - diff --git a/app/assets/javascripts/discourse/templates/modal/history.js.handlebars b/app/assets/javascripts/discourse/templates/modal/history.js.handlebars index 81d75ffdf01..65122ee8d72 100644 --- a/app/assets/javascripts/discourse/templates/modal/history.js.handlebars +++ b/app/assets/javascripts/discourse/templates/modal/history.js.handlebars @@ -35,6 +35,11 @@ {{boundAvatar user_changes.previous imageSize="small"}} {{user_changes.previous.username}} → {{boundAvatar user_changes.current imageSize="small"}} {{user_changes.current.username}} {{/if}} + {{#if wiki_changes}} +
+ {{{wiki_diff}}} +
+ {{/if}} {{{body_diff}}} diff --git a/app/assets/javascripts/discourse/templates/post.js.handlebars b/app/assets/javascripts/discourse/templates/post.js.handlebars index 0d7c9693bd5..468fb5fb133 100644 --- a/app/assets/javascripts/discourse/templates/post.js.handlebars +++ b/app/assets/javascripts/discourse/templates/post.js.handlebars @@ -31,6 +31,9 @@ {{/unless}} + {{#if wiki}} +
+ {{/if}}
diff --git a/app/assets/javascripts/discourse/views/post_menu_view.js b/app/assets/javascripts/discourse/views/post_menu_view.js index d402327bb13..3a8dfe68b6d 100644 --- a/app/assets/javascripts/discourse/views/post_menu_view.js +++ b/app/assets/javascripts/discourse/views/post_menu_view.js @@ -21,18 +21,17 @@ Discourse.PostMenuView = Discourse.View.extend({ 'post.bookmarked', 'post.shareUrl', 'post.topic.deleted_at', - 'post.replies.length'), + 'post.replies.length', + 'post.wiki'), render: function(buffer) { var post = this.get('post'); - buffer.push("