Skip to content

Commit 5af9710

Browse files
authored
Merge pull request #2343 from tf/ignore-motif-improvements
Ignore motif improvements
2 parents d08c84b + d7bb52f commit 5af9710

File tree

7 files changed

+220
-1
lines changed

7 files changed

+220
-1
lines changed

entry_types/scrolled/package/spec/editor/models/SectionBackdrop-spec.js

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,5 +247,136 @@ describe('SectionBackdrop', () => {
247247

248248
expect(listener).toHaveBeenCalled();
249249
});
250+
251+
});
252+
253+
describe('change:ignoreMissingMotif event', () => {
254+
it('is triggered when ignoreMissingMotif changes on backdrop image file', () => {
255+
const entry = createEntry({
256+
imageFiles: [{id: 100, perma_id: 10}],
257+
sections: [{id: 1, configuration: {backdropImage: 10}}]
258+
});
259+
const backdrop = entry.sections.get(1).configuration.getBackdrop();
260+
const file = entry.getFileCollection('image_files').get(100);
261+
const listener = jest.fn();
262+
263+
backdrop.on('change:ignoreMissingMotif', listener);
264+
file.configuration.set('ignoreMissingMotif', true);
265+
266+
expect(listener).toHaveBeenCalled();
267+
});
268+
269+
it('is triggered when ignoreMissingMotif changes on backdrop image mobile file', () => {
270+
const entry = createEntry({
271+
imageFiles: [{id: 100, perma_id: 10}],
272+
sections: [{id: 1, configuration: {backdropImageMobile: 10}}]
273+
});
274+
const backdrop = entry.sections.get(1).configuration.getBackdrop();
275+
const file = entry.getFileCollection('image_files').get(100);
276+
const listener = jest.fn();
277+
278+
backdrop.on('change:ignoreMissingMotif', listener);
279+
file.configuration.set('ignoreMissingMotif', true);
280+
281+
expect(listener).toHaveBeenCalled();
282+
});
283+
284+
it('is triggered when ignoreMissingMotif changes on new backdrop image file', () => {
285+
const entry = createEntry({
286+
imageFiles: [{id: 100, perma_id: 10}, {id: 101, perma_id: 11}],
287+
sections: [{id: 1, configuration: {backdropImage: 10}}]
288+
});
289+
const backdrop = entry.sections.get(1).configuration.getBackdrop();
290+
const newFile = entry.getFileCollection('image_files').get(101);
291+
const listener = jest.fn();
292+
293+
entry.sections.get(1).configuration.set('backdropImage', 11);
294+
backdrop.on('change:ignoreMissingMotif', listener);
295+
newFile.configuration.set('ignoreMissingMotif', true);
296+
297+
expect(listener).toHaveBeenCalled();
298+
});
299+
300+
it('is not triggered when ignoreMissingMotif changes on old backdrop image file', () => {
301+
const entry = createEntry({
302+
imageFiles: [{id: 100, perma_id: 10}, {id: 101, perma_id: 11}],
303+
sections: [{id: 1, configuration: {backdropImage: 10}}]
304+
});
305+
const backdrop = entry.sections.get(1).configuration.getBackdrop();
306+
const oldFile = entry.getFileCollection('image_files').get(100);
307+
const listener = jest.fn();
308+
309+
entry.sections.get(1).configuration.set('backdropImage', 11);
310+
backdrop.on('change:ignoreMissingMotif', listener);
311+
oldFile.configuration.set('ignoreMissingMotif', true);
312+
313+
expect(listener).not.toHaveBeenCalled();
314+
});
315+
316+
it('is triggered when ignoreMissingMotif changes on new backdrop image mobile file', () => {
317+
const entry = createEntry({
318+
imageFiles: [{id: 100, perma_id: 10}, {id: 101, perma_id: 11}],
319+
sections: [{id: 1, configuration: {backdropImageMobile: 10}}]
320+
});
321+
const backdrop = entry.sections.get(1).configuration.getBackdrop();
322+
const newFile = entry.getFileCollection('image_files').get(101);
323+
const listener = jest.fn();
324+
325+
entry.sections.get(1).configuration.set('backdropImageMobile', 11);
326+
backdrop.on('change:ignoreMissingMotif', listener);
327+
newFile.configuration.set('ignoreMissingMotif', true);
328+
329+
expect(listener).toHaveBeenCalled();
330+
});
331+
332+
it('is not triggered when ignoreMissingMotif changes on old backdrop image mobile file', () => {
333+
const entry = createEntry({
334+
imageFiles: [{id: 100, perma_id: 10}, {id: 101, perma_id: 11}],
335+
sections: [{id: 1, configuration: {backdropImageMobile: 10}}]
336+
});
337+
const backdrop = entry.sections.get(1).configuration.getBackdrop();
338+
const oldFile = entry.getFileCollection('image_files').get(100);
339+
const listener = jest.fn();
340+
341+
entry.sections.get(1).configuration.set('backdropImageMobile', 11);
342+
backdrop.on('change:ignoreMissingMotif', listener);
343+
oldFile.configuration.set('ignoreMissingMotif', true);
344+
345+
expect(listener).not.toHaveBeenCalled();
346+
});
347+
348+
it('is triggered when ignoreMissingMotif changes on video file after switching to video backdrop', () => {
349+
const entry = createEntry({
350+
imageFiles: [{id: 100, perma_id: 10}],
351+
videoFiles: [{id: 200, perma_id: 20}],
352+
sections: [{id: 1, configuration: {backdropImage: 10, backdropVideo: 20}}]
353+
});
354+
const backdrop = entry.sections.get(1).configuration.getBackdrop();
355+
const videoFile = entry.getFileCollection('video_files').get(200);
356+
const listener = jest.fn();
357+
358+
entry.sections.get(1).configuration.set('backdropType', 'video');
359+
backdrop.on('change:ignoreMissingMotif', listener);
360+
videoFile.configuration.set('ignoreMissingMotif', true);
361+
362+
expect(listener).toHaveBeenCalled();
363+
});
364+
365+
it('is not triggered when ignoreMissingMotif changes on image file after switching to video backdrop', () => {
366+
const entry = createEntry({
367+
imageFiles: [{id: 100, perma_id: 10}],
368+
videoFiles: [{id: 200, perma_id: 20}],
369+
sections: [{id: 1, configuration: {backdropImage: 10, backdropVideo: 20}}]
370+
});
371+
const backdrop = entry.sections.get(1).configuration.getBackdrop();
372+
const imageFile = entry.getFileCollection('image_files').get(100);
373+
const listener = jest.fn();
374+
375+
entry.sections.get(1).configuration.set('backdropType', 'video');
376+
backdrop.on('change:ignoreMissingMotif', listener);
377+
imageFile.configuration.set('ignoreMissingMotif', true);
378+
379+
expect(listener).not.toHaveBeenCalled();
380+
});
250381
});
251382
});

