Content
diff --git a/src/app/admin/admin.component.scss b/src/app/admin/admin.component.scss
index 729fed7..be80feb 100644
--- a/src/app/admin/admin.component.scss
+++ b/src/app/admin/admin.component.scss
@@ -4,7 +4,7 @@
.login-form-container {
text-align: center;
- padding: 40px;
+ padding: 30px 40px;
color: $white;
.login-label {
@@ -120,6 +120,7 @@
}
.selected-exhibition,
+ .selected-work,
.selected-video {
display: block;
position: relative;
diff --git a/src/app/admin/admin.component.ts b/src/app/admin/admin.component.ts
index efe953f..54e129b 100644
--- a/src/app/admin/admin.component.ts
+++ b/src/app/admin/admin.component.ts
@@ -26,6 +26,7 @@ export class AdminComponent implements OnInit {
public exhibitions: any = []
public works: any = []
public selectedExhibitions: any = []
+ public selectedWorks: any = []
public selectedVideos: any = []
public selectedGallery: any = []
@@ -34,6 +35,8 @@ export class AdminComponent implements OnInit {
public type: string = ''
public content: string = ''
public tags: string = ''
+ public dateFrom: string = ''
+ public dateTo: string = ''
public mainImage: string = ''
public videoType: string = ''
public videoURL: string = ''
@@ -55,26 +58,30 @@ export class AdminComponent implements OnInit {
const body = { token: window.sessionStorage.getItem('authToken') }
this.authService.authCheck(body).toPromise().then((response) => {
- this.authCheck = response.status == 200
+ this.authCheck = response.status && response.status == 200
- this.apisService.getPortfolio('exhibitions').toPromise().then((response) => {
- this.exhibitions = response.items
- },(error) => {
- console.error('getPortfolio ERROR', error)
- }).catch((e) => {
- console.error('getPortfolio CATCH', e)
- })
+ if(this.authCheck) {
+ this.apisService.getPortfolio('exhibitions').toPromise().then((response) => {
+ this.exhibitions = response.items
+ },(error) => {
+ console.error('getPortfolio ERROR', error)
+ }).catch((e) => {
+ console.error('getPortfolio CATCH', e)
+ })
- this.apisService.getPortfolio('portfolio').toPromise().then((response) => {
- this.works = response.items
- },(error) => {
- console.error('getPortfolio ERROR', error)
- }).catch((e) => {
- console.error('getPortfolio CATCH', e)
- })
+ this.apisService.getPortfolio('portfolio').toPromise().then((response) => {
+ this.works = response.items
+ },(error) => {
+ console.error('getPortfolio ERROR', error)
+ }).catch((e) => {
+ console.error('getPortfolio CATCH', e)
+ })
+ }
},(error) => {
+ this.authCheck = false
console.error('Auth ERROR', error)
}).catch((e) => {
+ this.authCheck = false
console.error('Auth CATCH', e)
})
}
@@ -104,6 +111,15 @@ export class AdminComponent implements OnInit {
case 'works-delete':
this.sectionTitle = 'Delete work'
break;
+ case 'exhibitions-add':
+ this.sectionTitle = 'Add exhibition'
+ break;
+ case 'exhibitions-modify':
+ this.sectionTitle = 'Modify exhibition'
+ break;
+ case 'exhibitions-delete':
+ this.sectionTitle = 'Delete exhibition'
+ break;
}
this.activeModify = false
this.activeEditor = section
@@ -125,6 +141,20 @@ export class AdminComponent implements OnInit {
this.selectedExhibitions = this.selectedExhibitions.filter(item => item.id != id)
}
+ workAdd(id): void {
+ this.selectedWorks.push(
+ this.works.filter(item => item.id == id)[0]
+ )
+ this.works = this.works.filter(item => item.id != id)
+ }
+
+ workRemove(id): void {
+ this.works.push(
+ this.selectedWorks.filter(item => item.id == id)[0]
+ )
+ this.selectedWorks = this.selectedWorks.filter(item => item.id != id)
+ }
+
videoAdd(): void {
this.selectedVideos.push({
type: this.videoType,
@@ -196,7 +226,6 @@ export class AdminComponent implements OnInit {
this.selectedGallery = detail.gallery ? JSON.parse(detail.gallery) : []
this.selectedVideos = detail.videos ? JSON.parse(detail.videos) : []
- console.log(detail.exhibitions, this.selectedExhibitions)
},(error) => {
console.error(error)
}).catch((e) => {
@@ -209,6 +238,45 @@ export class AdminComponent implements OnInit {
})
}
+ selectExhibition(id): void {
+
+ this.activeModify = true
+ this.modifyId = id
+ this.apisService.getDetails('exhibitions', id).toPromise().then((response) => {
+ const detail = response.item
+ this.apisService.getPortfolio('portfolio').toPromise().then((response) => {
+ this.works = response.items
+ this.title = detail.title
+ this.content = detail.content
+ this.tags = detail.tags
+ this.dateFrom = detail.date_from
+ this.dateTo = detail.date_to
+ this.selectedWorks = detail.works.length ?
+ this.works.filter(item => detail.works.map(a => a.id).indexOf(item.id) > -1) : []
+ this.selectedGallery = detail.gallery ? JSON.parse(detail.gallery) : []
+ this.selectedVideos = detail.videos ? JSON.parse(detail.videos) : []
+
+ },(error) => {
+ console.error(error)
+ }).catch((e) => {
+ console.error(e)
+ })
+ },(error) => {
+ console.error(error)
+ }).catch((e) => {
+ console.error(e)
+ })
+ }
+
+ saveData(): void {
+ if(this.activeEditor == 'works-add' || this.activeEditor == 'works-modify') {
+ this.saveWork()
+ }
+ if(this.activeEditor == 'exhibitions-add' || this.activeEditor == 'exhibitions-modify') {
+ this.saveExhibition()
+ }
+ }
+
saveWork(): void {
let error = false
let errorMessages = []
@@ -222,6 +290,7 @@ export class AdminComponent implements OnInit {
error = true
errorMessages.push('No type selected')
}
+
if(this.selectedGallery.length == 0 || mainImage.length == 0){
error = true
errorMessages.push('No main image selected')
@@ -254,6 +323,65 @@ export class AdminComponent implements OnInit {
}
}
+ saveExhibition(): 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.dateFrom){
+ error = true
+ errorMessages.push('No date from selected')
+ }
+ if(!this.dateTo){
+ error = true
+ errorMessages.push('No date to selected')
+ }
+ if(this.selectedGallery.length == 0 || mainImage.length == 0){
+ error = true
+ errorMessages.push('No main image selected')
+ }
+
+ if(error) {
+ console.log('ERRORS:',errorMessages)
+ } else {
+ const body = {
+ id: this.activeModify ? this.modifyId : null,
+ token: window.sessionStorage.getItem('authToken'),
+ title: this.title,
+ content: this.content,
+ date_from: this.dateFrom,
+ date_to: this.dateTo,
+ tags: this.tags,
+ image: mainImage[0].url,
+ works: this.selectedWorks.map(a => a.id).join(','),
+ gallery: JSON.stringify(this.selectedGallery),
+ videos: JSON.stringify(this.selectedVideos)
+ }
+
+ this.apisService.saveExhibition(body).toPromise().then((response) => {
+ this.resetFields()
+ this.exhibitions = response.items
+ },(error) => {
+ console.error(error)
+ }).catch((e) => {
+ console.error(e)
+ })
+ }
+ }
+
+ deleteData(id): void {
+ if(this.activeEditor == 'works-delete') {
+ this.deleteWork(id)
+ }
+ if(this.activeEditor == 'exhibitions-delete') {
+ this.deleteExhibition(id)
+ }
+ }
+
deleteWork(id): void {
const body = {
@@ -271,12 +399,32 @@ export class AdminComponent implements OnInit {
})
}
+ deleteExhibition(id): void {
+
+ const body = {
+ id: id,
+ token: window.sessionStorage.getItem('authToken')
+ }
+
+ this.apisService.deleteExhibition(body).toPromise().then((response) => {
+ this.resetFields()
+ this.exhibitions = response.items
+ },(error) => {
+ console.error(error)
+ }).catch((e) => {
+ console.error(e)
+ })
+ }
+
resetFields(): void {
this.title = ''
this.content = ''
this.type = ''
this.tags = ''
+ this.dateFrom = ''
+ this.dateTo = ''
this.selectedExhibitions = []
+ this.selectedWorks = []
this.selectedGallery = []
this.selectedVideos = []
this.modifyId = null
diff --git a/src/app/services/apis.service.ts b/src/app/services/apis.service.ts
index 0ffcf69..31e6ab1 100644
--- a/src/app/services/apis.service.ts
+++ b/src/app/services/apis.service.ts
@@ -59,5 +59,19 @@ export class ApisService extends BaseService {
)
}
+ saveExhibition(body): Observable
{
+ let urlApi = `${this.restApi}exhibition.php?act=save`
+ return this.http.post(urlApi, JSON.stringify(body)).pipe(
+ catchError(this.handleError)
+ )
+ }
+
+ deleteExhibition(body): Observable {
+ let urlApi = `${this.restApi}exhibition.php?act=delete`
+ return this.http.post(urlApi, JSON.stringify(body)).pipe(
+ catchError(this.handleError)
+ )
+ }
+
}