SUZUKI Miho
null+****@clear*****
Fri Sep 28 10:50:34 JST 2012
SUZUKI Miho 2012-09-28 10:50:34 +0900 (Fri, 28 Sep 2012) New Revision: afbb8bdabab6769e71ba41676e5512d432d98de0 https://github.com/logaling/logaling-server/commit/afbb8bdabab6769e71ba41676e5512d432d98de0 Merged 92895a5: Merge pull request #21 from logaling/enable-copy-user-glossary Log: Enable to create a new user glossary by copying other user glossary Modified files: app/controllers/user_glossaries_controller.rb app/models/user_glossary.rb app/views/user_glossaries/_form.html.haml Modified: app/controllers/user_glossaries_controller.rb (+6 -0) =================================================================== --- app/controllers/user_glossaries_controller.rb 2012-09-27 17:58:10 +0900 (e6744bb) +++ app/controllers/user_glossaries_controller.rb 2012-09-28 10:50:34 +0900 (68f9dca) @@ -2,6 +2,7 @@ class UserGlossariesController < ApplicationController before_filter :authenticate!, :except => :show before_filter :valid_user?, :only => [:new, :create] + before_filter :set_my_glossaries, :only => [:new, :create] # GET /user_glossaries/1 def show @@ -37,4 +38,9 @@ class UserGlossariesController < ApplicationController rescue ActiveRecord::RecordNotFound render :file => 'public/404.html', :status => 404, :layout => false end + + private + def set_my_glossaries + @my_glossaries = signed_in? ? current_user.user_glossaries : [] + end end Modified: app/models/user_glossary.rb (+9 -2) =================================================================== --- app/models/user_glossary.rb 2012-09-27 17:58:10 +0900 (51d5045) +++ app/models/user_glossary.rb 2012-09-28 10:50:34 +0900 (019c9dc) @@ -9,7 +9,8 @@ class UserGlossary < ActiveRecord::Base end end - attr_accessible :name, :source_language, :target_language + attr_accessor :original_user_glossary_id + attr_accessible :name, :source_language, :target_language, :original_user_glossary_id belongs_to :user @@ -93,7 +94,13 @@ class UserGlossary < ActiveRecord::Base end def create_personal_project! - LogalingServer.repository.create_personal_project(glossary_name, source_language, target_language) + dest_project = LogalingServer.repository.create_personal_project(glossary_name, source_language, target_language) + if original_user_glossary_id.present? + src_user_glossary = UserGlossary.find(original_user_glossary_id) + src_glossary = LogalingServer.repository.find_glossary(src_user_glossary.glossary_name, src_user_glossary.source_language, src_user_glossary.target_language) + dest_glossary = dest_project.glossary(source_language, target_language) + dest_glossary.merge!(src_glossary) + end LogalingServer.repository.index end Modified: app/views/user_glossaries/_form.html.haml (+5 -0) =================================================================== --- app/views/user_glossaries/_form.html.haml 2012-09-27 17:58:10 +0900 (411cd82) +++ app/views/user_glossaries/_form.html.haml 2012-09-28 10:50:34 +0900 (12ad021) @@ -6,6 +6,11 @@ - @user_glossary.errors.full_messages.each do |msg| %li= msg + - if signed_in? && !@my_glossaries.empty? + .control-group + = f.label :original_user_glossary_id, :class => 'control-label' + .controls + = f.collection_select :original_user_glossary_id, @my_glossaries, :id, :name, :prompt => true .control-group = f.label :name, :class => 'control-label required' .controls -------------- next part -------------- An HTML attachment was scrubbed... Download