[Library|Trunk]

Customizations: updates in the class attributes



git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@60828 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
argiro.kokogiannaki 2021-04-09 15:56:51 +00:00
parent a8a8ba4016
commit 75c600e51c
1 changed files with 45 additions and 14 deletions

View File

@ -9,49 +9,48 @@ export class Layout {
}
export class CustomizationOptions {
identity: {
isDefault: boolean;
mainColor: string;
secondaryColor: string;
};
identityIsCustom:boolean;
backgroundsAndButtonsIsCustom:boolean;
backgrounds: {
isDefault:boolean,
dark: {
isDefault:boolean,
color: string; //background
}
light: {
isDefault:boolean,
color: string; //background
},
form: {
color: string; //background
}
};
buttons: {
isDefault:boolean,
darkBackground: ButtonsCustomization;
lightBackground: ButtonsCustomization;
};
constructor(mainColor: string = null, secondaryColor: string = null) {
this.identity= {
mainColor: mainColor ? mainColor : CustomizationOptions.getIdentity().mainColor,
secondaryColor : secondaryColor ? secondaryColor : CustomizationOptions.getIdentity().secondaryColor,
isDefault : true
};
this.identityIsCustom = false;
this.backgroundsAndButtonsIsCustom = false;
this.backgrounds={
isDefault: true,
dark : {
isDefault: true,
color: this.identity.mainColor,
},
light : {
isDefault: true,
color: CustomizationOptions.getRGBA(this.identity.mainColor,0.1),
},
form : {
color: CustomizationOptions.getRGBA(this.identity.mainColor,0.2),
}
};
this.buttons = {
isDefault: true,
darkBackground: {
isDefault:true,
backgroundColor: "#ffffff",
@ -82,6 +81,40 @@ export class CustomizationOptions {
}
};
}
public static checkForObsoleteVersion(current:CustomizationOptions, communityId:string){
let updated = new CustomizationOptions(current.identity.mainColor,current.identity.secondaryColor);
let defaultCO = new CustomizationOptions(CustomizationOptions.getIdentity(communityId).mainColor,CustomizationOptions.getIdentity(communityId).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.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.identityIsCustom = (JSON.stringify(current.backgrounds) != JSON.stringify(updated.backgrounds) || JSON.stringify(current.buttons) != JSON.stringify(updated.buttons)) ;
}
return current;
}
public static getIdentity(community:string=null){
let COLORS= {
@ -108,7 +141,6 @@ export class CustomizationOptions {
public static isForLightBackground(color:string){
let L, r, g, b, a = 1;
// console.log(color + " " +color.length);
if(color.length == 7 || color.length == 9) {
r = parseInt(color.substring(1, 3), 16);
g = parseInt(color.substring(3, 5), 16);
@ -124,8 +156,7 @@ export class CustomizationOptions {
a = +array[3];
}
console.log(color, color.length, r, g, b, a);
const brightness = r* 0.299 + g * 0.587 + b * 0.114 + (1 - a) * 255;
const brightness = r* 0.299 + g * 0.587 + b * 0.114 + (1 - a) * 255;
return (brightness < 186)