Class DisplayService
In: lib/design_api.rb
Parent: DesignSubService

Design Web サービスで画面を扱う API を実装する。

Methods

export   import  

Classes and Modules

Class DisplayService::NoSuchDisplay
Class DisplayService::NoSuchProduct

Public Instance methods

book として与えられたデータで関連する画面情報を置き換える。

[Source]

      # File lib/design_api.rb, line 1103
1103:   def export(book)
1104:     raise NoSuchProduct if !book.product_id || book.product_id == 0
1105:     domain_id = book.client_identifier_y
1106:     product = Product.find(book.product_id)
1107:     # update or add displays
1108:     did = false
1109:     dids = []
1110:     book.main_sheet.display_items.each do |display_item|
1111:       display_id = display_item.display_id
1112:       proc = lambda do |display|
1113:         DisplayStruct::DisplayItem::REGULAR_MEMBER.each do |k,|
1114:           display.__send__("#{k}=", display_item.__send__(k))
1115:         end
1116:         if display.new_record?
1117:           display.save!
1118:           did = display.id # the latest display is expected to have new items as followed.
1119:           # copy items from the existing display.
1120:           source_display = display.class.find_by_product_id(book.product_id)
1121:           if source_display
1122:             source_display.items.each {|item| item.private_copy(did)}
1123:           end
1124:         end
1125:         display_item.display_names.each do |n|
1126:           lang = Language.find(n.language_id)
1127:           display.__send__("name_#{lang.code}=", n.display_name)
1128:         end
1129:         display.save!
1130:         dids << display.id
1131:       end
1132:       if !display_id || display_id == 0
1133:         # add a new one
1134:         display = "#{display_item.type}".constantize.new(:domain_id => domain_id,
1135:                                                          :product_id => book.product_id,
1136:                                                          :name_po => 0,
1137:                                                          :code => display_item.code)
1138:         proc.call(display)
1139:       else
1140:         display = Display.find(display_id)
1141:         # update the existing one
1142:         type = display.attributes["type"]
1143:         unless type == display_item.type
1144:           raise NoSuchDisplay, "type mismatch: #{type} vs #{display_item.type}"
1145:         end
1146:         proc.call(display)
1147:       end
1148:     end
1149:     # delete the inherent ones
1150:     edids = Display.find(:all, :conditions => {
1151:                            :product_id => book.product_id,
1152:                            :type => %w|DisplayToList DisplayToShow DisplayToEdit DisplayToNew|,
1153:                          }).map(&:id)
1154:     Display.delete(edids - dids)
1155:     # update or add items
1156:     iids = []
1157:     [:new, :edit, :show, :list].each_with_index do |k,i|
1158:       sheet = book.__send__("#{k}_sheet")
1159:       sheet_items = sheet.__send__("#{k}_items")
1160:       sheet_items.each do |sheet_item|
1161:         item_id = sheet_item.item_id
1162:         proc = lambda do |item|
1163:           sheet_item.class::REGULAR_MEMBER.each do |m,|
1164:             item.__send__("#{m}=", sheet_item.__send__(m))
1165:           end
1166:           item.save!
1167:           iids << item.id
1168:         end
1169:         if !item_id || item_id == 0
1170:           item_class = sheet_item.type.constantize
1171:           display_id = book.main_sheet.display_items[i].display_id || did
1172:           po_message = PoMessageSingular.create!(:domain_id => domain_id,
1173:                                                  :msgctxt   => "Application|",
1174:                                                  :msgid     => "Item|#{sheet_item.code}")
1175:           item = item_class.new(:domain_id  => domain_id,
1176:                                 :display_id => display_id,
1177:                                 :name_po    => po_message.id)
1178:           proc.call(item)
1179:         else
1180:           item = Item.find(item_id)
1181:           proc.call(item)
1182:         end
1183:       end
1184:     end
1185:     book.item_sheet.items.each(&:label_item)
1186:     # delete the inherent ones
1187:     eiids = Item.find(:all, :conditions => {:display_id => dids}).map(&:id)
1188:     Item.delete(eiids - iids)
1189:     return product.to_book.succeed
1190:   end

<em>book.product_id</e> を id にもつ product に関連する画面情報を返す。

[Source]

      # File lib/design_api.rb, line 1097
1097:   def import(book)
1098:     product = Product.find(book.product_id)
1099:     return product.to_book.succeed
1100:   end

[Validate]