2022-07-22 09:35:30 +02:00
|
|
|
import {properties} from "../../../../environments/environment";
|
|
|
|
|
2021-04-06 16:10:46 +02:00
|
|
|
export class Layout {
|
2023-05-27 21:46:07 +02:00
|
|
|
_id: string;
|
|
|
|
portalPid: string;
|
|
|
|
layoutOptions: CustomizationOptions;
|
2022-07-22 17:41:15 +02:00
|
|
|
date;
|
2023-05-27 21:46:07 +02:00
|
|
|
|
|
|
|
constructor(community, options: CustomizationOptions) {
|
2021-04-06 16:10:46 +02:00
|
|
|
this.portalPid = community;
|
|
|
|
this.layoutOptions = options;
|
|
|
|
}
|
2022-07-21 14:00:26 +02:00
|
|
|
|
2022-07-22 17:33:54 +02:00
|
|
|
public static getVariables(options: CustomizationOptions): {} | null {
|
2023-05-27 21:46:07 +02:00
|
|
|
if (options) {
|
2022-07-21 14:00:26 +02:00
|
|
|
let variables = {};
|
2023-05-27 21:46:07 +02:00
|
|
|
if (options.identity) {
|
|
|
|
variables['@global-primary-background'] = Layout.convertRGBAtoRGB(options.identity.mainColor);
|
|
|
|
variables['@global-secondary-background'] = Layout.convertRGBAtoRGB(options.identity.secondaryColor);
|
2022-07-22 09:35:30 +02:00
|
|
|
}
|
2023-05-27 21:46:07 +02:00
|
|
|
if (options.backgrounds) {
|
|
|
|
variables['@general-search-form-background'] = Layout.convertRGBAtoRGB(options.backgrounds.form.color);
|
|
|
|
variables['@global-background'] = Layout.convertRGBAtoRGB(options.backgrounds.light.color);
|
|
|
|
variables['@hero-background-image'] = (options.backgrounds.form.imageFile ? (this.getUrl(properties.utilsService + '/download/' + options.backgrounds.form.imageFile)) : 'none');
|
2022-09-26 13:00:37 +02:00
|
|
|
variables['@hero-background-position'] = options.backgrounds.form.position;
|
2023-06-19 10:04:26 +02:00
|
|
|
variables['@hero-fonts-mode'] = options.backgrounds.form.fontsDarkMode == true ?'dark':'light';
|
2022-07-21 14:00:26 +02:00
|
|
|
}
|
2023-05-27 21:46:07 +02:00
|
|
|
if (options.buttons) {
|
2022-08-01 11:23:57 +02:00
|
|
|
//general
|
|
|
|
variables['@button-border-width'] = options.buttons.lightBackground.borderWidth + "px";
|
|
|
|
variables['@button-border-radius'] = options.buttons.lightBackground.borderRadius + "px";
|
|
|
|
// default -> on dark background todo check again when we have sucj=h buttons
|
2023-05-27 21:46:07 +02:00
|
|
|
variables['@button-default-background'] = Layout.convertRGBAtoRGB(options.buttons.darkBackground.backgroundColor);
|
|
|
|
variables['@button-default-color'] = Layout.convertRGBAtoRGB(options.buttons.darkBackground.color);
|
|
|
|
variables['@button-default-border'] = Layout.convertRGBAtoRGB(options.buttons.darkBackground.borderColor);
|
|
|
|
variables['@button-default-hover-background'] = Layout.convertRGBAtoRGB(options.buttons.darkBackground.onHover.backgroundColor);
|
|
|
|
variables['@button-default-hover-color'] = Layout.convertRGBAtoRGB(options.buttons.darkBackground.onHover.color);
|
|
|
|
variables['@button-default-hover-border'] = Layout.convertRGBAtoRGB(options.buttons.darkBackground.onHover.borderColor);
|
|
|
|
variables['@button-default-active-background'] = Layout.convertRGBAtoRGB(options.buttons.darkBackground.onHover.backgroundColor);
|
|
|
|
variables['@button-default-active-color'] = Layout.convertRGBAtoRGB(options.buttons.darkBackground.onHover.color);
|
|
|
|
variables['@button-default-active-border'] = Layout.convertRGBAtoRGB(options.buttons.darkBackground.onHover.borderColor);
|
2022-08-01 11:23:57 +02:00
|
|
|
|
|
|
|
// primary
|
2023-05-27 21:46:07 +02:00
|
|
|
variables['@button-primary-background'] = Layout.convertRGBAtoRGB(options.buttons.lightBackground.backgroundColor);
|
|
|
|
variables['@button-primary-color'] = Layout.convertRGBAtoRGB(options.buttons.lightBackground.color);
|
|
|
|
variables['@button-primary-border'] = Layout.convertRGBAtoRGB(options.buttons.lightBackground.borderColor);
|
|
|
|
variables['@button-primary-hover-background'] = Layout.convertRGBAtoRGB(options.buttons.lightBackground.onHover.backgroundColor);
|
|
|
|
variables['@button-primary-hover-color'] = Layout.convertRGBAtoRGB(options.buttons.lightBackground.onHover.color);
|
|
|
|
variables['@button-primary-hover-border'] = Layout.convertRGBAtoRGB(options.buttons.lightBackground.onHover.borderColor);
|
|
|
|
variables['@button-primary-active-background'] = Layout.convertRGBAtoRGB(options.buttons.lightBackground.onHover.backgroundColor);
|
|
|
|
variables['@button-primary-active-color'] = Layout.convertRGBAtoRGB(options.buttons.lightBackground.onHover.color);
|
|
|
|
variables['@button-primary-active-border'] = Layout.convertRGBAtoRGB(options.buttons.lightBackground.onHover.borderColor);
|
2022-08-01 11:23:57 +02:00
|
|
|
|
|
|
|
// secondary
|
2023-05-27 21:46:07 +02:00
|
|
|
variables['@button-secondary-background'] = Layout.convertRGBAtoRGB(options.buttons.lightBackground.color);
|
|
|
|
variables['@button-secondary-color'] = Layout.convertRGBAtoRGB(options.buttons.lightBackground.backgroundColor);
|
|
|
|
variables['@button-secondary-border'] = Layout.convertRGBAtoRGB(options.buttons.lightBackground.backgroundColor);
|
|
|
|
variables['@button-secondary-hover-background'] = Layout.convertRGBAtoRGB(options.buttons.lightBackground.backgroundColor);
|
|
|
|
variables['@button-secondary-hover-color'] = Layout.convertRGBAtoRGB(options.buttons.lightBackground.color);
|
|
|
|
variables['@button-secondary-hover-border'] = Layout.convertRGBAtoRGB(options.buttons.lightBackground.borderColor);
|
|
|
|
variables['@button-secondary-active-background'] = Layout.convertRGBAtoRGB(options.buttons.lightBackground.backgroundColor);
|
|
|
|
variables['@button-secondary-active-color'] = Layout.convertRGBAtoRGB(options.buttons.lightBackground.color);
|
|
|
|
variables['@button-secondary-active-border'] = Layout.convertRGBAtoRGB(options.buttons.lightBackground.borderColor);
|
|
|
|
|
2022-08-01 11:23:57 +02:00
|
|
|
}
|
2022-07-21 14:00:26 +02:00
|
|
|
return variables;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2023-05-27 21:46:07 +02:00
|
|
|
|
|
|
|
public static getUrl(url) {
|
2022-07-22 09:35:30 +02:00
|
|
|
return 'url("' + url + '")';
|
|
|
|
}
|
2023-05-27 21:46:07 +02:00
|
|
|
|
|
|
|
public static convertRGBAtoRGB(color: string): string {
|
|
|
|
if(color.includes('rgba')) {
|
|
|
|
const regexPattern = /rgba\((\d+),\s*(\d+),\s*(\d+),\s*([\d.]+)\)/;
|
|
|
|
const matches = color.match(regexPattern);
|
|
|
|
const [, r, g, b, a] = matches;
|
|
|
|
let R = parseInt(r)*parseFloat(a) + (1 - parseFloat(a))*255;
|
|
|
|
let G = parseInt(g)*parseFloat(a) + (1 - parseFloat(a))*255;
|
|
|
|
let B = parseInt(b)*parseFloat(a) + (1 - parseFloat(a))*255;
|
|
|
|
return 'rgb(' + R + ',' + G + ',' + B + ',' + ')';
|
|
|
|
} else {
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
}
|
2021-04-06 16:10:46 +02:00
|
|
|
}
|
2023-05-27 21:46:07 +02:00
|
|
|
|
2019-09-12 11:40:17 +02:00
|
|
|
export class CustomizationOptions {
|
2021-04-05 15:14:43 +02:00
|
|
|
identity: {
|
|
|
|
mainColor: string;
|
|
|
|
secondaryColor: string;
|
2021-02-10 11:24:52 +01:00
|
|
|
};
|
2023-05-27 21:46:07 +02:00
|
|
|
identityIsCustom: boolean;
|
|
|
|
backgroundsIsCustom: boolean;
|
|
|
|
buttonsIsCustom: boolean;
|
2021-04-05 15:14:43 +02:00
|
|
|
backgrounds: {
|
|
|
|
dark: {
|
2023-05-27 21:46:07 +02:00
|
|
|
color: string; //background
|
2021-04-05 15:14:43 +02:00
|
|
|
}
|
|
|
|
light: {
|
2021-04-09 17:56:51 +02:00
|
|
|
color: string; //background
|
|
|
|
},
|
|
|
|
form: {
|
2019-10-07 08:58:49 +02:00
|
|
|
color: string; //background
|
2021-05-19 13:24:10 +02:00
|
|
|
imageUrl: string;
|
|
|
|
imageFile: string;
|
2023-05-27 21:46:07 +02:00
|
|
|
position: string;
|
2023-06-09 11:47:39 +02:00
|
|
|
fontsDarkMode:boolean;
|
2021-02-10 11:24:52 +01:00
|
|
|
}
|
2019-09-12 11:40:17 +02:00
|
|
|
};
|
|
|
|
buttons: {
|
2021-04-05 15:14:43 +02:00
|
|
|
darkBackground: ButtonsCustomization;
|
|
|
|
lightBackground: ButtonsCustomization;
|
2019-09-12 11:40:17 +02:00
|
|
|
};
|
2023-05-27 21:46:07 +02:00
|
|
|
|
2021-04-05 15:14:43 +02:00
|
|
|
constructor(mainColor: string = null, secondaryColor: string = null) {
|
2023-05-27 21:46:07 +02:00
|
|
|
this.identity = {
|
2021-04-05 15:14:43 +02:00
|
|
|
mainColor: mainColor ? mainColor : CustomizationOptions.getIdentity().mainColor,
|
2023-05-27 21:46:07 +02:00
|
|
|
secondaryColor: secondaryColor ? secondaryColor : CustomizationOptions.getIdentity().secondaryColor,
|
2019-10-07 08:58:49 +02:00
|
|
|
};
|
2021-04-09 17:56:51 +02:00
|
|
|
this.identityIsCustom = false;
|
2022-07-04 13:12:55 +02:00
|
|
|
this.backgroundsIsCustom = false;
|
|
|
|
this.buttonsIsCustom = false;
|
2023-05-27 21:46:07 +02:00
|
|
|
this.backgrounds = {
|
|
|
|
dark: {
|
2021-04-05 15:14:43 +02:00
|
|
|
color: this.identity.mainColor,
|
2019-10-07 08:58:49 +02:00
|
|
|
},
|
2023-05-27 21:46:07 +02:00
|
|
|
light: {
|
2022-07-28 15:51:13 +02:00
|
|
|
color: "#f9f9f9" //CustomizationOptions.getRGBA(this.identity.mainColor,0.05),
|
2021-04-09 17:56:51 +02:00
|
|
|
},
|
2023-05-27 21:46:07 +02:00
|
|
|
form: {
|
|
|
|
color: CustomizationOptions.getRGBA(this.identity.mainColor, 0.15),
|
|
|
|
imageUrl: null,
|
|
|
|
imageFile: null,
|
2023-06-09 11:47:39 +02:00
|
|
|
position: null,
|
|
|
|
fontsDarkMode: true
|
2019-10-07 08:58:49 +02:00
|
|
|
}
|
|
|
|
};
|
2023-05-27 21:46:07 +02:00
|
|
|
|
|
|
|
|
2019-10-07 08:58:49 +02:00
|
|
|
this.buttons = {
|
|
|
|
darkBackground: {
|
2023-05-27 21:46:07 +02:00
|
|
|
isDefault: true,
|
2019-10-07 08:58:49 +02:00
|
|
|
backgroundColor: "#ffffff",
|
2021-04-05 15:14:43 +02:00
|
|
|
color: "#000000",
|
|
|
|
borderStyle: "solid",
|
2019-10-07 08:58:49 +02:00
|
|
|
borderColor: "#ffffff",
|
|
|
|
borderWidth: 1,
|
2021-03-31 13:23:24 +02:00
|
|
|
borderRadius: 500,
|
2019-10-07 08:58:49 +02:00
|
|
|
onHover: {
|
|
|
|
backgroundColor: "#eeeeee",
|
2021-03-31 13:23:24 +02:00
|
|
|
color: "#000000",
|
2019-10-07 08:58:49 +02:00
|
|
|
borderColor: "#eeeeee",
|
|
|
|
}
|
|
|
|
},
|
|
|
|
lightBackground: {
|
2023-05-27 21:46:07 +02:00
|
|
|
isDefault: true,
|
2021-04-05 15:14:43 +02:00
|
|
|
backgroundColor: this.identity.mainColor,
|
2019-10-07 08:58:49 +02:00
|
|
|
color: '#ffffff',
|
|
|
|
borderStyle: "solid",
|
2021-04-05 15:14:43 +02:00
|
|
|
borderColor: this.identity.mainColor,
|
2019-10-07 08:58:49 +02:00
|
|
|
borderWidth: 1,
|
2021-03-31 13:23:24 +02:00
|
|
|
borderRadius: 500,
|
2019-10-07 08:58:49 +02:00
|
|
|
onHover: {
|
2021-04-05 15:14:43 +02:00
|
|
|
backgroundColor: this.identity.secondaryColor,
|
2019-10-07 08:58:49 +02:00
|
|
|
color: '#ffffff',
|
2021-04-05 15:14:43 +02:00
|
|
|
borderColor: this.identity.secondaryColor,
|
2019-10-07 08:58:49 +02:00
|
|
|
}
|
|
|
|
}
|
2023-05-27 21:46:07 +02:00
|
|
|
|
2019-10-07 08:58:49 +02:00
|
|
|
};
|
2021-04-09 17:56:51 +02:00
|
|
|
}
|
2023-05-27 21:46:07 +02:00
|
|
|
|
|
|
|
public static checkForObsoleteVersion(current: CustomizationOptions, communityId: string) {
|
2023-06-29 09:20:29 +02:00
|
|
|
if(communityId === 'connect') {
|
|
|
|
return null;
|
|
|
|
}
|
2023-05-27 21:46:07 +02:00
|
|
|
let defaultCO = new CustomizationOptions(CustomizationOptions.getIdentity(communityId).mainColor, CustomizationOptions.getIdentity(communityId).secondaryColor);
|
2021-04-16 11:59:54 +02:00
|
|
|
let updated = Object.assign({}, defaultCO);
|
2023-05-27 21:46:07 +02:00
|
|
|
if (!current) {
|
2022-08-08 12:16:13 +02:00
|
|
|
current = Object.assign({}, defaultCO);
|
2023-05-27 21:46:07 +02:00
|
|
|
} else {
|
2022-08-08 12:16:13 +02:00
|
|
|
if (current.identity && current.identity.mainColor && current.identity.secondaryColor) {
|
|
|
|
updated = new CustomizationOptions(current.identity.mainColor, current.identity.secondaryColor);
|
|
|
|
}
|
|
|
|
if (!current.backgrounds) {
|
|
|
|
current.backgrounds = Object.assign({}, updated.backgrounds);
|
|
|
|
}
|
|
|
|
if (!current.backgrounds.dark) {
|
|
|
|
current.backgrounds.dark = Object.assign({}, updated.backgrounds.dark);
|
|
|
|
}
|
|
|
|
if (!current.backgrounds.light) {
|
|
|
|
current.backgrounds.light = Object.assign({}, updated.backgrounds.light);
|
|
|
|
}
|
|
|
|
if (!current.backgrounds.form) {
|
|
|
|
current.backgrounds.form = Object.assign({}, updated.backgrounds.form);
|
|
|
|
}
|
|
|
|
if (!current.backgrounds.form.position) {
|
|
|
|
current.backgrounds.form.position = "center bottom"
|
|
|
|
}
|
2023-06-19 10:04:26 +02:00
|
|
|
if (current.backgrounds.form.fontsDarkMode == undefined) {
|
2023-06-09 11:47:39 +02:00
|
|
|
current.backgrounds.form.fontsDarkMode = true;
|
|
|
|
}
|
2022-08-08 12:16:13 +02:00
|
|
|
if (!current.buttons) {
|
|
|
|
current.buttons = Object.assign({}, updated.buttons);
|
|
|
|
}
|
|
|
|
if (!current.buttons.darkBackground) {
|
|
|
|
current.buttons.darkBackground = Object.assign({}, updated.buttons.darkBackground);
|
|
|
|
}
|
|
|
|
if (!current.buttons.lightBackground) {
|
|
|
|
current.buttons.lightBackground = Object.assign({}, updated.buttons.lightBackground);
|
|
|
|
}
|
|
|
|
if (!current.hasOwnProperty('identityIsCustom')) {
|
|
|
|
current.identityIsCustom = (JSON.stringify(current.identity) != JSON.stringify(defaultCO.identity));
|
|
|
|
}
|
|
|
|
if (!current.hasOwnProperty('backgroundsAndButtonsIsCustom') || (!current.hasOwnProperty('backgroundsIsCustom') || (!current.hasOwnProperty('buttonsIsCustom')))) {
|
|
|
|
current.identityIsCustom = (JSON.stringify(current.backgrounds) !=
|
|
|
|
JSON.stringify(updated.backgrounds) || JSON.stringify(current.buttons) != JSON.stringify(updated.buttons));
|
|
|
|
}
|
2021-04-09 17:56:51 +02:00
|
|
|
}
|
|
|
|
return current;
|
2023-05-27 21:46:07 +02:00
|
|
|
|
|
|
|
|
2019-10-07 08:58:49 +02:00
|
|
|
}
|
2023-05-27 21:46:07 +02:00
|
|
|
|
|
|
|
public static getIdentity(community: string = null) {
|
|
|
|
let COLORS = {
|
|
|
|
default: {
|
|
|
|
mainColor: '#4687E6',
|
2021-04-05 15:14:43 +02:00
|
|
|
secondaryColor: '#2D72D6'
|
|
|
|
},
|
2023-05-27 21:46:07 +02:00
|
|
|
"covid-19": {
|
|
|
|
mainColor: "#03ADEE",
|
2021-04-05 15:14:43 +02:00
|
|
|
secondaryColor: "#F15157"
|
|
|
|
}
|
|
|
|
};
|
2023-05-27 21:46:07 +02:00
|
|
|
if (community && COLORS[community]) {
|
2021-04-05 15:14:43 +02:00
|
|
|
return COLORS[community];
|
|
|
|
}
|
|
|
|
return COLORS.default;
|
|
|
|
}
|
2023-05-27 21:46:07 +02:00
|
|
|
|
|
|
|
public static getRGBA(color, A) {
|
|
|
|
if (color.indexOf("#") != -1) {
|
|
|
|
return 'rgba(' + parseInt(color.substring(1, 3), 16) + ',' + parseInt(color.substring(3, 5), 16) + ',' + parseInt(color.substring(5, 7), 16) + ',' + A + ')';
|
2021-04-05 15:14:43 +02:00
|
|
|
}
|
|
|
|
return color;
|
|
|
|
}
|
2023-05-27 21:46:07 +02:00
|
|
|
|
|
|
|
public static isForLightBackground(color: string) {
|
2021-04-06 16:10:46 +02:00
|
|
|
let L, r, g, b, a = 1;
|
2023-05-27 21:46:07 +02:00
|
|
|
if (color.length == 7 || color.length == 9) {
|
2021-04-06 16:10:46 +02:00
|
|
|
r = parseInt(color.substring(1, 3), 16);
|
|
|
|
g = parseInt(color.substring(3, 5), 16);
|
|
|
|
b = parseInt(color.substring(5, 7), 16);
|
2023-05-27 21:46:07 +02:00
|
|
|
if (color.length == 9) {
|
|
|
|
a = parseInt(color.substring(7, 9), 16);
|
2021-04-06 16:10:46 +02:00
|
|
|
}
|
2023-05-27 21:46:07 +02:00
|
|
|
} else if (color.length > 9) {
|
2021-04-06 16:10:46 +02:00
|
|
|
let array = color.split("rgba(")[1].split(")")[0].split(",");
|
|
|
|
r = parseInt(array[0]);
|
|
|
|
g = parseInt(array[1]);
|
|
|
|
b = parseInt(array[2]);
|
|
|
|
a = +array[3];
|
2023-05-27 21:46:07 +02:00
|
|
|
|
2021-04-06 16:10:46 +02:00
|
|
|
}
|
2023-05-27 21:46:07 +02:00
|
|
|
const brightness = r * 0.299 + g * 0.587 + b * 0.114 + (1 - a) * 255;
|
|
|
|
|
2021-04-06 16:10:46 +02:00
|
|
|
return (brightness < 186)
|
2023-05-27 21:46:07 +02:00
|
|
|
|
2021-04-06 16:10:46 +02:00
|
|
|
// return !(r*0.299 + g*0.587 + b*0.114 > 186);
|
|
|
|
/*for(let c of [r,g,b]){
|
|
|
|
c = c / 255.0;
|
|
|
|
if(c <= 0.03928){
|
|
|
|
c = c / 12.92;
|
|
|
|
}else {
|
|
|
|
c = ((c + 0.055) / 1.055) ^ 2.4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
L = 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
|
|
return L > 0.179// (L + 0.05) / (0.05) > (1.0 + 0.05) / (L + 0.05); //use #000000 else use #ffffff
|
|
|
|
*/
|
|
|
|
}
|
2023-05-27 21:46:07 +02:00
|
|
|
|
|
|
|
|
2019-09-12 11:40:17 +02:00
|
|
|
}
|
2023-05-27 21:46:07 +02:00
|
|
|
|
|
|
|
export class ButtonsCustomization {
|
|
|
|
isDefault: boolean;
|
2021-04-05 15:14:43 +02:00
|
|
|
backgroundColor: string;
|
|
|
|
color: string;
|
|
|
|
borderStyle: string;
|
|
|
|
borderColor: string;
|
|
|
|
borderWidth: number;
|
|
|
|
borderRadius: number;
|
|
|
|
onHover: {
|
|
|
|
backgroundColor: string;
|
|
|
|
color: string;
|
|
|
|
borderColor: string;
|
|
|
|
};
|
|
|
|
}
|