entry_types/scrolled/package/spec/editor/views/EditMotifAreaDialogView-spec.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,38 @@ describe('EditMotifAreaDialogView', () => {
153153
expect(model.get('imageMotifArea')).toBe(null);
154154
expect(file.configuration.get('motifArea')).toBe(null);
155155
});
156+
157+
it('sets ignoreMissingMotif on file when resetting motif area', () => {
158+
const model = new Backbone.Model({
159+
imageMotifArea: {
160+
left: 5, top: 10, width: 25, height: 50
161+
}
162+
});
163+
const file = factories.imageFile({
164+
width: 200,
165+
height: 100,
166+
configuration: {
167+
motifArea: {
168+
left: 5, top: 10, width: 25, height: 50
169+
}
170+
}
171+
});
172+
173+
const view = new EditMotifAreaDialogView({
174+
model,
175+
file,
176+
propertyName: 'image'
177+
});
178+
179+
view.render();
180+
view.onShow();
181+
182+
fireEvent.click(getByText(view.el, 'Reset'));
183+
fireEvent.click(getByText(view.el, 'Save'));
184+
185+
expect(file.configuration.get('ignoreMissingMotif')).toBe(true);
186+
});
187+
156188
});
157189

158190
function fakeImgAreaSelect() {

entry_types/scrolled/package/spec/editor/views/inputs/EditMotifAreaInputView-spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,27 @@ describe('EditMotifAreaInputView', () => {
465465

466466
expect(view.el).toHaveClass(styles.hidden);
467467
});
468+
469+
it('adds hidden class when ignoreMissingMotif is set externally on file', () => {
470+
const entry = createEntry({
471+
imageFiles: [{id: 100, perma_id: 10}],
472+
sections: [{id: 1, configuration: {backdropImage: 10}}]
473+
});
474+
const file = entry.getFileCollection('image_files').get(100);
475+
476+
const view = new EditMotifAreaInputView({
477+
model: entry.sections.get(1).configuration,
478+
onlyShowWhenMissing: true
479+
});
480+
481+
renderBackboneView(view);
482+
483+
expect(view.el).not.toHaveClass(styles.hidden);
484+
485+
file.configuration.set('ignoreMissingMotif', true);
486+
487+
expect(view.el).toHaveClass(styles.hidden);
488+
});
468489
});
469490

