pageflow-linkmap-page 2.5.0 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 20fd794281e40b28b10018b90477fbb17bdac8444e406dca532d0e0fb6b59368
4
- data.tar.gz: 0ae08ee96055ef4ceb0e005eeb3f498d9640a46cfcdf28e830bef5541dc41b8a
3
+ metadata.gz: 69769f94b00cc835ff6fa21c1aba78de3b00e39c6019f9819dad9bcb4072302f
4
+ data.tar.gz: 0d6aa6ab8692766983576bfa3ad9d17614fadf343b9a415046dcc49b291d497f
5
5
  SHA512:
6
- metadata.gz: 356ef2fe7137f4e8050a584923dbe76408937241bbcfa02697b5cef01818f7b21bd0b565e8baa3265f6d313c9355be84dbdbf6692e76790638b4bb0f5c787808
7
- data.tar.gz: 8fa009d774f3f2db7e5f66e9bbc1573e6dca6fa6a8c83cd0fc726773d1ac0c151303616247a9cf95fc0c43b95eff00a2c75ebba4e2536ba1280da5d82ab318e8
6
+ metadata.gz: 35f77e151491e8bbf30783b7b7d3c49998ca3e103c4bffa7f42cfe4e061b59b0c811ea0da4d265f2c19e9e26f3fd16ed9bebcef60e84943487097e9152cfbaba
7
+ data.tar.gz: cf62ebfb4b5504b49c68d50733a2b93762b308e2cd06296c7079c3274ba63baf2604e8a27c9246f03a77014be08ef4f1aa3245d4b8c17757c06a3e4edde487dc
@@ -12,3 +12,6 @@ services:
12
12
 
13
13
  script:
14
14
  - bin/rspec
15
+
16
+ services:
17
+ - mysql
@@ -1,18 +1,20 @@
1
1
  # CHANGELOG
2
2
 
3
- ### Version 2.5.0
3
+ ### Version 2.6.0
4
4
 
5
- 2019-07-24
5
+ 2019-11-04
6
6
 
