pageflow-linkmap-page 2.4.0 → 2.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -0
  3. data/CHANGELOG.md +17 -6
  4. data/Gemfile +2 -0
  5. data/app/assets/javascript/pageflow/linkmap_page/editor.js +1 -1
  6. data/app/assets/javascript/pageflow/linkmap_page/editor/models/area.js +1 -1
  7. data/app/assets/javascript/pageflow/linkmap_page/editor/models/color_map_file.js +1 -1
  8. data/app/assets/javascript/pageflow/linkmap_page/editor/models/{processed_file.js → generated_image_file.js} +1 -1
  9. data/app/assets/javascript/pageflow/linkmap_page/editor/models/masked_image_file.js +1 -1
  10. data/app/assets/javascript/pageflow/linkmap_page/editor/models/new_area_file_selection_handler.js +1 -1
  11. data/app/assets/javascript/pageflow/linkmap_page/editor/models/page_configuration_mixin.js +11 -10
  12. data/app/assets/javascript/pageflow/linkmap_page/page_type.js +23 -10
  13. data/app/assets/javascript/pageflow/linkmap_page/widgets/hover_video.js +5 -0
  14. data/app/assets/javascript/pageflow/linkmap_page/widgets/linkmap.js +4 -0
  15. data/app/assets/javascript/pageflow/linkmap_page/widgets/linkmap/color_map.js +5 -5
  16. data/app/helpers/pageflow/linkmap_page/areas_helper.rb +5 -4
  17. data/app/jobs/pageflow/linkmap_page/process_source_image_file_job.rb +4 -0
  18. data/app/models/pageflow/linkmap_page/color_map_file.rb +4 -2
  19. data/app/models/pageflow/linkmap_page/{processed_image_file.rb → generated_image_file.rb} +14 -16
  20. data/app/models/pageflow/linkmap_page/masked_image_file.rb +5 -1
  21. data/app/views/pageflow/linkmap_page/areas/_div.html.erb +1 -2
  22. data/app/views/pageflow/linkmap_page/page.html.erb +1 -1
  23. data/config/locales/de.yml +1 -3
  24. data/config/locales/en.yml +1 -1
  25. data/lib/pageflow/linkmap_page/page_type.rb +18 -4
  26. data/lib/pageflow/linkmap_page/paperclip_processors/colors.rb +1 -0
  27. data/lib/pageflow/linkmap_page/version.rb +1 -1
  28. data/pageflow-linkmap-page.gemspec +5 -2
  29. data/spec/factories/image_file.rb +6 -0
  30. data/spec/helpers/pageflow/linkmap_page/areas_helper_spec.rb +50 -33
  31. data/spec/integration/masked_image_file_type_spec.rb +10 -2
  32. data/spec/models/pageflow/linkmap_page/color_map_file_spec.rb +21 -1
  33. data/spec/models/pageflow/linkmap_page/masked_image_file_spec.rb +49 -1
  34. data/spec/pageflow/linkmap_page/paperclip_processors/colors_spec.rb +36 -2
  35. data/spec/support/config/active_job.rb +11 -0
  36. data/spec/support/config/timecop.rb +11 -0
  37. metadata +27 -12
  38. data/lib/tasks/pageflow_linkmap_page_tasks.rake +0 -149
  39. data/spec/support/config/resque.rb +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bdf4cd722e530a4c6cd5415a63c213c591b843a48b4bc538750f1ab46c74ee67
4
- data.tar.gz: c1e44bf9e9185529a86f6d6d9507c4f5ab006723a743fd08eb49d5c769723062
3
+ metadata.gz: f3fb56e43873a0680f0aa09f672fdbe2653db7378a68fc8cda40489dafdb8f22
4
+ data.tar.gz: 17e6bf2a58871c3ceb2bfd4f700e3c20721228a74afca783dcdcd4e333ed7ad3
5
5
  SHA512:
6
- metadata.gz: 32e50b565cc8badc9903468b367a2198130c0f25b34e15e480dc24a52a1473d0e5ffa60fbd8e569ecd9d4de1f96703d0d779e123b4190f51f9f43546987f3341
7
- data.tar.gz: e1501cf8952a8b2f35cda9b97c8dc70afee99d92f00612fd6865d236c24de4fdf84f7d04193863af9d947584a8b099fe3f25ca15bc5b5b5ad9825eda8ee71586
6
+ metadata.gz: ba26260154e63ae7b2c0ca60cb504109c808a24118d665d7e8bd46c41262ac3bc04284a34145495b48677b806d8f1b7abafbf73411713a4fadf0a69cf3830393
7
+ data.tar.gz: ab0bb4eb2593f77eb5b1d522ecbbff44ea76cce3b82a19ccce70909c61fab5cb4f1f54dfb49112cc1bfddd3a883c86d8cfc576168ef87f8e779e1f53846fa29c
@@ -12,3 +12,6 @@ services:
12
12
 
13
13
  script:
14
14
  - bin/rspec
15
+
16
+ services:
17
+ - mysql
@@ -1,14 +1,25 @@
1
1
  # CHANGELOG
2
2
 
3
- ### Version 2.4.0
3
+ ### Version 2.7.1
4
4
 
5
- 2019-05-20
5
+ 2020-08-13
6
6
 
