Commit fca6ac8b5d698fda6e4232993c285cd771814eb4
1 parent
e1df99fb
Exists in
master
and in
5 other branches
correcoes_aderencia: Correct complete registration percentage
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Showing
5 changed files
with
62 additions
and
52 deletions
Show diff stats
lib/mpog_software_plugin.rb
| @@ -268,7 +268,7 @@ class MpogSoftwarePlugin < Noosfero::Plugin | @@ -268,7 +268,7 @@ class MpogSoftwarePlugin < Noosfero::Plugin | ||
| 268 | end | 268 | end |
| 269 | 269 | ||
| 270 | def profile_required_list | 270 | def profile_required_list |
| 271 | - required_list = ["cell_phone","contact_phone","institutions","comercial_phone","country","city","state","organization_website","image"] | 271 | + ["cell_phone","contact_phone","comercial_phone","country","city","state","organization_website","image"] |
| 272 | end | 272 | end |
| 273 | 273 | ||
| 274 | def profile_required_empty_list person | 274 | def profile_required_empty_list person |
public/mpog-incomplete-registration.js
| 1 | -function hide_incomplete_percentage(evt) { | ||
| 2 | - evt.preventDefault(); | 1 | +(function() { |
| 2 | + function hide_incomplete_percentage(evt) { | ||
| 3 | + evt.preventDefault(); | ||
| 3 | 4 | ||
| 4 | - jQuery.get("/plugin/mpog_software/hide_registration_incomplete_percentage", {hide:true}, function(response){ | ||
| 5 | - if( response == true ) | ||
| 6 | - jQuery("#complete_registration").fadeOut(); | ||
| 7 | - }); | ||
| 8 | -} | 5 | + jQuery.get("/plugin/mpog_software/hide_registration_incomplete_percentage", {hide:true}, function(response){ |
| 6 | + if( response == true ) | ||
| 7 | + jQuery("#complete_registration").fadeOut(); | ||
| 8 | + }); | ||
| 9 | + } | ||
| 9 | 10 | ||
| 10 | -function show_complete_progressbar() { | ||
| 11 | - var percentage = jQuery("#complete_registration_message span").html(); | ||
| 12 | - var canvas_tag = document.getElementById("complete_registration_percentage"); | 11 | + function show_complete_progressbar() { |
| 12 | + var percentage = jQuery("#complete_registration_message span").html(); | ||
| 13 | + var canvas_tag = document.getElementById("complete_registration_percentage"); | ||
| 13 | 14 | ||
| 14 | - if( canvas_tag != null ) { | ||
| 15 | - var context = canvas_tag.getContext("2d"); | 15 | + if( canvas_tag != null ) { |
| 16 | + var context = canvas_tag.getContext("2d"); | ||
| 16 | 17 | ||
| 17 | - percentage = canvas_tag.width*(percentage/100.0); | 18 | + percentage = canvas_tag.width*(percentage/100.0); |
| 18 | 19 | ||
| 19 | - context.beginPath(); | ||
| 20 | - context.rect(0, 0, percentage, canvas_tag.height); | ||
| 21 | - context.fillStyle = '#00FF00'; | ||
| 22 | - context.fill(); | 20 | + context.beginPath(); |
| 21 | + context.rect(0, 0, percentage, canvas_tag.height); | ||
| 22 | + context.fillStyle = '#00FF00'; | ||
| 23 | + context.fill(); | ||
| 24 | + } | ||
| 23 | } | 25 | } |
| 24 | -} | ||
| 25 | 26 | ||
| 26 | -jQuery(document).ready(function(){ | ||
| 27 | - jQuery(".hide-incomplete-percentage").click(hide_incomplete_percentage); | 27 | + jQuery(document).ready(function(){ |
| 28 | + jQuery(".hide-incomplete-percentage").click(hide_incomplete_percentage); | ||
| 28 | 29 | ||
| 29 | - show_complete_progressbar(); | ||
| 30 | -}); | 30 | + show_complete_progressbar(); |
| 31 | + }); | ||
| 32 | +})(); | ||
| 31 | \ No newline at end of file | 33 | \ No newline at end of file |
test/unit/mpog_software_plugin_test.rb
| @@ -6,13 +6,11 @@ class MpogSoftwarePluginTest < ActiveSupport::TestCase | @@ -6,13 +6,11 @@ class MpogSoftwarePluginTest < ActiveSupport::TestCase | ||
| 6 | 6 | ||
| 7 | def setup | 7 | def setup |
| 8 | @plugin = MpogSoftwarePlugin.new | 8 | @plugin = MpogSoftwarePlugin.new |
| 9 | - @user = create_user("login", "user@email.com", "123456", "123456", "user@secondary_email.com") | ||
| 10 | - @person = @user.person | 9 | + @person = create_person("My Name", "user@email.com", "123456", "123456", "user@secondary_email.com", "Any State", "Some City") |
| 11 | end | 10 | end |
| 12 | 11 | ||
| 13 | def teardown | 12 | def teardown |
| 14 | - @user.person.destroy | ||
| 15 | - @user.destroy | 13 | + @person.destroy |
| 16 | end | 14 | end |
| 17 | 15 | ||
| 18 | 16 | ||
| @@ -21,16 +19,17 @@ class MpogSoftwarePluginTest < ActiveSupport::TestCase | @@ -21,16 +19,17 @@ class MpogSoftwarePluginTest < ActiveSupport::TestCase | ||
| 21 | end | 19 | end |
| 22 | 20 | ||
| 23 | should 'calculate the percentege of person incomplete fields' do | 21 | should 'calculate the percentege of person incomplete fields' do |
| 24 | - @person.name = "Person Name" | ||
| 25 | @person.cell_phone = "76888919" | 22 | @person.cell_phone = "76888919" |
| 23 | + @person.contact_phone = "987654321" | ||
| 26 | 24 | ||
| 27 | - required_list = ["cell_phone","contact_phone","institution","comercial_phone","country","city","state","organization_website","image"] | 25 | + assert_equal(50, @plugin.calc_percentage_registration(@person)) |
| 28 | 26 | ||
| 29 | - empty_fields = required_list.count - 1 | ||
| 30 | - test_percentege = 100 - ((empty_fields * 100) / required_list.count) | 27 | + @person.comercial_phone = "11223344" |
| 28 | + @person.country = "I dont know" | ||
| 29 | + @person.organization_website = "www.whatever.com" | ||
| 30 | + @person.image = Image::new :uploaded_data=>fixture_file_upload('/files/rails.png', 'image/png') | ||
| 31 | + @person.save | ||
| 31 | 32 | ||
| 32 | - plugin_percentege = @plugin.calc_percentage_registration(@person) | ||
| 33 | - | ||
| 34 | - assert_equal(test_percentege, plugin_percentege) | 33 | + assert_equal(100, @plugin.calc_percentage_registration(@person)) |
| 35 | end | 34 | end |
| 36 | end | 35 | end |
test/unit/plugin_test_helper.rb
| @@ -35,25 +35,32 @@ module PluginTestHelper | @@ -35,25 +35,32 @@ module PluginTestHelper | ||
| 35 | community | 35 | community |
| 36 | end | 36 | end |
| 37 | 37 | ||
| 38 | + def create_person name, email, password, password_confirmation, secondary_email, state, city | ||
| 39 | + user = create_user(name.to_slug, email, password, password_confirmation, secondary_email) | ||
| 40 | + person = Person::new | ||
| 41 | + | ||
| 42 | + person.name = name | ||
| 43 | + person.state = state | ||
| 44 | + person.city = city | ||
| 45 | + person.user = user | ||
| 46 | + person.save | ||
| 47 | + | ||
| 48 | + person | ||
| 49 | + end | ||
| 50 | + | ||
| 51 | + private | ||
| 52 | + | ||
| 38 | def create_user login, email, password, password_confirmation, secondary_email | 53 | def create_user login, email, password, password_confirmation, secondary_email |
| 39 | user = User.new | 54 | user = User.new |
| 55 | + | ||
| 40 | user.login = login | 56 | user.login = login |
| 41 | user.email = email | 57 | user.email = email |
| 42 | user.password = password | 58 | user.password = password |
| 43 | user.password_confirmation = password_confirmation | 59 | user.password_confirmation = password_confirmation |
| 44 | user.secondary_email = secondary_email | 60 | user.secondary_email = secondary_email |
| 61 | + | ||
| 45 | user.save | 62 | user.save |
| 46 | - user.person.save | ||
| 47 | user | 63 | user |
| 48 | end | 64 | end |
| 49 | 65 | ||
| 50 | - def create_person name, email, password, password_confirmation, secondary_email, state, city | ||
| 51 | - user = create_user(name.downcase, email, password, password_confirmation, secondary_email) | ||
| 52 | - user.person.name = name | ||
| 53 | - user.person.state = state | ||
| 54 | - user.person.city = city | ||
| 55 | - user.person.save | ||
| 56 | - user.person | ||
| 57 | - end | ||
| 58 | - | ||
| 59 | end | 66 | end |
views/incomplete_registration.html.erb
| 1 | -<div id='complete_registration'> | ||
| 2 | - <div id="complete_registration_message"> | ||
| 3 | - <div><%= _("Complete Profile")+": <span>#{@percentege}</span>%" %></div> | ||
| 4 | - <canvas id="complete_registration_percentage" width="100%" height="20"></canvas> | ||
| 5 | - <div> | ||
| 6 | - <%= @profile_edit_link %> | | ||
| 7 | - <%= link_to _("Hide"), "#", :class=>"hide-incomplete-percentage" %> | 1 | +<% if @percentege < 100 then %> |
| 2 | + <div id='complete_registration'> | ||
| 3 | + <div id="complete_registration_message"> | ||
| 4 | + <div><%= _("Complete Profile")+": <span>#{@percentege}</span>%" %></div> | ||
| 5 | + <canvas id="complete_registration_percentage" width="100%" height="20"></canvas> | ||
| 6 | + <div> | ||
| 7 | + <%= @profile_edit_link %> | | ||
| 8 | + <%= link_to _("Hide"), "#", :class=>"hide-incomplete-percentage" %> | ||
| 9 | + </div> | ||
| 8 | </div> | 10 | </div> |
| 9 | </div> | 11 | </div> |
| 10 | -</div> | ||
| 11 | \ No newline at end of file | 12 | \ No newline at end of file |
| 13 | +<% end %> | ||
| 12 | \ No newline at end of file | 14 | \ No newline at end of file |