From d78fc019ee1216cb1e2916d3f803ab868c6cbab3 Mon Sep 17 00:00:00 2001 From: Dslak Date: Sat, 5 Dec 2020 17:42:16 +0100 Subject: [PATCH] admin exhibitions --- src/apis/exhibition.php | 61 ++++++++++ src/app/admin/admin.component.html | 61 ++++++++-- src/app/admin/admin.component.scss | 3 +- src/app/admin/admin.component.ts | 180 ++++++++++++++++++++++++++--- src/app/services/apis.service.ts | 14 +++ 5 files changed, 294 insertions(+), 25 deletions(-) create mode 100644 src/apis/exhibition.php diff --git a/src/apis/exhibition.php b/src/apis/exhibition.php new file mode 100644 index 0000000..2c30b34 --- /dev/null +++ b/src/apis/exhibition.php @@ -0,0 +1,61 @@ +token) && $data->token == base64_encode('admin:JohnHolmes'.date("Y-m-d"))) { + + if(isset($_GET['act']) && $_GET['act'] == 'save') { + + if(isset($data->id)) { + $q = mysqli_query($conn,"UPDATE `exhibitions` SET title = '".addslashes($data->title)."', content = '".addslashes($data->content)."', + tags = '".$data->tags."', date_from = '".$data->date_from."', date_to = '".$data->date_to."', + image = '".$data->image."', exhibitions = '".$data->exhibitions."', gallery = '".$data->gallery."', + videos = '".$data->videos."' WHERE id = ".$data->id.""); + } else { + $q = mysqli_query($conn,"INSERT INTO `exhibitions` + (`id`, `title`, `content`, `tags`, `date_from`, `date_to`, `image`, `works`, `gallery`, `videos`) + VALUES (NULL, '".addslashes($data->title)."', '".addslashes($data->content)."', '".$data->tags."', + '".$data->date_from."', '".$data->date_to."', '".$data->image."', '".$data->exhibitions."', + '".$data->gallery."', '".$data->videos."')"); + } + + $qe = mysqli_query($conn,"SELECT * FROM `exhibitions` ORDER BY id DESC"); + if(mysqli_num_rows($qe) > 0) { + $content->items = array(); + while($re = mysqli_fetch_array($qe)) { + $item = null; + $item->id = $re['id']; + $item->title = $re['title']; + $item->date_from = $re['date_from']; + $item->date_to = $re['date_to']; + $item->tags = $re['tags']; + $item->image = $re['image']; + array_push($content->items, $item); + } + } + + if($q) { + http_response_code(201); + $content->status = 201; + } else { + http_response_code(403); + $content->status = 403; + } + } + +} else { + http_response_code(401); + $content->status = 401; +} +header("Access-Control-Allow-Origin: *"); +header("Content-Type: application/json; charset=UTF-8"); +header("Access-Control-Allow-Methods: POST"); +header("Access-Control-Max-Age: 3600"); + +echo json_encode($content); + +?> diff --git a/src/app/admin/admin.component.html b/src/app/admin/admin.component.html index 711c236..e5615a0 100644 --- a/src/app/admin/admin.component.html +++ b/src/app/admin/admin.component.html @@ -24,12 +24,17 @@ + + Exhibitions + + + -
+
{{sectionTitle}} -
+
-
-
+ +
+ +
+ +
+
Title
-
+
Type
+
+ Date from + +
+
+ Date to + +
Content @@ -73,7 +99,8 @@
-
+ +
Exhibitions + + + + + Selected works + + {{sw.type}} | {{sw.title}} + + +
+
Video
@@ -114,10 +157,12 @@ -
+
Title -
{{title}} | {{type}}
+
{{type}} | {{title}}
+
{{dateFrom}} | {{title}}
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) + ) + } + }