7
- [Compare changes](https://github.com/codevise/pageflow-linkmap-page/compare/2-4-stable...v2.5.0)
7
+ [Compare changes](https://github.com/codevise/pageflow-linkmap-page/compare/2-5-stable...v2.6.0)
8
8
 
9
- - Make processing jobs wait for prerequisites. Prevent cases where
10
- masked processing already starts before image file has finished
11
- uploading.
12
- ([#62](https://github.com/codevise/pageflow-linkmap-page/pull/62))
13
- - Fix specs depending on color parsing with ImageMagick 6.9
14
- ([#61](https://github.com/codevise/pageflow-linkmap-page/pull/61))
9
+ - Specify mysql service for Travis build
10
+ ([#66](https://github.com/codevise/pageflow-linkmap-page/pull/66))
11
+ - Use perma id for color map file and components
12
+ ([#65](https://github.com/codevise/pageflow-linkmap-page/pull/65))
13
+ - Wait for color map file to be persisted
14
+ ([#64](https://github.com/codevise/pageflow-linkmap-page/pull/64))
15
+ - Add import and export
16
+ ([#63](https://github.com/codevise/pageflow-linkmap-page/pull/63))
15
17
 
16
18
  See
17
- [2-4-stable branch](https://github.com/codevise/pageflow-linkmap-page/blob/2-4-stable/CHANGELOG.md)
19
+ [2-5-stable branch](https://github.com/codevise/pageflow-linkmap-page/blob/2-5-stable/CHANGELOG.md)
18
20
  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
@@ -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',
@@ -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 {
@@ -21,10 +23,10 @@
21
23
  'change:' + attribute +
22
24
  ' change:linkmap_color_map_file_id',
23
25
  function() {
24
- var colorMapFile = colorMapFiles().get(this.get('linkmap_color_map_file_id'));
25
- 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);
26
28
 
27
- if (imageFile && colorMapFile) {
29
+ if (imageFile && colorMapFile && !colorMapFile.isNew()) {
28
30
  this.setReference('linkmap_masked_' + attribute,
29
31
  maskedImageFiles().findOrCreateBy({
30
32
  source_image_file_id: imageFile.id,
@@ -39,8 +41,8 @@
39
41
  },
40
42
 
41
43
  linkmapReadyColorMapFileId: function() {
42
- var colorMapFile = colorMapFiles().get(this.get('linkmap_color_map_file_id'));
43
- 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;
44
46
  },
45
47
 
46
48
  linkmapPageLinks: function() {
@@ -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",
@@ -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
 
@@ -29,22 +29,7 @@ module Pageflow
29
29
  end
30
30
  end
31
31
 
32
- def url
33
- ''
34
- end
35
-
36
- def original_url
37
- ''
38
- end
39
-
40
- def retry!
41
- process!
42
- end
43
-
44
- def publish!
45
- process!
46
- end
47
-
32
+ # ReusableFile-overrides:
48
33
  def retryable?
49
34
  processing_failed?
50
35
  end
@@ -57,8 +42,12 @@ module Pageflow
57
42
  processing_failed?
58
43
  end
59
44
 
60
- def basename
61
- 'unused'
45
+ def retry!
46
+ process!
47
+ end
48
+
49
+ def publish!
50
+ process!
62
51
  end
63
52
 
64
53
  def prerequisite_files
@@ -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|
@@ -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',
@@ -0,0 +1,9 @@
1
+ # Deletes orphaned color map files, along with their usages
2
+ # and the associated masked image files along with their usages
3
+ class DeleteOrphanedGeneratedImageFiles < ActiveRecord::Migration[5.2]
4
+ def up
5
+ Pageflow::LinkmapPage::ColorMapFile.find_each do |color_map_file|
6
+ color_map_file.destroy unless color_map_file.source_image_file.present?
7
+ end
8
+ end
9
+ end
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Pageflow
2
2
  module LinkmapPage
3
- VERSION = '2.5.0'.freeze
3
+ VERSION = '2.6.0'.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.3.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'
@@ -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
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.5.0
4
+ version: 2.6.0
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-07-24 00:00:00.000000000 Z
11
+ date: 2019-11-04 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.3.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.3.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
@@ -230,11 +230,11 @@ files:
230
230
  - app/assets/javascript/pageflow/linkmap_page/editor/models/color_map_delegator.js
231
231
  - app/assets/javascript/pageflow/linkmap_page/editor/models/color_map_file.js
232
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
233
234
  - app/assets/javascript/pageflow/linkmap_page/editor/models/masked_image_file.js
234
235
  - app/assets/javascript/pageflow/linkmap_page/editor/models/new_area_file_selection_handler.js
235
236
  - app/assets/javascript/pageflow/linkmap_page/editor/models/page_configuration_mixin.js
236
237
  - app/assets/javascript/pageflow/linkmap_page/editor/models/page_link_area_type.js
237
- - app/assets/javascript/pageflow/linkmap_page/editor/models/processed_file.js
238
238
  - app/assets/javascript/pageflow/linkmap_page/editor/models/stored_mask_sprite.js
239
239
  - app/assets/javascript/pageflow/linkmap_page/editor/models/text_only_area_type.js
240
240
  - app/assets/javascript/pageflow/linkmap_page/editor/patterns/area_pattern.js
@@ -300,8 +300,8 @@ files:
300
300
  - app/helpers/pageflow/linkmap_page/areas_helper.rb
301
301
  - app/jobs/pageflow/linkmap_page/process_source_image_file_job.rb
302
302
  - app/models/pageflow/linkmap_page/color_map_file.rb
303
+ - app/models/pageflow/linkmap_page/generated_image_file.rb
303
304
  - app/models/pageflow/linkmap_page/masked_image_file.rb
304
- - app/models/pageflow/linkmap_page/processed_image_file.rb
305
305
  - app/views/pageflow/linkmap_page/areas/_div.html.erb
306
306
  - app/views/pageflow/linkmap_page/color_map_files/_color_map_file.json.jbuilder
307
307
  - app/views/pageflow/linkmap_page/editor/color_map_files/_color_map_file.json.jbuilder
@@ -316,6 +316,7 @@ files:
316
316
  - db/migrate/20171106151700_create_masked_image_files.rb
317
317
  - db/migrate/20180111145100_create_color_map_files.rb
318
318
  - db/migrate/20180214201200_drop_mask_sprites.rb
319
+ - db/migrate/20190724114801_delete_orphaned_generated_image_files.rb
319
320
  - lib/generators/pageflow_linkmap_page/install/install_generator.rb
320
321
  - lib/pageflow-linkmap-page.rb
321
322
  - lib/pageflow/linkmap_page/engine.rb
@@ -329,7 +330,6 @@ files:
329
330
  - lib/pageflow/linkmap_page/plugin.rb
330
331
  - lib/pageflow/linkmap_page/progress.rb
331
332
  - lib/pageflow/linkmap_page/version.rb
332
- - lib/tasks/pageflow_linkmap_page_tasks.rake
333
333
  - pageflow-linkmap-page.gemspec
334
334
  - spec/factories/color_map_file.rb
335
335
  - spec/factories/image_file.rb
@@ -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