|
|
@ -13,6 +13,7 @@ import { editorConfig } from '../../config/config' |
|
|
|
export class AdminComponent implements OnInit { |
|
|
|
|
|
|
|
private restApi = `${environment.API_URL}` |
|
|
|
public basePath = `${environment.BASE_PATH}` |
|
|
|
|
|
|
|
public authCheck: boolean = false |
|
|
|
public userName: string = '' |
|
|
@ -29,7 +30,7 @@ export class AdminComponent implements OnInit { |
|
|
|
public type: string = '' |
|
|
|
public content: string = '' |
|
|
|
public tags: string = '' |
|
|
|
public mainImage: any = null |
|
|
|
public mainImage: string = '' |
|
|
|
public videoType: string = '' |
|
|
|
public videoURL: string = '' |
|
|
|
|
|
|
@ -42,18 +43,6 @@ export class AdminComponent implements OnInit { |
|
|
|
|
|
|
|
ngOnInit(): void { |
|
|
|
|
|
|
|
this.selectedGallery = [ |
|
|
|
{ |
|
|
|
main: true, |
|
|
|
title: '', |
|
|
|
url: 'http://unsplash.it/800/600' |
|
|
|
}, |
|
|
|
{ |
|
|
|
title: '', |
|
|
|
url: 'http://unsplash.it/800/700' |
|
|
|
} |
|
|
|
] |
|
|
|
|
|
|
|
const body = { token: window.sessionStorage.getItem('authToken') } |
|
|
|
this.authService.authCheck(body).toPromise().then((response) => { |
|
|
|
this.authCheck = response.status == 200 |
|
|
@ -119,6 +108,8 @@ export class AdminComponent implements OnInit { |
|
|
|
onFileChanged(e) { |
|
|
|
const file = (<HTMLInputElement>e.target).files[0] |
|
|
|
const uploadData = new FormData() |
|
|
|
uploadData.append('token', window.sessionStorage.getItem('authToken')) |
|
|
|
uploadData.append('path', 'assets') |
|
|
|
uploadData.append('file', file, file.name) |
|
|
|
this.apisService.uploadImage(uploadData).toPromise().then((response) => { |
|
|
|
this.selectedGallery.push({ |
|
|
@ -143,7 +134,11 @@ export class AdminComponent implements OnInit { |
|
|
|
} |
|
|
|
|
|
|
|
galleryRemove(url): void { |
|
|
|
this.apisService.removeImage(url).toPromise().then((response) => { |
|
|
|
const body = { |
|
|
|
token: window.sessionStorage.getItem('authToken'), |
|
|
|
url: url |
|
|
|
} |
|
|
|
this.apisService.removeImage(body).toPromise().then((response) => { |
|
|
|
this.selectedGallery = this.selectedGallery.filter(item => item.url != url) |
|
|
|
},(error) => { |
|
|
|
console.error(error) |
|
|
@ -151,4 +146,55 @@ export class AdminComponent implements OnInit { |
|
|
|
console.error(e) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
saveWork(): void { |
|
|
|
|
|
|
|
let error = false |
|
|
|
let errorMessages = [] |
|
|
|
const mainImage = this.selectedGallery.filter(item => item.main) |
|
|
|
|
|
|
|
if(!this.title){ |
|
|
|
error = true |
|
|
|
errorMessages.push('No title') |
|
|
|
} |
|
|
|
if(!this.type){ |
|
|
|
error = true |
|
|
|
errorMessages.push('No type selected') |
|
|
|
} |
|
|
|
if(this.selectedGallery.length == 0 || mainImage.length == 0){ |
|
|
|
error = true |
|
|
|
errorMessages.push('No main image selected') |
|
|
|
} |
|
|
|
|
|
|
|
if(error) { |
|
|
|
console.log('ERORS:',errorMessages) |
|
|
|
} else { |
|
|
|
const body = { |
|
|
|
token: window.sessionStorage.getItem('authToken'), |
|
|
|
title: this.title, |
|
|
|
content: this.content, |
|
|
|
type: this.type, |
|
|
|
tags: this.tags, |
|
|
|
image: mainImage[0].url, |
|
|
|
exhibitions: this.selectedExhibitions.map(a => a.id).join(','), |
|
|
|
gallery: JSON.stringify(this.selectedGallery), |
|
|
|
videos: JSON.stringify(this.selectedVideos) |
|
|
|
} |
|
|
|
|
|
|
|
this.apisService.saveWork(body).toPromise().then((response) => { |
|
|
|
console.log(response) |
|
|
|
this.title = '' |
|
|
|
this.content = '' |
|
|
|
this.type = '' |
|
|
|
this.tags = '' |
|
|
|
this.selectedExhibitions = [] |
|
|
|
this.selectedGallery = [] |
|
|
|
this.selectedVideos = [] |
|
|
|
},(error) => { |
|
|
|
console.error(error) |
|
|
|
}).catch((e) => { |
|
|
|
console.error(e) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|