[logaling-commit] logaling/logaling-server [github-project-related-to-user] Load note when editing term

Zurück zum Archiv-Index

SHIMADA Koji null+****@clear*****
Thu Sep 20 17:59:41 JST 2012


SHIMADA Koji	2012-09-20 17:59:41 +0900 (Thu, 20 Sep 2012)

  New Revision: dc13daadd435c27b9263e2cd86adebc59482e009
  https://github.com/logaling/logaling-server/commit/dc13daadd435c27b9263e2cd86adebc59482e009

  Merged c5d082c: Merge pull request #13 from logaling/enable-creating-user-glossary

  Log:
    Load note when editing term

  Modified files:
    app/controllers/terms_controller.rb
    app/models/term.rb
    app/models/user_glossary.rb

  Modified: app/controllers/terms_controller.rb (+1 -1)
===================================================================
--- app/controllers/terms_controller.rb    2012-09-20 17:49:52 +0900 (d7098fd)
+++ app/controllers/terms_controller.rb    2012-09-20 17:59:41 +0900 (d8b0f89)
@@ -17,7 +17,7 @@ class TermsController < ApplicationController
   end
 
   def edit
-    @term = Term.find(params[:id])
+    @term = Term.load(params[:id], @user_glossary)
   end
 
   def update

  Modified: app/models/term.rb (+10 -0)
===================================================================
--- app/models/term.rb    2012-09-20 17:49:52 +0900 (f2d1c1a)
+++ app/models/term.rb    2012-09-20 17:59:41 +0900 (74bd97f)
@@ -9,6 +9,10 @@ class Term
       end
     end
 
+    def load(id, user_glossary)
+      self.find(id).load(user_glossary)
+    end
+
     def id_to_source_term_and_target_term(id)
       id.split("source:")[1].split(" target:", 2)
     end
@@ -24,4 +28,10 @@ class Term
   def id
     "source:#{source_term} target:#{target_term}"
   end
+
+  def load(user_glossary)
+    term_data = user_glossary.find_bilingual_pair(source_term, target_term)
+    self.note = term_data[:note]
+    self
+  end
 end

  Modified: app/models/user_glossary.rb (+7 -0)
===================================================================
--- app/models/user_glossary.rb    2012-09-20 17:49:52 +0900 (82c0e80)
+++ app/models/user_glossary.rb    2012-09-20 17:59:41 +0900 (4f11532)
@@ -55,6 +55,13 @@ class UserGlossary < ActiveRecord::Base
     LogalingServer.repository.index
   end
 
+  def find_bilingual_pair(soruce_term, target_term)
+    glossary = find_glossary
+    raise Logaling::GlossaryNotFound unless glossary
+
+    glossary.find_bilingual_pairs(soruce_term, target_term).first
+  end
+
   def terms(annotation=nil)
     glossary = find_glossary
     raise Logaling::GlossaryNotFound unless glossary
-------------- next part --------------
An HTML attachment was scrubbed...
Download 



More information about the logaling-commit mailing list
Zurück zum Archiv-Index