import { Component } from '@angular/core'; import { navItems } from '../../_nav'; import { environment } from '../../../environments/environment'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable } from 'rxjs'; import { Router } from '@angular/router'; import { NewCategoryModalComponent } from '../new-category-modal/new-category-modal.component'; import { BsModalService, BsModalRef } from 'ngx-bootstrap'; import { EditCategoryModalComponent } from '../../views/categoryModals/edit-category-modal/edit-category-modal.component'; import { HomeSlidersComponent } from '../../views/categoryModals/home-sliders/home-sliders.component'; @Component({ selector: 'app-dashboard', templateUrl: './default-layout.component.html' }) export class DefaultLayoutComponent { public sidebarMinimized = false; public navItems = navItems; bsModalRef: BsModalRef; modalRef2: BsModalRef; constructor(private httpClient: HttpClient, private router: Router, private modalService: BsModalService) { } toggleMinimize(e) { this.sidebarMinimized = e; } // Generate a temporary hyperlink to download a file with text data with given file name` generateDownloadLink(filename, text) { const element = document.createElement('a'); element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); element.setAttribute('download', filename); element.style.display = 'none'; document.body.appendChild(element); element.click(); document.body.removeChild(element); } // Call api to get log text and download a log file. downloadLogFile() { this.httpClient.get(`${environment.apiUrl}/api/v1/logger`, { responseType: 'text' } ).subscribe((text) => { this.generateDownloadLink('log.txt', text); }); } newCategory() { this.modalRef2 = this.modalService.show(NewCategoryModalComponent, { backdrop: 'static', keyboard: false, animated: true, ignoreBackdropClick: true, initialState: { title: 'New Category', config: "{ backdrop: 'static' }", } }); } editCategory() { this.bsModalRef = this.modalService.show(EditCategoryModalComponent, { backdrop: 'static', keyboard: false, animated: true, ignoreBackdropClick: true, initialState: { title: 'Edit Category', config: "{ backdrop: 'static' }", } }); } homeSlider() { this.bsModalRef = this.modalService.show(HomeSlidersComponent, { backdrop: 'static', keyboard: false, animated: true, ignoreBackdropClick: true, initialState: { title: 'New Home Slider', config: "{ backdrop: 'static' }", } }); } manageConfig() { this.router.navigate(['admin/manageConfiguration']) } }