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';
|
2020-04-01 15:40:48 +02:00
|
|
|
import {DomSanitizer, Title} from '@angular/platform-browser';
|
2019-10-07 16:36:53 +02:00
|
|
|
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
|
|
|
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;
|
2020-01-20 15:33:36 +01:00
|
|
|
public errorMessage = '';
|
2019-10-07 16:36:53 +02:00
|
|
|
public successfulSaveMessage = '';
|
|
|
|
|
|
|
|
|
|
|
|
public communityId = null;
|
|
|
|
|
|
|
|
public properties: EnvProperties = null;
|
|
|
|
|
|
|
|
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,
|
2020-04-01 15:40:48 +02:00
|
|
|
private title: Title,
|
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'];
|
2020-04-01 15:40:48 +02:00
|
|
|
this.title.setTitle('Administration Dashboard | Customization');
|
2019-10-07 16:36:53 +02:00
|
|
|
this.showLoading = true;
|
2020-01-20 15:33:36 +01:00
|
|
|
this.errorMessage = '';
|
|
|
|
this.successfulSaveMessage = '';
|
2020-04-08 13:59:20 +02:00
|
|
|
this.layoutService.getLayout(this.properties, this.communityId).subscribe(layout => {
|
2020-01-20 15:33:36 +01:00
|
|
|
this.publishedCustomizationOptions = (layout?layout:new CustomizationOptions());
|
2019-10-10 17:17:43 +02:00
|
|
|
this.initializeCustomizationOptions(true);
|
|
|
|
}, error => {
|
|
|
|
this.publishedCustomizationOptions = new CustomizationOptions();
|
|
|
|
this.initializeCustomizationOptions(true);
|
2020-01-20 15:33:36 +01:00
|
|
|
this.errorMessage = "An error occured fetching customizations options"
|
2019-10-08 16:18:38 +02:00
|
|
|
});
|
2019-10-07 16:36:53 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2020-01-20 15:33:36 +01:00
|
|
|
hasChanges(object1,object2):boolean{
|
|
|
|
return JSON.stringify(object1) != JSON.stringify(object2);
|
|
|
|
}
|
2019-10-08 16:18:38 +02:00
|
|
|
saveLayout() {
|
2020-01-20 15:33:36 +01:00
|
|
|
if (!Session.isLoggedIn()) {
|
|
|
|
this._router.navigate(['/user-info'], {
|
|
|
|
queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': this._router.url}
|
|
|
|
});
|
|
|
|
}
|
2020-04-08 13:59:20 +02:00
|
|
|
this.layoutService.saveLayout(this.properties, this.communityId, this.draftCustomizationOptions).subscribe(layout => {
|
2019-10-10 17:17:43 +02:00
|
|
|
this.publishedCustomizationOptions = layout;
|
|
|
|
this.initializeCustomizationOptions(JSON.stringify(this.publishedCustomizationOptions) != this.previewCustomization);
|
2020-01-20 15:33:36 +01:00
|
|
|
this.successfulSaveMessage = "Customization Options saved!"
|
|
|
|
}, error => {
|
|
|
|
this.errorMessage = "An error occured on save"
|
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);
|
2020-01-20 15:33:36 +01:00
|
|
|
|
|
|
|
this.linkDarkBackgroundPreview=this.changeFontsStyle(this.publishedCustomizationOptions.links.darkBackground, this.publishedCustomizationOptions.links.darkBackground.color);
|
2019-10-10 17:17:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2020-01-20 15:33:36 +01:00
|
|
|
|
|
|
|
this.linkLightBackgroundPreview=this.changeFontsStyle(this.publishedCustomizationOptions.links.lightBackground, this.publishedCustomizationOptions.links.lightBackground.color);
|
2019-10-10 17:17:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2020-01-20 15:33:36 +01:00
|
|
|
|
|
|
|
this.buttonDarkBackgroundPreview=this.changeStyle(this.publishedCustomizationOptions.buttons.darkBackground);
|
2019-10-10 17:17:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resetButtonsLight() {
|
|
|
|
this.draftCustomizationOptions.buttons.lightBackground = this.copyObject(this.publishedCustomizationOptions.buttons.lightBackground);
|
|
|
|
|
|
|
|
this.appliedCustomizationOptions.buttons.lightBackground = this.copyObject(this.publishedCustomizationOptions.buttons.lightBackground);
|
2020-01-20 15:33:36 +01:00
|
|
|
|
|
|
|
this.buttonLightBackgroundPreview=this.changeStyle(this.publishedCustomizationOptions.buttons.lightBackground);
|
2019-10-10 17:17:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
2020-01-20 15:33:36 +01:00
|
|
|
getCommunityUrl() {
|
|
|
|
return 'https://'+ (this.properties.environment == 'production'?'':'beta.')+this.communityId+'.openaire.eu';
|
|
|
|
}
|
2019-10-07 16:36:53 +02:00
|
|
|
|
2019-10-10 17:17:43 +02:00
|
|
|
getCommunityUrlNewLayout(layout: string) {
|
|
|
|
this.previewCustomization = layout;
|
2020-01-20 15:33:36 +01:00
|
|
|
return this.getCommunityUrl()+'/?' + 'layout=' + StringUtils.URIEncode(layout);
|
2019-10-07 16:36:53 +02:00
|
|
|
}
|
|
|
|
|
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}
|
|
|
|
});
|
|
|
|
}
|
2020-01-20 15:33:36 +01:00
|
|
|
downloadCustomization(){
|
|
|
|
this.errorMessage = "";
|
|
|
|
let options= JSON.parse(JSON.stringify(this.publishedCustomizationOptions));
|
|
|
|
delete options['_id'];
|
|
|
|
console.info("Here!" +JSON.stringify(options));
|
|
|
|
if(typeof document !== 'undefined') {
|
|
|
|
let dataStr = JSON.stringify(options);
|
|
|
|
let dataUri = 'data:application/json;charset=utf-8,' + encodeURIComponent(dataStr);
|
|
|
|
|
|
|
|
let exportFileDefaultName = 'layoutOptions.json';
|
|
|
|
|
|
|
|
let linkElement = document.createElement('a');
|
|
|
|
linkElement.setAttribute('href', dataUri);
|
|
|
|
linkElement.setAttribute('download', exportFileDefaultName);
|
|
|
|
linkElement.click();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fileChangeEvent(fileInput: any) {
|
|
|
|
this.errorMessage = "";
|
|
|
|
let filesToUpload = <Array<File>>fileInput.target.files;
|
|
|
|
|
|
|
|
|
|
|
|
if (filesToUpload.length == 0) {
|
|
|
|
this.errorMessage = "There is no selected file to upload.";
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
if (filesToUpload[0].name.indexOf(".json") == -1 ||
|
|
|
|
(filesToUpload[0].type != "application/json" )) {
|
|
|
|
this.errorMessage = "No valid file type. The required type is json "+filesToUpload[0].type;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.makeFileRequest(this.properties.utilsService + '/upload?type=json', [], filesToUpload).then((result) => {
|
|
|
|
let layout:CustomizationOptions = JSON.parse(result.toString());
|
|
|
|
if( layout && layout.panel && layout.links && layout.buttons && layout.box){
|
|
|
|
this.draftCustomizationOptions = layout;
|
|
|
|
//put the same id to not have any difference
|
|
|
|
if(this.publishedCustomizationOptions['_id']){
|
|
|
|
this.draftCustomizationOptions['_id'] = this.publishedCustomizationOptions['_id'];
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
this.errorMessage = "No valid file";
|
|
|
|
}
|
|
|
|
|
|
|
|
}, (error) => {
|
|
|
|
this.errorMessage = "No valid file";
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
makeFileRequest(url: string, params: Array<string>, files: Array<File>) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const formData: any = new FormData();
|
|
|
|
const xhr = new XMLHttpRequest();
|
|
|
|
for (let i = 0; i < files.length; i++) {
|
|
|
|
formData.append("uploads[]", files[i], files[i].name);
|
|
|
|
}
|
|
|
|
xhr.onreadystatechange = function () {
|
|
|
|
if (xhr.readyState == 4) {
|
|
|
|
if (xhr.status == 200) {
|
|
|
|
resolve(xhr.response);
|
|
|
|
} else {
|
|
|
|
reject(xhr.response);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xhr.open("POST", url, true);
|
|
|
|
xhr.send(formData);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-10-07 16:36:53 +02:00
|
|
|
}
|