From 7b56b5c463c32db2796dc8f392874dd12604472c Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Tue, 27 Nov 2007 14:27:10 +0000 Subject: [PATCH] ActionItem21: checkpoint --- app/controllers/my_profile/cms_controller.rb | 17 ++++++++++++++++- app/models/profile.rb | 6 +----- app/views/cms/view.rhtml | 36 ++++++++++++++++++++++++++++++++++-- db/migrate/003_create_profiles.rb | 3 ++- public/images/icons-mime/README | 46 ++++++++++++++++++++++++++++++++++++++++++++++ public/images/icons-mime/gnome-mime-text-html.png | Bin 0 -> 1220 bytes public/images/icons-mime/text-html.png | 1 + public/stylesheets/common.css | 37 +++++++++++++++++++++++++++++++++++++ test/functional/cms_controller_test.rb | 28 ++++++++++++++++++++++++++-- test/unit/application_helper_test.rb | 11 +++++++++++ test/unit/profile_test.rb | 44 ++++++++++++-------------------------------- 11 files changed, 186 insertions(+), 43 deletions(-) create mode 100644 public/images/icons-mime/README create mode 100644 public/images/icons-mime/gnome-mime-text-html.png create mode 120000 public/images/icons-mime/text-html.png create mode 100644 test/unit/application_helper_test.rb diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 86124d9..45bc0a4 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -4,7 +4,22 @@ class CmsController < MyProfileController # protect 'post_content', :profile, :only => [:edit, :new, :reorder, :delete] def view - @document = profile.documents.find(params[:id]) + @article = profile.articles.find(params[:id]) + @subitems = @article.children + end + + def index + @article = profile.home_page + @subitems = profile.top_level_articles + render :action => 'view' + end + + post_only :set_home_page + def set_home_page + @article = profile.articles.find(params[:id]) + profile.home_page = @article + profile.save! + redirect_to :back end protected diff --git a/app/models/profile.rb b/app/models/profile.rb index 606d29f..ea905c3 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -43,6 +43,7 @@ class Profile < ActiveRecord::Base has_many :role_assignments, :as => :resource has_many :articles + belongs_to :home_page, :class_name => Article.name, :foreign_key => 'home_page_id' def top_level_articles(reload = false) if reload @@ -78,11 +79,6 @@ class Profile < ActiveRecord::Base find_tagged_with(term) + find_all_by_name(term) end - def homepage(reload = false) - # FIXME - raise 'needs to be implemented' - end - # Returns information about the profile's owner that was made public by # him/her. # diff --git a/app/views/cms/view.rhtml b/app/views/cms/view.rhtml index 4584344..b676991 100644 --- a/app/views/cms/view.rhtml +++ b/app/views/cms/view.rhtml @@ -1,3 +1,35 @@ -<%# FIXME %> +<% if @article %> +

+ <%= link_to profile.identifier, :action => 'index' %> + <%= @article.hierarchy.map {|item| " / " + ((item == @article) ? item.name : link_to(item.name, :id => item.id)) } %> +

+<% end %> -

<%= @document.title %>

+<%# list the children %> + +
+ +
+
    + <% @subitems.each do |item| %> +
  • + <%= file_manager_button(item.name, "icons-mime/#{item.icon_name}", :action => 'view', :id => item.id) %> +
  • + <% end %> +
+
+ + <% if @article %> + <%= link_to _('New subitem'), :action => 'new', :parent_id => @article.id %> + <% else %> + <%= link_to _('New article'), :action => 'new' %> + <% end %> + +
+ +<%# display the article content %> + +<% if @article %> +

<%= @article.name %>

