From 907bb8d2c28353bcbc14da35e6d26b5caa023ab2 Mon Sep 17 00:00:00 2001 From: Joenio Costa Date: Tue, 20 Oct 2009 15:46:50 -0300 Subject: [PATCH] A profile can have multiple blogs --- app/controllers/my_profile/cms_controller.rb | 8 +++++++- app/models/blog.rb | 15 +++++++++------ app/models/blog_archives_block.rb | 16 +++++++++++----- app/models/profile.rb | 8 ++++---- app/views/box_organizer/_blog_archives_block.rhtml | 4 ++++ app/views/cms/_blog.rhtml | 48 +++++++++++++++++++++++++++++++++++++++++++++--- app/views/cms/edit.rhtml | 4 +++- app/views/cms/view.rhtml | 1 + app/views/profile_editor/_organization.rhtml | 57 ++++++++++++++++++++++++++++----------------------------- app/views/profile_editor/index.rhtml | 13 ++++++++----- db/migrate/074_move_title_to_name_from_blogs.rb | 15 +++++++++++++++ db/schema.rb | 2 +- features/blog.feature | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ features/edit_blog_archives_block.feature | 34 ++++++++++++++++++++++++++++++++++ features/step_definitions/noosfero_steps.rb | 36 +++++++++++++++++++++++++++++++----- features/step_definitions/webrat_steps.rb | 6 +++++- features/support/paths.rb | 9 +++++++++ lib/acts_as_filesystem.rb | 9 ++++++--- lib/authenticated_system.rb | 2 +- public/designs/icons/tango/Tango-mod/16x16/apps/text-editor.png | Bin 0 -> 724 bytes public/designs/icons/tango/Tango-mod/32x32/apps/text-editor.png | Bin 0 -> 1669 bytes public/designs/icons/tango/Tango-mod/48x48/apps/text-editor.png | Bin 0 -> 2529 bytes public/designs/icons/tango/Tango-mod/scalable/apps/text-editor.svg | 799 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ public/designs/icons/tango/style.css | 1 + public/images/control-panel/text-editor-disabled.png | Bin 2529 -> 0 bytes public/images/control-panel/text-editor-disabled.png | 1 + public/images/control-panel/text-editor-disabled.svg | 799 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- public/images/control-panel/text-editor-disabled.svg | 1 + public/javascripts/application.js | 25 +++++++++++++++++++++++++ public/stylesheets/common.css | 18 ++++++++++++++++++ public/stylesheets/controller_profile_editor.css | 16 ---------------- test/functional/cms_controller_test.rb | 22 ++++++---------------- test/functional/content_viewer_controller_test.rb | 4 ++-- test/functional/tasks_controller_test.rb | 4 ++-- test/unit/article_test.rb | 7 +++++++ test/unit/blog_archives_block_test.rb | 28 +++++++++++++++++++++++----- test/unit/blog_test.rb | 16 ++++++++++++++++ test/unit/profile_test.rb | 9 +++++++++ 38 files changed, 1221 insertions(+), 905 deletions(-) create mode 100644 app/views/box_organizer/_blog_archives_block.rhtml create mode 100644 db/migrate/074_move_title_to_name_from_blogs.rb create mode 100644 features/blog.feature create mode 100644 features/edit_blog_archives_block.feature create mode 100644 public/designs/icons/tango/Tango-mod/16x16/apps/text-editor.png create mode 100644 public/designs/icons/tango/Tango-mod/32x32/apps/text-editor.png create mode 100644 public/designs/icons/tango/Tango-mod/48x48/apps/text-editor.png create mode 100644 public/designs/icons/tango/Tango-mod/scalable/apps/text-editor.svg delete mode 100644 public/images/control-panel/text-editor-disabled.png create mode 120000 public/images/control-panel/text-editor-disabled.png delete mode 100644 public/images/control-panel/text-editor-disabled.svg create mode 120000 public/images/control-panel/text-editor-disabled.svg diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 352fc37..7d0a34a 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -275,7 +275,7 @@ class CmsController < MyProfileController elsif @article.parent redirect_to :action => 'view', :id => @article.parent else - redirect_to :action => 'index' + redirect_back_or_default :action => 'index' end end @@ -286,6 +286,9 @@ class CmsController < MyProfileController @back_to = 'public_view' @back_url = @article.view_url end + if !request.post? and @article.blog? + store_location(request.referer) + end end def record_creating_from_public_view @@ -294,6 +297,9 @@ class CmsController < MyProfileController @back_to = 'public_view' @back_url = referer end + if !request.post? and @article.blog? + store_location(request.referer) + end end def maybe_ssl(url) diff --git a/app/models/blog.rb b/app/models/blog.rb index b9228ef..156d8f3 100644 --- a/app/models/blog.rb +++ b/app/models/blog.rb @@ -11,12 +11,6 @@ class Blog < Folder end settings_items :posts_per_page, :type => :integer, :default => 5 - settings_items :title, :type => :string, :default => N_('Blog') - - def initialize(*args) - super(*args) - self.name = 'blog' - end def self.short_description _('Blog') @@ -96,4 +90,13 @@ class Blog < Folder end end + def name=(value) + self.set_name(value) + if self.slug.blank? + self.slug = self.name.to_slug + else + self.slug = self.slug.to_slug + end + end + end diff --git a/app/models/blog_archives_block.rb b/app/models/blog_archives_block.rb index fe41ff3..47a851d 100644 --- a/app/models/blog_archives_block.rb +++ b/app/models/blog_archives_block.rb @@ -14,21 +14,27 @@ class BlogArchivesBlock < Block _('Blog posts') end + settings_items :blog_id, Integer + + def blog + blog_id ? owner.blogs.find(blog_id) : owner.blog + end + def content - return nil unless owner.has_blog? + owner_blog = self.blog + return nil unless owner_blog results = '' - posts = owner.blog.posts - posts.group_by {|i| i.published_at.year }.sort_by { |year,count| -year }.each do |year, results_by_year| + owner_blog.posts.group_by {|i| i.published_at.year }.sort_by { |year,count| -year }.each do |year, results_by_year| results << content_tag('li', content_tag('strong', "#{year} (#{results_by_year.size})")) results << "" end block_title(title) + content_tag('ul', results, :class => 'blog-archives') + - content_tag('div', link_to(_('Subscribe RSS Feed'), owner.blog.feed.url), :class => 'subscribe-feed') + content_tag('div', link_to(_('Subscribe RSS Feed'), owner_blog.feed.url), :class => 'subscribe-feed') end end diff --git a/app/models/profile.rb b/app/models/profile.rb index 5a0e3b3..452cb4b 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -590,14 +590,14 @@ private :generate_url, :url_options LayoutTemplate.find(layout_template).number_of_boxes end + has_many :blogs, :source => 'articles', :class_name => 'Blog' + def blog - if self.has_blog? - self.articles.find(:first, :conditions => {:type => 'Blog'}) - end + self.has_blog? ? self.blogs.first : nil end def has_blog? - !self.articles.count(:conditions => {:type => 'Blog'}).zero? + self.blogs.count.nonzero? end def admins diff --git a/app/views/box_organizer/_blog_archives_block.rhtml b/app/views/box_organizer/_blog_archives_block.rhtml new file mode 100644 index 0000000..95308b6 --- /dev/null +++ b/app/views/box_organizer/_blog_archives_block.rhtml @@ -0,0 +1,4 @@ +<% blogs = @block.box.owner.blogs %> +<% if blogs.count > 1 %> + <%= labelled_form_field _('Choose a blog:'), select('block', 'blog_id', blogs.map {|item| [ item.path, item.id ]}, :selected => @block.blog.id) %> +<% end %> diff --git a/app/views/cms/_blog.rhtml b/app/views/cms/_blog.rhtml index 5e529af..f9993aa 100644 --- a/app/views/cms/_blog.rhtml +++ b/app/views/cms/_blog.rhtml @@ -4,7 +4,51 @@ <%= render :file => 'shared/tiny_mce' %> -<%= f.text_field('title', :size => '64') %> +<%= required f.text_field(:name, :size => '64', :onchange => "updateUrlField(this, 'article_slug')") %> + + + +<%= hidden_field_tag 'old_article_slug', @article.slug %> +
+ <%= labelled_form_field( _('Address'), + content_tag('code', + url_for(@article.url).gsub(/#{@article.slug}$/, '') + + text_field(:article, :slug, :onchange => "warn_value_change()", :size => 25) + ) + + content_tag('div', + content_tag('strong', _('WARNING!')) + ' ' + + _("You are about to change the address, and this will break external links to this blog or to posts inside it. Do you really want to change?") + + content_tag('div', + button_to_function(:ok, _("Yes"), "confirm_change()") + ' ' + + button_to_function(:cancel, _('No'), 'no_change()') + ), + :id => 'slug-change-confirmation', + :class => 'change-confirmation', + :style => 'display: none;' + ) + ) + %> +
<%= labelled_form_field(_('Description:'), text_area(:article, :body, :cols => 64, :rows => 10)) %> @@ -34,5 +78,3 @@ <% end %> - -<%= javascript_tag "$('back_to').value = 'control_panel'" %> diff --git a/app/views/cms/edit.rhtml b/app/views/cms/edit.rhtml index 5175398..aee8956 100644 --- a/app/views/cms/edit.rhtml +++ b/app/views/cms/edit.rhtml @@ -37,7 +37,9 @@ <% button_bar do %> <%= submit_button :save, _('Save') %> - <% if @back_url %> + <% if @return_to %> + <%= button :cancel, _('Cancel'), @return_to %> + <% elsif @back_url %> <%= button :cancel, _('Cancel'), @back_url %> <% elsif @parent_id || @article.parent %> <%= button :cancel, _('Cancel'), :action => 'view', :id => @parent_id || @article.parent %> diff --git a/app/views/cms/view.rhtml b/app/views/cms/view.rhtml index 7a1ec9a..d339eab 100644 --- a/app/views/cms/view.rhtml +++ b/app/views/cms/view.rhtml @@ -7,6 +7,7 @@ <% if !@article or !@article.blog? %> <%= button :newfolder, _('New folder'), :action => 'new', :type => 'Folder', :parent_id => parent_id %> + <%= button :newblog, _('New Blog'), :action => 'new', :type => 'Blog', :parent_id => parent_id %> <%= button('upload-file', _('Upload files'), :action => 'upload_files', :parent_id => parent_id) %> <% end %> <%= lightbox_button('new', label_for_new_article(@article), :action => 'new', :parent_id => parent_id) %> diff --git a/app/views/profile_editor/_organization.rhtml b/app/views/profile_editor/_organization.rhtml index 395a311..46098e9 100644 --- a/app/views/profile_editor/_organization.rhtml +++ b/app/views/profile_editor/_organization.rhtml @@ -2,16 +2,6 @@ <%= required_fields_message if @profile.required_fields.any? %> -<% if @environment.enabled?('enable_organization_url_change') %> - -<% end %> -
@@ -23,33 +13,42 @@ <% if @environment.enabled?('enable_organization_url_change') %> <%= hidden_field_tag 'old_profile_identifier', @profile.identifier %>
<%= labelled_form_field( _('Address'), - '' + url_for(profile.url).gsub(/#{profile.identifier}$/, '') + - text_field(:profile_data, :identifier, :onchange => "warn_value_change(this)", :size => 15) + '' + - content_tag('div', '' + _('WARNING!') + ' ' + _("You are about to change the address, and this will break external links to the homepage or to content inside it. Do you really want to change? ") + - '
' + button_to_function(:ok, _("Yes"), 'hide_warning()') + ' ' + - button_to_function(:cancel, _('No'), '$("profile_data_identifier").value = $("old_profile_identifier").value; hide_warning()') + '
', - :id => 'identifier-change-confirmation', :style => 'display: none;' - ) + content_tag('code', + url_for(profile.url).gsub(/#{profile.identifier}$/, '') + + text_field(:profile_data, :identifier, :onchange => "warn_value_change()", :size => 25) + ) + + content_tag('div', + content_tag('strong', _('WARNING!')) + ' ' + + _("You are about to change the address, and this will break external links to the homepage or to content inside it. Do you really want to change?") + + content_tag('div', + button_to_function(:ok, _("Yes"), "confirm_change()") + ' ' + + button_to_function(:cancel, _('No'), 'no_change()') + ), + :id => 'identifier-change-confirmation', + :class => 'change-confirmation', + :style => 'display: none;' + ) ) %>
diff --git a/app/views/profile_editor/index.rhtml b/app/views/profile_editor/index.rhtml index 8244e40..25717a8 100644 --- a/app/views/profile_editor/index.rhtml +++ b/app/views/profile_editor/index.rhtml @@ -27,11 +27,14 @@ <%= control_panel_button(_('Manage Content'), 'cms', :controller => 'cms') if !environment.enabled?('disable_cms') || profile.community? %> <% unless profile.enterprise? %> - <% if profile.has_blog? %> - <%= control_panel_button(_('Configure blog'), 'blog', :controller => 'cms', :action => 'edit', :id => profile.blog) %> - <% else %> - <%= control_panel_button(_('Create blog'), 'blog-disabled', :controller => 'cms', :action => 'new', :type => 'Blog') %> - <% end %> + <%= case profile.blogs.count + when 0 + control_panel_button(_('Create blog'), 'blog-disabled', :controller => 'cms', :action => 'new', :type => 'Blog') + when 1 + control_panel_button(_('Configure blog'), 'blog', :controller => 'cms', :action => 'edit', :id => profile.blog) + else + control_panel_button(_('Configure blog'), 'blog', :controller => 'cms') + end %> <% end %> <%= control_panel_button(_('Change Password'), 'change-password', :controller => 'account', :action => 'change_password') if profile.person? %> diff --git a/db/migrate/074_move_title_to_name_from_blogs.rb b/db/migrate/074_move_title_to_name_from_blogs.rb new file mode 100644 index 0000000..f404907 --- /dev/null +++ b/db/migrate/074_move_title_to_name_from_blogs.rb @@ -0,0 +1,15 @@ +class MoveTitleToNameFromBlogs < ActiveRecord::Migration + def self.up + Blog.find(:all).each do |blog| + blog.name = blog.title + blog.save + end + end + + def self.down + Blog.find(:all).each do |blog| + blog.title = blog.name + blog.save + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 59854da..942106e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -9,7 +9,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 73) do +ActiveRecord::Schema.define(:version => 74) do create_table "article_versions", :force => true do |t| t.integer "article_id" diff --git a/features/blog.feature b/features/blog.feature new file mode 100644 index 0000000..b557a65 --- /dev/null +++ b/features/blog.feature @@ -0,0 +1,89 @@ +Feature: blog + As a noosfero user + I want to have one or mutiple blogs + + Background: + Given I am on the homepage + And the following users + | login | name | + | joaosilva | Joao Silva | + And I am logged in as "joaosilva" + + Scenario: create a blog + Given I follow "Control panel" + And I follow "Create blog" + Then I should see "My Blog" + When I fill in "Title" with "My Blog" + And I press "Save" + And I follow "Control panel" + Then I should see "Configure blog" + + Scenario: redirect to control panel after create blog + Given I follow "Control panel" + And I follow "Create blog" + Then I should see "My Blog" + When I fill in "Title" with "My Blog" + And I press "Save" + Then I should be on /myprofile/joaosilva + + Scenario: redirect to cms after create blog + Given I follow "Control panel" + And I follow "Manage Content" + When I follow "New Blog" + Then I should see "My Blog" + When I fill in "Title" with "My Blog" + And I press "Save" + Then I should be on /myprofile/joaosilva/cms + + Scenario: create multiple blogs + Given I follow "Control panel" + And I follow "Manage Content" + And I follow "New Blog" + And I fill in "Title" with "Blog One" + And I press "Save" + And I follow "New Blog" + And I fill in "Title" with "Blog Two" + And I press "Save" + Then I should not see "error" + And I should be on /myprofile/joaosilva/cms + + Scenario: cancel button back to cms + Given I follow "Control panel" + And I follow "Manage Content" + And I follow "New Blog" + When I follow "Cancel" + Then I should be on /myprofile/joaosilva/cms + + Scenario: cancel button back to myprofile + Given I follow "Control panel" + And I follow "Create blog" + When I follow "Cancel" + Then I should be on /myprofile/joaosilva + + Scenario: configure blog link to cms + Given the following blogs + | owner | name | + | joaosilva | Blog One | + | joaosilva | Blog Two | + And I follow "Control panel" + When I follow "Configure blog" + Then I should be on /myprofile/joaosilva/cms + + Scenario: configure blog link to edit blog + Given the following blogs + | owner | name | + | joaosilva | Blog One | + And I follow "Control panel" + When I follow "Configure blog" + Then I should be on edit "Blog One" by joaosilva + + Scenario: change address of blog + Given the following blogs + | owner | name | + | joaosilva | Blog One | + And I follow "Control panel" + And I follow "Configure blog" + And I fill in "Address" with "blog-two" + And I press "Save" + When I am on /joaosilva/blog-two + Then I should see "Blog One" diff --git a/features/edit_blog_archives_block.feature b/features/edit_blog_archives_block.feature new file mode 100644 index 0000000..f550849 --- /dev/null +++ b/features/edit_blog_archives_block.feature @@ -0,0 +1,34 @@ +Feature: edit_blog_archives_block + As a blog owner + I want to edit a Blog Archive Block + + Scenario: not offer to select blog when I have once blog + Given I am on the homepage + And the following users + | login | name | + | joaosilva | Joao Silva | + And the following blogs + | owner | name | + | joaosilva | Blog One | + And the following blocks + | owner | type | + | joaosilva | BlogArchivesBlock | + And I am logged in as "joaosilva" + When I go to edit BlogArchivesBlock of joaosilva + Then I should not see "Choose a blog:" + + Scenario: offer to select blog when I have multiple blogs + Given I am on the homepage + And the following users + | login | name | + | joaosilva | Joao Silva | + And the following blogs + | owner | name | + | joaosilva | Blog One | + | joaosilva | Blog Two | + And the following blocks + | owner | type | + | joaosilva | BlogArchivesBlock | + And I am logged in as "joaosilva" + When I go to edit BlogArchivesBlock of joaosilva + Then I should see "Choose a blog:" diff --git a/features/step_definitions/noosfero_steps.rb b/features/step_definitions/noosfero_steps.rb index 48d4a65..f5ae66b 100644 --- a/features/step_definitions/noosfero_steps.rb +++ b/features/step_definitions/noosfero_steps.rb @@ -19,16 +19,37 @@ Given /^the following enterprises$/ do |table| end end -Given /^the following (articles|events)$/ do |content, table| +Given /^the following blocks$/ do |table| + table.hashes.map{|item| item.dup}.each do |item| + klass = item.delete('type') + owner = Profile[item.delete('owner')] + box_id = owner.boxes.last.id + klass.constantize.create!(item.merge(:box_id => box_id)) + end +end + +Given /^the following (articles|events|blogs)$/ do |content, table| klass = { 'articles' => TextileArticle, 'events' => Event, + 'blogs' => Blog, }[content] || raise("Don't know how to build %s" % content) - table.hashes.each do |item| - data = item.dup - owner_identifier = data.delete("owner") + table.hashes.map{|item| item.dup}.each do |item| + owner_identifier = item.delete("owner") owner = Profile[owner_identifier] - TextileArticle.create!(data.merge(:profile => owner)) + klass.create!(item.merge(:profile => owner)) + end +end + +Given /^the following files$/ do |table| + table.hashes.each do |item| + owner = Profile[item[:owner]] + file = "/files/#{item[:file]}" + article = UploadedFile.create!(:profile => owner, :uploaded_data => fixture_file_upload(file, item[:mime])) + if item[:homepage] + owner.home_page = article + owner.save! + end end end @@ -40,3 +61,8 @@ Given /^the following products$/ do |table| end end +Given /^I am logged in as "(.+)"$/ do |username| + fill_in("Username", :with => username) + fill_in("Password", :with => '123456') + click_button("Log in") +end diff --git a/features/step_definitions/webrat_steps.rb b/features/step_definitions/webrat_steps.rb index 5fe991d..2cd3cc2 100644 --- a/features/step_definitions/webrat_steps.rb +++ b/features/step_definitions/webrat_steps.rb @@ -186,4 +186,8 @@ end Then /^show me the page$/ do save_and_open_page -end \ No newline at end of file +end + +Then /^the source should contain tag ([^\"]+)$/ do |tag| + response_body.should have_tag(tag, {id => 10}) +end diff --git a/features/support/paths.rb b/features/support/paths.rb index 84c52da..3961cda 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -13,7 +13,16 @@ module NavigationHelpers when /^\// page_name + + when /edit "(.+)" by (.+)/ + article_id = Person[$2].articles.find_by_slug($1.to_slug).id + "/myprofile/#{$2}/cms/edit/#{article_id}" + when /edit BlogArchivesBlock of (.+)/ + owner = Profile[$1] + block = BlogArchivesBlock.find(:all).select{|i| i.owner == owner}.first + "/myprofile/#{$1}/profile_design/edit/#{block.id}" + # Add more mappings here. # Here is a more fancy example: # diff --git a/lib/acts_as_filesystem.rb b/lib/acts_as_filesystem.rb index 7e505a0..b9aea69 100644 --- a/lib/acts_as_filesystem.rb +++ b/lib/acts_as_filesystem.rb @@ -97,13 +97,16 @@ module ActsAsFileSystem self.children.empty? end - # sets the name of the category. Also sets #slug accordingly. - def name=(value) + def set_name(value) if self.name != value self.recalculate_path = true end - self[:name] = value + end + + # sets the name of the category. Also sets #slug accordingly. + def name=(value) + self.set_name(value) unless self.name.blank? self.slug = self.name.to_slug end diff --git a/lib/authenticated_system.rb b/lib/authenticated_system.rb index 70ded91..161eaa7 100644 --- a/lib/authenticated_system.rb +++ b/lib/authenticated_system.rb @@ -80,7 +80,7 @@ module AuthenticatedSystem # # We can return to this location by calling #redirect_back_or_default. def store_location(location = request.request_uri) - session[:return_to] = location + @return_to = session[:return_to] = location end # Redirect to the URI stored by the most recent store_location call or diff --git a/public/designs/icons/tango/Tango-mod/16x16/apps/text-editor.png b/public/designs/icons/tango/Tango-mod/16x16/apps/text-editor.png new file mode 100644 index 0000000..a7d1587 Binary files /dev/null and b/public/designs/icons/tango/Tango-mod/16x16/apps/text-editor.png differ diff --git a/public/designs/icons/tango/Tango-mod/32x32/apps/text-editor.png b/public/designs/icons/tango/Tango-mod/32x32/apps/text-editor.png new file mode 100644 index 0000000..6edca4c Binary files /dev/null and b/public/designs/icons/tango/Tango-mod/32x32/apps/text-editor.png differ diff --git a/public/designs/icons/tango/Tango-mod/48x48/apps/text-editor.png b/public/designs/icons/tango/Tango-mod/48x48/apps/text-editor.png new file mode 100644 index 0000000..0a7094b Binary files /dev/null and b/public/designs/icons/tango/Tango-mod/48x48/apps/text-editor.png differ diff --git a/public/designs/icons/tango/Tango-mod/scalable/apps/text-editor.svg b/public/designs/icons/tango/Tango-mod/scalable/apps/text-editor.svg new file mode 100644 index 0000000..df3d1b1 --- /dev/null +++ b/public/designs/icons/tango/Tango-mod/scalable/apps/text-editor.svg @@ -0,0 +1,799 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + Jakub Steiner + + + http://jimmac.musichall.cz + + Text Editor + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/designs/icons/tango/style.css b/public/designs/icons/tango/style.css index 264de25..9f602aa 100644 --- a/public/designs/icons/tango/style.css +++ b/public/designs/icons/tango/style.css @@ -5,6 +5,7 @@ .icon-new { background-image: url(Tango/16x16/actions/filenew.png) } .icon-close { background-image: url(Tango/16x16/actions/gtk-cancel.png) } .icon-newfolder { background-image: url(Tango/16x16/actions/folder-new.png) } +.icon-newblog { background-image: url(Tango-mod/16x16/apps/text-editor.png) } /*.icon-open { background-image: url(folder-open.gif) } UNUSED*/ /*.icon-cms { background-image: url(abiword_48.png) } UNUSED*/ .icon-save { background-image: url(Tango/16x16/actions/filesave.png) } diff --git a/public/images/control-panel/text-editor-disabled.png b/public/images/control-panel/text-editor-disabled.png deleted file mode 100644 index 0a7094b..0000000 Binary files a/public/images/control-panel/text-editor-disabled.png and /dev/null differ diff --git a/public/images/control-panel/text-editor-disabled.png b/public/images/control-panel/text-editor-disabled.png new file mode 120000 index 0000000..f6a674e --- /dev/null +++ b/public/images/control-panel/text-editor-disabled.png @@ -0,0 +1 @@ +../../designs/icons/tango/Tango-mod/48x48/apps/text-editor.png \ No newline at end of file diff --git a/public/images/control-panel/text-editor-disabled.svg b/public/images/control-panel/text-editor-disabled.svg deleted file mode 100644 index 2071605..0000000 --- a/public/images/control-panel/text-editor-disabled.svg +++ /dev/null @@ -1,799 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - Jakub Steiner - - - http://jimmac.musichall.cz - - Text Editor - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/public/images/control-panel/text-editor-disabled.svg b/public/images/control-panel/text-editor-disabled.svg new file mode 120000 index 0000000..637e5d9 --- /dev/null +++ b/public/images/control-panel/text-editor-disabled.svg @@ -0,0 +1 @@ +../../designs/icons/tango/Tango-mod/scalable/apps/text-editor.svg \ No newline at end of file diff --git a/public/javascripts/application.js b/public/javascripts/application.js index acc19de..4d76cad 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -45,3 +45,28 @@ function convToValidIdentifier( str, sep ) { .replace( /รง/g, "c" ) .replace( /[^-_a-z0-9.]+/g, sep ) } + +function updateUrlField(name_field, id) { + url_field = $(id); + url_field.value = convToValidIdentifier(name_field.value, "-"); + warn_value_change(url_field); +} + +function show_warning(field, message) { + new Effect.Highlight(field, {duration:3}); + $(message).show(); +} + +function hide_warning(field) { + $(field).hide(); +} + +function enable_button(button) { + button.enable(); + button.removeClassName("disabled"); +} + +function disable_button(button) { + button.disable(); + button.addClassName("disabled"); +} diff --git a/public/stylesheets/common.css b/public/stylesheets/common.css index d40dcbe..e17eb37 100644 --- a/public/stylesheets/common.css +++ b/public/stylesheets/common.css @@ -577,3 +577,21 @@ div.pending-tasks { .post-date { color: #E68A00; } + +/**** Change confirmation message ****/ + +.change-confirmation { + background-color: #ef2929; + border: 6px solid #a40000; + padding: 20px; + margin: 5px 30px 10px 30px; +} + +.change-confirmation div { + text-align: right; + padding: 20px 10px 0px 0px; +} + +code input { + font-family: monospace; +} diff --git a/public/stylesheets/controller_profile_editor.css b/public/stylesheets/controller_profile_editor.css index 234e3a8..87f95f4 100644 --- a/public/stylesheets/controller_profile_editor.css +++ b/public/stylesheets/controller_profile_editor.css @@ -31,22 +31,6 @@ -moz-border-radius: 3px; } -#identifier-change-confirmation { - background-color: #ef2929; - border: 6px solid #a40000; - padding: 20px; - margin: 5px 30px 10px 30px; -} - -#identifier-change-confirmation div { - text-align: right; - padding: 20px 10px 0px 0px; -} - -code input { - font-family: monospace; -} - a.control-panel-groups { background-image: url(../images/control-panel/system-users.png) } .msie6 a.control-panel-groups { background-image: url(../images/control-panel/system-users.gif) } diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index 69665c0..7b67457 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -583,7 +583,7 @@ class CmsControllerTest < Test::Unit::TestCase should 'record when coming from public view on edit' do article = @profile.articles.create!(:name => 'myarticle') - @request.expects(:referer).returns('http://colivre.net/testinguser/myarticle') + @request.expects(:referer).returns('http://colivre.net/testinguser/myarticle').at_least_once get :edit, :profile => 'testinguser', :id => article.id assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => 'public_view' } @@ -591,7 +591,7 @@ class CmsControllerTest < Test::Unit::TestCase end should 'detect when comming from home page' do - @request.expects(:referer).returns('http://colivre.net/testinguser') + @request.expects(:referer).returns('http://colivre.net/testinguser').at_least_once get :edit, :profile => 'testinguser', :id => @profile.home_page.id assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => 'public_view' } assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => /^https?:\/\/colivre.net\/testinguser\/#{@profile.home_page.slug}$/ } @@ -605,7 +605,7 @@ class CmsControllerTest < Test::Unit::TestCase end should 'record as coming from public view when creating article' do - @request.expects(:referer).returns('http://colivre.net/testinguser/testingusers-home-page') + @request.expects(:referer).returns('http://colivre.net/testinguser/testingusers-home-page').at_least_once get :new, :profile => 'testinguser', :type => 'TextileArticle' assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => 'public_view' } assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => 'http://colivre.net/testinguser/testingusers-home-page' } @@ -712,11 +712,6 @@ class CmsControllerTest < Test::Unit::TestCase assert_no_tag :tag => 'div', :descendant => { :tag => 'h4', :content => 'Categorize your article' } end - should 'not display input name on create blog' do - get :new, :profile => profile.identifier, :type => 'Blog' - assert_no_tag :tag => 'input', :attributes => { :name => 'article[name]', :type => 'text' } - end - should 'display posts per page input with default value on edit blog' do n = Blog.new.posts_per_page.to_s get :new, :profile => profile.identifier, :type => 'Blog' @@ -789,11 +784,6 @@ class CmsControllerTest < Test::Unit::TestCase assert_equal 5, profile.blog.posts_per_page end - should 'display input title on create blog' do - get :new, :profile => profile.identifier, :type => 'Blog' - assert_tag :tag => 'input', :attributes => { :name => 'article[title]', :type => 'text' } - end - should "display 'New article' when create children of folder" do a = Folder.new(:name => 'article folder'); profile.articles << a; a.save! Article.stubs(:short_description).returns('bli') @@ -868,7 +858,7 @@ class CmsControllerTest < Test::Unit::TestCase should 'record when coming from public view on upload files' do folder = Folder.create!(:name => 'testfolder', :profile => profile) - @request.expects(:referer).returns("http://colivre.net/#{profile.identifier}/#{folder.slug}") + @request.expects(:referer).returns("http://colivre.net/#{profile.identifier}/#{folder.slug}").at_least_once get :upload_files, :profile => profile.identifier, :parent_id => folder.id assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => 'public_view' } @@ -931,14 +921,14 @@ class CmsControllerTest < Test::Unit::TestCase end should "display 'Fetch posts from an external feed' checked if blog has enabled external feed" do - profile.articles << Blog.new(:title => 'test blog', :profile => profile) + profile.articles << Blog.new(:name => 'test blog', :profile => profile) profile.blog.create_external_feed(:address => 'address', :enabled => true) get :edit, :profile => profile.identifier, :id => profile.blog.id assert_tag :tag => 'input', :attributes => { :name => 'article[external_feed_builder][enabled]', :checked => 'checked' } end should "display 'Fetch posts from an external feed' unchecked if blog has disabled external feed" do - profile.articles << Blog.new(:title => 'test blog', :profile => profile) + profile.articles << Blog.new(:name => 'test blog', :profile => profile) profile.blog.create_external_feed(:address => 'address', :enabled => false) get :edit, :profile => profile.identifier, :id => profile.blog.id assert_tag :tag => 'input', :attributes => { :name => 'article[external_feed_builder][enabled]', :checked => nil } diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb index 5af6cff..6b6a008 100644 --- a/test/functional/content_viewer_controller_test.rb +++ b/test/functional/content_viewer_controller_test.rb @@ -719,14 +719,14 @@ class ContentViewerControllerTest < Test::Unit::TestCase should 'add meta tag to rss feed on view blog' do login_as(profile.identifier) - profile.articles << Blog.new(:title => 'article blog', :profile => profile) + profile.articles << Blog.new(:name => 'Blog', :profile => profile) get :view_page, :profile => profile.identifier, :page => ['blog'] assert_tag :tag => 'link', :attributes => { :rel => 'alternate', :type => 'application/rss+xml', :title => 'feed', :href => "http://#{environment.default_hostname}/testinguser/blog/feed" } end should 'add meta tag to rss feed on view post blog' do login_as(profile.identifier) - profile.articles << Blog.new(:name => 'article folder', :profile => profile) + profile.articles << Blog.new(:name => 'Blog', :profile => profile) profile.blog.posts << TextileArticle.new(:name => 'first post', :parent => profile.blog, :profile => profile) get :view_page, :profile => profile.identifier, :page => ['blog', 'first-post'] assert_tag :tag => 'link', :attributes => { :rel => 'alternate', :type => 'application/rss+xml', :title => 'feed', :href => "http://#{environment.default_hostname}/testinguser/blog/feed" } diff --git a/test/functional/tasks_controller_test.rb b/test/functional/tasks_controller_test.rb index 7b82093..b25cba0 100644 --- a/test/functional/tasks_controller_test.rb +++ b/test/functional/tasks_controller_test.rb @@ -208,8 +208,8 @@ class TasksControllerTest < Test::Unit::TestCase @controller.stubs(:profile).returns(c) c.affiliate(profile, Profile::Roles.all_roles(c.environment)) person = create_user('test_user').person - p_blog = Blog.create!(:profile => person) - c_blog1 = Blog.create!(:profile => c) + p_blog = Blog.create!(:profile => person, :name => 'Blog') + c_blog1 = Blog.create!(:profile => c, :name => 'Blog') c_blog2 = Blog.new(:profile => c); c_blog2.name = 'blog2'; c_blog2.save! article = person.articles.create!(:name => 'test article', :parent => p_blog) diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 62c325e..db98290 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -794,4 +794,11 @@ class ArticleTest < Test::Unit::TestCase assert a.allow_post_content?(p) end + should 'update slug from name' do + article = Article.create!(:name => 'A test article', :profile => profile) + assert_equal 'a-test-article', article.slug + article.name = 'Changed name' + assert_equal 'changed-name', article.slug + end + end diff --git a/test/unit/blog_archives_block_test.rb b/test/unit/blog_archives_block_test.rb index c7121a5..39c2103 100644 --- a/test/unit/blog_archives_block_test.rb +++ b/test/unit/blog_archives_block_test.rb @@ -4,7 +4,7 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase def setup @profile = create_user('flatline').person - @profile.articles << Blog.new(:name => 'blog-test', :profile => @profile) + @profile.articles << Blog.new(:name => 'Blog One', :profile => @profile) end attr_reader :profile @@ -34,11 +34,11 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase blog = profile.blog for i in 1..10 do post = TextileArticle.create!(:name => "post #{i} test", :profile => profile, :parent => blog) - post.update_attribute(:published_at, date) + assert post.update_attribute(:published_at, date) end block = BlogArchivesBlock.new block.stubs(:owner).returns(profile) - assert_tag_in_string block.content, :tag => 'a', :content => 'January (10)', :attributes => {:href => /^http:\/\/.*\/flatline\/blog\?month=01&year=2008$/ } + assert_tag_in_string block.content, :tag => 'a', :content => 'January (10)', :attributes => {:href => /^http:\/\/.*\/flatline\/blog-one\?month=01&year=2008$/ } end should 'order list of amount posts' do @@ -77,11 +77,29 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase end should 'not display any content if has no blog' do - profile.stubs(:has_blog?).returns(false) - assert !profile.has_blog? + profile.blogs.destroy_all block = BlogArchivesBlock.new block.stubs(:owner).returns(profile) assert_nil block.content end + should 'has field to configure blog' do + b = BlogArchivesBlock.new + assert b.respond_to?(:blog_id) + assert b.respond_to?(:blog_id=) + end + + should 'show posts from first blog' do + (blog_one, blog_two) = profile.blogs + profile.articles << Blog.new(:name => 'Blog Two', :profile => profile) + for month in 1..3 + TextileArticle.create!(:name => "blog one - post #{month}", :profile => profile, :parent => blog_one) + TextileArticle.create!(:name => "blog two - post #{month}", :profile => profile, :parent => blog_two) + end + block = BlogArchivesBlock.new + block.stubs(:owner).returns(profile) + assert_match(/blog-one/m, block.content) + assert_no_match(/blog-two/m, block.content) + end + end diff --git a/test/unit/blog_test.rb b/test/unit/blog_test.rb index 125d68c..8d357b6 100644 --- a/test/unit/blog_test.rb +++ b/test/unit/blog_test.rb @@ -139,4 +139,20 @@ class BlogTest < ActiveSupport::TestCase end end + should 'profile has more then one blog' do + p = create_user('testuser').person + Blog.create!(:name => 'Blog test', :profile => p) + assert_nothing_raised ActiveRecord::RecordInvalid do + Blog.create!(:name => 'Another Blog', :profile => p) + end + end + + should 'not update slug from name for existing blog' do + p = create_user('testuser').person + blog = Blog.create!(:name => 'Blog test', :profile => p) + assert_equal 'blog-test', blog.slug + blog.name = 'Changed name' + assert_not_equal 'changed-name', blog.slug + end + end diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index 2de1e7e..cbe0385 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -1393,6 +1393,15 @@ class ProfileTest < Test::Unit::TestCase assert_equal [c], profile.categories end + should 'get first blog when has multiple blogs' do + p = create_user('testuser').person + p.blogs << Blog.new(:profile => p, :name => 'Blog one') + p.blogs << Blog.new(:profile => p, :name => 'Blog two') + p.blogs << Blog.new(:profile => p, :name => 'Blog three') + assert_equal 'Blog one', p.blog.name + assert_equal 3, p.blogs.count + end + private def assert_invalid_identifier(id) -- libgit2 0.21.2