* added new table printproducts_defaults and script for inserting values * Only run for posters * Added support for when focusXpoint2 and focusYpoint2 is null, default to center * changed CASE to COALESCE * renamed file
99 lines
3.2 KiB
SQL
99 lines
3.2 KiB
SQL
|
|
-- DROP TABLE IF EXISTS "product-printproducts_defaults";
|
|
-- DROP TABLE IF EXISTS "printproducts_defaults";
|
|
-- DROP TYPE IF EXISTS border_types;
|
|
|
|
CREATE TYPE border_types AS ENUM ('white', 'black', 'none');
|
|
|
|
CREATE TABLE printproducts_defaults (
|
|
print_id INTEGER PRIMARY KEY,
|
|
width_mm numeric NOT NULL,
|
|
height_mm numeric NOT NULL,
|
|
crop_x numeric NOT NULL DEFAULT 0,
|
|
crop_y numeric NOT NULL DEFAULT 0,
|
|
border border_types NOT NULL
|
|
);
|
|
|
|
ALTER TABLE printproducts_defaults
|
|
ADD CONSTRAINT printid_fkey
|
|
FOREIGN KEY (print_id)
|
|
REFERENCES "product-printproducts"(printid) MATCH SIMPLE;
|
|
|
|
------------------------------------
|
|
|
|
INSERT INTO printproducts_defaults (print_id, width_mm, height_mm, crop_x, crop_y, border)
|
|
SELECT
|
|
printid as print_id,
|
|
|
|
(CASE
|
|
WHEN width_height_ratio >= 1.4 THEN 700 -- landscape in landscape
|
|
ELSE 500 -- else square in landscape, square in square or square in portrait or portrait in portrait
|
|
END) as width_mm,
|
|
|
|
(CASE
|
|
WHEN width_height_ratio <= 0.7142857143 THEN 700 -- portrait in portrait
|
|
ELSE 500 -- else square in portrait, square in square, square in landscape or landscape in landscape
|
|
END) as height_mm,
|
|
|
|
(CASE
|
|
WHEN width_height_ratio >= 1.4 THEN ( -- landscape in landscape
|
|
LEAST(
|
|
width - (height * 1.4 / 2), -- max right side
|
|
GREATEST(
|
|
height * 1.4 / 2, -- max left side = 0
|
|
COALESCE("focusXpoint2", 50) / 100 * width -- focuspoint
|
|
)
|
|
) - (height * 1.4 / 2) -- convert to left edge
|
|
) / width -- convert to percent
|
|
--------------------
|
|
WHEN width_height_ratio > 1 AND width_height_ratio < 1.4 THEN ( -- square in landscape
|
|
LEAST(
|
|
width - (height / 2), -- max right side
|
|
GREATEST(
|
|
height / 2, -- max left side = 0
|
|
COALESCE("focusXpoint2", 50) / 100 * width -- focuspoint
|
|
)
|
|
) - (height / 2) -- convert to left edge
|
|
) / width -- convert to percent
|
|
--------------------
|
|
WHEN width_height_ratio < 1 AND width_height_ratio > 0.7142857143 THEN 0 -- square in portrait
|
|
--------------------
|
|
WHEN width_height_ratio <= 0.7142857143 THEN 0 -- portrait in portrait
|
|
--------------------
|
|
ELSE 0 -- square in square
|
|
END) as crop_x,
|
|
|
|
(CASE
|
|
WHEN width_height_ratio >= 1.4 THEN 0 -- landscape in landscape
|
|
--------------------
|
|
WHEN width_height_ratio > 1 AND width_height_ratio < 1.4 THEN 0 -- square in landscape
|
|
--------------------
|
|
WHEN width_height_ratio < 1 AND width_height_ratio > 0.7142857143 THEN ( -- square in portrait
|
|
LEAST(
|
|
height - ((width) / 2), -- max bottom side
|
|
GREATEST(
|
|
(width) / 2, -- max top side = 0
|
|
COALESCE("focusYpoint2", 50) / 100 * height -- focuspoint
|
|
)
|
|
) - (width) / 2) -- convert to top edge
|
|
/ height -- convert to percent
|
|
--------------------
|
|
WHEN width_height_ratio <= 0.7142857143 THEN ( -- portrait in portrait
|
|
LEAST(
|
|
height - ((width / 0.7142857143) / 2), -- max bottom side
|
|
GREATEST(
|
|
(width / 0.7142857143) / 2, -- max top side = 0
|
|
COALESCE("focusYpoint2", 50) / 100 * height -- focuspoint
|
|
)
|
|
) - (width / 0.7142857143) / 2) -- convert to top edge
|
|
/ height -- convert to percent
|
|
--------------------
|
|
ELSE 0 -- square in square
|
|
END) as crop_y,
|
|
|
|
'none'
|
|
FROM
|
|
"product-printproducts" ppp
|
|
JOIN v_product vp ON ppp.productid = vp.id
|
|
WHERE groupid = 7;
|