• R/O
  • HTTP
  • SSH
  • HTTPS

pettanr: コミット

サーバ側、Railsシステム本体


コミットメタ情報

リビジョン8ec74dec6d3b971a050d2a14979783ccd54f06a2 (tree)
日時2015-10-02 08:40:12
作者yasushiito <yas@pen-...>
コミッターyasushiito

ログメッセージ

fix:pp link

変更サマリ

差分

--- a/app/assets/javascripts/views/panel_pictures/element.js.coffee
+++ b/app/assets/javascripts/views/panel_pictures/element.js.coffee
@@ -17,6 +17,7 @@ class Pettanr.Views.PanelPicture.Element extends Pettanr.View
1717 picture: @picture,
1818 spot: @spot
1919 })
20+ @listenTo(img, 'http_get', @http_get)
2021 @restyle()
2122 this.$el.html(img.render().el)
2223 @init_picture(img)
@@ -42,7 +43,34 @@ class Pettanr.Views.PanelPicture.Element extends Pettanr.View
4243 Pettanr.Views[element.singular()].Element
4344
4445 img_class: () ->
45- Pettanr.Views.PanelPicture.Element.Img
46+ if @element.get('link')
47+ if @element.get('link').match(/\:\/\//)
48+ Pettanr.Views.PanelPicture.Element.LinkedImg
49+ else
50+ Pettanr.Views.PanelPicture.Element.ButtonImg
51+ else
52+ Pettanr.Views.PanelPicture.Element.Img
53+
54+ http_get: (url) ->
55+ @trigger('http_get', url)
56+
57+class Pettanr.Views.PanelPicture.Element.LinkedImg extends Tag.A_
58+
59+ initialize: (options) ->
60+ img = new Pettanr.Views.PanelPicture.Element.Img(options)
61+ super({content: img.render().el, attr: {href: options.element.get('link')}})
62+
63+class Pettanr.Views.PanelPicture.Element.ButtonImg extends Tag.A
64+
65+ initialize: (options) ->
66+ img = new Pettanr.Views.PanelPicture.Element.Img(options)
67+ @link = options.element.get('link')
68+ super({content: img.render().el, attr: {href: '/' + @link}})
69+
70+ click: () ->
71+ super()
72+ @trigger('http_get', @link)
73+ return false
4674
4775 class Pettanr.Views.PanelPicture.Element.Img extends Pettanr.View
4876 tagName: 'img'
--- a/app/assets/javascripts/views/panels/body.js.coffee
+++ b/app/assets/javascripts/views/panels/body.js.coffee
@@ -37,11 +37,15 @@ class Pettanr.Views.Panel.Body extends Pettanr.View
3737 index = element.get('z') - 1
3838 c = @element_class(element)
3939 view = new c({element: element, root: @panel, spot: @spot})
40+ @add_event(view)
4041 @views.splice(index, 0, view)
4142 if @is_visible()
4243 this.$el.append(view.render().el)
4344 view
4445
46+ add_event: (view) ->
47+ @listenTo(view, 'http_get', @http_get)
48+
4549 remove_element: (element) ->
4650 _.each @views, (view) =>
4751 if view.element.cid == element.cid
@@ -63,6 +67,9 @@ class Pettanr.Views.Panel.Body extends Pettanr.View
6367 'background-color': 'white'
6468 }
6569
70+ http_get: (url) ->
71+ @trigger('http_get', url)
72+
6673 class Pettanr.Views.Panel.Body.Edit extends Pettanr.Views.Panel.Body
6774
6875 initialize: (options) ->
@@ -111,3 +118,6 @@ class Pettanr.Views.Panel.Body.Edit extends Pettanr.Views.Panel.Body
111118 element_class: (element) ->
112119 Pettanr.Views[element.singular()].Element.Edit
113120
121+ # stop listen link msg
122+ add_event: (view) ->
123+
--- a/app/assets/javascripts/views/panels/show.js.coffee
+++ b/app/assets/javascripts/views/panels/show.js.coffee
@@ -16,6 +16,7 @@ class Pettanr.Views.Panel.Show extends Pettanr.View.Show
1616 @owner = new Pettanr.View.Show.Footer(@item, this, @default_footer_options())
1717 @listenTo(@header, 'click:pick', @click_pick)
1818 @listenTo(@authored_by, 'click', @click_authored_by)
19+ @listenTo(@body, 'http_get', @http_get)
1920
2021 render: () ->
2122 this.$el.html('')
@@ -27,6 +28,9 @@ class Pettanr.Views.Panel.Show extends Pettanr.View.Show
2728 this.$el.append(@owner.render().el) if @item.is_own()
2829 this
2930
31+ http_get: (url) ->
32+ @trigger('http_get', url)
33+
3034 click_pick: () ->
3135 @trigger('pick', @item)
3236
--- a/app/models/panel_picture.rb
+++ b/app/models/panel_picture.rb
@@ -5,7 +5,8 @@ class PanelPicture < Peta::Element
55
66 validates :panel_id, :numericality => {:allow_blank => true}
77 validates :picture_id, :numericality => true, :existence => {:both => false}
8- validates :link, :length => {:maximum => 200}, :url => {:allow_blank => true, :message => I18n.t('errors.messages.url')}
8+ validates :link, :length => {:maximum => 200}, :allow_blank => true
9+ #validates :link, :length => {:maximum => 200}, :url => {:allow_blank => true, :message => I18n.t('errors.messages.url')}
910 validates :x, :presence => true, :numericality => true
1011 validates :y, :presence => true, :numericality => true
1112 validates :width, :presence => true, :numericality => true, :not_zero => true, :reverse => true, :sync_vh => true
@@ -125,6 +126,14 @@ class PanelPicture < Peta::Element
125126 {:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}}
126127 end
127128
129+ def disp_link
130+ if self.link =~ /\:\/\//
131+ self.link
132+ else
133+ '/' + self.link
134+ end
135+ end
136+
128137 def scenario
129138 if caption.blank?
130139 ''
--- a/app/views/panel_pictures/_element.html.erb
+++ b/app/views/panel_pictures/_element.html.erb
@@ -1,3 +1,3 @@
11 <%= content_tag :div, element.tag_attributes(:div, {'class' => "pettanr-panel-picture-wrapper", 'style' => element.opt_div_style()}) do %>
2- <%= link_to_unless(element.link.blank?, tag(:img, element.opt_img_tag(spot)), element.link) %>
2+ <%= link_to_unless(element.link.blank?, tag(:img, element.opt_img_tag(spot)), element.disp_link) %>
33 <% end %>
--- a/bin/panel_import.rb
+++ b/bin/panel_import.rb
@@ -7,8 +7,7 @@ require 'json'
77 require 'base64'
88
99 if ARGV.size < 1
10- puts "uploader.rb src_host src_email src_token dest_host dest_email dest_token"
11- puts "upload on child dirs"
10+ puts "panel_import.rb src_host src_email src_token dest_host dest_email dest_token"
1211 exit
1312 end
1413
@@ -40,12 +39,11 @@ class Importer
4039 @src_speech_balloon_templates[sb['id'].to_i] = sb
4140 end
4241 @dest_speech_balloon_templates = {}
43- self.speech_balloon_templates(@dest_host, @src_email, @src_token).each do |sb|
42+ self.speech_balloon_templates(@dest_host, @dest_email, @dest_token).each do |sb|
4443 @dest_speech_balloon_templates[sb['name']] = sb
4544 end
4645 @src_writing_formats = {}
47- self.writing_formats(@dest_host, @src_email, @src_token).each do |wf|
48- # self.writing_formats(@src_host, @src_auth).each do |wf|
46+ self.writing_formats(@src_host, @src_email, @src_token).each do |wf|
4947 @src_writing_formats[wf['id'].to_i] = wf
5048 end
5149 @dest_writing_formats = {}
@@ -66,14 +64,16 @@ class Importer
6664 res = {}
6765 u = host + 'licenses.json'
6866 r = RestClient.get(u, :params => {:page_size => 100})
69- JSON.parse r
67+ j = JSON.parse r
68+ j['list']
7069 end
7170
7271 def license_groups host
7372 res = {}
7473 u = host + 'license_groups.json'
7574 r = RestClient.get(u, :params => {:page_size => 100})
76- ary = JSON.parse r
75+ j = JSON.parse r
76+ ary = j['list']
7777 ary.each do |l|
7878 res[l['id'].to_i] = l
7979 end
@@ -83,28 +83,31 @@ class Importer
8383 def speech_balloon_templates host, email, token
8484 res = {}
8585 u = host + 'speech_balloon_templates.json'
86- r = RestClient.get(u, {:params => {:page_size => 100}}, {:email => email, :token => token})
87- JSON.parse r
86+ r = RestClient.get(u, {:params => {:page_size => 100}, :email => email, :token => token})
87+ j = JSON.parse r
88+ j['list']
8889 end
8990
9091 def writing_formats host, email, token
9192 res = {}
9293 u = host + 'writing_formats.json'
93- r = RestClient.get(u, {:params => {:page_size => 100}}, {:email => email, :token => token})
94- JSON.parse r
94+ r = RestClient.get(u, {:params => {:page_size => 100}, :email => email, :token => token})
95+ j = JSON.parse r
96+ j['list']
9597 end
9698
9799 def system_pictures host, email, token
98100 res = {}
99101 u = host + 'system_pictures.json'
100- r = RestClient.get(u, {:params => {:page_size => 100}}, {:email => email, :token => token})
101- JSON.parse r
102+ r = RestClient.get(u, {:params => {:page_size => 100}, :email => email, :token => token})
103+ j = JSON.parse r
104+ j['list']
102105 end
103106
104107 def panels host, email, token
105108 res = {}
106109 u = host + 'home/panels.json'
107- r = RestClient.get(u, {:params => {:page_size => 100}}, {:email => email, :token => token})
110+ r = RestClient.get(u, {:params => {:page_size => 100}, :email => email, :token => token})
108111 resp = JSON.parse r
109112 status = resp['page_status']
110113 resp['list'].each do |panel|
@@ -113,21 +116,27 @@ class Importer
113116 res
114117 end
115118
116- def picture id, host, email, token
119+ def panel pid, host, email, token
117120 res = {}
118- u = host + 'pictures/'
119- r = RestClient.get(u, {:params => {:id => id}}, {:email => email, :token => token})
121+ u = host + 'panels/' + pid.to_s + '.json'
122+ r = RestClient.get(u, {:params => {:with_elements => true}, :email => email, :token => token})
123+ j = JSON.parse r
124+ end
125+
126+ def picture id, host, email, token
127+ u = host + 'pictures/' + id.to_s + '.json'
128+ r = RestClient.get(u, {:email => email, :token => token})
120129 JSON.parse r
121130 end
122131
123132 def search_resource_picture md5, host, email, token
124133 res = {}
125134 u = host + 'resource_pictures/search.json'
126- r = RestClient.get(u, {:params => {:md5 => md5}}, {:email => email, :token => token})
135+ r = RestClient.get(u, {:params => {:md5 => md5}, :email => email, :token => token})
127136 JSON.parse r
128137 end
129138
130- def prepare_panel_picture panel_picture
139+ def prepare_panel_pictures panel_picture
131140 element_name = 'panel_pictures'
132141 puts 'panel_picture:' + panel_picture['id'].to_s
133142 # get picture from src
@@ -145,7 +154,7 @@ class Importer
145154 return
146155 end
147156 # get lisence's id if exists?
148- src_ls_name = @src_licenses[picture['license_id']]['name'].gsub /License\:/, 'Licenses:'
157+ src_ls_name = @src_licenses[picture['license_id']]['name']
149158 puts 'license:' + picture['license_id'].to_s + '(' + src_ls_name + ')'
150159 if dl = @dest_licenses[src_ls_name]
151160 puts 'license ok(' + dl['id'].to_s + ')'
@@ -155,13 +164,14 @@ class Importer
155164 return
156165 end
157166 panel_picture['picture_id'] = rp['picture_id']
167+ true
158168 end
159169
160- def prepare_speech_balloon speech_balloon
170+ def prepare_speech_balloons speech_balloon
161171 element_name = 'speech_balloons'
162- puts 'sb:' + e['id'].to_s
163- src_sb_name = @src_speech_balloon_templates[e['speech_balloon_template_id']]['name']
164- puts 'speech_balloon_template:' + e['speech_balloon_template_id'].to_s + '(' + src_sb_name + ')'
172+ puts 'sb:' + speech_balloon['id'].to_s
173+ src_sb_name = @src_speech_balloon_templates[speech_balloon['speech_balloon_template_id']]['name']
174+ puts 'speech_balloon_template:' + speech_balloon['speech_balloon_template_id'].to_s + '(' + src_sb_name + ')'
165175 if dsb = @dest_speech_balloon_templates[src_sb_name]
166176 puts 'speech_balloon_template ok(' + dsb['id'].to_s + ')'
167177 else
@@ -169,8 +179,8 @@ class Importer
169179 c = false
170180 return
171181 end
172- src_sp_md5 = @src_system_pictures[e['balloon']['system_picture_id']]['md5']
173- puts 'balloon picture:' + e['balloon']['system_picture_id'].to_s + '(' + src_sp_md5 + ')'
182+ src_sp_md5 = @src_system_pictures[speech_balloon['balloon']['system_picture_id']]['md5']
183+ puts 'balloon picture:' + speech_balloon['balloon']['system_picture_id'].to_s + '(' + src_sp_md5 + ')'
174184 if dsp = @dest_system_pictures[src_sp_md5]
175185 puts 'balloon picture ok(' + dsp['id'].to_s + ')'
176186 else
@@ -178,8 +188,8 @@ class Importer
178188 c = false
179189 return
180190 end
181- src_wf_name = @src_writing_formats[e['speech']['writing_format_id']]['name']
182- puts 'speech writing_format:' + e['speech']['writing_format_id'].to_s + '(' + src_wf_name + ')'
191+ src_wf_name = @src_writing_formats[speech_balloon['speech']['writing_format_id']]['name']
192+ puts 'speech writing_format:' + speech_balloon['speech']['writing_format_id'].to_s + '(' + src_wf_name + ')'
183193 if dwf = @dest_writing_formats[src_wf_name]
184194 puts 'speech writing_format ok(' + dwf['id'].to_s + ')'
185195 else
@@ -187,47 +197,48 @@ class Importer
187197 c = false
188198 return
189199 end
190- e['speech_balloon_template_id'] = dsb['id']
191- e["speech_balloon_template_settings"] = e["settings"]
192- e.delete 'settings'
193- e["speech_balloon_template_classname"] = dsb["classname"]
194- e.delete 'classname'
200+ speech_balloon['speech_balloon_template_id'] = dsb['id']
201+ speech_balloon["speech_balloon_template_settings"] = speech_balloon["settings"]
202+ speech_balloon.delete 'settings'
203+ speech_balloon["speech_balloon_template_module_name"] = dsb["module_name"]
204+ speech_balloon.delete 'module_name'
195205 #e.delete 'speech_balloon_template'
196- balloon = e['balloon']
197- e.delete 'balloon'
206+ balloon = speech_balloon['balloon']
207+ speech_balloon.delete 'balloon'
198208 balloon.delete 'id'
199209 balloon.delete 'speech_balloon_id'
200- balloon["speech_balloon_template_settings"] = e["settings"]
210+ balloon["speech_balloon_template_settings"] = speech_balloon["settings"]
201211 balloon.delete 'settings'
202212 balloon['system_picture_id'] = dsp['id']
203213 balloon['speech_balloon_template_id'] = dsb['id']
204- balloon["speech_balloon_template_classname"] = dsb["classname"]
214+ balloon["speech_balloon_template_module_name"] = dsb["module_name"]
205215
206- speech = e['speech']
207- e.delete 'speech'
216+ speech = speech_balloon['speech']
217+ speech_balloon.delete 'speech'
208218 speech.delete 'id'
209219 speech.delete 'speech_balloon_id'
210- speech["speech_balloon_template_settings"] = e["settings"]
220+ speech["speech_balloon_template_settings"] = speech_balloon["settings"]
211221 speech.delete 'settings'
212222 speech['speech_balloon_template_id'] = dsb['id']
213- speech["speech_balloon_template_classname"] = dsb["classname"]
223+ speech["speech_balloon_template_module_name"] = dsb["module_name"]
214224 speech['writing_format_id'] = dwf['id']
215-# speech["writing_format_classname"] = 'Pettanr' + dwf["classname"]
216- speech["writing_format_classname"] = dwf["classname"]
225+ speech["writing_format_module_name"] = dwf["module_name"]
217226
218- e['balloon_attributes'] = balloon
219- e['speech_attributes'] = speech
227+ speech_balloon['balloon_attributes'] = balloon
228+ speech_balloon['speech_attributes'] = speech
229+ true
220230 end
221231
222- def prepare_ground_color ground_color
232+ def prepare_ground_colors ground_color
223233 element_name = 'ground_colors'
224234 puts 'ground_color:' + ground_color['id'].to_s
235+ true
225236 end
226237
227- def prepare_ground_picture ground_picture
238+ def prepare_ground_pictures ground_picture
228239 element_name = 'ground_pictures'
229240 puts 'ground_picture:' + ground_picture['id'].to_s
230- rps = self.resource_picture ground_picture['picture']['md5'], @dest_host, @dest_auth
241+ rps = self.resource_picture ground_picture['picture']['md5'], @dest_host, @dest_email, @dest_token
231242 if rps.any?
232243 rp = rps.first
233244 puts 'picture ok(' + rp['id'].to_s + ')'
@@ -238,35 +249,38 @@ class Importer
238249 end
239250 #e['license_id'] = dl['id']
240251 ground_picture['picture_id'] = rp['id']
241- #e.delete 'license'
252+ true
253+ end
254+
255+ def add_attribute element_name, panel_json, attribute
256+ eid = attribute['id']
257+ attribute.delete 'id'
258+ attribute.delete 'panel_id'
259+ panel_json[element_name + '_attributes'] ||= []
260+ panel_json[element_name + '_attributes'].push attribute
242261 end
243262
244- def add_attribute panel_json, attribute
245- eid = e['id']
246- e.delete 'id'
247- e.delete 'panel_id'
248- panel_json[element_name + '_attributes'] ||= {}
249- panel_json[element_name + '_attributes']['new' + eid.to_s] = e
263+ def edit_elements panel_json, element_name
264+ r = true
265+ (panel_json[element_name] || {}).each do |attr|
266+ r = self.__send__ 'prepare_' + element_name, attr
267+ break unless r
268+ self.add_attribute element_name, panel_json, attr
269+ end
270+ panel_json.delete element_name
271+ r
250272 end
251273
252274 def each_panel
253- self.panels(@src_host, @src_email, @src_token).each do |key, panel_json|
275+ self.panels(@src_host, @src_email, @src_token).each do |key, attrs|
254276 puts 'source panel:' + key.to_s
255- c = true
256- panel_json['panel_pictures'].each do |panel_picture|
257- self.prepare_panel_picture panel_picture
258- self.add_attribute panel_json, panel_picture
259- end
260- panel_json['speech_balloons'].each do |speech_balloon|
261- self.prepare_speech_balloon speech_balloon
262- end
263- panel_json['ground_colors'].each do |ground_color|
264- self.prepare_ground_color ground_color
265- end
266- panel_json['ground_pictures'].each do |ground_picture|
267- self.prepare_ground_picture ground_picture
277+ panel_json = self.panel(key, @src_host, @src_email, @src_token)
278+ r = true
279+ ['panel_pictures', 'speech_balloons', 'ground_pictures', 'ground_colors'].each do |element_name|
280+ r = self.edit_elements(panel_json, element_name)
281+ break unless r
268282 end
269- next unless c
283+ next unless r
270284 puts '============ importable'
271285 panel_json.delete 'id'
272286 panel_json.delete 'author'
@@ -289,7 +303,7 @@ u.each_panel do |panel_json|
289303 end
290304 begin
291305 r = RestClient.post(u,
292- {:json => panel_json}.to_json,
306+ {:panel => panel_json}.to_json,
293307 :content_type => :json, :accept => :json, :email => dest_email, :token => dest_token
294308 )
295309 res = JSON.parse r
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -326,6 +326,7 @@ Pettanr::Application.routes.draw do
326326 collection do
327327 get :index
328328 get :show
329+ get :search
329330 get :new
330331 post :create
331332 end
旧リポジトリブラウザで表示