[Library|Trunk]

Customization:
-add Layout class
- add method for color contrast



git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@60805 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
argiro.kokogiannaki 2021-04-06 14:10:46 +00:00
parent f4574a4273
commit b7ecadc8e0
2 changed files with 51 additions and 5 deletions

View File

@ -1,3 +1,12 @@
export class Layout {
_id:string;
portalPid:string;
layoutOptions:CustomizationOptions;
constructor(community, options:CustomizationOptions){
this.portalPid = community;
this.layoutOptions = options;
}
}
export class CustomizationOptions {
identity: {
isDefault: boolean;
@ -97,6 +106,43 @@ export class CustomizationOptions {
return color;
}
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);
b = parseInt(color.substring(5, 7), 16);
if(color.length == 9) {
a = parseInt(color.substring(7, 9), 16);
}
}else if(color.length > 9){
let array = color.split("rgba(")[1].split(")")[0].split(",");
r = parseInt(array[0]);
g = parseInt(array[1]);
b = parseInt(array[2]);
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;
return (brightness < 186)
// 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
*/
}
}
export class ButtonsCustomization{

View File

@ -2,7 +2,7 @@ import {Injectable} from '@angular/core';
import {HttpClient, HttpErrorResponse} from '@angular/common/http';
import {Observable, throwError} from 'rxjs';
import {CustomOptions} from './servicesUtils/customOptions.class';
import {CustomizationOptions} from '../connect/community/CustomizationOptions';
import {CustomizationOptions, Layout} from '../connect/community/CustomizationOptions';
import {EnvProperties} from "../utils/properties/env-properties";
@Injectable()
@ -21,14 +21,14 @@ export class LayoutService {
}
}
saveLayout(properties: EnvProperties, pid: string, layout: CustomizationOptions): Observable<CustomizationOptions> {
saveLayout(properties: EnvProperties, pid: string, layout: Layout): Observable<Layout> {
LayoutService.removeNulls(layout);
return this.http.post<CustomizationOptions>(properties.adminToolsAPIURL + '/' + properties.adminToolsPortalType + '/'
return this.http.post<Layout>(properties.adminToolsAPIURL + '/' + properties.adminToolsPortalType + '/'
+ pid + '/layout', layout, CustomOptions.getAuthOptionsWithBody());
}
getLayout(properties: EnvProperties, pid: string): Observable<CustomizationOptions> {
return this.http.get<CustomizationOptions>(properties.adminToolsAPIURL+"/" + properties.adminToolsPortalType + '/'
getLayout(properties: EnvProperties, pid: string): Observable<Layout> {
return this.http.get<Layout>(properties.adminToolsAPIURL+"/" + properties.adminToolsPortalType + '/'
+ pid + '/layout');
}