リビジョン | 8ec74dec6d3b971a050d2a14979783ccd54f06a2 (tree) |
---|---|
日時 | 2015-10-02 08:40:12 |
作者 | ![]() |
コミッター | yasushiito |
fix:pp link
@@ -17,6 +17,7 @@ class Pettanr.Views.PanelPicture.Element extends Pettanr.View | ||
17 | 17 | picture: @picture, |
18 | 18 | spot: @spot |
19 | 19 | }) |
20 | + @listenTo(img, 'http_get', @http_get) | |
20 | 21 | @restyle() |
21 | 22 | this.$el.html(img.render().el) |
22 | 23 | @init_picture(img) |
@@ -42,7 +43,34 @@ class Pettanr.Views.PanelPicture.Element extends Pettanr.View | ||
42 | 43 | Pettanr.Views[element.singular()].Element |
43 | 44 | |
44 | 45 | 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 | |
46 | 74 | |
47 | 75 | class Pettanr.Views.PanelPicture.Element.Img extends Pettanr.View |
48 | 76 | tagName: 'img' |
@@ -37,11 +37,15 @@ class Pettanr.Views.Panel.Body extends Pettanr.View | ||
37 | 37 | index = element.get('z') - 1 |
38 | 38 | c = @element_class(element) |
39 | 39 | view = new c({element: element, root: @panel, spot: @spot}) |
40 | + @add_event(view) | |
40 | 41 | @views.splice(index, 0, view) |
41 | 42 | if @is_visible() |
42 | 43 | this.$el.append(view.render().el) |
43 | 44 | view |
44 | 45 | |
46 | + add_event: (view) -> | |
47 | + @listenTo(view, 'http_get', @http_get) | |
48 | + | |
45 | 49 | remove_element: (element) -> |
46 | 50 | _.each @views, (view) => |
47 | 51 | if view.element.cid == element.cid |
@@ -63,6 +67,9 @@ class Pettanr.Views.Panel.Body extends Pettanr.View | ||
63 | 67 | 'background-color': 'white' |
64 | 68 | } |
65 | 69 | |
70 | + http_get: (url) -> | |
71 | + @trigger('http_get', url) | |
72 | + | |
66 | 73 | class Pettanr.Views.Panel.Body.Edit extends Pettanr.Views.Panel.Body |
67 | 74 | |
68 | 75 | initialize: (options) -> |
@@ -111,3 +118,6 @@ class Pettanr.Views.Panel.Body.Edit extends Pettanr.Views.Panel.Body | ||
111 | 118 | element_class: (element) -> |
112 | 119 | Pettanr.Views[element.singular()].Element.Edit |
113 | 120 | |
121 | + # stop listen link msg | |
122 | + add_event: (view) -> | |
123 | + |
@@ -16,6 +16,7 @@ class Pettanr.Views.Panel.Show extends Pettanr.View.Show | ||
16 | 16 | @owner = new Pettanr.View.Show.Footer(@item, this, @default_footer_options()) |
17 | 17 | @listenTo(@header, 'click:pick', @click_pick) |
18 | 18 | @listenTo(@authored_by, 'click', @click_authored_by) |
19 | + @listenTo(@body, 'http_get', @http_get) | |
19 | 20 | |
20 | 21 | render: () -> |
21 | 22 | this.$el.html('') |
@@ -27,6 +28,9 @@ class Pettanr.Views.Panel.Show extends Pettanr.View.Show | ||
27 | 28 | this.$el.append(@owner.render().el) if @item.is_own() |
28 | 29 | this |
29 | 30 | |
31 | + http_get: (url) -> | |
32 | + @trigger('http_get', url) | |
33 | + | |
30 | 34 | click_pick: () -> |
31 | 35 | @trigger('pick', @item) |
32 | 36 |
@@ -5,7 +5,8 @@ class PanelPicture < Peta::Element | ||
5 | 5 | |
6 | 6 | validates :panel_id, :numericality => {:allow_blank => true} |
7 | 7 | 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')} | |
9 | 10 | validates :x, :presence => true, :numericality => true |
10 | 11 | validates :y, :presence => true, :numericality => true |
11 | 12 | validates :width, :presence => true, :numericality => true, :not_zero => true, :reverse => true, :sync_vh => true |
@@ -125,6 +126,14 @@ class PanelPicture < Peta::Element | ||
125 | 126 | {:include => {:panel => {:author => {}}, :picture => {:artist => {}, :license => {}}}} |
126 | 127 | end |
127 | 128 | |
129 | + def disp_link | |
130 | + if self.link =~ /\:\/\// | |
131 | + self.link | |
132 | + else | |
133 | + '/' + self.link | |
134 | + end | |
135 | + end | |
136 | + | |
128 | 137 | def scenario |
129 | 138 | if caption.blank? |
130 | 139 | '' |
@@ -1,3 +1,3 @@ | ||
1 | 1 | <%= 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) %> | |
3 | 3 | <% end %> |
@@ -7,8 +7,7 @@ require 'json' | ||
7 | 7 | require 'base64' |
8 | 8 | |
9 | 9 | 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" | |
12 | 11 | exit |
13 | 12 | end |
14 | 13 |
@@ -40,12 +39,11 @@ class Importer | ||
40 | 39 | @src_speech_balloon_templates[sb['id'].to_i] = sb |
41 | 40 | end |
42 | 41 | @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| | |
44 | 43 | @dest_speech_balloon_templates[sb['name']] = sb |
45 | 44 | end |
46 | 45 | @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| | |
49 | 47 | @src_writing_formats[wf['id'].to_i] = wf |
50 | 48 | end |
51 | 49 | @dest_writing_formats = {} |
@@ -66,14 +64,16 @@ class Importer | ||
66 | 64 | res = {} |
67 | 65 | u = host + 'licenses.json' |
68 | 66 | r = RestClient.get(u, :params => {:page_size => 100}) |
69 | - JSON.parse r | |
67 | + j = JSON.parse r | |
68 | + j['list'] | |
70 | 69 | end |
71 | 70 | |
72 | 71 | def license_groups host |
73 | 72 | res = {} |
74 | 73 | u = host + 'license_groups.json' |
75 | 74 | r = RestClient.get(u, :params => {:page_size => 100}) |
76 | - ary = JSON.parse r | |
75 | + j = JSON.parse r | |
76 | + ary = j['list'] | |
77 | 77 | ary.each do |l| |
78 | 78 | res[l['id'].to_i] = l |
79 | 79 | end |
@@ -83,28 +83,31 @@ class Importer | ||
83 | 83 | def speech_balloon_templates host, email, token |
84 | 84 | res = {} |
85 | 85 | 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'] | |
88 | 89 | end |
89 | 90 | |
90 | 91 | def writing_formats host, email, token |
91 | 92 | res = {} |
92 | 93 | 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'] | |
95 | 97 | end |
96 | 98 | |
97 | 99 | def system_pictures host, email, token |
98 | 100 | res = {} |
99 | 101 | 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'] | |
102 | 105 | end |
103 | 106 | |
104 | 107 | def panels host, email, token |
105 | 108 | res = {} |
106 | 109 | 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}) | |
108 | 111 | resp = JSON.parse r |
109 | 112 | status = resp['page_status'] |
110 | 113 | resp['list'].each do |panel| |
@@ -113,21 +116,27 @@ class Importer | ||
113 | 116 | res |
114 | 117 | end |
115 | 118 | |
116 | - def picture id, host, email, token | |
119 | + def panel pid, host, email, token | |
117 | 120 | 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}) | |
120 | 129 | JSON.parse r |
121 | 130 | end |
122 | 131 | |
123 | 132 | def search_resource_picture md5, host, email, token |
124 | 133 | res = {} |
125 | 134 | 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}) | |
127 | 136 | JSON.parse r |
128 | 137 | end |
129 | 138 | |
130 | - def prepare_panel_picture panel_picture | |
139 | + def prepare_panel_pictures panel_picture | |
131 | 140 | element_name = 'panel_pictures' |
132 | 141 | puts 'panel_picture:' + panel_picture['id'].to_s |
133 | 142 | # get picture from src |
@@ -145,7 +154,7 @@ class Importer | ||
145 | 154 | return |
146 | 155 | end |
147 | 156 | # 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'] | |
149 | 158 | puts 'license:' + picture['license_id'].to_s + '(' + src_ls_name + ')' |
150 | 159 | if dl = @dest_licenses[src_ls_name] |
151 | 160 | puts 'license ok(' + dl['id'].to_s + ')' |
@@ -155,13 +164,14 @@ class Importer | ||
155 | 164 | return |
156 | 165 | end |
157 | 166 | panel_picture['picture_id'] = rp['picture_id'] |
167 | + true | |
158 | 168 | end |
159 | 169 | |
160 | - def prepare_speech_balloon speech_balloon | |
170 | + def prepare_speech_balloons speech_balloon | |
161 | 171 | 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 + ')' | |
165 | 175 | if dsb = @dest_speech_balloon_templates[src_sb_name] |
166 | 176 | puts 'speech_balloon_template ok(' + dsb['id'].to_s + ')' |
167 | 177 | else |
@@ -169,8 +179,8 @@ class Importer | ||
169 | 179 | c = false |
170 | 180 | return |
171 | 181 | 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 + ')' | |
174 | 184 | if dsp = @dest_system_pictures[src_sp_md5] |
175 | 185 | puts 'balloon picture ok(' + dsp['id'].to_s + ')' |
176 | 186 | else |
@@ -178,8 +188,8 @@ class Importer | ||
178 | 188 | c = false |
179 | 189 | return |
180 | 190 | 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 + ')' | |
183 | 193 | if dwf = @dest_writing_formats[src_wf_name] |
184 | 194 | puts 'speech writing_format ok(' + dwf['id'].to_s + ')' |
185 | 195 | else |
@@ -187,47 +197,48 @@ class Importer | ||
187 | 197 | c = false |
188 | 198 | return |
189 | 199 | 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' | |
195 | 205 | #e.delete 'speech_balloon_template' |
196 | - balloon = e['balloon'] | |
197 | - e.delete 'balloon' | |
206 | + balloon = speech_balloon['balloon'] | |
207 | + speech_balloon.delete 'balloon' | |
198 | 208 | balloon.delete 'id' |
199 | 209 | balloon.delete 'speech_balloon_id' |
200 | - balloon["speech_balloon_template_settings"] = e["settings"] | |
210 | + balloon["speech_balloon_template_settings"] = speech_balloon["settings"] | |
201 | 211 | balloon.delete 'settings' |
202 | 212 | balloon['system_picture_id'] = dsp['id'] |
203 | 213 | 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"] | |
205 | 215 | |
206 | - speech = e['speech'] | |
207 | - e.delete 'speech' | |
216 | + speech = speech_balloon['speech'] | |
217 | + speech_balloon.delete 'speech' | |
208 | 218 | speech.delete 'id' |
209 | 219 | speech.delete 'speech_balloon_id' |
210 | - speech["speech_balloon_template_settings"] = e["settings"] | |
220 | + speech["speech_balloon_template_settings"] = speech_balloon["settings"] | |
211 | 221 | speech.delete 'settings' |
212 | 222 | 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"] | |
214 | 224 | 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"] | |
217 | 226 | |
218 | - e['balloon_attributes'] = balloon | |
219 | - e['speech_attributes'] = speech | |
227 | + speech_balloon['balloon_attributes'] = balloon | |
228 | + speech_balloon['speech_attributes'] = speech | |
229 | + true | |
220 | 230 | end |
221 | 231 | |
222 | - def prepare_ground_color ground_color | |
232 | + def prepare_ground_colors ground_color | |
223 | 233 | element_name = 'ground_colors' |
224 | 234 | puts 'ground_color:' + ground_color['id'].to_s |
235 | + true | |
225 | 236 | end |
226 | 237 | |
227 | - def prepare_ground_picture ground_picture | |
238 | + def prepare_ground_pictures ground_picture | |
228 | 239 | element_name = 'ground_pictures' |
229 | 240 | 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 | |
231 | 242 | if rps.any? |
232 | 243 | rp = rps.first |
233 | 244 | puts 'picture ok(' + rp['id'].to_s + ')' |
@@ -238,35 +249,38 @@ class Importer | ||
238 | 249 | end |
239 | 250 | #e['license_id'] = dl['id'] |
240 | 251 | 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 | |
242 | 261 | end |
243 | 262 | |
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 | |
250 | 272 | end |
251 | 273 | |
252 | 274 | 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| | |
254 | 276 | 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 | |
268 | 282 | end |
269 | - next unless c | |
283 | + next unless r | |
270 | 284 | puts '============ importable' |
271 | 285 | panel_json.delete 'id' |
272 | 286 | panel_json.delete 'author' |
@@ -289,7 +303,7 @@ u.each_panel do |panel_json| | ||
289 | 303 | end |
290 | 304 | begin |
291 | 305 | r = RestClient.post(u, |
292 | - {:json => panel_json}.to_json, | |
306 | + {:panel => panel_json}.to_json, | |
293 | 307 | :content_type => :json, :accept => :json, :email => dest_email, :token => dest_token |
294 | 308 | ) |
295 | 309 | res = JSON.parse r |
@@ -326,6 +326,7 @@ Pettanr::Application.routes.draw do | ||
326 | 326 | collection do |
327 | 327 | get :index |
328 | 328 | get :show |
329 | + get :search | |
329 | 330 | get :new |
330 | 331 | post :create |
331 | 332 | end |