You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.5 KiB

import { Component, OnInit } from '@angular/core'
5 years ago
import { ApisService } from '../services/apis.service'
import { AuthService } from '../services/auth.service'
@Component({
selector: 'app-admin',
templateUrl: './admin.component.html',
styleUrls: ['./admin.component.scss']
})
export class AdminComponent implements OnInit {
public authCheck: boolean = false
public userName: string = ''
public password: string = ''
5 years ago
public activeEditor: string = ''
public exhibitions: any = []
5 years ago
public selectedExhibitions: any = []
public selectedVideos: any = []
5 years ago
// ngModels
public videoType: string = ''
public videoURL: string = ''
5 years ago
constructor(
private authService: AuthService,
private apisService: ApisService
) { }
5 years ago
ngOnInit(): void {
const body = { token: window.sessionStorage.getItem('authToken') }
this.authService.authCheck(body).toPromise().then((response) => {
this.authCheck = response.status == 200
5 years ago
this.apisService.getPortfolio('exhibitions').toPromise().then((response) => {
this.exhibitions = response.items
},(error) => {
console.error('getPortfolio ERROR', error)
}).catch((e) => {
console.error('getPortfolio CATCH', e)
})
},(error) => {
console.error('Auth ERROR', error)
}).catch((e) => {
console.error('Auth CATCH', e)
})
}
login(): void {
5 years ago
const body = { usr: this.userName, pwd: this.password }
this.authService.login(body).toPromise().then((response) => {
this.authCheck = response.status == 200
if(this.authCheck) {
window.sessionStorage.setItem('authToken', response.authToken)
}
},(error) => {
console.error('Auth ERROR', error)
}).catch((e) => {
console.error('Auth CATCH', e)
})
5 years ago
}
showEditor(section): void {
this.activeEditor = section
}
5 years ago
exhibitionAdd(id): void {
5 years ago
this.selectedExhibitions.push(
this.exhibitions.filter(item => item.id == id)[0]
)
this.exhibitions = this.exhibitions.filter(item => item.id != id)
5 years ago
}
5 years ago
exhibitionRemove(id): void {
this.exhibitions.push(
this.selectedExhibitions.filter(item => item.id == id)[0]
)
5 years ago
this.selectedExhibitions = this.selectedExhibitions.filter(item => item.id != id)
}
5 years ago
videoAdd(): void {
this.selectedVideos.push({
type: this.videoType,
url: this.videoURL
})
this.videoURL = ''
}
5 years ago
videoRemove(url): void {
this.selectedVideos = this.selectedVideos.filter(item => item.url != url)
}
}