Skip to content

Commit

Permalink
Merge pull request #4343 from guardian/only-display-crop-gutters-via-…
Browse files Browse the repository at this point in the history
…url-param

add a `shouldShowCropGuttersIfApplicable` query param
  • Loading branch information
twrichards authored Oct 8, 2024
2 parents bdc53c3 + 2ac4d87 commit 76ed039
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
5 changes: 3 additions & 2 deletions kahuna/public/js/crop/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,9 @@ crop.controller('ImageCropCtrl', [

const maybeCropRatioIfStandard = cropOptions.find(_ => _.key === ctrl.cropType)?.ratioString;
ctrl.shouldShowVerticalWarningGutters =
getFeatureSwitchActive("show-cropping-gutters-switch")
&& window._clientConfig.staffPhotographerOrganisation === "GNM"
window._clientConfig.staffPhotographerOrganisation === "GNM"
&& cropSettings.shouldShowCropGuttersIfApplicable()
&& getFeatureSwitchActive("show-cropping-gutters-switch")
&& maybeCropRatioIfStandard === "5:3";

if (isCropTypeDisabled) {
Expand Down
2 changes: 1 addition & 1 deletion kahuna/public/js/crop/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ crop.config(['$stateProvider',
function($stateProvider) {

$stateProvider.state('crop', {
url: '/images/:imageId/crop?cropType&customRatio',
url: '/images/:imageId/crop?cropType&customRatio&shouldShowCropGuttersIfApplicable',
template: cropTemplate,
controller: 'ImageCropCtrl',
controllerAs: 'ctrl',
Expand Down
2 changes: 1 addition & 1 deletion kahuna/public/js/image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ image.config(['$stateProvider',
function($stateProvider) {

$stateProvider.state('image', {
url: '/images/:imageId?crop?cropType&customRatio',
url: '/images/:imageId?crop?cropType&customRatio&shouldShowCropGuttersIfApplicable',
template: imageTemplate,
controller: 'ImageCtrl',
controllerAs: 'ctrl',
Expand Down
2 changes: 1 addition & 1 deletion kahuna/public/js/search/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ search.config(['$stateProvider', '$urlMatcherFactoryProvider',
$stateProvider.state('search', {
// FIXME [1]: This state should be abstract, but then we can't navigate to
// it, which we need to do to access it's deeper / remembered chile state
url: '/?cropType&customRatio',
url: '/?cropType&customRatio&shouldShowCropGuttersIfApplicable',
template: searchTemplate,
deepStateRedirect: {
// Inject a transient $stateParams for the results state
Expand Down
21 changes: 19 additions & 2 deletions kahuna/public/js/util/crop.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { landscape, portrait, video, square, freeform, cropOptions } from './con

const CROP_TYPE_STORAGE_KEY = 'cropType';
const CUSTOM_CROP_STORAGE_KEY = 'customCrop';
const SHOULD_SHOW_CROP_GUTTERS_IF_APPLICABLE_STORAGE_KEY = 'shouldShowCropGuttersIfApplicable';

const customCrop = (label, xRatio, yRatio) => {
return { key:label, ratio: xRatio / yRatio, ratioString: `${xRatio}:${yRatio}`};
Expand Down Expand Up @@ -61,7 +62,15 @@ cropUtil.factory('cropSettings', ['storage', function(storage) {
}
};

function set({cropType, customRatio}) {
const setShouldShowCropGuttersIfApplicable = shouldShowCropGuttersIfApplicableStr => {
storage.setJs(
SHOULD_SHOW_CROP_GUTTERS_IF_APPLICABLE_STORAGE_KEY,
shouldShowCropGuttersIfApplicableStr === "true",
true
);
};

function set({cropType, customRatio, shouldShowCropGuttersIfApplicable}) {
// set customRatio first in case cropType relies on a custom crop
if (customRatio) {
setCustomCrop(customRatio);
Expand All @@ -71,6 +80,10 @@ cropUtil.factory('cropSettings', ['storage', function(storage) {
setCropType(cropType);
}

if (shouldShowCropGuttersIfApplicable) {
setShouldShowCropGuttersIfApplicable(shouldShowCropGuttersIfApplicable);
}

}

function getCropType() {
Expand All @@ -81,7 +94,11 @@ cropUtil.factory('cropSettings', ['storage', function(storage) {
}
}

return { set, getCropType, getCropOptions };
function shouldShowCropGuttersIfApplicable() {
return storage.getJs(SHOULD_SHOW_CROP_GUTTERS_IF_APPLICABLE_STORAGE_KEY, true);
}

return { set, getCropType, getCropOptions, shouldShowCropGuttersIfApplicable };
}]);

cropUtil.filter('asCropType', function() {
Expand Down

0 comments on commit 76ed039

Please sign in to comment.