diff --git a/src/app/admin/admin.component.html b/src/app/admin/admin.component.html index 97cb952..ca38265 100644 --- a/src/app/admin/admin.component.html +++ b/src/app/admin/admin.component.html @@ -27,9 +27,20 @@
-
- Add work -
+
+ {{sectionTitle}} + +
+ Select work + +
+ +
Title @@ -37,10 +48,7 @@
Type
@@ -61,8 +69,8 @@
- - + +
diff --git a/src/app/admin/admin.component.ts b/src/app/admin/admin.component.ts index e441e1e..9f015cc 100644 --- a/src/app/admin/admin.component.ts +++ b/src/app/admin/admin.component.ts @@ -19,8 +19,12 @@ export class AdminComponent implements OnInit { public userName: string = '' public password: string = '' public activeEditor: string = '' - public exhibitions: any = [] + public sectionTitle: string = '' + public activeModify: boolean = false + public modifyId: number = null + public exhibitions: any = [] + public works: any = [] public selectedExhibitions: any = [] public selectedVideos: any = [] public selectedGallery: any = [] @@ -34,7 +38,13 @@ export class AdminComponent implements OnInit { public videoType: string = '' public videoURL: string = '' - editorConfig: AngularEditorConfig = editorConfig + public editorConfig: AngularEditorConfig = editorConfig + public workSections: any = [ + {title: 'Entertainment', section: 'entertainment'}, + {title: 'Installations', section: 'installations'}, + {title: 'Performances', section: 'performances'}, + {title: 'Workshops', section: 'workshops'} + ] constructor( private authService: AuthService, @@ -54,6 +64,14 @@ export class AdminComponent implements OnInit { }).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) => { console.error('Auth ERROR', error) }).catch((e) => { @@ -76,7 +94,20 @@ export class AdminComponent implements OnInit { } showEditor(section): void { + switch(section) { + case 'works-add': + this.sectionTitle = 'Add work' + break; + case 'works-modify': + this.sectionTitle = 'Modify work' + break; + case 'works-delete': + this.sectionTitle = 'Delete work' + break; + } + this.activeModify = false this.activeEditor = section + this.resetFields() } exhibitionAdd(id): void { @@ -147,6 +178,36 @@ export class AdminComponent implements OnInit { }) } + selectWork(id): void { + + this.activeModify = true + this.modifyId = id + this.apisService.getDetails('works', id).toPromise().then((response) => { + const detail = response.item + this.apisService.getPortfolio('exhibitions').toPromise().then((response) => { + this.exhibitions = response.items + this.title = detail.title + this.content = detail.content + this.type = detail.type + this.tags = detail.tags + this.selectedExhibitions = detail.exhibitions.length ? + this.exhibitions.filter(item => detail.exhibitions.map(a => a.id).indexOf(item.id) > -1) : [] + 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) => { + console.error(e) + }) + },(error) => { + console.error(error) + }).catch((e) => { + console.error(e) + }) + } + saveWork(): void { let error = false @@ -167,9 +228,10 @@ export class AdminComponent implements OnInit { } if(error) { - console.log('ERORS:',errorMessages) + console.log('ERRORS:',errorMessages) } else { const body = { + id: this.activeModify ? this.modifyId : null, token: window.sessionStorage.getItem('authToken'), title: this.title, content: this.content, @@ -182,14 +244,9 @@ export class AdminComponent implements OnInit { } this.apisService.saveWork(body).toPromise().then((response) => { - console.log(response) - this.title = '' - this.content = '' - this.type = '' - this.tags = '' - this.selectedExhibitions = [] - this.selectedGallery = [] - this.selectedVideos = [] + this.resetFields() + + this.works = response.items },(error) => { console.error(error) }).catch((e) => { @@ -197,4 +254,14 @@ export class AdminComponent implements OnInit { }) } } + + resetFields(): void { + this.title = '' + this.content = '' + this.type = '' + this.tags = '' + this.selectedExhibitions = [] + this.selectedGallery = [] + this.selectedVideos = [] + } }