+ <%= @article.to_html %> +<% end %> diff --git a/db/migrate/003_create_profiles.rb b/db/migrate/003_create_profiles.rb index 8047c85..f1f26b5 100644 --- a/db/migrate/003_create_profiles.rb +++ b/db/migrate/003_create_profiles.rb @@ -7,10 +7,11 @@ class CreateProfiles < ActiveRecord::Migration t.column :environment_id, :integer t.column :design_data, :text - t.column :active, :boolean, :default => true t.column :address, :string t.column :contact_phone, :string + + t.column :home_page_id, :integer #person fields t.column :user_id, :integer diff --git a/public/images/icons-mime/README b/public/images/icons-mime/README new file mode 100644 index 0000000..5e15e73 --- /dev/null +++ b/public/images/icons-mime/README @@ -0,0 +1,46 @@ +dlg-neu icons in Noosfero +========================= + +The icons in this directory are taken from the dlg-neu icon theme for GNOME, +section "mimetypes/". We take the SVG files and convert to 64x64 PNG images, so +these icons are in fact derived works based on dlg-neu's SVG files. + +Structure +========= + +To keep a trace back to dlg-neu theme, when rasterizing the SVG files we keep +the original filenames (replacing .svg by .png, obviously) and create symbolic +links with names more sensible for Noosfero. + +Icons rasterization +=================== + +With rsvg, from the librsvg2-bin package (i.e. we use the same rasterization +library as GNOME, so the icons must look like they do in GNOME). + +$ rsvg -w 64 -h 64 .svg .png + +Licensing +========= + +Their License is as follows (taken from +/usr/share/doc/gnome-icon-theme-dlg-neu/copyright on a Debian system): + + This package is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This package is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this package; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + 02110-1301 USA + +On Debian systems, the complete text of the GNU General +Public License can be found in `/usr/share/common-licenses/GPL'. + diff --git a/public/images/icons-mime/gnome-mime-text-html.png b/public/images/icons-mime/gnome-mime-text-html.png new file mode 100644 index 0000000..5693e7a Binary files /dev/null and b/public/images/icons-mime/gnome-mime-text-html.png differ diff --git a/public/images/icons-mime/text-html.png b/public/images/icons-mime/text-html.png new file mode 120000 index 0000000..16cc51f --- /dev/null +++ b/public/images/icons-mime/text-html.png @@ -0,0 +1 @@ +gnome-mime-text-html.png \ No newline at end of file diff --git a/public/stylesheets/common.css b/public/stylesheets/common.css index 830f317..fc7b681 100644 --- a/public/stylesheets/common.css +++ b/public/stylesheets/common.css @@ -96,10 +96,13 @@ margin-right: 20px; height: 20px; } +/* file manager (big) style */ + div.file-manager { clear: both; } +div.file-manager div.file-manager-button { float: left; width: 140px; @@ -108,9 +111,12 @@ div.file-manager-button { margin-top: 0.5em; } +div.file-manager div.file-manager-button a img { border: none; } + +div.file-manager div.file-manager-button a { border: 1px solid #e0e0e0; display: block; @@ -118,8 +124,39 @@ div.file-manager-button a { height: 80px; overflow: hidden; } + +div.file-manager div.file-manager-button a:hover { border: 1px solid #006; background: #acf; color: #006; } + +/************* file manager (small) style *****************/ +div.file-manager-small li { + list-style: none; +} + +div.file-manager-small +div.file-manager-button a div { + display: inline; +} + +div.file-manager-small +div.file-manager-button a img { + border: none; + vertical-align: middle; +} + +div.file-manager-small +div.file-manager-button a { + border: 1px solid transparent; +} + +div.file-manager-small +div.file-manager-button a:hover { + border: 1px solid #006; + background: #acf; + color: #006; +} + diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index cf72e63..31a2402 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -5,20 +5,40 @@ require 'cms_controller' class CmsController; def rescue_action(e) raise e end; end class CmsControllerTest < Test::Unit::TestCase + + fixtures :environments + def setup @controller = CmsController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new + + @profile = create_user('testinguser').person end attr_reader :profile should 'list top level documents on index' do - flunk 'not yet' + get :index, :profile => profile.identifier + + assert_template 'view' + assert_equal profile, assigns(:profile) + assert_nil assigns(:article) + assert_kind_of Array, assigns(:subitems) end should 'be able to view a particular document' do - flunk 'not yet' + + a = profile.articles.build(:name => 'blablabla') + a.save! + + get :view, :profile => profile.identifier, :id => a.id + + assert_template 'view' + assert_equal a, assigns(:article) + assert_equal [], assigns(:subitems) + + assert_kind_of Array, assigns(:subitems) end should 'be able to edit a document' do @@ -29,4 +49,8 @@ class CmsControllerTest < Test::Unit::TestCase flunk 'not yet' end + should 'be able to set home page' do + flunk 'pending' + end + end diff --git a/test/unit/application_helper_test.rb b/test/unit/application_helper_test.rb new file mode 100644 index 0000000..df74ff0 --- /dev/null +++ b/test/unit/application_helper_test.rb @@ -0,0 +1,11 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class ApplicationHelperTest < Test::Unit::TestCase + + include ApplicationHelper + + should 'generate control panel buttons' do + + end + +end diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index 0868f1c..0606e1f 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -46,11 +46,17 @@ class ProfileTest < Test::Unit::TestCase end end - def test_should_provide_access_to_homepage + should 'provide access to home page' do profile = Profile.create!(:identifier => 'newprofile', :name => 'New Profile') - page = profile.homepage - assert_kind_of Article, page - assert_equal profile.identifier, page.slug + assert_nil profile.home_page + + page = profile.articles.build(:name => "My custom home page") + page.save! + + profile.home_page = page + profile.save! + + assert_equal page, profile.home_page end def test_name_should_be_mandatory @@ -107,37 +113,11 @@ class ProfileTest < Test::Unit::TestCase end def test_should_provide_recent_documents - profile = Profile.create!(:name => 'Testing Recent documents', :identifier => 'testing_recent_documents') - doc1 = Article.new(:name => 'document 1', :body => 'la la la la la') - doc1.parent = profile.homepage - doc1.save! - - doc2 = Article.new(:name => 'document 2', :body => 'la la la la la') - doc2.parent = profile.homepage - doc2.save! - - docs = profile.recent_documents(2) - assert_equal 2, docs.size - assert docs.map(&:id).include?(doc1.id) - assert docs.map(&:id).include?(doc2.id) + flunk 'pending' end def test_should_provide_most_recent_documents - profile = Profile.create!(:name => 'Testing Recent documents', :identifier => 'testing_recent_documents') - doc1 = Article.new(:name => 'document 1', :body => 'la la la la la') - doc1.parent = profile.homepage - doc1.save! - - docs = profile.recent_documents(1) - assert_equal 1, docs.size - assert_equal doc1.id, docs.first.id - end - - should 'provide a contact_email method which returns a ... contact email address' do - p = Profile.create!(:name => 'Profile for testing ', :identifier => 'profilefortesting') - assert_nil p.contact_email - p.user = User.new(:email => 'testprofile@example.com') - assert_equal 'testprofile@example.com', p.contact_email + flunk 'pending' end should 'affiliate and provide a list of the affiliated users' do -- libgit2 0.21.2