From 275fdc75bcbff79e6e5ff4732c7dc0fdc3b8ed2a Mon Sep 17 00:00:00 2001 From: Daniela Soares Feitosa Date: Fri, 19 Dec 2008 15:56:01 -0300 Subject: [PATCH] ActionItem856: adding list of products in article EnterpriseHomepage --- app/helpers/application_helper.rb | 26 ++------------------------ app/helpers/catalog_helper.rb | 19 +++++++++++++++++++ app/helpers/display_helper.rb | 26 ++++++++++++++++++++++++++ app/helpers/enterprise_homepage_helper.rb | 1 - app/models/enterprise_homepage.rb | 6 +++++- app/views/catalog/index.rhtml | 28 +--------------------------- public/stylesheets/controller_catalog.css | 82 +--------------------------------------------------------------------------------- public/stylesheets/controller_content_viewer.css | 2 ++ public/stylesheets/products.css | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/unit/application_helper_test.rb | 4 +++- test/unit/enterprise_homepage_test.rb | 29 +++++++++++++++++++++++++++++ 11 files changed, 168 insertions(+), 135 deletions(-) create mode 100644 app/helpers/display_helper.rb create mode 100644 public/stylesheets/products.css diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6091096..6cdebe2 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -22,6 +22,8 @@ module ApplicationHelper include ProfileEditorHelper + include DisplayHelper + # Displays context help. You can pass the content of the help message as the # first parameter or using template code inside a block passed to this # method. *Note*: the block is ignored if content is not @@ -261,19 +263,6 @@ module ApplicationHelper concat(content_tag('div', capture(&block) + tag('br', :style => 'clear: left;'), { :class => 'button-bar' }.merge(options)), block.binding) end - def link_to_category(category, full = true) - return _('Uncategorized product') unless category - name = full ? category.full_name(' → ') : category.name - link_to name, :controller => 'search', :action => 'category_index', :category_path => category.path.split('/') - end - - def link_to_product(product, opts={}) - return _('No product') unless product - link_to content_tag( 'span', product.name ), - { :controller => 'catalog', :action => 'show', :id => product, :profile => product.enterprise.identifier }, - opts - end - def partial_for_class(klass) if klass.nil? raise ArgumentError, 'No partial for object. Is there a partial for any class in the inheritance hierarchy?' @@ -578,17 +567,6 @@ module ApplicationHelper end end - def txt2html(txt) - txt. - gsub( /\n\s*\n/, '

' ). - gsub( /\n/, '
' ). - gsub( /(^|\s)(www\.[^\s])/, '\1http://\2' ). - gsub( /(https?:\/\/([^\s]+))/, - '\2' ) - end - # Should be on the forms_helper file but when its there the translation of labels doesn't work class NoosferoFormBuilder < ActionView::Helpers::FormBuilder include GetText diff --git a/app/helpers/catalog_helper.rb b/app/helpers/catalog_helper.rb index 5db5cf8..984b5b4 100644 --- a/app/helpers/catalog_helper.rb +++ b/app/helpers/catalog_helper.rb @@ -1,2 +1,21 @@ module CatalogHelper + +include DisplayHelper + + def display_products_list(profile, products) + data = '' + products.each { |product| + + data << content_tag('li', + link_to_product(product, :class => 'product-pic', :style => 'background-image:url(%s)' % ( product.image ? product.image.public_filename(:portrait) : '/images/icons-app/product-default-pic-portrait.png' )) + + content_tag('h3', link_to_product(product)) + + content_tag('ul', + (product.price ? content_tag('li', _('Price: %s') % ( "%.2f" % product.price), :class => 'product_price') : '') + + content_tag('li', link_to_category(product.product_category), :class => 'product_category') + ) + + (product.description ? content_tag('div', txt2html(product.description), :class => 'description') : tag('br', :style => 'clear:both')), + :class => 'product') + } + content_tag('h1', _('Products/Services')) + content_tag('ul', data, :id => 'product_list') + end end diff --git a/app/helpers/display_helper.rb b/app/helpers/display_helper.rb new file mode 100644 index 0000000..09d82bf --- /dev/null +++ b/app/helpers/display_helper.rb @@ -0,0 +1,26 @@ +module DisplayHelper + + def link_to_product(product, opts={}) + return _('No product') unless product + link_to content_tag( 'span', product.name ), + product.enterprise.generate_url(:controller => 'catalog', :action => 'show', :id => product), + opts + end + + def link_to_category(category, full = true) + return _('Uncategorized product') unless category + name = full ? category.full_name(' → ') : category.name + link_to name, Noosfero.url_options.merge({:controller => 'search', :action => 'category_index', :category_path => category.path.split('/'),:host => category.environment.default_hostname }) + end + + def txt2html(txt) + txt. + gsub( /\n\s*\n/, '

