Skip to content

Commit

Permalink
WIP add a shouldShowCropGuttersIfApplicable query param and only sh…
Browse files Browse the repository at this point in the history
…ow crop gutters if `true` (and other conditions for showing the gutters)
  • Loading branch information
twrichards committed Oct 1, 2024
1 parent 3a9f3f3 commit e91ec84
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
7 changes: 4 additions & 3 deletions kahuna/public/js/crop/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import angular from 'angular';

import '../components/gr-keyboard-shortcut/gr-keyboard-shortcut';
import {radioList} from '../components/gr-radio-list/gr-radio-list';
import {cropUtil} from "../util/crop";
import {cropUtil } from "../util/crop";
import {cropOptions} from "../util/constants/cropOptions";
import {getFeatureSwitchActive} from "../components/gr-feature-switch-panel/gr-feature-switch-panel";

Expand Down 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
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) === "true";
}

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

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

0 comments on commit e91ec84

Please sign in to comment.