7
- [Compare changes](https://github.com/codevise/pageflow-linkmap-page/compare/2-3-stable...v2.4.0)
7
+ [Compare changes](https://github.com/codevise/pageflow-linkmap-page/compare/v2.7.0...v2.7.1)
8
8
 
9
- - Use theme variable for overlay text color
10
- ([#58](https://github.com/codevise/pageflow-linkmap-page/pull/58))
9
+ - Bug fix: Use perma id for audio hotspot files
10
+ ([#72](https://github.com/codevise/pageflow-linkmap-page/pull/72))
11
+
12
+ ### Version 2.7.0
13
+
14
+ 2020-04-01
15
+
16
+ [Compare changes](https://github.com/codevise/pageflow-linkmap-page/compare/2-6-stable...v2.7.0)
17
+
18
+ - Enabled video autoplay for mobile devices.
19
+ ([#70](https://github.com/codevise/pageflow-linkmap-page/pull/70))
20
+ - Delete cleanup migration
21
+ ([#68](https://github.com/codevise/pageflow-linkmap-page/pull/68))
11
22
 
12
23
  See
13
- [2-3-stable branch](https://github.com/codevise/pageflow-linkmap-page/blob/2-3-stable/CHANGELOG.md)
24
+ [2-6-stable branch](https://github.com/codevise/pageflow-linkmap-page/blob/2-6-stable/CHANGELOG.md)
14
25
  for previous changes.
data/Gemfile CHANGED
@@ -5,3 +5,5 @@ gemspec
5
5
 
6
6
  gem 'spring-commands-rspec', group: :development
7
7
  gem 'spring-commands-teaspoon', group: :development
8
+
9
+ gem 'pageflow-external-links', git: 'https://github.com/codevise/pageflow-external-links', branch: 'master'
@@ -1,6 +1,6 @@
1
1
  //= require_self
2
2
 
3
- //= require ./editor/models/processed_file
3
+ //= require ./editor/models/generated_image_file
4
4
  //= require_tree ./editor/models
5
5
  //= require_tree ./editor/collections
6
6
  //= require_tree ./editor/routers
@@ -11,7 +11,7 @@ pageflow.linkmapPage.Area = Backbone.Model.extend({
11
11
  // pageflow.xxx.getPolymorphic(this.get('target_type'), this.get('target_id'));
12
12
  //
13
13
  if (this.get('target_type') === 'audio_file') {
14
- return pageflow.audioFiles.get(this.get('target_id'));
14
+ return pageflow.audioFiles.getByPermaId(this.get('target_id'));
15
15
  }
16
16
  else if (this.get('target_type') === 'page') {
17
17
  return pageflow.pages.getByPermaId(this.get('target_id'));
@@ -1,4 +1,4 @@
1
- pageflow.linkmapPage.ColorMapFile = pageflow.linkmapPage.ProcessedFile.extend({
1
+ pageflow.linkmapPage.ColorMapFile = pageflow.linkmapPage.GeneratedImageFile.extend({
2
2
  toJSON: function() {
3
3
  return _.pick(this.attributes,
4
4
  'source_image_file_id');
@@ -1,4 +1,4 @@
1
- pageflow.linkmapPage.ProcessedFile = pageflow.UploadedFile.extend({
1
+ pageflow.linkmapPage.GeneratedImageFile = pageflow.ReusableFile.extend({
2
2
  stages: [
3
3
  {
4
4
  name: 'processing',
@@ -1,4 +1,4 @@
1
- pageflow.linkmapPage.MaskedImageFile = pageflow.linkmapPage.ProcessedFile.extend({
1
+ pageflow.linkmapPage.MaskedImageFile = pageflow.linkmapPage.GeneratedImageFile.extend({
2
2
  toJSON: function() {
3
3
  return _.pick(this.attributes,
4
4
  'source_image_file_id',
@@ -2,7 +2,7 @@ pageflow.linkmapPage.NewAreaFileSelectionHandler = function(options) {
2
2
  var page = pageflow.pages.get(options.id);
3
3
 
4
4
  this.call = function(file) {
5
- page.configuration.linkmapAreas().addAudioFile(file.id);
5
+ page.configuration.linkmapAreas().addAudioFile(file.get('perma_id'));
6
6
  return false;
7
7
  };
8
8
 
@@ -3,11 +3,13 @@
3
3
  initialize: function(options) {
4
4
  this.listenTo(this,
5
5
  'change:linkmap_color_map_image_id',
6
- function(model, imageFileId) {
7
- if (imageFileId) {
6
+ function(model, imageFilePermaId) {
7
+ if (imageFilePermaId) {
8
+ var sourceImageFile = pageflow.imageFiles.getByPermaId(imageFilePermaId);
9
+
8
10
  this.setReference('linkmap_color_map_file_id',
9
11
  colorMapFiles().findOrCreateBy({
10
- source_image_file_id: imageFileId
12
+ source_image_file_id: sourceImageFile.id
11
13
  }));
12
14
  }
13
15
  else {
@@ -19,13 +21,12 @@
19
21
  this.listenTo(
20
22
  this,
21
23
  'change:' + attribute +
22
- ' change:linkmap_color_map_file_id' +
23
- ' change:linkmap_color_map_file_id:ready',
24
+ ' change:linkmap_color_map_file_id',
24
25
  function() {
25
- var colorMapFile = colorMapFiles().get(this.get('linkmap_color_map_file_id'));
26
- var imageFile = pageflow.imageFiles.get(this.get(attribute));
26
+ var colorMapFile = this.getReference('linkmap_color_map_file_id', colorMapFiles());
27
+ var imageFile = this.getReference(attribute, pageflow.imageFiles);
27
28
 
28
- if (imageFile && colorMapFile && colorMapFile.isReady()) {
29
+ if (imageFile && colorMapFile && !colorMapFile.isNew()) {
29
30
  this.setReference('linkmap_masked_' + attribute,
30
31
  maskedImageFiles().findOrCreateBy({
31
32
  source_image_file_id: imageFile.id,
@@ -40,8 +41,8 @@
40
41
  },
41
42
 
42
43
  linkmapReadyColorMapFileId: function() {
43
- var colorMapFile = colorMapFiles().get(this.get('linkmap_color_map_file_id'));
44
- return colorMapFile && colorMapFile.isReady() ? colorMapFile.id : null;
44
+ var colorMapFile = this.getReference('linkmap_color_map_file_id', colorMapFiles());
45
+ return colorMapFile && colorMapFile.isReady() ? colorMapFile.get('perma_id') : null;
45
46
  },
46
47
 
47
48
  linkmapPageLinks: function() {
@@ -187,14 +187,20 @@ pageflow.pageType.register('linkmap_page', _.extend({
187
187
  wrapper
188
188
  .attr('data-width', template.data('videoWidth'))
189
189
  .attr('data-height', template.data('videoHeight'));
190
-
191
- var videoPlayer = this.videoPlayer = new pageflow.VideoPlayer.Lazy(template, {
190
+
191
+ var options = {
192
192
  volumeFading: true,
193
193
  fallbackToMutedAutoplay: true,
194
-
195
194
  width: '100%',
196
195
  height: '100%'
197
- });
196
+ }
197
+ if (pageflow.browser.has('mobile platform')) {
198
+ // to enable autoplay videos on mobile, 'muted' and 'playsinline' needs to be set
199
+ // video can be unmuted on user interaction
200
+ options.muted = true;
201
+ options.playsinline = true;
202
+ }
203
+ var videoPlayer = this.videoPlayer = new pageflow.VideoPlayer.Lazy(template, options);
198
204
 
199
205
  videoPlayer.ready(function() {
200
206
  videoPlayer.on('playmuted', function() {
@@ -431,18 +437,25 @@ pageflow.pageType.register('linkmap_page', _.extend({
431
437
  },
432
438
 
433
439
  isVideoEnabled: function(configuration) {
434
- return !pageflow.browser.has('mobile platform') &&
435
- (configuration.background_type === 'video' || configuration.background_type === 'hover_video');
440
+ return this.isBackgroundVideoEnabled(configuration) || this.isHoverVideoEnabled(configuration)
436
441
  },
437
442
 
438
443
  isBackgroundVideoEnabled: function(configuration) {
439
- return !pageflow.browser.has('mobile platform') &&
440
- configuration.background_type === 'video';
444
+ if (pageflow.browser.has('mobile platform')) {
445
+ return configuration.background_type === 'video' && configuration.panorama_image_id == undefined
446
+ }
447
+ else{
448
+ return configuration.background_type === 'video'
449
+ }
441
450
  },
442
451
 
443
452
  isHoverVideoEnabled: function(configuration) {
444
- return !pageflow.browser.has('mobile platform') &&
445
- configuration.background_type === 'hover_video';
453
+ if (pageflow.browser.has('mobile platform')) {
454
+ return configuration.background_type === 'hover_video' && configuration.hover_image_id == undefined
455
+ }
456
+ else{
457
+ return configuration.background_type === 'hover_video'
458
+ }
446
459
  },
447
460
 
448
461
  updateNavigationMode: function(configuration) {
@@ -75,6 +75,11 @@
75
75
  }, 300);
76
76
 
77
77
  this.element.removeClass('playing');
78
+ },
79
+
80
+ unmute: function () {
81
+ var videoPlayer = this.options.video.data('videoPlayer');
82
+ videoPlayer.muted(false);
78
83
  }
79
84
  });
80
85
  }(jQuery));
@@ -33,6 +33,10 @@
33
33
  'click': function(event) {
34
34
  var area = this.areaAt(this.positionFromEvent(event));
35
35
 
36
+ if (area.length && area.hasClass('hover_area')){
37
+ this.options.hoverVideo.unmute();
38
+ }
39
+
36
40
  if (area.length && area.hasClass('enabled')) {
37
41
  area.first().trigger($.Event('linkmapareaclick', {originalEvent: event}));
38
42
  }
@@ -5,7 +5,7 @@ pageflow.linkmapPage.ColorMap = (function() {
5
5
  var colorMapSprite = options.colorMapSprite;
6
6
 
7
7
  this.color = attributes.color;
8
- this.permaId = options.colorMapId + ':' + attributes.color;
8
+ this.permaId = options.colorMapPermaId + ':' + attributes.color;
9
9
 
10
10
  this.draw = function(context, width) {
11
11
  var scale = width / attributes.width;
@@ -53,7 +53,7 @@ pageflow.linkmapPage.ColorMap = (function() {
53
53
  function ColorMap(attributes, sprite) {
54
54
  var components = _(attributes.components).map(function(componentAttributes) {
55
55
  return new ColorMapComponent(componentAttributes, {
56
- colorMapId: attributes.id,
56
+ colorMapPermaId: attributes.perma_id,
57
57
  colorMapWidth: attributes.width,
58
58
  colorMapHeight: attributes.height,
59
59
  colorMapSprite: sprite
@@ -87,8 +87,8 @@ pageflow.linkmapPage.ColorMap = (function() {
87
87
  height: 0
88
88
  });
89
89
 
90
- ColorMap.load = function(id) {
91
- var colorMapFile = pageflow.entryData.getFile('pageflow_linkmap_page_color_map_files', id);
90
+ ColorMap.load = function(permaId) {
91
+ var colorMapFile = pageflow.entryData.getFile('pageflow_linkmap_page_color_map_files', permaId);
92
92
 
93
93
  if (!colorMapFile) {
94
94
  return $.when(ColorMap.empty);
@@ -100,4 +100,4 @@ pageflow.linkmapPage.ColorMap = (function() {
100
100
  };
101
101
 
102
102
  return ColorMap;
103
- }());
103
+ }());
@@ -2,6 +2,7 @@ module Pageflow
2
2
  module LinkmapPage
3
3
  module AreasHelper
4
4
  include BackgroundImageHelper
5
+ include RevisionFileHelper
5
6
 
6
7
  def linkmap_content_and_background_css_classes(configuration)
7
8
  hide_overlay_boxes =
@@ -16,11 +17,11 @@ module Pageflow
16
17
 
17
18
  def linkmap_areas_div(entry, configuration)
18
19
  color_map_file =
19
- ColorMapFile.find_by_id(configuration['linkmap_color_map_file_id'])
20
+ find_file_in_entry(ColorMapFile, configuration['linkmap_color_map_file_id'])
20
21
  masked_hover_image_file =
21
- MaskedImageFile.find_by_id(configuration['linkmap_masked_hover_image_id'])
22
+ find_file_in_entry(MaskedImageFile, configuration['linkmap_masked_hover_image_id'])
22
23
  masked_visited_image_file =
23
- MaskedImageFile.find_by_id(configuration['linkmap_masked_visited_image_id'])
24
+ find_file_in_entry(MaskedImageFile, configuration['linkmap_masked_visited_image_id'])
24
25
 
25
26
  render('pageflow/linkmap_page/areas/div',
26
27
  entry: entry,
@@ -37,7 +38,7 @@ module Pageflow
37
38
  color_map_component_id = attributes['color_map_component_id'] || attributes['mask_perma_id']
38
39
  if color_map_file &&
39
40
  color_map_component_id.present? &&
40
- color_map_component_id.split(':').first.to_i == color_map_file.id
41
+ color_map_component_id.split(':').first.to_i == color_map_file.perma_id
41
42
  background_image_div(configuration,
42
43
  "linkmap_masked_#{prefix}_image",
43
44
  class: "#{prefix}_image",
@@ -6,8 +6,12 @@ module Pageflow
6
6
  include StateMachineJob
7
7
 
8
8
  def perform_with_result(file, _options)
9
+ return :error if file.prerequisite_files.any?(&:failed?)
10
+ return :pending unless file.prerequisite_files.all?(&:ready?)
11
+
9
12
  file.attachment = file.source_image_file.attachment
10
13
  file.save!
14
+
11
15
  :ok
12
16
  end
13
17
  end
@@ -1,7 +1,9 @@
1
1
  module Pageflow
2
2
  module LinkmapPage
3
- class ColorMapFile < ProcessedImageFile
4
- belongs_to :source_image_file, class_name: 'Pageflow::ImageFile'
3
+ class ColorMapFile < GeneratedImageFile
4
+ has_one :masked_image_file,
5
+ class_name: 'Pageflow::LinkmapPage::MaskedImageFile',
6
+ dependent: :destroy
5
7
 
6
8
  # Prevent anti aliasing. Otherwise, when processing color map
7
9
  # images, borders between areas are blurred.
@@ -1,9 +1,9 @@
1
1
  module Pageflow
2
2
  module LinkmapPage
3
- class ProcessedImageFile < ActiveRecord::Base
3
+ class GeneratedImageFile < ActiveRecord::Base
4
4
  self.abstract_class = true
5
5
 
6
- include Pageflow::UploadedFile
6
+ include Pageflow::ReusableFile
7
7
 
8
8
  belongs_to :source_image_file, class_name: 'Pageflow::ImageFile'
9
9
 
@@ -23,17 +23,23 @@ module Pageflow
23
23
 
24
24
  job ProcessSourceImageFileJob do
25
25
  on_enter 'processing'
26
+ result :pending, retry_after: 3.seconds
26
27
  result ok: 'processed'
27
28
  result error: 'processing_failed'
28
29
  end
29
30
  end
30
31
 
31
- def url
32
- ''
32
+ # ReusableFile-overrides:
33
+ def retryable?
34
+ processing_failed?
35
+ end
36
+
37
+ def ready?
38
+ processed?
33
39
  end
34
40
 
35
- def original_url
36
- ''
41
+ def failed?
42
+ processing_failed?
37
43
  end
38
44
 
39
45
  def retry!
@@ -44,16 +50,8 @@ module Pageflow
44
50
  process!
45
51
  end
46
52
 
47
- def retryable?
48
- processing_failed?
49
- end
50
-
51
- def ready?
52
- processed?
53
- end
54
-
55
- def basename
56
- 'unused'
53
+ def prerequisite_files
54
+ [source_image_file]
57
55
  end
58
56
  end
59
57
  end
@@ -1,6 +1,6 @@
1
1
  module Pageflow
2
2
  module LinkmapPage
3
- class MaskedImageFile < ProcessedImageFile
3
+ class MaskedImageFile < GeneratedImageFile
4
4
  belongs_to :color_map_file, class_name: 'Pageflow::LinkmapPage::ColorMapFile'
5
5
 
6
6
  STYLES = lambda do |attachment|
@@ -39,6 +39,10 @@ module Pageflow
39
39
  color_map_file.present_colors
40
40
  end
41
41
 
42
+ def prerequisite_files
43
+ [color_map_file, source_image_file]
44
+ end
45
+
42
46
  private
43
47
 
44
48
  def update_processing_progress(style)
@@ -7,8 +7,7 @@
7
7
  color_map_file) %>
8
8
 
9
9
  <% if configuration['background_type'] == 'hover_video' &&
10
- !Pageflow::ImageFile.find_by_id(configuration['hover_image_id']) %>
11
-
10
+ !find_file_in_entry(Pageflow::ImageFile, configuration['hover_image_id']) %>
12
11
  <%= background_image_div(configuration,
13
12
  'panorama_video',
14
13
  file_type: 'video_file',
@@ -7,7 +7,7 @@
7
7
  <div class="pan_zoom_safe_area_wrapper">
8
8
  <div class="panorama_wrapper">
9
9
  <% if configuration['background_type'] == 'video' &&
10
- !Pageflow::ImageFile.find_by_id(configuration['panorama_image_id']) %>
10
+ !find_file_in_entry(Pageflow::ImageFile, configuration['panorama_image_id']) %>
11
11
 
12
12
  <%= background_image_div_with_size(configuration,
13
13
  'panorama_video',
@@ -101,9 +101,7 @@ de:
101
101
  so viele Hotspots angelegt werden wie gewünscht.
102
102
 
103
103
  Der Panorama Typ entscheidet darüber, ob die Seite ein
104
- Hintergrund-Bild oder Hintergrund-Video zeigt. (Beachte, dass
105
- Hintergrund-Videos auf mobilen Geräten nicht abgespielt werden,
106
- deshalb wähle ein zusätzliches Panorama-Bild für die mobile Version)
104
+ Hintergrund-Bild oder Hintergrund-Video zeigt. (Ein zusätzliches Fallback-Image für die mobile Version kann bereitgestellt werden, wenn das Video nicht passt)
107
105
 
108
106
  Die Hotspot-Seite ermöglicht auch die Nutzung von Panorama-Bildern,
109
107
  die größer sind, als der sichtbare Bildschirmbereich. So können Nutzer
@@ -98,7 +98,7 @@ en:
98
98
 
99
99
  Hotspots can play audio files, link to other pages in a Pageflow or to external websites. You can define as many hotspots as you want.
100
100
 
101
- Decide if you want to show a background image or a background video. (Keep in mind, that background videos will not be played on mobile devices, therefore use an additional fallback image for the mobile version)
101
+ Decide if you want to show a background image or a background video. (An additional fallback image for the mobile version can be provided if video does not fit)
102
102
 
103
103
  The hotspot page type allows to use panoramic images that are wider and taller than the screen-size. It enables users to explore these images by horizontal or vertical scrolling.
104
104
 
@@ -25,21 +25,35 @@ module Pageflow
25
25
 
26
26
  def self.color_map_file_type
27
27
  FileType.new(model: ColorMapFile,
28
- custom_attributes: [:source_image_file_id],
29
28
  partial: 'pageflow/linkmap_page/color_map_files/color_map_file',
30
- editor_partial: 'pageflow/linkmap_page/editor/color_map_files/color_map_file')
29
+ editor_partial: 'pageflow/linkmap_page/editor/color_map_files/color_map_file',
30
+ custom_attributes: {
31
+ source_image_file_id: {
32
+ model: 'Pageflow::ImageFile',
33
+ permitted_create_param: true
34
+ }
35
+ })
31
36
  end
32
37
 
33
38
  def self.masked_image_file_type
34
39
  FileType.new(model: MaskedImageFile,
35
- custom_attributes: [:source_image_file_id, :color_map_file_id],
36
40
  editor_partial: 'pageflow/linkmap_page/editor/' \
37
41
  'masked_image_files/masked_image_file',
38
42
  css_background_image_urls: lambda do |masked_image_file|
39
43
  masked_image_file.present_styles.each_with_object({}) do |color, result|
40
44
  result[color] = masked_image_file.url_for_color(color)
41
45
  end
42
- end)
46
+ end,
47
+ custom_attributes: {
48
+ source_image_file_id: {
49
+ model: 'Pageflow::ImageFile',
50
+ permitted_create_param: true
51
+ },
52
+ color_map_file_id: {
53
+ model: 'Pageflow::LinkmapPage::ColorMapFile',
54
+ permitted_create_param: true
55
+ }
56
+ })
43
57
  end
44
58
  end
45
59
  end
@@ -186,6 +186,7 @@ module Pageflow
186
186
  .reject { |color| color == TRANSPARENT }
187
187
  .map { |color| color.tr('#', '') }
188
188
  .map(&:downcase)
189
+ .map { |color| color.gsub(/(.{6})ff/, '\1') }
189
190
  .sort
190
191
  end
191
192
 
@@ -1,5 +1,5 @@
1
1
  module Pageflow
2
2
  module LinkmapPage
3
- VERSION = '2.4.0'.freeze
3
+ VERSION = '2.7.1'.freeze
4
4
  end
5
5
  end
@@ -18,11 +18,11 @@ Gem::Specification.new do |spec|
18
18
 
19
19
  spec.required_ruby_version = '~> 2.1'
20
20
 
21
- spec.add_runtime_dependency 'pageflow', '~> 14.x'
21
+ spec.add_runtime_dependency 'pageflow', '~> 15.x'
22
22
  spec.add_runtime_dependency 'pageflow-external-links', '~> 2.x'
23
23
 
24
24
  spec.add_development_dependency 'bundler', ['>= 1.0', '< 3']
25
- spec.add_development_dependency 'pageflow-support', '~> 14.x'
25
+ spec.add_development_dependency 'pageflow-support', '~> 15.x'
26
26
  spec.add_development_dependency 'rake', '~> 12.0'
27
27
  spec.add_development_dependency 'rspec-rails', '~> 3.7'
28
28
  spec.add_development_dependency 'factory_bot_rails', '~> 4.8'
@@ -39,4 +39,7 @@ Gem::Specification.new do |spec|
39
39
 
40
40
  # Semantic versioning rake tasks
41
41
  spec.add_development_dependency 'semmy', '~> 1.0'
42
+
43
+ # Freeze time in tests
44
+ spec.add_development_dependency 'timecop', '~> 0.7.1'
42
45
  end
@@ -2,6 +2,12 @@ FactoryBot.modify do
2
2
  fixtures = Pageflow::LinkmapPage::Engine.root.join('spec', 'support', 'fixtures')
3
3
 
4
4
  factory :image_file do
5
+ trait :not_yet_uploaded do
6
+ attachment { nil }
7
+ file_name { 'image.jpg' }
8
+ state { 'uploading' }
9
+ end
10
+
5
11
  trait :red_fixture do
6
12
  attachment { File.open(fixtures.join('red.png')) }
7
13
  end
@@ -1,8 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
+ require 'pageflow/used_file_test_helper'
4
+
3
5
  module Pageflow
4
6
  module LinkmapPage
5
7
  describe AreasHelper do
8
+ include UsedFileTestHelper
9
+
6
10
  describe '#linkmap_content_and_background_css_classes' do
7
11
  it 'contains default css classes' do
8
12
  classes = helper.linkmap_content_and_background_css_classes({}).split(' ')
@@ -50,6 +54,8 @@ module Pageflow
50
54
  entry = create(:entry)
51
55
  configuration = {}
52
56
 
57
+ allow(helper).to receive(:find_file_in_entry).and_return(nil)
58
+
53
59
  html = helper.linkmap_areas_div(entry, configuration)
54
60
 
55
61
  expect(html).to have_selector('div.linkmap_areas')
@@ -59,6 +65,8 @@ module Pageflow
59
65
  entry = create(:entry)
60
66
  configuration = {'linkmap_areas' => [{}]}
61
67
 
68
+ allow(helper).to receive(:find_file_in_entry).and_return(nil)
69
+
62
70
  html = helper.linkmap_areas_div(entry, configuration)
63
71
 
64
72
  expect(html).to have_selector('div a[href]')
@@ -68,35 +76,37 @@ module Pageflow
68
76
  entry = create(:entry)
69
77
  configuration = {'linkmap_areas' => [{}], 'hover_image_id' => 5}
70
78
 
79
+ allow(helper).to receive(:find_file_in_entry).and_return(nil)
80
+
71
81
  html = helper.linkmap_areas_div(entry, configuration)
72
82
 
73
- expect(html).to have_selector('a div[class~="image_panorama_5"]')
83
+ expect(html).to have_selector("a div[class~='image_panorama_5']")
74
84
  end
75
85
 
76
86
  it 'renders masked hover image inside masked linkmap areas' do
77
- entry = create(:entry)
78
- color_map_file = create(:color_map_file)
79
- masked_image_file = create(:masked_image_file)
87
+ entry = PublishedEntry.new(create(:entry, :published))
88
+ color_map_file = create_used_file(:color_map_file, entry: entry)
89
+ masked_image_file = create_used_file(:masked_image_file, entry: entry)
80
90
  configuration = {
81
- 'linkmap_areas' => [{'color_map_component_id' => "#{color_map_file.id}:aaa"}],
91
+ 'linkmap_areas' => [{'color_map_component_id' => "#{color_map_file.perma_id}:aaa"}],
82
92
  'hover_image_id' => 5,
83
- 'linkmap_color_map_file_id' => color_map_file.id,
84
- 'linkmap_masked_hover_image_id' => masked_image_file.id
93
+ 'linkmap_color_map_file_id' => color_map_file.perma_id,
94
+ 'linkmap_masked_hover_image_id' => masked_image_file.perma_id
85
95
  }
86
96
 
87
97
  html = helper.linkmap_areas_div(entry, configuration)
88
98
 
89
- image_class = "pageflow_linkmap_page_masked_image_file_aaa_#{masked_image_file.id}"
99
+ image_class = "pageflow_linkmap_page_masked_image_file_aaa_#{masked_image_file.perma_id}"
90
100
  expect(html).to have_selector("a div[class~=#{image_class}]")
91
101
  end
92
102
 
93
103
  it 'only uses masked hover image if area is masked' do
94
- entry = create(:entry)
95
- masked_image_file = create(:masked_image_file)
104
+ entry = PublishedEntry.new(create(:entry, :published))
105
+ masked_image_file = create_used_file(:masked_image_file, entry: entry)
96
106
  configuration = {
97
107
  'linkmap_areas' => [{}],
98
108
  'hover_image_id' => 5,
99
- 'linkmap_masked_hover_image_id' => masked_image_file.id
109
+ 'linkmap_masked_hover_image_id' => masked_image_file.perma_id
100
110
  }
101
111
 
102
112
  html = helper.linkmap_areas_div(entry, configuration)
@@ -105,14 +115,15 @@ module Pageflow
105
115
  end
106
116
 
107
117
  it 'does not use masked hover image if area color map component id references other image' do
108
- entry = create(:entry)
109
- masked_image_file = create(:masked_image_file)
110
- color_map_file = create(:color_map_file)
111
- other_id = color_map_file.id + 1
118
+ entry = PublishedEntry.new(create(:entry, :published))
119
+ color_map_file = create_used_file(:color_map_file, entry: entry)
120
+ masked_image_file = create_used_file(:masked_image_file, entry: entry)
121
+
122
+ other_id = color_map_file.perma_id + 1
112
123
  configuration = {
113
124
  'linkmap_areas' => [{'color_map_component_id' => "#{other_id}:aaa"}],
114
125
  'hover_image_id' => 5,
115
- 'linkmap_masked_hover_image_id' => masked_image_file.id
126
+ 'linkmap_masked_hover_image_id' => masked_image_file.perma_id
116
127
  }
117
128
 
118
129
  html = helper.linkmap_areas_div(entry, configuration)
@@ -124,25 +135,27 @@ module Pageflow
124
135
  entry = create(:entry)
125
136
  configuration = {'linkmap_areas' => [{}], 'visited_image_id' => 5}
126
137
 
138
+ allow(helper).to receive(:find_file_in_entry).and_return(nil)
139
+
127
140
  html = helper.linkmap_areas_div(entry, configuration)
128
141
 
129
142
  expect(html).to have_selector('a div[class~="image_panorama_5"]')
130
143
  end
131
144
 
132
145
  it 'renders masked visited image inside masked linkmap areas' do
133
- entry = create(:entry)
134
- color_map_file = create(:color_map_file)
135
- masked_image_file = create(:masked_image_file)
146
+ entry = PublishedEntry.new(create(:entry, :published))
147
+ color_map_file = create_used_file(:color_map_file, entry: entry)
148
+ masked_image_file = create_used_file(:masked_image_file, entry: entry)
136
149
  configuration = {
137
- 'linkmap_areas' => [{'color_map_component_id' => "#{color_map_file.id}:aaa"}],
150
+ 'linkmap_areas' => [{'color_map_component_id' => "#{color_map_file.perma_id}:aaa"}],
138
151
  'hover_image_id' => 5,
139
- 'linkmap_color_map_file_id' => color_map_file.id,
140
- 'linkmap_masked_visited_image_id' => masked_image_file.id
152
+ 'linkmap_color_map_file_id' => color_map_file.perma_id,
153
+ 'linkmap_masked_visited_image_id' => masked_image_file.perma_id
141
154
  }
142
155
 
143
156
  html = helper.linkmap_areas_div(entry, configuration)
144
157
 
145
- image_class = "pageflow_linkmap_page_masked_image_file_aaa_#{masked_image_file.id}"
158
+ image_class = "pageflow_linkmap_page_masked_image_file_aaa_#{masked_image_file.perma_id}"
146
159
  expect(html).to have_selector("a div[class~='#{image_class}']")
147
160
  end
148
161
 
@@ -150,35 +163,37 @@ module Pageflow
150
163
  entry = create(:entry)
151
164
  configuration = {'linkmap_areas' => [{'color_map_component_id' => '1:aaa'}]}
152
165
 
166
+ allow(helper).to receive(:find_file_in_entry).and_return(nil)
167
+
153
168
  html = helper.linkmap_areas_div(entry, configuration)
154
169
 
155
170
  expect(html).to have_selector('a[data-color-map-component-id="1:aaa"]')
156
171
  end
157
172
 
158
173
  it 'uses color map component id if present, preceding mask perma id' do
159
- entry = create(:entry)
160
- color_map_file_1 = create(:color_map_file)
161
- color_map_file_2 = create(:color_map_file)
174
+ entry = PublishedEntry.new(create(:entry, :published))
175
+ color_map_file_1 = create_used_file(:color_map_file, entry: entry)
176
+ color_map_file_2 = create_used_file(:color_map_file, entry: entry)
162
177
  configuration = {
163
- 'linkmap_areas' => [{'color_map_component_id' => "#{color_map_file_2.id}:aaa",
164
- 'mask_perma_id' => "#{color_map_file_1.id}:aaa"}]
178
+ 'linkmap_areas' => [{'color_map_component_id' => "#{color_map_file_2.perma_id}:aaa",
179
+ 'mask_perma_id' => "#{color_map_file_1.perma_id}:aaa"}]
165
180
  }
166
181
 
167
182
  html = helper.linkmap_areas_div(entry, configuration)
168
183
 
169
- expect(html).to have_selector("a[data-color-map-component-id='#{color_map_file_2.id}:aaa']")
184
+ expect(html).to have_selector("a[data-color-map-component-id='#{color_map_file_2.perma_id}:aaa']")
170
185
  end
171
186
 
172
187
  it 'uses mask perma id as fallback if present and color map component id is blank' do
173
- entry = create(:entry)
174
- color_map_file = create(:color_map_file)
188
+ entry = PublishedEntry.new(create(:entry, :published))
189
+ color_map_file = create_used_file(:color_map_file, entry: entry)
175
190
  configuration = {
176
- 'linkmap_areas' => [{'mask_perma_id' => "#{color_map_file.id}:aaa"}]
191
+ 'linkmap_areas' => [{'mask_perma_id' => "#{color_map_file.perma_id}:aaa"}]
177
192
  }
178
193
 
179
194
  html = helper.linkmap_areas_div(entry, configuration)
180
195
 
181
- expect(html).to have_selector("a[data-color-map-component-id='#{color_map_file.id}:aaa']")
196
+ expect(html).to have_selector("a[data-color-map-component-id='#{color_map_file.perma_id}:aaa']")
182
197
  end
183
198
 
184
199
  it 'does not set data-color-map-component-id attribute if background type is hover_video' do
@@ -188,6 +203,8 @@ module Pageflow
188
203
  'background_type' => 'hover_video'
189
204
  }
190
205
 
206
+ allow(helper).to receive(:find_file_in_entry).and_return(nil)
207
+
191
208
  html = helper.linkmap_areas_div(entry, configuration)
192
209
 
193
210
  expect(html).not_to have_selector('a[data-color-map-component-id]')
@@ -6,10 +6,18 @@ module Pageflow
6
6
  module LinkmapPage
7
7
  Pageflow::Lint.file_type(:masked_image_file,
8
8
  create_file_type: -> { LinkmapPage.masked_image_file_type },
9
- create_file: -> { create(:masked_image_file) })
9
+ create_file: -> { create(:masked_image_file) },
10
+ create_prerequisite_file_types: -> {
11
+ [BuiltInFileType.image, LinkmapPage.color_map_file_type]
12
+ },
13
+ get_prerequisite_files: ->(file) {
14
+ [*file.prerequisite_files, *file.color_map_file.prerequisite_files]
15
+ })
10
16
 
11
17
  Pageflow::Lint.file_type(:color_map_file,
12
18
  create_file_type: -> { LinkmapPage.color_map_file_type },
13
- create_file: -> { create(:color_map_file) })
19
+ create_file: -> { create(:color_map_file) },
20
+ create_prerequisite_file_types: -> { [BuiltInFileType.image] },
21
+ get_prerequisite_files: ->(file) { file.prerequisite_files })
14
22
  end
15
23
  end
@@ -2,11 +2,31 @@ require 'spec_helper'
2
2
 
3
3
  module Pageflow
4
4
  module LinkmapPage
5
- describe ColorMapFile, inline_resque: true do
5
+ describe ColorMapFile, perform_jobs: :except_enqued_at do
6
6
  let(:red_from_palette) { 'f65b57' }
7
7
  let(:green_from_palette) { '69a77b' }
8
8
 
9
9
  describe 'process' do
10
+ it 're-schedules job if source image file is not uploaded yet' do
11
+ image_file = create(:image_file, :not_yet_uploaded)
12
+ color_map_file = create(:color_map_file, source_image_file: image_file)
13
+
14
+ color_map_file.process
15
+
16
+ expect(ProcessSourceImageFileJob)
17
+ .to have_been_enqueued.at(3.seconds.from_now)
18
+ end
19
+
20
+ it 'fails if source image file failed' do
21
+ image_file = create(:image_file, :uploading_failed)
22
+ color_map_file = create(:color_map_file, source_image_file: image_file)
23
+
24
+ color_map_file.process
25
+ color_map_file.reload
26
+
27
+ expect(color_map_file).to be_failed
28
+ end
29
+
10
30
  it 'remaps colors to fixed palette' do
11
31
  image_file = create(:image_file, :red_fixture)
12
32
  color_map_file = create(:color_map_file, source_image_file: image_file)
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  module Pageflow
4
4
  module LinkmapPage
5
- describe MaskedImageFile, inline_resque: true do
5
+ describe MaskedImageFile, perform_jobs: :except_enqued_at do
6
6
  let :color_map_file do
7
7
  color_map_image_file = create(:image_file, :color_map_fixture)
8
8
 
@@ -29,6 +29,54 @@ module Pageflow
29
29
  let(:color_of_source_image) { '#ff0000' }
30
30
 
31
31
  describe 'process' do
32
+ it 're-schedules job if source image file is not uploaded yet' do
33
+ image_file = create(:image_file, :not_yet_uploaded)
34
+ masked_image_file = create(:masked_image_file,
35
+ color_map_file: color_map_file,
36
+ source_image_file: image_file)
37
+
38
+ masked_image_file.process
39
+
40
+ expect(ProcessSourceImageFileJob)
41
+ .to have_been_enqueued.at(3.seconds.from_now)
42
+ end
43
+
44
+ it 're-schedules job if color map file is not ready yet' do
45
+ color_map_file = create(:color_map_file, state: 'processing')
46
+ masked_image_file = create(:masked_image_file,
47
+ color_map_file: color_map_file,
48
+ source_image_file: single_color_source_image_file)
49
+
50
+ masked_image_file.process
51
+
52
+ expect(ProcessSourceImageFileJob)
53
+ .to have_been_enqueued.at(3.seconds.from_now)
54
+ end
55
+
56
+ it 'fails if source image file failed' do
57
+ image_file = create(:image_file, :uploading_failed)
58
+ masked_image_file = create(:masked_image_file,
59
+ color_map_file: color_map_file,
60
+ source_image_file: image_file)
61
+
62
+ masked_image_file.process
63
+ masked_image_file.reload
64
+
65
+ expect(masked_image_file).to be_failed
66
+ end
67
+
68
+ it 'fails if color map file failed' do
69
+ color_map_file = create(:color_map_file, state: 'processing_failed')
70
+ masked_image_file = create(:masked_image_file,
71
+ color_map_file: color_map_file,
72
+ source_image_file: single_color_source_image_file)
73
+
74
+ masked_image_file.process
75
+ masked_image_file.reload
76
+
77
+ expect(masked_image_file).to be_failed
78
+ end
79
+
32
80
  it 'creates images for each color in color map masked to the area of that color' do
33
81
  masked_image_file = create(:masked_image_file,
34
82
  color_map_file: color_map_file,
@@ -9,13 +9,47 @@ module Pageflow
9
9
  output = <<-OUTPUT.unindent
10
10
  # ImageMagick pixel enumeration: 3,1,255,srgba
11
11
  0,0: (246,91,87,1) #F65B57 srgba(246,91,87,1)
12
- 1,0: (105,167,123,1) #69A77B srgba(105,167,123,1)
12
+ 1,0: (105,167,123,1) #69A77B66 srgba(105,167,123,0.4)
13
+ OUTPUT
14
+
15
+ result = Colors::ConvertOutput.parse_unique_colors(output)
16
+
17
+ expect(result).to eq(%w(69a77b66 f65b57))
18
+ end
19
+
20
+ it 'filters out transparent color' do
21
+ output = <<-OUTPUT.unindent
22
+ # ImageMagick pixel enumeration: 3,1,255,srgba
23
+ 0,0: (246,91,87,1) #F65B57 srgba(246,91,87,1)
13
24
  2,0: (0,0,0,0) #00000000 none
14
25
  OUTPUT
15
26
 
16
27
  result = Colors::ConvertOutput.parse_unique_colors(output)
17
28
 
18
- expect(result).to eq(%w(69a77b f65b57))
29
+ expect(result).to eq(%w(f65b57))
30
+ end
31
+
32
+ it 'removes trailing FF of rgba string added between ImageMagick 6.7 and 6.9' do
33
+ output = <<-OUTPUT.unindent
34
+ # ImageMagick pixel enumeration: 589,1,65535,srgba
35
+ 0,0: (0,30069,48573,65535) #0075BDFF srgba(0,117,189,1)
36
+ 1,0: (257,30069,48573,65535) #0175BDFF srgba(1,117,189,1)
37
+ OUTPUT
38
+
39
+ result = Colors::ConvertOutput.parse_unique_colors(output)
40
+
41
+ expect(result).to eq(%w(0075bd 0175bd))
42
+ end
43
+
44
+ it 'does not remove trailing FF of rgb string ' do
45
+ output = <<-OUTPUT.unindent
46
+ # ImageMagick pixel enumeration: 589,1,65535,srgba
47
+ 0,0: (0,30069,48573,65535) #0075FF srgba(0,117,255,1)
48
+ OUTPUT
49
+
50
+ result = Colors::ConvertOutput.parse_unique_colors(output)
51
+
52
+ expect(result).to eq(%w(0075ff))
19
53
  end
20
54
  end
21
55
 
@@ -0,0 +1,11 @@
1
+ RSpec.configure do |config|
2
+ config.before(:each) do |example|
3
+ ActiveJob::Base.queue_adapter = :test
4
+ queue_adapter = ActiveJob::Base.queue_adapter
5
+
6
+ queue_adapter.perform_enqueued_jobs = !!example.metadata[:perform_jobs]
7
+
8
+ queue_adapter.perform_enqueued_at_jobs = (example.metadata[:perform_jobs] &&
9
+ example.metadata[:perform_jobs] != :except_enqued_at)
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'timecop'
2
+
3
+ RSpec.configure do |config|
4
+ config.before(:each) do
5
+ Timecop.freeze(Time.local(2013))
6
+ end
7
+
8
+ config.after(:each) do
9
+ Timecop.return
10
+ end
11
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pageflow-linkmap-page
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Codevise Solutions Ltd.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-20 00:00:00.000000000 Z
11
+ date: 2020-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pageflow
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 14.x
19
+ version: 15.x
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 14.x
26
+ version: 15.x
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pageflow-external-links
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -64,14 +64,14 @@ dependencies:
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: 14.x
67
+ version: 15.x
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: 14.x
74
+ version: 15.x
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: rake
77
77
  requirement: !ruby/object:Gem::Requirement
@@ -184,6 +184,20 @@ dependencies:
184
184
  - - "~>"
185
185
  - !ruby/object:Gem::Version
186
186
  version: '1.0'
187
+ - !ruby/object:Gem::Dependency
188
+ name: timecop
189
+ requirement: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - "~>"
192
+ - !ruby/object:Gem::Version
193
+ version: 0.7.1
194
+ type: :development
195
+ prerelease: false
196
+ version_requirements: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - "~>"
199
+ - !ruby/object:Gem::Version
200
+ version: 0.7.1
187
201
  description:
188
202
  email:
189
203
  - info@codevise.de
@@ -216,11 +230,11 @@ files:
216
230
  - app/assets/javascript/pageflow/linkmap_page/editor/models/color_map_delegator.js
217
231
  - app/assets/javascript/pageflow/linkmap_page/editor/models/color_map_file.js
218
232
  - app/assets/javascript/pageflow/linkmap_page/editor/models/external_link_area_type.js
233
+ - app/assets/javascript/pageflow/linkmap_page/editor/models/generated_image_file.js
219
234
  - app/assets/javascript/pageflow/linkmap_page/editor/models/masked_image_file.js
220
235
  - app/assets/javascript/pageflow/linkmap_page/editor/models/new_area_file_selection_handler.js
221
236
  - app/assets/javascript/pageflow/linkmap_page/editor/models/page_configuration_mixin.js
222
237
  - app/assets/javascript/pageflow/linkmap_page/editor/models/page_link_area_type.js
223
- - app/assets/javascript/pageflow/linkmap_page/editor/models/processed_file.js
224
238
  - app/assets/javascript/pageflow/linkmap_page/editor/models/stored_mask_sprite.js
225
239
  - app/assets/javascript/pageflow/linkmap_page/editor/models/text_only_area_type.js
226
240
  - app/assets/javascript/pageflow/linkmap_page/editor/patterns/area_pattern.js
@@ -286,8 +300,8 @@ files:
286
300
  - app/helpers/pageflow/linkmap_page/areas_helper.rb
287
301
  - app/jobs/pageflow/linkmap_page/process_source_image_file_job.rb
288
302
  - app/models/pageflow/linkmap_page/color_map_file.rb
303
+ - app/models/pageflow/linkmap_page/generated_image_file.rb
289
304
  - app/models/pageflow/linkmap_page/masked_image_file.rb
290
- - app/models/pageflow/linkmap_page/processed_image_file.rb
291
305
  - app/views/pageflow/linkmap_page/areas/_div.html.erb
292
306
  - app/views/pageflow/linkmap_page/color_map_files/_color_map_file.json.jbuilder
293
307
  - app/views/pageflow/linkmap_page/editor/color_map_files/_color_map_file.json.jbuilder
@@ -315,7 +329,6 @@ files:
315
329
  - lib/pageflow/linkmap_page/plugin.rb
316
330
  - lib/pageflow/linkmap_page/progress.rb
317
331
  - lib/pageflow/linkmap_page/version.rb
318
- - lib/tasks/pageflow_linkmap_page_tasks.rake
319
332
  - pageflow-linkmap-page.gemspec
320
333
  - spec/factories/color_map_file.rb
321
334
  - spec/factories/image_file.rb
@@ -328,9 +341,10 @@ files:
328
341
  - spec/pageflow/linkmap_page/paperclip_processors/colors_spec.rb
329
342
  - spec/pageflow/linkmap_page/progress_spec.rb
330
343
  - spec/spec_helper.rb
344
+ - spec/support/config/active_job.rb
331
345
  - spec/support/config/devise.rb
332
346
  - spec/support/config/factory_bot.rb
333
- - spec/support/config/resque.rb
347
+ - spec/support/config/timecop.rb
334
348
  - spec/support/fixtures/black_dots.png
335
349
  - spec/support/fixtures/color_map.png
336
350
  - spec/support/fixtures/dots_and_lines.png
@@ -358,7 +372,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
358
372
  version: '0'
359
373
  requirements: []
360
374
  rubyforge_project:
361
- rubygems_version: 2.7.5
375
+ rubygems_version: 2.7.9
362
376
  signing_key:
363
377
  specification_version: 4
364
378
  summary: Pageflow page type for a page that contains customizable link areas
@@ -374,9 +388,10 @@ test_files:
374
388
  - spec/pageflow/linkmap_page/paperclip_processors/colors_spec.rb
375
389
  - spec/pageflow/linkmap_page/progress_spec.rb
376
390
  - spec/spec_helper.rb
391
+ - spec/support/config/active_job.rb
377
392
  - spec/support/config/devise.rb
378
393
  - spec/support/config/factory_bot.rb
379
- - spec/support/config/resque.rb
394
+ - spec/support/config/timecop.rb
380
395
  - spec/support/fixtures/black_dots.png
381
396
  - spec/support/fixtures/color_map.png
382
397
  - spec/support/fixtures/dots_and_lines.png
@@ -1,149 +0,0 @@
1
- namespace :pageflow_linkmap_page do
2
- desc 'Migrate to server generated files'
3
- task migrate_to_masked_image_files: :environment do
4
- Pageflow::LinkmapPage::MaskedImageFilesMigrator.run
5
- end
6
- end
7
-
8
- module Pageflow
9
- module LinkmapPage
10
- module MaskedImageFilesMigrator
11
- extend self
12
-
13
- def run
14
- Resque.inline = true
15
- total = pages_with_mask_image.count
16
-
17
- pages_with_mask_image.find_each.with_index do |page, index|
18
- puts "== Migrating page #{page.id} (#{index}/#{total})"
19
- color_map_file = create_files(page)
20
-
21
- if color_map_file
22
- puts '-- Migrating mask perma ids...'
23
- migrate_mask_perma_ids(page, color_map_file)
24
- end
25
-
26
- page.save!
27
- end
28
- end
29
-
30
- private
31
-
32
- def create_files(page)
33
- color_map_image_file =
34
- ImageFile.find_by_id(page.configuration['linkmap_color_map_image_id'])
35
-
36
- if color_map_image_file
37
- revision = page.chapter.storyline.revision
38
-
39
- puts "-- Color map file for image file #{color_map_image_file.id}"
40
-
41
- color_map_file = color_map_file_for(color_map_image_file, revision)
42
- page.configuration['linkmap_color_map_file_id'] = color_map_file.id
43
-
44
- hover_image_file = ImageFile.find_by_id(page.configuration['hover_image_id'])
45
-
46
- if hover_image_file
47
- puts "-- Masked image file for hover image file #{hover_image_file.id}"
48
-
49
- masked_image_file = masked_image_file_for(hover_image_file, color_map_file, revision)
50
- page.configuration['linkmap_masked_hover_image_id'] = masked_image_file.id
51
- end
52
-
53
- visited_image_file = ImageFile.find_by_id(page.configuration['visited_image_id'])
54
-
55
- if visited_image_file
56
- puts "-- Masked image file for visited image file #{visited_image_file.id}"
57
-
58
- masked_image_file = masked_image_file_for(visited_image_file, color_map_file, revision)
59
- page.configuration['linkmap_masked_visited_image_id'] = masked_image_file.id
60
- end
61
-
62
- color_map_file
63
- end
64
- end
65
-
66
- def color_map_file_for(image_file, revision)
67
- color_map_file = ColorMapFile.find_or_create_by(source_image_file_id: image_file.id) do |c|
68
- c.entry_id = revision.entry_id
69
- end
70
-
71
- unless color_map_file.processed?
72
- puts ' Processing...'
73
-
74
- color_map_file.process!
75
- color_map_file.reload
76
- end
77
-
78
- revision.file_usages.find_or_create_by(file: color_map_file)
79
- color_map_file
80
- end
81
-
82
- def masked_image_file_for(image_file, color_map_file, revision)
83
- masked_image_file = MaskedImageFile.find_or_create_by(source_image_file: image_file,
84
- color_map_file: color_map_file) do |m|
85
- m.entry_id = revision.entry_id
86
- end
87
-
88
- unless masked_image_file.processed?
89
- puts ' Processing...'
90
-
91
- masked_image_file.process!
92
- masked_image_file.reload
93
- end
94
-
95
- revision.file_usages.find_or_create_by(file: masked_image_file)
96
- masked_image_file
97
- end
98
-
99
- def migrate_mask_perma_ids(page, color_map_file)
100
- areas = page.configuration['linkmap_areas'] || []
101
-
102
- page.configuration['linkmap_areas'] = areas.map do |area_attributes|
103
- mask_perma_id = area_attributes['mask_perma_id']
104
-
105
- if mask_perma_id && !area_attributes['color_map_component_id']
106
- sprite_id = page.configuration.fetch('linkmap_masks').fetch('id')
107
- colors =
108
- page
109
- .configuration
110
- .fetch('linkmap_masks')
111
- .fetch('c')
112
- .fetch('c')
113
- .map { |component| component['c'] }
114
-
115
- area_attributes.merge(color_map_component_id: convert_mask_perma_id(mask_perma_id,
116
- colors,
117
- color_map_file,
118
- sprite_id))
119
- else
120
- area_attributes
121
- end
122
- end
123
- end
124
-
125
- def convert_mask_perma_id(perma_id, colors, color_map_file, sprite_id)
126
- target_sprite_id, color_index = perma_id.split(':')
127
-
128
- if target_sprite_id.to_i == sprite_id
129
- "#{color_map_file.id}:#{nearest_color(color_map_file, *colors[color_index.to_i])}"
130
- end
131
- end
132
-
133
- def nearest_color(color_map_file, r, g, b)
134
- color_map_file.present_colors.min_by do |color|
135
- (color[0..1].to_i(16) - r).abs +
136
- (color[2..3].to_i(16) - g).abs +
137
- (color[4..5].to_i(16) - b).abs
138
- end
139
- end
140
-
141
- def pages_with_mask_image
142
- Page
143
- .where(template: 'linkmap_page')
144
- .where('configuration LIKE "%linkmap_color_map_image_id%"')
145
- .includes(chapter: {storyline: :revision})
146
- end
147
- end
148
- end
149
- end
@@ -1,9 +0,0 @@
1
- RSpec.configure do |config|
2
- config.before(:each, inline_resque: true) do
3
- Resque.inline = true
4
- end
5
-
6
- config.after(:each, inline_resque: true) do
7
- Resque.inline = false
8
- end
9
- end