' ). + gsub( /\n/, '
' ). + gsub( /(^|\s)(www\.[^\s])/, '\1http://\2' ). + gsub( /(https?:\/\/([^\s]+))/, + '\2' ) + end +end diff --git a/app/helpers/enterprise_homepage_helper.rb b/app/helpers/enterprise_homepage_helper.rb index bb46866..d0acffd 100644 --- a/app/helpers/enterprise_homepage_helper.rb +++ b/app/helpers/enterprise_homepage_helper.rb @@ -22,5 +22,4 @@ module EnterpriseHomepageHelper end content_tag('div', content_tag('ul', data), :class => 'enterprise-info') end - end diff --git a/app/models/enterprise_homepage.rb b/app/models/enterprise_homepage.rb index b4e2389..4e9069a 100644 --- a/app/models/enterprise_homepage.rb +++ b/app/models/enterprise_homepage.rb @@ -14,8 +14,12 @@ class EnterpriseHomepage < Article include ActionController::UrlWriter include ActionView::Helpers::AssetTagHelper include EnterpriseHomepageHelper + include CatalogHelper + def to_html - display_profile_info(self.profile) + content_tag('div', self.body || '') + products = self.profile.products + display_profile_info(self.profile) + content_tag('div', self.body || '') + + (self.profile.environment.enabled?('disable_products_for_enterprises') ? '' : display_products_list(self.profile, products)) end end diff --git a/app/views/catalog/index.rhtml b/app/views/catalog/index.rhtml index f76fc0c..20db5d1 100644 --- a/app/views/catalog/index.rhtml +++ b/app/views/catalog/index.rhtml @@ -1,27 +1 @@ -

<%= _('Products/Services') % @profile.name %>

