gfdnavi 1.3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +10949 -0
- data/LICENCE.txt +57 -0
- data/Makefile +18 -0
- data/TODO +132 -0
- data/app/controllers/analysis_controller.rb +700 -0
- data/app/controllers/application.rb +41 -0
- data/app/controllers/draw_method_controller.rb +172 -0
- data/app/controllers/explorer_controller.rb +197 -0
- data/app/controllers/finder_controller.rb +331 -0
- data/app/controllers/function_controller.rb +204 -0
- data/app/controllers/group_controller.rb +115 -0
- data/app/controllers/keyword_attributes_controller.rb +52 -0
- data/app/controllers/knowledge_controller.rb +928 -0
- data/app/controllers/nodes_controller.rb +515 -0
- data/app/controllers/search_controller.rb +341 -0
- data/app/controllers/user_controller.rb +337 -0
- data/app/helpers/analysis_helper.rb +2 -0
- data/app/helpers/application_helper.rb +105 -0
- data/app/helpers/description_helper.rb +2 -0
- data/app/helpers/function_helper.rb +2 -0
- data/app/helpers/group_helper.rb +2 -0
- data/app/helpers/search_helper.rb +3 -0
- data/app/helpers/user_helper.rb +2 -0
- data/app/helpers/work_flow_helper.rb +92 -0
- data/app/models/actual_file.rb +3 -0
- data/app/models/analysis.rb +715 -0
- data/app/models/analysis_history.rb +42 -0
- data/app/models/cross_array.rb +22 -0
- data/app/models/cross_result.rb +254 -0
- data/app/models/derived_spatial_attribute.rb +3 -0
- data/app/models/diagram_cache.rb +16 -0
- data/app/models/diagram_cache_datum.rb +4 -0
- data/app/models/diagram_cache_session.rb +8 -0
- data/app/models/directory.rb +21 -0
- data/app/models/draw_method.rb +48 -0
- data/app/models/draw_method_attribute.rb +8 -0
- data/app/models/draw_parameter.rb +12 -0
- data/app/models/explorer_query.rb +354 -0
- data/app/models/explorer_result.rb +312 -0
- data/app/models/function.rb +75 -0
- data/app/models/function_argument.rb +6 -0
- data/app/models/function_output.rb +4 -0
- data/app/models/group.rb +153 -0
- data/app/models/image.rb +20 -0
- data/app/models/keyword_attribute.rb +179 -0
- data/app/models/knowledge.rb +94 -0
- data/app/models/knowledge_backup.rb +32 -0
- data/app/models/knowledge_figure.rb +16 -0
- data/app/models/knowledge_figure_backup.rb +16 -0
- data/app/models/knowledge_parser.rb +392 -0
- data/app/models/node.rb +605 -0
- data/app/models/node_entity_abstract.rb +112 -0
- data/app/models/node_lineage.rb +6 -0
- data/app/models/node_relation.rb +4 -0
- data/app/models/path_node.rb +60 -0
- data/app/models/query.rb +193 -0
- data/app/models/query_history.rb +12 -0
- data/app/models/results.rb +48 -0
- data/app/models/sign_up_user.rb +25 -0
- data/app/models/spatial_and_time_attribute.rb +11 -0
- data/app/models/user.rb +115 -0
- data/app/models/user_mailer.rb +48 -0
- data/app/models/value_type.rb +3 -0
- data/app/models/variable.rb +70 -0
- data/app/models/virtual_node.rb +457 -0
- data/app/views/analysis/__help_analysis_tab.en.html +57 -0
- data/app/views/analysis/__help_draw_share.en.html +12 -0
- data/app/views/analysis/__help_draw_tab.en.html +6 -0
- data/app/views/analysis/_analysis_function_settings.rhtml +61 -0
- data/app/views/analysis/_analysis_settings.rhtml +28 -0
- data/app/views/analysis/_diagram.rhtml +70 -0
- data/app/views/analysis/_dimension_option.rhtml +59 -0
- data/app/views/analysis/_draw_general_settings.rhtml +217 -0
- data/app/views/analysis/_draw_settings.rhtml +73 -0
- data/app/views/analysis/_history.rhtml +19 -0
- data/app/views/analysis/_popular_diagrams.rhtml +42 -0
- data/app/views/analysis/_save_form.rhtml +44 -0
- data/app/views/analysis/_variables.rhtml +66 -0
- data/app/views/analysis/_variables_order.rhtml +56 -0
- data/app/views/analysis/index.rhtml +195 -0
- data/app/views/analysis/preview.rhtml +3 -0
- data/app/views/analysis/save.rhtml +73 -0
- data/app/views/analysis/show_diagram.rhtml +42 -0
- data/app/views/cross/_display_map.rhtml +201 -0
- data/app/views/cross/_result.rhtml +205 -0
- data/app/views/cross/_show_result_tree.rhtml +40 -0
- data/app/views/cross/_show_results.rhtml +80 -0
- data/app/views/cross/_style.rhtml +21 -0
- data/app/views/cross/index.rhtml +271 -0
- data/app/views/draw_method/_edit_form.rhtml +110 -0
- data/app/views/draw_method/create.rhtml +8 -0
- data/app/views/draw_method/details.rhtml +113 -0
- data/app/views/draw_method/edit.rhtml +8 -0
- data/app/views/draw_method/list.rhtml +80 -0
- data/app/views/explorer/_display_map.rhtml +199 -0
- data/app/views/explorer/_show_result_tree.rhtml +40 -0
- data/app/views/explorer/_show_results.rhtml +101 -0
- data/app/views/explorer/_style.rhtml +21 -0
- data/app/views/explorer/index.rhtml +214 -0
- data/app/views/finder/_children.html.erb +84 -0
- data/app/views/finder/_children_details.html.erb +74 -0
- data/app/views/finder/_children_details_tr.html.erb +196 -0
- data/app/views/finder/create_tree.html.erb +15 -0
- data/app/views/finder/flex.html.erb +52 -0
- data/app/views/finder/index.html.erb +47 -0
- data/app/views/finder/show_details.html.erb +3 -0
- data/app/views/finder/show_images.html.erb +3 -0
- data/app/views/function/_edit_form.rhtml +106 -0
- data/app/views/function/create.rhtml +8 -0
- data/app/views/function/details.rhtml +96 -0
- data/app/views/function/edit.rhtml +8 -0
- data/app/views/function/list.rhtml +80 -0
- data/app/views/group/add_member.rhtml +13 -0
- data/app/views/group/change_owner.rhtml +15 -0
- data/app/views/group/create.rhtml +11 -0
- data/app/views/group/delete_member.rhtml +14 -0
- data/app/views/group/list.rhtml +63 -0
- data/app/views/knowledge/_backup.rhtml +135 -0
- data/app/views/knowledge/_category.rhtml +58 -0
- data/app/views/knowledge/_category_list.rhtml +34 -0
- data/app/views/knowledge/_category_table.rhtml +23 -0
- data/app/views/knowledge/_comment.rhtml +64 -0
- data/app/views/knowledge/_comment_input_form.rhtml +19 -0
- data/app/views/knowledge/_comments.rhtml +84 -0
- data/app/views/knowledge/_form.rhtml +139 -0
- data/app/views/knowledge/_group_figure_form.rhtml +187 -0
- data/app/views/knowledge/_layout_figure.rhtml +61 -0
- data/app/views/knowledge/_layout_figures_in_a_row_above_text.rhtml +42 -0
- data/app/views/knowledge/_layout_figures_under_text.rhtml +45 -0
- data/app/views/knowledge/_layout_one_figure_above_text.rhtml +28 -0
- data/app/views/knowledge/_summary.rhtml +21 -0
- data/app/views/knowledge/edit.rhtml +37 -0
- data/app/views/knowledge/list.rhtml +287 -0
- data/app/views/knowledge/new.rhtml +23 -0
- data/app/views/knowledge/new_from_analysis.rhtml +21 -0
- data/app/views/knowledge/show.rhtml +196 -0
- data/app/views/layouts/gfdnavi.rhtml +105 -0
- data/app/views/nodes/_ancestors.html.erb +89 -0
- data/app/views/nodes/_description_methods_table.html.erb +75 -0
- data/app/views/nodes/_mode.html.erb +16 -0
- data/app/views/nodes/description.html.erb +181 -0
- data/app/views/nodes/description_methods.html.erb +1 -0
- data/app/views/nodes/edit.html.erb +73 -0
- data/app/views/nodes/index.html.erb +25 -0
- data/app/views/nodes/show.html.erb +20 -0
- data/app/views/search/_children_details_mapsearch.rhtml +68 -0
- data/app/views/search/_children_details_tr.rhtml +205 -0
- data/app/views/search/_show_grouplist.rhtml +74 -0
- data/app/views/search/_show_results.rhtml +43 -0
- data/app/views/search/_show_results_global.rhtml +36 -0
- data/app/views/search/_show_results_partial.rhtml +39 -0
- data/app/views/search/_show_results_partial_groupbyfile.rhtml +50 -0
- data/app/views/search/_show_variablelist.rhtml +28 -0
- data/app/views/search/mapsearch.rhtml +176 -0
- data/app/views/search/remapsearch.rjs +18 -0
- data/app/views/search/show_details.rhtml +3 -0
- data/app/views/user/add_user.rhtml +30 -0
- data/app/views/user/change_password.rhtml +25 -0
- data/app/views/user/edit.html.erb +50 -0
- data/app/views/user/index.rhtml +162 -0
- data/app/views/user/login.rhtml +41 -0
- data/app/views/user/logout.rhtml +4 -0
- data/app/views/user/signup.rhtml +36 -0
- data/app/views/user/signup_succeeded.rhtml +36 -0
- data/app/views/user_mailer/authorization_inform.rhtml +15 -0
- data/app/views/user_mailer/signup_accepted.rhtml +12 -0
- data/app/views/user_mailer/signup_confirm.rhtml +14 -0
- data/app/views/user_mailer/signup_inform.rhtml +13 -0
- data/app/views/user_mailer/signup_rejected.rhtml +11 -0
- data/app/views/work_flow/_push_wsdls.rhtml +55 -0
- data/app/views/work_flow/index.rhtml +46 -0
- data/config/database.yml.example +35 -0
- data/config/environment.rb +68 -0
- data/config/gfdnavi.yml.example +95 -0
- data/config/load_config.rb +151 -0
- data/config/routes.rb +35 -0
- data/consistency_checker.rb +129 -0
- data/data/gfdnavi_docs/how_to_draw_multiple_images.knlge +68 -0
- data/data/gfdnavi_docs/how_to_knowledge.knlge +138 -0
- data/data/gfdnavi_docs/how_to_write_document_about_Gfdnavi.knlge +30 -0
- data/data/samples/jmadata.SIGEN +8 -0
- data/data/samples/jmadata.yml +6 -0
- data/data/samples/jmadata/MSM-P/2006.nc.yml +2 -0
- data/data/samples/jmadata/MSM-P/2006.yml +17 -0
- data/data/samples/jmadata/MSM-P/2006/0101.nc +0 -0
- data/data/samples/jmadata/MSM-P/2006/0101.nc.yml +13 -0
- data/data/samples/jmadata/MSM-P/2006/0102.nc +0 -0
- data/data/samples/jmadata/MSM-P/2006/0103.nc +0 -0
- data/data/samples/jmadata/MSM-P/2006/0104.nc +0 -0
- data/data/samples/jmadata/MSM-P/2006/0105.nc +0 -0
- data/data/samples/jmadata/MSM-P/2006/010[1-3].nc.yml +2 -0
- data/data/samples/jmadata/MSM-P/2006/skip_data.rb +96 -0
- data/data/samples/jmadata/MSM-P/2006/skip_data.sh +6 -0
- data/data/samples/reanalysis.SIGEN +8 -0
- data/data/samples/reanalysis/era40.SIGEN +8 -0
- data/data/samples/reanalysis/era40.yml +2 -0
- data/data/samples/reanalysis/era40/t.jan.nc +0 -0
- data/data/samples/reanalysis/era40/t.jan.nc.yml +1 -0
- data/data/samples/reanalysis/ncep.SIGEN +9 -0
- data/data/samples/reanalysis/ncep/T.jan.100hPa.png +0 -0
- data/data/samples/reanalysis/ncep/T.jan.100hPa.png.yml +43 -0
- data/data/samples/reanalysis/ncep/T.jan.nc +0 -0
- data/data/samples/reanalysis/ncep/T.jan.zonal_mean.nc +0 -0
- data/data/samples/reanalysis/ncep/T.jan.zonal_mean.nc.yml +8 -0
- data/data/samples/reanalysis/ncep/T.jan_only_root.nc +0 -0
- data/data/samples/reanalysis/ncep/T.jan_only_root.nc.yml +4 -0
- data/data/samples/reanalysis/ncep/UV.jan.nc +0 -0
- data/data/samples/reanalysis/ncep/UV.jan.nc.yml +10 -0
- data/data/samples/reanalysis/ncep/UV.jan.nc.yml.ja +11 -0
- data/data/samples/sonde_operational.yml +5 -0
- data/data/samples/sonde_operational/std_plev.yml +12 -0
- data/data/samples/sonde_operational/std_plev/41256.spl.nc +0 -0
- data/data/samples/sonde_operational/std_plev/42410.spl.nc +0 -0
- data/data/samples/sonde_operational/std_plev/43333.spl.nc +0 -0
- data/data/samples/sonde_operational/std_plev/43346.spl.nc +0 -0
- data/data/samples/sonde_operational/std_plev/48698.spl.nc +0 -0
- data/data/samples/sonde_operational/std_plev/61641.spl.nc +0 -0
- data/data/samples/sonde_operational/std_plev/63741.spl.nc +0 -0
- data/data/samples/sonde_operational/std_plev/67083.spl.nc +0 -0
- data/data/samples/sonde_operational/std_plev/72261.spl.nc +0 -0
- data/data/samples/sonde_operational/std_plev/76805.spl.nc +0 -0
- data/data/samples/sonde_operational/std_plev/82193.spl.nc +0 -0
- data/data/samples/sonde_operational/std_plev/91165.spl.nc +0 -0
- data/data/samples/sonde_operational/std_plev/91610.spl.nc +0 -0
- data/data/samples/sonde_operational/std_plev/91948.spl.nc +0 -0
- data/data/samples/sonde_operational/std_plev/94294.spl.nc +0 -0
- data/db/NetCDFparser.rb +406 -0
- data/db/create_derived_spatial_attributes.sql +12 -0
- data/db/draw_methods/line.yml +6 -0
- data/db/draw_methods/scatter.yml +38 -0
- data/db/draw_methods/tone.yml +64 -0
- data/db/draw_methods/vector.yml +19 -0
- data/db/dump_db.rb +43 -0
- data/db/functions/additions.yml +10 -0
- data/db/functions/cut.yml +10 -0
- data/db/functions/division.yml +10 -0
- data/db/functions/mean.yml +28 -0
- data/db/functions/multiplication.yml +10 -0
- data/db/functions/stddev.yml +28 -0
- data/db/functions/subtraction.yml +10 -0
- data/db/migrate/001_initial_scheme.rb +289 -0
- data/db/migrate/002_add_open_id_authentication_tables.rb +20 -0
- data/db/register_directory_tree.rb +760 -0
- data/db/restore_db.rb +60 -0
- data/gfdnavi-install +828 -0
- data/install.rb +828 -0
- data/lib/activerecord_gfdnavi.rb +31 -0
- data/lib/basic_authorization.rb +50 -0
- data/lib/create_activeresources.rb +108 -0
- data/lib/execute_analysis.rb +472 -0
- data/lib/file_gfdnavi.rb +38 -0
- data/lib/gphys_gfdnavi.rb +81 -0
- data/lib/localdir.rb +110 -0
- data/lib/login_system.rb +110 -0
- data/lib/multibytes.rb +20 -0
- data/lib/narray_yaml.rb +58 -0
- data/lib/no_rdb_base.rb +40 -0
- data/lib/opendapdir.rb +171 -0
- data/lib/tar.rb +127 -0
- data/lib/tasks/clean.rake +65 -0
- data/lib/tasks/setup.rake +316 -0
- data/lib/tasks/update.rake +62 -0
- data/lib/vizshot_gfdnavi.rb +224 -0
- data/public/crossdomain.xml +4 -0
- data/public/flex/NodeTreeDescriptor.as +55 -0
- data/public/flex/TreeNode.as +253 -0
- data/public/flex/finder.mxml +304 -0
- data/public/flex/finder.swf +0 -0
- data/public/flex/gfdnavi.mxml +52 -0
- data/public/flex/gfdnavi.swf +0 -0
- data/public/images/Help_S-shots/dir_tree_with_add.jpg +0 -0
- data/public/images/analyze.gif +0 -0
- data/public/images/circle.gif +0 -0
- data/public/images/create_from_analysis_button.png +0 -0
- data/public/images/delete.png +0 -0
- data/public/images/down.png +0 -0
- data/public/images/drawbutton.gif +0 -0
- data/public/images/gfdnavi_home_logo.png +0 -0
- data/public/images/gfdnavi_logo_big.png +0 -0
- data/public/images/gfdnavi_logo_med.png +0 -0
- data/public/images/gfdnavi_logo_mini.png +0 -0
- data/public/images/gfdnavi_logo_nobg_big.png +0 -0
- data/public/images/gfdnavi_logo_nobg_med.png +0 -0
- data/public/images/gfdnavi_logo_nobg_small.png +0 -0
- data/public/images/gfdnavi_logo_small.png +0 -0
- data/public/images/gfdnavi_logo_xsmall.png +0 -0
- data/public/images/hbar.png +0 -0
- data/public/images/helpmark16.png +0 -0
- data/public/images/helpmark18.png +0 -0
- data/public/images/kikyu_g.gif +0 -0
- data/public/images/kikyu_r.gif +0 -0
- data/public/images/map_icon_g.gif +0 -0
- data/public/images/map_icon_r.gif +0 -0
- data/public/images/new_knowledge.png +0 -0
- data/public/images/openid.png +0 -0
- data/public/images/read_in_the_form.png +0 -0
- data/public/images/slider_f.gif +0 -0
- data/public/images/slider_f_red.gif +0 -0
- data/public/images/star1.gif +0 -0
- data/public/images/star2.gif +0 -0
- data/public/images/startanim.gif +0 -0
- data/public/images/stopanim.gif +0 -0
- data/public/images/tree/DL.png +0 -0
- data/public/images/tree/anal_viz.png +0 -0
- data/public/images/tree/analyze_visualize_checked_items.png +0 -0
- data/public/images/tree/binary.png +0 -0
- data/public/images/tree/details.png +0 -0
- data/public/images/tree/download_checked_items.png +0 -0
- data/public/images/tree/folder.png +0 -0
- data/public/images/tree/folder_close.gif +0 -0
- data/public/images/tree/image2.png +0 -0
- data/public/images/tree/knowledge.png +0 -0
- data/public/images/tree/knowledges.png +0 -0
- data/public/images/tree/last.gif +0 -0
- data/public/images/tree/last.png +0 -0
- data/public/images/tree/minus.gif +0 -0
- data/public/images/tree/minus_simple.gif +0 -0
- data/public/images/tree/none.gif +0 -0
- data/public/images/tree/none.png +0 -0
- data/public/images/tree/plus.gif +0 -0
- data/public/images/tree/plus_simple.gif +0 -0
- data/public/images/tree/show.png +0 -0
- data/public/images/tree/show_checked_items.png +0 -0
- data/public/images/tree/t.gif +0 -0
- data/public/images/tree/t.png +0 -0
- data/public/images/tree/tate.gif +0 -0
- data/public/images/tree/tate.png +0 -0
- data/public/images/up.png +0 -0
- data/public/images/vbar.png +0 -0
- data/public/images/white.bmp +0 -0
- data/public/images/x.gif +0 -0
- data/public/index.html +100 -0
- data/public/javascripts/AC_OETags.js +269 -0
- data/public/javascripts/analysis.js +751 -0
- data/public/javascripts/application.js +29 -0
- data/public/javascripts/directory_tree.js +102 -0
- data/public/javascripts/draw_method.js +83 -0
- data/public/javascripts/excanvas.js +704 -0
- data/public/javascripts/function.js +107 -0
- data/public/javascripts/gfdnavi.js +175 -0
- data/public/javascripts/knowledge.js +384 -0
- data/public/javascripts/mapsearch.js +313 -0
- data/public/javascripts/progress.js +42 -0
- data/public/javascripts/resizable_box.js +164 -0
- data/public/javascripts/slider.js +260 -0
- data/public/javascripts/tab.js +17 -0
- data/public/javascripts/work_flow.js +452 -0
- data/public/stylesheets/analysis.css +111 -0
- data/public/stylesheets/description.css +71 -0
- data/public/stylesheets/gfdnavi.css +141 -0
- data/public/stylesheets/knowledge.css +218 -0
- data/public/stylesheets/search.css +184 -0
- data/public/stylesheets/tree.css +45 -0
- data/public/stylesheets/tree_for_ie.css +3 -0
- data/public/stylesheets/work_flow.css +78 -0
- data/script/cleaner +11 -0
- data/script/server_ssl +131 -0
- data/test/fixtures/diagram_cache_data.yml +5 -0
- data/test/fixtures/diagram_cache_sessions.yml +6 -0
- data/test/fixtures/diagram_caches.yml +6 -0
- data/test/fixtures/directories.yml +57 -0
- data/test/fixtures/draw_parameters.yml +6 -0
- data/test/fixtures/function_arguments.yml +15 -0
- data/test/fixtures/function_outputs.yml +15 -0
- data/test/fixtures/functions.yml +29 -0
- data/test/fixtures/group_members.yml +33 -0
- data/test/fixtures/groups.yml +25 -0
- data/test/fixtures/images.yml +12 -0
- data/test/fixtures/keyword_attributes.yml +73 -0
- data/test/fixtures/knowledges.yml +10 -0
- data/test/fixtures/node_relations.yml +11 -0
- data/test/fixtures/nodes.yml +298 -0
- data/test/fixtures/sign_up_users.yml +8 -0
- data/test/fixtures/spatial_and_time_attributes.yml +29 -0
- data/test/fixtures/user_mailer/authorization_inform +11 -0
- data/test/fixtures/user_mailer/signup_accepted +10 -0
- data/test/fixtures/user_mailer/signup_confirm +17 -0
- data/test/fixtures/user_mailer/signup_inform +10 -0
- data/test/fixtures/user_mailer/signup_rejected +9 -0
- data/test/fixtures/users.yml +31 -0
- data/test/fixtures/value_types.yml +10 -0
- data/test/fixtures/variables.yml +17 -0
- data/test/functional/analysis_controller_test.rb +169 -0
- data/test/functional/description_controller_test.rb +18 -0
- data/test/functional/function_controller_test.rb +18 -0
- data/test/functional/group_controller_test.rb +18 -0
- data/test/functional/search_controller_test.rb +83 -0
- data/test/functional/user_controller_test.rb +77 -0
- data/test/functional/webservice_analysis_api_test.rb +12 -0
- data/test/functional/work_flow_controller_test.rb +18 -0
- data/test/test_helper.rb +28 -0
- data/test/unit/diagram_cache_datum_test.rb +10 -0
- data/test/unit/diagram_cache_session_test.rb +10 -0
- data/test/unit/diagram_cache_test.rb +10 -0
- data/test/unit/directory_test.rb +49 -0
- data/test/unit/draw_parameter_test.rb +10 -0
- data/test/unit/function_argument_test.rb +10 -0
- data/test/unit/function_output_test.rb +10 -0
- data/test/unit/function_test.rb +10 -0
- data/test/unit/group_test.rb +48 -0
- data/test/unit/image_test.rb +13 -0
- data/test/unit/keyword_attribute_test.rb +33 -0
- data/test/unit/knowledge_test.rb +13 -0
- data/test/unit/node_relation_test.rb +20 -0
- data/test/unit/node_test.rb +85 -0
- data/test/unit/sign_up_user_test.rb +20 -0
- data/test/unit/spatial_and_time_attribute_test.rb +29 -0
- data/test/unit/user_mailer_test.rb +101 -0
- data/test/unit/user_test.rb +134 -0
- data/test/unit/value_type_test.rb +10 -0
- data/test/unit/variable_test.rb +35 -0
- data/vendor/plugins/acts_as_list/README +23 -0
- data/vendor/plugins/acts_as_list/init.rb +3 -0
- data/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb +256 -0
- data/vendor/plugins/acts_as_list/test/list_test.rb +332 -0
- data/vendor/plugins/acts_as_tree/README +26 -0
- data/vendor/plugins/acts_as_tree/Rakefile +22 -0
- data/vendor/plugins/acts_as_tree/init.rb +1 -0
- data/vendor/plugins/acts_as_tree/lib/active_record/acts/tree.rb +96 -0
- data/vendor/plugins/acts_as_tree/test/abstract_unit.rb +0 -0
- data/vendor/plugins/acts_as_tree/test/acts_as_tree_test.rb +219 -0
- data/vendor/plugins/acts_as_tree/test/database.yml +0 -0
- data/vendor/plugins/acts_as_tree/test/fixtures/mixin.rb +0 -0
- data/vendor/plugins/acts_as_tree/test/fixtures/mixins.yml +0 -0
- data/vendor/plugins/acts_as_tree/test/schema.rb +0 -0
- data/vendor/plugins/will_paginate/CHANGELOG +92 -0
- data/vendor/plugins/will_paginate/LICENSE +18 -0
- data/vendor/plugins/will_paginate/README.rdoc +131 -0
- data/vendor/plugins/will_paginate/Rakefile +62 -0
- data/vendor/plugins/will_paginate/examples/apple-circle.gif +0 -0
- data/vendor/plugins/will_paginate/examples/index.haml +69 -0
- data/vendor/plugins/will_paginate/examples/index.html +92 -0
- data/vendor/plugins/will_paginate/examples/pagination.css +90 -0
- data/vendor/plugins/will_paginate/examples/pagination.sass +91 -0
- data/vendor/plugins/will_paginate/init.rb +1 -0
- data/vendor/plugins/will_paginate/lib/will_paginate.rb +86 -0
- data/vendor/plugins/will_paginate/lib/will_paginate/array.rb +16 -0
- data/vendor/plugins/will_paginate/lib/will_paginate/collection.rb +145 -0
- data/vendor/plugins/will_paginate/lib/will_paginate/core_ext.rb +32 -0
- data/vendor/plugins/will_paginate/lib/will_paginate/finder.rb +247 -0
- data/vendor/plugins/will_paginate/lib/will_paginate/named_scope.rb +132 -0
- data/vendor/plugins/will_paginate/lib/will_paginate/named_scope_patch.rb +39 -0
- data/vendor/plugins/will_paginate/lib/will_paginate/version.rb +9 -0
- data/vendor/plugins/will_paginate/lib/will_paginate/view_helpers.rb +373 -0
- data/vendor/plugins/will_paginate/will_paginate.gemspec +21 -0
- metadata +586 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class SignUpUserTest < Test::Unit::TestCase
|
4
|
+
fixtures :sign_up_users
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@user = SignUpUser.find(1)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_create
|
11
|
+
dave = sign_up_users(:dave)
|
12
|
+
assert_kind_of SignUpUser, @user
|
13
|
+
assert_equal dave.id, @user.id
|
14
|
+
assert_equal dave.login, @user.login
|
15
|
+
assert_equal dave.full_name, @user.full_name
|
16
|
+
assert_equal dave.email_address, @user.email_address
|
17
|
+
assert_equal dave.affiliation, @user.affiliation
|
18
|
+
assert_equal dave.password, @user.password
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class SpatialAndTimeAttributeTest < Test::Unit::TestCase
|
4
|
+
fixtures :spatial_and_time_attributes, :nodes
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@sa = SpatialAndTimeAttribute.find(1)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_create
|
11
|
+
global = spatial_and_time_attributes(:ncep_jan_u_global)
|
12
|
+
assert_kind_of SpatialAndTimeAttribute, @sa
|
13
|
+
assert_equal global.node_id, @sa.node_id
|
14
|
+
assert_equal global.longitude_lb, @sa.longitude_lb
|
15
|
+
assert_equal global.latitude_lb, @sa.latitude_lb
|
16
|
+
assert_equal global.longitude_rt, @sa.longitude_rt
|
17
|
+
assert_equal global.latitude_rt, @sa.latitude_rt
|
18
|
+
assert_equal global.starttime, @sa.starttime
|
19
|
+
assert_equal global.endtime, @sa.endtime
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_variable
|
23
|
+
node = nodes(:ncep_uv_jan_u)
|
24
|
+
assert_kind_of Node, @sa.node
|
25
|
+
assert_kind_of Variable, @sa.node.entity
|
26
|
+
assert_equal node, @sa.node
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
require 'user_mailer'
|
3
|
+
|
4
|
+
class UserMailerTest < Test::Unit::TestCase
|
5
|
+
FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures'
|
6
|
+
CHARSET = "utf-8"
|
7
|
+
|
8
|
+
include ActionMailer::Quoting
|
9
|
+
|
10
|
+
fixtures :users, :sign_up_users
|
11
|
+
|
12
|
+
def setup
|
13
|
+
ActionMailer::Base.delivery_method = :test
|
14
|
+
ActionMailer::Base.perform_deliveries = true
|
15
|
+
ActionMailer::Base.deliveries = []
|
16
|
+
|
17
|
+
@expected = TMail::Mail.new
|
18
|
+
@expected.set_content_type "text", "plain", { "charset" => CHARSET }
|
19
|
+
@expected.from = "#{GFDNAVI_ADMIN_NAME} <#{GFDNAVI_ADMIN_EMAIL}>"
|
20
|
+
|
21
|
+
@user = SignUpUser.find(1)
|
22
|
+
@suser = User.find(1)
|
23
|
+
@url = "http://example.com"
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_signup_confirm
|
27
|
+
@expected.to = "#{@user.full_name} <#{@user.email_address}>"
|
28
|
+
@expected.subject = '[gfdnavi] sign up confirmation'
|
29
|
+
@expected.body = read_fixture('signup_confirm')
|
30
|
+
@expected.date = Time.now
|
31
|
+
|
32
|
+
email = UserMailer.create_signup_confirm(@user, @url)
|
33
|
+
assert_equal @expected.subject, email.subject
|
34
|
+
assert_equal @expected.to, email.to
|
35
|
+
assert_equal @expected.from, email.from
|
36
|
+
assert_match /Dave/, email.body
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_signup_inform
|
40
|
+
@expected.to = User.find(:all, :conditions => ["super_user=?",true]).collect{|u| u.email_address}
|
41
|
+
@expected.subject = '[gfdnavi] sign up information'
|
42
|
+
@expected.body = read_fixture('signup_inform')
|
43
|
+
@expected.date = Time.now
|
44
|
+
|
45
|
+
email = UserMailer.create_signup_inform(@user, @url)
|
46
|
+
assert_equal @expected.subject, email.subject
|
47
|
+
assert_equal @expected.to, email.to
|
48
|
+
assert_equal @expected.from, email.from
|
49
|
+
assert_match /Dave/, email.body
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_signup_accepted
|
53
|
+
@expected.to = "#{@user.full_name} <#{@user.email_address}>"
|
54
|
+
@expected.subject = '[gfdnavi] Your signup request was accepted'
|
55
|
+
@expected.body = read_fixture('signup_accepted')
|
56
|
+
@expected.date = Time.now
|
57
|
+
|
58
|
+
email = UserMailer.create_signup_accepted(@user, @url)
|
59
|
+
assert_equal @expected.subject, email.subject
|
60
|
+
assert_equal @expected.to, email.to
|
61
|
+
assert_equal @expected.from, email.from
|
62
|
+
assert_match /Dave/, email.body
|
63
|
+
assert_match /accepted/, email.body
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_signup_rejected
|
67
|
+
@expected.to = "#{@user.full_name} <#{@user.email_address}>"
|
68
|
+
@expected.subject = '[gfdnavi] Your signup request was rejected'
|
69
|
+
@expected.body = read_fixture('signup_rejected')
|
70
|
+
@expected.date = Time.now
|
71
|
+
|
72
|
+
email = UserMailer.create_signup_rejected(@user, @url)
|
73
|
+
assert_equal @expected.subject, email.subject
|
74
|
+
assert_equal @expected.to, email.to
|
75
|
+
assert_equal @expected.from, email.from
|
76
|
+
assert_match /Dave/, email.body
|
77
|
+
assert_match /rejected/, email.body
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_authorization_inform
|
81
|
+
@expected.to = User.find(:all, :conditions => ["super_user=?",true]).collect{|u| u.email_address}
|
82
|
+
@expected.subject = '[gfdnavi] authorization information'
|
83
|
+
@expected.body = read_fixture('authorization_inform')
|
84
|
+
@expected.date = Time.now
|
85
|
+
|
86
|
+
email = UserMailer.create_authorization_inform(@user, @url, @suser, "accept")
|
87
|
+
assert_equal @expected.subject, email.subject
|
88
|
+
assert_equal @expected.to, email.to
|
89
|
+
assert_match /Dave/, email.body
|
90
|
+
assert_match /accept/, email.body
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
def read_fixture(action)
|
95
|
+
IO.readlines("#{FIXTURES_PATH}/user_mailer/#{action}")
|
96
|
+
end
|
97
|
+
|
98
|
+
def encode(subject)
|
99
|
+
quoted_printable(subject, CHARSET)
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class UserTest < Test::Unit::TestCase
|
4
|
+
self.use_instantiated_fixtures = true
|
5
|
+
|
6
|
+
fixtures :users, :groups
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@root = User.find(1)
|
10
|
+
@bob = User.find(2)
|
11
|
+
@longbob = User.find(3)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_auth
|
15
|
+
assert_equal @bob, User.authenticate("bob", "bobbob")
|
16
|
+
assert_nil User.authenticate("bob", "test")
|
17
|
+
assert_nil User.authenticate("nonbob", "test")
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_belonging_groups
|
21
|
+
assert_equal @root.belonging_groups.collect{|g| g.name}.sort,
|
22
|
+
["all", "root"]
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_passwordchange
|
26
|
+
new_password = "nonbobpasswd"
|
27
|
+
assert ! @longbob.change_password(new_password, new_password+"dummy")
|
28
|
+
assert @longbob.change_password(new_password, new_password)
|
29
|
+
assert_equal @longbob, User.authenticate("longbob", "nonbobpasswd")
|
30
|
+
assert_nil User.authenticate("longbob", "longtest")
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_disallowed_passwords
|
34
|
+
u = new_user("nonbob")
|
35
|
+
u.password = u.password_confirmation = "tiny"
|
36
|
+
assert !u.save
|
37
|
+
assert u.errors.invalid?('password')
|
38
|
+
|
39
|
+
u.password = u.password_confirmation = "hugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehuge"
|
40
|
+
assert !u.save
|
41
|
+
assert u.errors.invalid?('password')
|
42
|
+
|
43
|
+
u.password = u.password_confirmation = ""
|
44
|
+
assert !u.save
|
45
|
+
assert u.errors.invalid?('password')
|
46
|
+
|
47
|
+
u.password = u.password_confirmation = "bobs_secure_password"
|
48
|
+
assert u.save
|
49
|
+
assert u.errors.empty?
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_bad_logins
|
54
|
+
u = new_user("x")
|
55
|
+
assert !u.save
|
56
|
+
assert u.errors.invalid?('login')
|
57
|
+
|
58
|
+
u.login = "hugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhug"
|
59
|
+
assert !u.save
|
60
|
+
assert u.errors.invalid?('login')
|
61
|
+
|
62
|
+
u.login = ""
|
63
|
+
assert !u.save
|
64
|
+
assert u.errors.invalid?('login')
|
65
|
+
|
66
|
+
u.login = "oklogin"
|
67
|
+
assert u.save
|
68
|
+
assert u.errors.empty?
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
def test_uniq
|
74
|
+
u = new_user("bob")
|
75
|
+
assert !u.save
|
76
|
+
assert u.errors.invalid?('login')
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
def test_full_name
|
81
|
+
u = new_user("bobfullname")
|
82
|
+
u.full_name = ""
|
83
|
+
assert !u.save
|
84
|
+
assert u.errors.invalid?('full_name')
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
def test_affiliation
|
89
|
+
u = new_user("bobaffiliation")
|
90
|
+
u.affiliation = ""
|
91
|
+
assert !u.save
|
92
|
+
assert u.errors.invalid?('affiliation')
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
def test_email_address
|
97
|
+
u = new_user("bobemail")
|
98
|
+
u.email_address = ""
|
99
|
+
assert !u.save
|
100
|
+
assert u.errors.invalid?('email_address')
|
101
|
+
|
102
|
+
u.email_address = "@example.com"
|
103
|
+
assert !u.save
|
104
|
+
assert u.errors.invalid?('email_address')
|
105
|
+
|
106
|
+
u.email_address = "bob@example"
|
107
|
+
assert !u.save
|
108
|
+
assert u.errors.invalid?('email_address')
|
109
|
+
|
110
|
+
u.email_address = "bobexample.com"
|
111
|
+
assert !u.save
|
112
|
+
assert u.errors.invalid?('email_address')
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
def test_sha1
|
117
|
+
u = new_user("bobsha")
|
118
|
+
u.password = u.password_confirmation = "okpassword"
|
119
|
+
assert u.save
|
120
|
+
assert_equal User.sha1("okpassword"), u.password
|
121
|
+
end
|
122
|
+
|
123
|
+
private
|
124
|
+
def new_user(login)
|
125
|
+
u = User.new
|
126
|
+
u.login = login
|
127
|
+
u.full_name = "Non BoB"
|
128
|
+
u.email_address = "nonbob@example.com"
|
129
|
+
u.affiliation = "BOB coorp"
|
130
|
+
u.password = u.password_confirmation = "nonbob"
|
131
|
+
u
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../lib/narray_yaml")
|
3
|
+
|
4
|
+
class VariableTest < Test::Unit::TestCase
|
5
|
+
fixtures :variables, :directories, :nodes, :users, :groups
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@var = Variable.find(:first,:conditions=>["path=?","/samples/reanalysis/ncep/UV.jan.nc/U"])
|
9
|
+
@root = User.find_by_login("root")
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_db
|
13
|
+
u = nodes(:ncep_uv_jan_u).entity
|
14
|
+
assert_kind_of Variable, @var
|
15
|
+
assert_equal u.id, @var.id
|
16
|
+
assert_equal u.node_id, @var.node_id
|
17
|
+
assert_kind_of Node, @var.node
|
18
|
+
assert_equal u.parent, @var.parent
|
19
|
+
assert_equal u.path, @var.path
|
20
|
+
assert_equal u.name, @var.name
|
21
|
+
assert_equal nodes(:ncep_uv_jan).entity, @var.parent.entity
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_create
|
25
|
+
var = Variable.new
|
26
|
+
assert_equal Node::VARIABLE, var.node.node_type
|
27
|
+
assert_raise(ActiveRecord::RecordNotSaved){ var.save! }
|
28
|
+
var.name = "test"
|
29
|
+
var.path = "/test"
|
30
|
+
var.owner = @root
|
31
|
+
assert var.save
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
ActsAsList
|
2
|
+
==========
|
3
|
+
|
4
|
+
This acts_as extension provides the capabilities for sorting and reordering a number of objects in a list. The class that has this specified needs to have a +position+ column defined as an integer on the mapped database table.
|
5
|
+
|
6
|
+
|
7
|
+
Example
|
8
|
+
=======
|
9
|
+
|
10
|
+
class TodoList < ActiveRecord::Base
|
11
|
+
has_many :todo_items, :order => "position"
|
12
|
+
end
|
13
|
+
|
14
|
+
class TodoItem < ActiveRecord::Base
|
15
|
+
belongs_to :todo_list
|
16
|
+
acts_as_list :scope => :todo_list
|
17
|
+
end
|
18
|
+
|
19
|
+
todo_list.first.move_to_bottom
|
20
|
+
todo_list.last.move_higher
|
21
|
+
|
22
|
+
|
23
|
+
Copyright (c) 2007 David Heinemeier Hansson, released under the MIT license
|
@@ -0,0 +1,256 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module Acts #:nodoc:
|
3
|
+
module List #:nodoc:
|
4
|
+
def self.included(base)
|
5
|
+
base.extend(ClassMethods)
|
6
|
+
end
|
7
|
+
|
8
|
+
# This +acts_as+ extension provides the capabilities for sorting and reordering a number of objects in a list.
|
9
|
+
# The class that has this specified needs to have a +position+ column defined as an integer on
|
10
|
+
# the mapped database table.
|
11
|
+
#
|
12
|
+
# Todo list example:
|
13
|
+
#
|
14
|
+
# class TodoList < ActiveRecord::Base
|
15
|
+
# has_many :todo_items, :order => "position"
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# class TodoItem < ActiveRecord::Base
|
19
|
+
# belongs_to :todo_list
|
20
|
+
# acts_as_list :scope => :todo_list
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# todo_list.first.move_to_bottom
|
24
|
+
# todo_list.last.move_higher
|
25
|
+
module ClassMethods
|
26
|
+
# Configuration options are:
|
27
|
+
#
|
28
|
+
# * +column+ - specifies the column name to use for keeping the position integer (default: +position+)
|
29
|
+
# * +scope+ - restricts what is to be considered a list. Given a symbol, it'll attach <tt>_id</tt>
|
30
|
+
# (if it hasn't already been added) and use that as the foreign key restriction. It's also possible
|
31
|
+
# to give it an entire string that is interpolated if you need a tighter scope than just a foreign key.
|
32
|
+
# Example: <tt>acts_as_list :scope => 'todo_list_id = #{todo_list_id} AND completed = 0'</tt>
|
33
|
+
def acts_as_list(options = {})
|
34
|
+
configuration = { :column => "position", :scope => "1 = 1" }
|
35
|
+
configuration.update(options) if options.is_a?(Hash)
|
36
|
+
|
37
|
+
configuration[:scope] = "#{configuration[:scope]}_id".intern if configuration[:scope].is_a?(Symbol) && configuration[:scope].to_s !~ /_id$/
|
38
|
+
|
39
|
+
if configuration[:scope].is_a?(Symbol)
|
40
|
+
scope_condition_method = %(
|
41
|
+
def scope_condition
|
42
|
+
if #{configuration[:scope].to_s}.nil?
|
43
|
+
"#{configuration[:scope].to_s} IS NULL"
|
44
|
+
else
|
45
|
+
"#{configuration[:scope].to_s} = \#{#{configuration[:scope].to_s}}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
)
|
49
|
+
else
|
50
|
+
scope_condition_method = "def scope_condition() \"#{configuration[:scope]}\" end"
|
51
|
+
end
|
52
|
+
|
53
|
+
class_eval <<-EOV
|
54
|
+
include ActiveRecord::Acts::List::InstanceMethods
|
55
|
+
|
56
|
+
def acts_as_list_class
|
57
|
+
::#{self.name}
|
58
|
+
end
|
59
|
+
|
60
|
+
def position_column
|
61
|
+
'#{configuration[:column]}'
|
62
|
+
end
|
63
|
+
|
64
|
+
#{scope_condition_method}
|
65
|
+
|
66
|
+
before_destroy :remove_from_list
|
67
|
+
before_create :add_to_list_bottom
|
68
|
+
EOV
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# All the methods available to a record that has had <tt>acts_as_list</tt> specified. Each method works
|
73
|
+
# by assuming the object to be the item in the list, so <tt>chapter.move_lower</tt> would move that chapter
|
74
|
+
# lower in the list of all chapters. Likewise, <tt>chapter.first?</tt> would return +true+ if that chapter is
|
75
|
+
# the first in the list of all chapters.
|
76
|
+
module InstanceMethods
|
77
|
+
# Insert the item at the given position (defaults to the top position of 1).
|
78
|
+
def insert_at(position = 1)
|
79
|
+
insert_at_position(position)
|
80
|
+
end
|
81
|
+
|
82
|
+
# Swap positions with the next lower item, if one exists.
|
83
|
+
def move_lower
|
84
|
+
return unless lower_item
|
85
|
+
|
86
|
+
acts_as_list_class.transaction do
|
87
|
+
lower_item.decrement_position
|
88
|
+
increment_position
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# Swap positions with the next higher item, if one exists.
|
93
|
+
def move_higher
|
94
|
+
return unless higher_item
|
95
|
+
|
96
|
+
acts_as_list_class.transaction do
|
97
|
+
higher_item.increment_position
|
98
|
+
decrement_position
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# Move to the bottom of the list. If the item is already in the list, the items below it have their
|
103
|
+
# position adjusted accordingly.
|
104
|
+
def move_to_bottom
|
105
|
+
return unless in_list?
|
106
|
+
acts_as_list_class.transaction do
|
107
|
+
decrement_positions_on_lower_items
|
108
|
+
assume_bottom_position
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# Move to the top of the list. If the item is already in the list, the items above it have their
|
113
|
+
# position adjusted accordingly.
|
114
|
+
def move_to_top
|
115
|
+
return unless in_list?
|
116
|
+
acts_as_list_class.transaction do
|
117
|
+
increment_positions_on_higher_items
|
118
|
+
assume_top_position
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
# Removes the item from the list.
|
123
|
+
def remove_from_list
|
124
|
+
if in_list?
|
125
|
+
decrement_positions_on_lower_items
|
126
|
+
update_attribute position_column, nil
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# Increase the position of this item without adjusting the rest of the list.
|
131
|
+
def increment_position
|
132
|
+
return unless in_list?
|
133
|
+
update_attribute position_column, self.send(position_column).to_i + 1
|
134
|
+
end
|
135
|
+
|
136
|
+
# Decrease the position of this item without adjusting the rest of the list.
|
137
|
+
def decrement_position
|
138
|
+
return unless in_list?
|
139
|
+
update_attribute position_column, self.send(position_column).to_i - 1
|
140
|
+
end
|
141
|
+
|
142
|
+
# Return +true+ if this object is the first in the list.
|
143
|
+
def first?
|
144
|
+
return false unless in_list?
|
145
|
+
self.send(position_column) == 1
|
146
|
+
end
|
147
|
+
|
148
|
+
# Return +true+ if this object is the last in the list.
|
149
|
+
def last?
|
150
|
+
return false unless in_list?
|
151
|
+
self.send(position_column) == bottom_position_in_list
|
152
|
+
end
|
153
|
+
|
154
|
+
# Return the next higher item in the list.
|
155
|
+
def higher_item
|
156
|
+
return nil unless in_list?
|
157
|
+
acts_as_list_class.find(:first, :conditions =>
|
158
|
+
"#{scope_condition} AND #{position_column} = #{(send(position_column).to_i - 1).to_s}"
|
159
|
+
)
|
160
|
+
end
|
161
|
+
|
162
|
+
# Return the next lower item in the list.
|
163
|
+
def lower_item
|
164
|
+
return nil unless in_list?
|
165
|
+
acts_as_list_class.find(:first, :conditions =>
|
166
|
+
"#{scope_condition} AND #{position_column} = #{(send(position_column).to_i + 1).to_s}"
|
167
|
+
)
|
168
|
+
end
|
169
|
+
|
170
|
+
# Test if this record is in a list
|
171
|
+
def in_list?
|
172
|
+
!send(position_column).nil?
|
173
|
+
end
|
174
|
+
|
175
|
+
private
|
176
|
+
def add_to_list_top
|
177
|
+
increment_positions_on_all_items
|
178
|
+
end
|
179
|
+
|
180
|
+
def add_to_list_bottom
|
181
|
+
self[position_column] = bottom_position_in_list.to_i + 1
|
182
|
+
end
|
183
|
+
|
184
|
+
# Overwrite this method to define the scope of the list changes
|
185
|
+
def scope_condition() "1" end
|
186
|
+
|
187
|
+
# Returns the bottom position number in the list.
|
188
|
+
# bottom_position_in_list # => 2
|
189
|
+
def bottom_position_in_list(except = nil)
|
190
|
+
item = bottom_item(except)
|
191
|
+
item ? item.send(position_column) : 0
|
192
|
+
end
|
193
|
+
|
194
|
+
# Returns the bottom item
|
195
|
+
def bottom_item(except = nil)
|
196
|
+
conditions = scope_condition
|
197
|
+
conditions = "#{conditions} AND #{self.class.primary_key} != #{except.id}" if except
|
198
|
+
acts_as_list_class.find(:first, :conditions => conditions, :order => "#{position_column} DESC")
|
199
|
+
end
|
200
|
+
|
201
|
+
# Forces item to assume the bottom position in the list.
|
202
|
+
def assume_bottom_position
|
203
|
+
update_attribute(position_column, bottom_position_in_list(self).to_i + 1)
|
204
|
+
end
|
205
|
+
|
206
|
+
# Forces item to assume the top position in the list.
|
207
|
+
def assume_top_position
|
208
|
+
update_attribute(position_column, 1)
|
209
|
+
end
|
210
|
+
|
211
|
+
# This has the effect of moving all the higher items up one.
|
212
|
+
def decrement_positions_on_higher_items(position)
|
213
|
+
acts_as_list_class.update_all(
|
214
|
+
"#{position_column} = (#{position_column} - 1)", "#{scope_condition} AND #{position_column} <= #{position}"
|
215
|
+
)
|
216
|
+
end
|
217
|
+
|
218
|
+
# This has the effect of moving all the lower items up one.
|
219
|
+
def decrement_positions_on_lower_items
|
220
|
+
return unless in_list?
|
221
|
+
acts_as_list_class.update_all(
|
222
|
+
"#{position_column} = (#{position_column} - 1)", "#{scope_condition} AND #{position_column} > #{send(position_column).to_i}"
|
223
|
+
)
|
224
|
+
end
|
225
|
+
|
226
|
+
# This has the effect of moving all the higher items down one.
|
227
|
+
def increment_positions_on_higher_items
|
228
|
+
return unless in_list?
|
229
|
+
acts_as_list_class.update_all(
|
230
|
+
"#{position_column} = (#{position_column} + 1)", "#{scope_condition} AND #{position_column} < #{send(position_column).to_i}"
|
231
|
+
)
|
232
|
+
end
|
233
|
+
|
234
|
+
# This has the effect of moving all the lower items down one.
|
235
|
+
def increment_positions_on_lower_items(position)
|
236
|
+
acts_as_list_class.update_all(
|
237
|
+
"#{position_column} = (#{position_column} + 1)", "#{scope_condition} AND #{position_column} >= #{position}"
|
238
|
+
)
|
239
|
+
end
|
240
|
+
|
241
|
+
# Increments position (<tt>position_column</tt>) of all items in the list.
|
242
|
+
def increment_positions_on_all_items
|
243
|
+
acts_as_list_class.update_all(
|
244
|
+
"#{position_column} = (#{position_column} + 1)", "#{scope_condition}"
|
245
|
+
)
|
246
|
+
end
|
247
|
+
|
248
|
+
def insert_at_position(position)
|
249
|
+
remove_from_list
|
250
|
+
increment_positions_on_lower_items(position)
|
251
|
+
self.update_attribute(position_column, position)
|
252
|
+
end
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|