470491
describe('with required option', () => {

entry_types/scrolled/package/src/editor/models/SectionBackdrop.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ export const SectionBackdrop = Object.extend({
1616
'change:backdropType',
1717
() => this.trigger('change:type')
1818
);
19+
20+
this.listenToFiles();
21+
this.listenTo(
22+
configuration,
23+
'change:backdropType ' +
24+
'change:backdropImage change:backdropImageMobile ' +
25+
'change:backdropVideo change:backdropVideoMobile',
26+
this.listenToFiles
27+
);
1928
},
2029

2130
getMotifAreaStatus({portrait} = {}) {
@@ -68,5 +77,26 @@ export const SectionBackdrop = Object.extend({
6877
else {
6978
return backdropType === 'video' ? 'backdropVideoMotifArea' : 'backdropImageMotifArea';
7079
}
80+
},
81+
82+
listenToFiles() {
83+
this.listenToFile('currentFile', {portrait: false});
84+
this.listenToFile('currentPortraitFile', {portrait: true});
85+
},
86+
87+
listenToFile(property, options) {
88+
if (this[property]) {
89+
this.stopListening(this[property].configuration);
90+
}
91+
92+
this[property] = this.getFile(options);
93+
94+
if (this[property]) {
95+
this.listenTo(
96+
this[property].configuration,
97+
'change:ignoreMissingMotif',
98+
() => this.trigger('change:ignoreMissingMotif')
99+
);
100+
}
71101
}
72102
});

entry_types/scrolled/package/src/editor/views/EditMotifAreaDialogView.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ export const EditMotifAreaDialogView = Marionette.ItemView.extend({
7373

7474
this.model.set(this.getPropertyName(), motifArea);
7575
this.options.file.configuration.set('motifArea', motifArea);
76+
77+
if (!motifArea) {
78+
this.options.file.configuration.set('ignoreMissingMotif', true);
79+
}
7680
},
7781

7882
onRender() {

entry_types/scrolled/package/src/editor/views/EditSectionPaddingsView.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export const EditSectionPaddingsView = EditConfigurationView.extend({
9898
toggleExposeMotifAreaInputs(tab, {portrait, disabled, paddingTopProperty});
9999
}
100100
else {
101-
tab.listenTo(backdropFile, 'change:configuration:ignoreMissingMotif', () => {
101+
tab.listenTo(backdrop, 'change:ignoreMissingMotif', () => {
102102
configurationEditor.refresh();
103103
});
104104

entry_types/scrolled/package/src/editor/views/inputs/EditMotifAreaInputView.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export const EditMotifAreaInputView = Marionette.ItemView.extend({
4141
this.backdrop = this.model.getBackdrop();
4242

4343
this.listenTo(this.backdrop, 'change:motifArea', this.update);
44+
this.listenTo(this.backdrop, 'change:ignoreMissingMotif', this.update);
4445
this.listenTo(this.backdrop, 'change:type', this.render);
4546
},
4647

0 commit comments

Comments
 (0)