- - - +<%= display_products_list @profile, @products %> diff --git a/public/stylesheets/controller_catalog.css b/public/stylesheets/controller_catalog.css index 0985b18..d9e075e 100644 --- a/public/stylesheets/controller_catalog.css +++ b/public/stylesheets/controller_catalog.css @@ -1,81 +1 @@ - -/* * * List Products * * * * * * * * * * * * */ - -#product_list { - margin: 0px; - padding: 0px; -} - -#product_list ul { - margin: 0px; - padding: 0px; -} - -#content #product_list li { - margin: 0px; - padding: 0px; - list-style: none; -} - -#content #product_list li.product { - border: 1px solid #888; - margin-bottom: 10px; - padding: 5px 10px; -} - -#product_list .product-pic { - display: block; - width: 64px; - height: 64px; - background-repeat: no-repeat; - background-position: 50% 50%; - float: left; - margin-right: 15px; - position: relative; /* work arround msie bug */ -} - -#product_list .product-pic span { - display: none; -} - -#content #product_list h3 { - margin: 0px; - padding: 0px; - font-size: 120%; -} -.msie #content #product_list h3 { - margin-top: -15px; -} -#product_list h3 a { - text-decoration: none; -} - -#product_list .product_category { - font-size: 11px; -} - -#product_list .description { - clear: left; - font-size: 11px; - text-align: justify; - padding: 5px 10px 0px 10px; -} -.msie #product_list .description { - padding: 5px 10px 10px 10px; -} - -/* * * Show Product * * * * * * * * * * * * */ - -#show_product .product-pic { - float: left; - margin-right: 15px; - border: 1px solid #444; - padding: 2px; - background: #FFF; -} - -#show_product .product_category { - padding-top: 10px; - clear: left; -} - +@import url('products.css'); diff --git a/public/stylesheets/controller_content_viewer.css b/public/stylesheets/controller_content_viewer.css index b1ffec3..d6e3169 100644 --- a/public/stylesheets/controller_content_viewer.css +++ b/public/stylesheets/controller_content_viewer.css @@ -1,3 +1,5 @@ +@import url('products.css'); + /************* enterprise homepage style *****************/ div.event-info { diff --git a/public/stylesheets/products.css b/public/stylesheets/products.css new file mode 100644 index 0000000..530285c --- /dev/null +++ b/public/stylesheets/products.css @@ -0,0 +1,80 @@ +/* * * List Products * * * * * * * * * * * * */ + +#product_list { + margin: 0px; + padding: 0px; +} + +#product_list ul { + margin: 0px; + padding: 0px; +} + +#content #product_list li { + margin: 0px; + padding: 0px; + list-style: none; +} + +#content #product_list li.product { + border: 1px solid #888; + margin-bottom: 10px; + padding: 5px 10px; +} + +#product_list .product-pic { + display: block; + width: 64px; + height: 64px; + background-repeat: no-repeat; + background-position: 50% 50%; + float: left; + margin-right: 15px; + position: relative; /* work arround msie bug */ +} + +#product_list .product-pic span { + display: none; +} + +#content #product_list h3 { + margin: 0px; + padding: 0px; + font-size: 120%; +} +.msie #content #product_list h3 { + margin-top: -15px; +} +#product_list h3 a { + text-decoration: none; +} + +#product_list .product_category { + font-size: 11px; +} + +#product_list .description { + clear: left; + font-size: 11px; + text-align: justify; + padding: 5px 10px 0px 10px; +} +.msie #product_list .description { + padding: 5px 10px 10px 10px; +} + +/* * * Show Product * * * * * * * * * * * * */ + +#show_product .product-pic { + float: left; + margin-right: 15px; + border: 1px solid #444; + padding: 2px; + background: #FFF; +} + +#show_product .product_category { + padding-top: 10px; + clear: left; +} + diff --git a/test/unit/application_helper_test.rb b/test/unit/application_helper_test.rb index beec812..e6a71c8 100644 --- a/test/unit/application_helper_test.rb +++ b/test/unit/application_helper_test.rb @@ -62,9 +62,11 @@ class ApplicationHelperTest < Test::Unit::TestCase cat = mock cat.expects(:path).returns('my-category/my-subcatagory') cat.expects(:full_name).returns('category name') + cat.expects(:environment).returns(Environment.default) + Environment.any_instance.expects(:default_hostname).returns('example.com') result = "/cat/my-category/my-subcatagory" - expects(:link_to).with('category name', :controller => 'search', :action => 'category_index', :category_path => ['my-category', 'my-subcatagory']).returns(result) + expects(:link_to).with('category name', :controller => 'search', :action => 'category_index', :category_path => ['my-category', 'my-subcatagory'], :host => 'example.com').returns(result) assert_same result, link_to_category(cat) end diff --git a/test/unit/enterprise_homepage_test.rb b/test/unit/enterprise_homepage_test.rb index 8008ec0..4026127 100644 --- a/test/unit/enterprise_homepage_test.rb +++ b/test/unit/enterprise_homepage_test.rb @@ -24,4 +24,33 @@ class EnterpriseHomepageTest < Test::Unit::TestCase assert_match /5555 5555/, result end + should 'display products list' do + ent = Enterprise.create!(:identifier => 'test_enterprise', :name => 'Test enteprise') + prod = ent.products.create!(:name => 'Product test') + a = EnterpriseHomepage.new(:name => 'article homepage') + ent.articles << a + result = a.to_html + assert_match /Product test/, result + end + + should 'not display products list if environment do not let' do + e = Environment.default + e.enable('disable_products_for_enterprises') + e.save! + ent = Enterprise.create!(:identifier => 'test_enterprise', :name => 'Test enteprise', :environment => e) + prod = ent.products.create!(:name => 'Product test') + a = EnterpriseHomepage.new(:name => 'article homepage') + ent.articles << a + result = a.to_html + assert_no_match /Product test/, result + end + + should 'display link to product' do + ent = Enterprise.create!(:identifier => 'test_enterprise', :name => 'Test enteprise') + prod = ent.products.create!(:name => 'Product test') + a = EnterpriseHomepage.new(:name => 'article homepage') + ent.articles << a + result = a.to_html + assert_match /catalog\/test_enterprise\/#{prod.id}/, result + end end -- libgit2 0.21.2