2019-10-10 17:17:43 +02:00
|
|
|
import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
|
2019-10-07 16:36:53 +02:00
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
|
|
|
|
|
|
|
import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties';
|
|
|
|
|
|
|
|
import {Session} from '../../openaireLibrary/login/utils/helper.class';
|
|
|
|
import {LoginErrorCodes} from '../../openaireLibrary/login/utils/guardHelper.class';
|
|
|
|
import {Curator} from '../../openaireLibrary/utils/entities/CuratorInfo';
|
|
|
|
import {DomSanitizer} from '@angular/platform-browser';
|
|
|
|
import {CustomizationOptions} from '../../openaireLibrary/connect/community/CustomizationOptions';
|
|
|
|
import {StringUtils} from '../../openaireLibrary/utils/string-utils.class';
|
2019-10-10 17:17:43 +02:00
|
|
|
import {LayoutService} from '../../openaireLibrary/services/layout.service';
|
|
|
|
import {AlertModal} from '../../openaireLibrary/utils/modal/alert';
|
2019-10-07 16:36:53 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'customization',
|
|
|
|
templateUrl: './customization.component.html',
|
|
|
|
})
|
|
|
|
|
|
|
|
export class CustomizationComponent implements OnInit {
|
|
|
|
|
|
|
|
menuSelected = 'main';
|
|
|
|
color = 'white';
|
2019-10-10 17:17:43 +02:00
|
|
|
communityUrl = 'http://scoobydoo.di.uoa.gr:4200/?communityId=ee';
|
|
|
|
publishedCustomizationOptions: CustomizationOptions = null;
|
|
|
|
draftCustomizationOptions: CustomizationOptions = null;
|
|
|
|
appliedCustomizationOptions: CustomizationOptions = null;
|
|
|
|
previewUrl = null;
|
|
|
|
previewCustomization = null;
|
2019-10-07 16:36:53 +02:00
|
|
|
buttonDarkBackgroundPreview;
|
|
|
|
buttonLightBackgroundPreview;
|
|
|
|
linkDarkBackgroundPreview;
|
|
|
|
linkLightBackgroundPreview;
|
2019-10-10 17:17:43 +02:00
|
|
|
hoveredText;
|
2019-10-07 16:36:53 +02:00
|
|
|
public showLoading = true;
|
|
|
|
public updateErrorMessage = '';
|
|
|
|
public successfulSaveMessage = '';
|
|
|
|
|
|
|
|
|
|
|
|
public communityId = null;
|
|
|
|
|
|
|
|
public hasChanged = false;
|
|
|
|
public properties: EnvProperties = null;
|
|
|
|
|
|
|
|
private file: File = null;
|
|
|
|
private maxsize: number = 200 * 1024;
|
|
|
|
public enabled = true;
|
2019-10-10 17:17:43 +02:00
|
|
|
@ViewChild('backAlert') backAlert: AlertModal;
|
|
|
|
@ViewChild('exitAlert') exitAlert: AlertModal;
|
2019-10-07 16:36:53 +02:00
|
|
|
|
|
|
|
constructor(private element: ElementRef,
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
private _router: Router,
|
2019-10-08 16:18:38 +02:00
|
|
|
private sanitizer: DomSanitizer,
|
|
|
|
private layoutService: LayoutService) {
|
2019-10-07 16:36:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.route.data.subscribe((data: { envSpecific: EnvProperties }) => {
|
|
|
|
this.properties = data.envSpecific;
|
|
|
|
if (!Session.isLoggedIn()) {
|
|
|
|
this._router.navigate(['/user-info'], {
|
|
|
|
queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.route.queryParams.subscribe((params) => {
|
|
|
|
this.communityId = params['communityId'];
|
|
|
|
this.showLoading = true;
|
|
|
|
this.updateErrorMessage = '';
|
2019-10-08 16:18:38 +02:00
|
|
|
this.layoutService.getLayout(this.communityId, this.properties.adminToolsAPIURL + 'community/').subscribe(layout => {
|
2019-10-10 17:17:43 +02:00
|
|
|
this.publishedCustomizationOptions = layout;
|
|
|
|
this.initializeCustomizationOptions(true);
|
|
|
|
}, error => {
|
|
|
|
this.publishedCustomizationOptions = new CustomizationOptions();
|
|
|
|
this.initializeCustomizationOptions(true);
|
2019-10-08 16:18:38 +02:00
|
|
|
});
|
2019-10-07 16:36:53 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-10-08 16:18:38 +02:00
|
|
|
saveLayout() {
|
2019-10-10 17:17:43 +02:00
|
|
|
this.layoutService.saveLayout(this.communityId, this.properties.adminToolsAPIURL + 'community/', this.draftCustomizationOptions).subscribe(layout => {
|
|
|
|
this.publishedCustomizationOptions = layout;
|
|
|
|
this.initializeCustomizationOptions(JSON.stringify(this.publishedCustomizationOptions) != this.previewCustomization);
|
|
|
|
|
2019-10-08 16:18:38 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-10-10 17:17:43 +02:00
|
|
|
initializeCustomizationOptions(updatePreviewUrl) {
|
|
|
|
this.draftCustomizationOptions = this.copyObject(this.publishedCustomizationOptions);
|
|
|
|
this.appliedCustomizationOptions = this.copyObject(this.publishedCustomizationOptions);
|
|
|
|
|
|
|
|
if(updatePreviewUrl){
|
|
|
|
this.previewUrl = this.getCommunityUrlSatinized(JSON.stringify(this.appliedCustomizationOptions));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.buttonDarkBackgroundPreview = this.changeStyle(this.draftCustomizationOptions.buttons.darkBackground);
|
|
|
|
this.buttonLightBackgroundPreview = this.changeStyle(this.draftCustomizationOptions.buttons.lightBackground);
|
|
|
|
this.linkDarkBackgroundPreview = this.changeFontsStyle(this.draftCustomizationOptions.links.darkBackground, this.draftCustomizationOptions.links.darkBackground.color);
|
|
|
|
this.linkLightBackgroundPreview = this.changeStyle(this.draftCustomizationOptions.links.lightBackground, this.draftCustomizationOptions.links.lightBackground.color);
|
|
|
|
}
|
|
|
|
|
|
|
|
applyLayout() {
|
|
|
|
this.appliedCustomizationOptions = this.copyObject(this.draftCustomizationOptions);
|
|
|
|
if(JSON.stringify(this.appliedCustomizationOptions) != this.previewCustomization){
|
|
|
|
this.previewUrl = this.getCommunityUrlSatinized(JSON.stringify(this.appliedCustomizationOptions));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resetLayout() {
|
|
|
|
|
|
|
|
if (this.menuSelected == 'backgrounds') {
|
|
|
|
this.resetBackgrounds();
|
|
|
|
} else if (this.menuSelected == 'fonts') {
|
|
|
|
this.resetFonts();
|
|
|
|
} else if (this.menuSelected == 'elements') {
|
|
|
|
this.resetElements();
|
|
|
|
} else if (this.menuSelected == 'buttons') {
|
|
|
|
this.resetButtons();
|
|
|
|
} else if (this.menuSelected == 'identity') {
|
|
|
|
this.resetIdentity();
|
|
|
|
} else {
|
|
|
|
this.draftCustomizationOptions = this.copyObject(this.publishedCustomizationOptions);
|
|
|
|
|
|
|
|
this.appliedCustomizationOptions = this.copyObject(this.publishedCustomizationOptions);
|
|
|
|
}
|
|
|
|
// console.log(JSON.stringify(this.appliedCustomizationOptions))
|
|
|
|
// console.log(this.previewCustomization)
|
|
|
|
this.initializeCustomizationOptions(JSON.stringify(this.appliedCustomizationOptions) != this.previewCustomization);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
resetBackgrounds() {
|
|
|
|
this.draftCustomizationOptions.panel.onDarkBackground = this.publishedCustomizationOptions.panel.onDarkBackground;
|
|
|
|
this.draftCustomizationOptions.panel.background.color = this.publishedCustomizationOptions.panel.background.color;
|
|
|
|
|
|
|
|
this.appliedCustomizationOptions.panel.onDarkBackground = this.publishedCustomizationOptions.panel.onDarkBackground;
|
|
|
|
this.appliedCustomizationOptions.panel.background.color = this.publishedCustomizationOptions.panel.background.color;
|
|
|
|
}
|
|
|
|
|
|
|
|
resetFonts() {
|
|
|
|
this.resetFontsBig();
|
|
|
|
this.resetFontsSmall();
|
|
|
|
this.resetFontsLinksDark();
|
|
|
|
this.resetFontsLinksLight();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
resetFontsBig() {
|
|
|
|
this.draftCustomizationOptions.panel.title = this.copyObject(this.publishedCustomizationOptions.panel.title);
|
|
|
|
|
|
|
|
this.appliedCustomizationOptions.panel.title = this.copyObject(this.publishedCustomizationOptions.panel.title);
|
|
|
|
}
|
|
|
|
|
|
|
|
resetFontsSmall() {
|
|
|
|
this.draftCustomizationOptions.panel.fonts = this.copyObject(this.publishedCustomizationOptions.panel.fonts);
|
|
|
|
|
|
|
|
this.appliedCustomizationOptions.panel.fonts = this.copyObject(this.publishedCustomizationOptions.panel.fonts);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
resetFontsLinksDark() {
|
|
|
|
this.draftCustomizationOptions.links.darkBackground = this.copyObject(this.publishedCustomizationOptions.links.darkBackground);
|
|
|
|
|
|
|
|
this.appliedCustomizationOptions.links.darkBackground = this.copyObject(this.publishedCustomizationOptions.links.darkBackground);
|
|
|
|
}
|
|
|
|
|
|
|
|
resetFontsLinksLight() {
|
|
|
|
this.draftCustomizationOptions.panel.title = this.copyObject(this.publishedCustomizationOptions.panel.title);
|
|
|
|
this.draftCustomizationOptions.links.lightBackground = this.copyObject(this.publishedCustomizationOptions.links.lightBackground);
|
|
|
|
|
|
|
|
this.appliedCustomizationOptions.panel.title = this.copyObject(this.publishedCustomizationOptions.panel.title);
|
|
|
|
this.appliedCustomizationOptions.links.lightBackground = this.copyObject(this.publishedCustomizationOptions.links.lightBackground);
|
|
|
|
}
|
|
|
|
|
|
|
|
resetElements() {
|
|
|
|
this.draftCustomizationOptions.panel.panelElements = this.copyObject(this.publishedCustomizationOptions.panel.panelElements);
|
|
|
|
|
|
|
|
this.appliedCustomizationOptions.panel.panelElements = this.copyObject(this.publishedCustomizationOptions.panel.panelElements);
|
|
|
|
}
|
|
|
|
|
|
|
|
resetButtons() {
|
|
|
|
this.resetButtonsDark();
|
|
|
|
this.resetButtonsLight();
|
|
|
|
}
|
|
|
|
|
|
|
|
resetButtonsDark() {
|
|
|
|
this.draftCustomizationOptions.buttons.darkBackground = this.copyObject(this.publishedCustomizationOptions.buttons.darkBackground);
|
|
|
|
|
|
|
|
this.appliedCustomizationOptions.buttons.darkBackground = this.copyObject(this.publishedCustomizationOptions.buttons.darkBackground);
|
|
|
|
}
|
|
|
|
|
|
|
|
resetButtonsLight() {
|
|
|
|
this.draftCustomizationOptions.buttons.lightBackground = this.copyObject(this.publishedCustomizationOptions.buttons.lightBackground);
|
|
|
|
|
|
|
|
this.appliedCustomizationOptions.buttons.lightBackground = this.copyObject(this.publishedCustomizationOptions.buttons.lightBackground);
|
|
|
|
}
|
|
|
|
|
|
|
|
resetIdentity() {
|
|
|
|
this.draftCustomizationOptions.mainColor = this.publishedCustomizationOptions.mainColor;
|
|
|
|
this.draftCustomizationOptions.secondaryColor = this.publishedCustomizationOptions.secondaryColor;
|
|
|
|
|
|
|
|
this.appliedCustomizationOptions.mainColor = this.publishedCustomizationOptions.mainColor;
|
|
|
|
this.appliedCustomizationOptions.secondaryColor = this.publishedCustomizationOptions.secondaryColor;
|
2019-10-07 16:36:53 +02:00
|
|
|
}
|
|
|
|
|
2019-10-08 16:18:38 +02:00
|
|
|
changeStyle(colorOptions, borderOptions = null) {
|
2019-10-07 16:36:53 +02:00
|
|
|
let style = '';
|
2019-10-08 16:18:38 +02:00
|
|
|
if (!borderOptions) {
|
2019-10-07 16:36:53 +02:00
|
|
|
borderOptions = colorOptions;
|
|
|
|
}
|
|
|
|
if (colorOptions.color) {
|
2019-10-10 17:17:43 +02:00
|
|
|
style = style.concat('; color:' + colorOptions.color);
|
2019-10-07 16:36:53 +02:00
|
|
|
}
|
|
|
|
if (colorOptions.backgroundColor) {
|
2019-10-10 17:17:43 +02:00
|
|
|
style = style.concat( '; background-color:' + colorOptions.backgroundColor);
|
2019-10-07 16:36:53 +02:00
|
|
|
}
|
|
|
|
if (colorOptions.borderColor) {
|
2019-10-10 17:17:43 +02:00
|
|
|
style = style.concat('; border-color:' + colorOptions.borderColor);
|
2019-10-07 16:36:53 +02:00
|
|
|
}
|
|
|
|
if (borderOptions.borderStyle) {
|
2019-10-10 17:17:43 +02:00
|
|
|
style = style.concat('; border-style:' + borderOptions.borderStyle);
|
2019-10-07 16:36:53 +02:00
|
|
|
}
|
|
|
|
if (borderOptions.borderWidth) {
|
2019-10-10 17:17:43 +02:00
|
|
|
style = style.concat( '; border-width:' + borderOptions.borderWidth + 'px');
|
2019-10-07 16:36:53 +02:00
|
|
|
}
|
|
|
|
if (borderOptions.borderRadius) {
|
2019-10-10 17:17:43 +02:00
|
|
|
style = style.concat('; border-radius:' + borderOptions.borderRadius + 'px');
|
2019-10-07 16:36:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.sanitizer.bypassSecurityTrustStyle(style);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-10-08 16:18:38 +02:00
|
|
|
changeFontsStyle(options, color = null) {
|
2019-10-07 16:36:53 +02:00
|
|
|
let style = '';
|
|
|
|
|
|
|
|
|
|
|
|
if (options.family) {
|
2019-10-10 17:17:43 +02:00
|
|
|
style = style.concat('; font-family:' + options.family);
|
2019-10-07 16:36:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (options.size) {
|
2019-10-10 17:17:43 +02:00
|
|
|
style = style.concat('; font-size:' + options.size + 'px');
|
2019-10-07 16:36:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (options.weight) {
|
2019-10-10 17:17:43 +02:00
|
|
|
style = style.concat('; font-weight:' + options.weight);
|
2019-10-07 16:36:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (color) {
|
2019-10-10 17:17:43 +02:00
|
|
|
style = style.concat('; color:' + color);
|
2019-10-07 16:36:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.sanitizer.bypassSecurityTrustStyle(style);
|
|
|
|
}
|
|
|
|
|
2019-10-10 17:17:43 +02:00
|
|
|
getCommunityUrlSatinized(layout: string) {
|
|
|
|
return this.sanitizer.bypassSecurityTrustResourceUrl(this.getCommunityUrlNewLayout(layout));
|
2019-10-07 16:36:53 +02:00
|
|
|
}
|
|
|
|
|
2019-10-10 17:17:43 +02:00
|
|
|
getCommunityUrlNewLayout(layout: string) {
|
|
|
|
this.previewCustomization = layout;
|
2019-10-07 16:36:53 +02:00
|
|
|
return this.communityUrl + '&layout=' + StringUtils.URIEncode(layout);
|
|
|
|
}
|
|
|
|
|
2019-10-08 16:18:38 +02:00
|
|
|
copyObject(obj) {
|
|
|
|
return JSON.parse(JSON.stringify(obj));
|
|
|
|
}
|
|
|
|
|
2019-10-10 17:17:43 +02:00
|
|
|
back() {
|
|
|
|
if (JSON.stringify(this.draftCustomizationOptions) == JSON.stringify(this.publishedCustomizationOptions) ||
|
|
|
|
JSON.stringify(this.draftCustomizationOptions) == JSON.stringify(this.appliedCustomizationOptions)) {
|
|
|
|
this.menuSelected = 'main';
|
|
|
|
} else {
|
|
|
|
this.backAlert.okButtonText = 'Yes';
|
|
|
|
this.backAlert.cancelButtonText = 'No';
|
|
|
|
this.backAlert.alertTitle = '';
|
|
|
|
this.backAlert.okButtonLeft = true;
|
|
|
|
this.backAlert.open();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
resetToAppliedOptions() {
|
|
|
|
this.draftCustomizationOptions = this.copyObject(this.appliedCustomizationOptions);
|
|
|
|
this.menuSelected = 'main';
|
2019-10-08 16:18:38 +02:00
|
|
|
}
|
2019-10-07 16:36:53 +02:00
|
|
|
|
2019-10-10 17:17:43 +02:00
|
|
|
exit() {
|
|
|
|
if (JSON.stringify(this.appliedCustomizationOptions) == JSON.stringify(this.publishedCustomizationOptions)) {
|
|
|
|
this.exitCustomization();
|
|
|
|
} else {
|
|
|
|
this.exitAlert.okButtonText = 'Yes';
|
|
|
|
this.exitAlert.cancelButtonText = 'No';
|
|
|
|
this.exitAlert.alertTitle = '';
|
|
|
|
this.exitAlert.okButtonLeft = true;
|
|
|
|
this.exitAlert.open();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
exitCustomization() {
|
|
|
|
this._router.navigate(['/dashboard'], {
|
|
|
|
queryParams: {'communityId': this.communityId}
|
|
|
|
});
|
|
|
|
}
|
2019-10-07 16:36:53 +02:00
|
|
|
}
|