Browse Source

admin exhibitions

hotfix/class_typo
Dslak 5 years ago
parent
commit
d78fc019ee
  1. 61
      src/apis/exhibition.php
  2. 61
      src/app/admin/admin.component.html
  3. 3
      src/app/admin/admin.component.scss
  4. 180
      src/app/admin/admin.component.ts
  5. 14
      src/app/services/apis.service.ts

61
src/apis/exhibition.php

@ -0,0 +1,61 @@
<?php
@include 'conn.conn';
$GLOBALS['conn'];
$conn = @mysqli_connect($DATAhst,$DATAusr,$DATApwd,$DATAdtb)or die("CONNECTION ERROR");
$content = null;
$data = json_decode(file_get_contents("php://input"));
if(isset($data->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);
?>

61
src/app/admin/admin.component.html

@ -24,12 +24,17 @@
<button class="action" [ngClass]="{'active': activeEditor == 'works-add'}" (click)="showEditor('works-add')">Add</button>
<button class="action" [ngClass]="{'active': activeEditor == 'works-modify'}" (click)="showEditor('works-modify')">Modify</button>
<button class="action" [ngClass]="{'active': activeEditor == 'works-delete'}" (click)="showEditor('works-delete')">Delete</button>
<span class="section-title">Exhibitions</span>
<button class="action" [ngClass]="{'active': activeEditor == 'exhibitions-add'}" (click)="showEditor('exhibitions-add')">Add</button>
<button class="action" [ngClass]="{'active': activeEditor == 'exhibitions-modify'}" (click)="showEditor('exhibitions-modify')">Modify</button>
<button class="action" [ngClass]="{'active': activeEditor == 'exhibitions-delete'}" (click)="showEditor('exhibitions-delete')">Delete</button>
</div>
</div>
<div class="col p-5">
<div class="col px-5 py-4">
<div class="edit-container">
<span class="title">{{sectionTitle}}</span>
<form class="form row" (submit)="saveWork()" *ngIf="activeEditor == 'works-modify' || activeEditor == 'works-delete'">
<form class="form row" *ngIf="activeEditor == 'works-modify' || activeEditor == 'works-delete'">
<div class="col-12">
<select class="input-select">
<option value="">- Select work from list -</option>
@ -39,17 +44,38 @@
</select>
</div>
</form>
<form class="form row" (submit)="saveWork()" *ngIf="activeEditor == 'works-add' || (activeEditor == 'works-modify' && activeModify)">
<div class="col-8">
<form class="form row" *ngIf="activeEditor == 'exhibitions-modify' || activeEditor == 'exhibitions-delete'">
<div class="col-12">
<select class="input-select">
<option value="">- Select exhibition from list -</option>
<option value="{{exhibition.title}}" *ngFor="let exhibition of exhibitions" (click)="selectExhibition(exhibition.id)">
{{exhibition.date_from | date}} | {{exhibition.title}}
</option>
</select>
</div>
</form>
<form class="form row" (submit)="saveData()"
*ngIf="activeEditor == 'works-add' || (activeEditor == 'works-modify' && activeModify) ||
activeEditor == 'exhibitions-add' || (activeEditor == 'exhibitions-modify' && activeModify)">
<div [ngClass]="{'col-8': activeEditor == 'works-add' || activeEditor == 'works-modify',
'col-7': activeEditor == 'exhibitions-add' || activeEditor == 'exhibitions-modify'}">
<span class="label">Title</span>
<input type="text" class="input-text" name="title" [(ngModel)]="title">
</div>
<div class="col-4">
<div class="col-4" *ngIf="activeEditor == 'works-add' || activeEditor == 'works-modify'">
<span class="label">Type</span>
<select class="input-select" name="type" [(ngModel)]="type">
<option [value]="sec.section" *ngFor="let sec of workSections">{{sec.title}}</option>
</select>
</div>
<div class="col" *ngIf="activeEditor == 'exhibitions-add' || activeEditor == 'exhibitions-modify'">
<span class="label">Date from</span>
<input type="date" class="input-text w-100" name="dateFrom" [(ngModel)]="dateFrom">
</div>
<div class="col" *ngIf="activeEditor == 'exhibitions-add' || activeEditor == 'exhibitions-modify'">
<span class="label">Date to</span>
<input type="date" class="input-text w-100" name="dateTo" [(ngModel)]="dateTo">
</div>
<div class="col-12">
<span class="label">Content</span>
<angular-editor [placeholder]="'Enter text here...'" [config]="editorConfig" name="content" [(ngModel)]="content"></angular-editor>
@ -73,7 +99,8 @@
</div>
</div>
</div>
<div class="col-6">
<div class="col-6" *ngIf="activeEditor == 'works-add' || activeEditor == 'works-modify'">
<span class="label">Exhibitions</span>
<select class="input-select" name="exhibitions">
<option value=""></option>
@ -88,6 +115,22 @@
</span>
</div>
<div class="col-6" *ngIf="activeEditor == 'exhibitions-add' || activeEditor == 'exhibitions-modify'">
<span class="label">Works</span>
<select class="input-select" name="works">
<option value=""></option>
<option value="{{work.title}}" *ngFor="let work of works" (click)="workAdd(work.id)">
{{work.type}} | {{work.title}}
</option>
</select>
<span class="label font-12 pt-2">Selected works</span>
<span class="selected-work" *ngFor="let sw of selectedWorks" (click)="workRemove(sw.id)">
{{sw.type}} | {{sw.title}}
</span>
</div>
<div class="col-6">
<span class="label">Video</span>
<div class="w-30 d-inline-block pr-2">
@ -114,10 +157,12 @@
</form>
<form class="form row" (submit)="deleteWork(modifyId)" *ngIf="activeEditor == 'works-delete' && modifyId">
<form class="form row" (submit)="deleteData(modifyId)"
*ngIf="(activeEditor == 'works-delete' || activeEditor == 'exhibitions-delete') && modifyId">
<div class="col-12">
<span class="label">Title</span>
<div class="preview-box">{{title}} | {{type}}</div>
<div class="preview-box" *ngIf="activeEditor == 'works-delete'">{{type}} | {{title}}</div>
<div class="preview-box" *ngIf="activeEditor == 'exhibitions-delete'">{{dateFrom}} | {{title}}</div>
</div>
<div class="col-12">
<span class="label">Content</span>

3
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;

180
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

14
src/app/services/apis.service.ts

@ -59,5 +59,19 @@ export class ApisService extends BaseService {
)
}
saveExhibition(body): Observable<any> {
let urlApi = `${this.restApi}exhibition.php?act=save`
return this.http.post<any>(urlApi, JSON.stringify(body)).pipe(
catchError(this.handleError)
)
}
deleteExhibition(body): Observable<any> {
let urlApi = `${this.restApi}exhibition.php?act=delete`
return this.http.post<any>(urlApi, JSON.stringify(body)).pipe(
catchError(this.handleError)
)
}
}

Loading…
Cancel
Save