import { Component } from '@angular/core'; import { navItems } from '../../_nav'; import { environment } from '../../../environments/environment'; import { HttpClient } from '@angular/common/http'; 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'; import { PushNotificationModalComponent } from '../../views/categoryModals/push-notification-modal/push-notification-modal.component'; import { UploadVideoComponent } from '../../views/categoryModals/upload-video/upload-video.component'; import { CreateUserComponent } from '../../views/categoryModals/create-user/create-user.component'; import { NewSubCategoryComponent } from '../../views/categoryModals/new-subcategory-modal/new-subcategory-modal.component'; import { CreateLocationComponent } from '../../views/categoryModals/location-code/create-location.component'; import { CreateTaxesComponent } from '../../views/categoryModals/create-taxes/create-taxes.component'; import { CreateAccountComponent } from '../../views/categoryModals/create-account/create-account.component'; import { SearchKeywordsComponent } from '../../views/categoryModals/search-keywords/search-keywords.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', popupType: 'Edit', caption: 'Category Name', 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' }", } }); } fallBackImage(){ this.bsModalRef=this.modalService.show(EditCategoryModalComponent,{ backdrop: 'static', keyboard: false, animated: true, ignoreBackdropClick: true, initialState: { title: 'Fallback Images', popupType: 'Fallback_Images', caption: 'Fallback Image Category', config: "{ backdrop: 'static' }", } }); } pushNotification(){ this.bsModalRef=this.modalService.show(PushNotificationModalComponent,{ backdrop: 'static', keyboard: false, animated: true, ignoreBackdropClick: true, initialState: { caption: 'Push Notification', config: "{ backdrop: 'static' }", } }); } uploadVideo(){ this.bsModalRef=this.modalService.show(UploadVideoComponent,{ backdrop: 'static', keyboard: false, animated: true, ignoreBackdropClick: true, initialState: { title: 'Upload Video', config: "{ backdrop: 'static' }", } }); } manageConfig() { this.router.navigate(['admin/manageConfiguration']) } createUser(){ this.bsModalRef = this.modalService.show(CreateUserComponent, { backdrop: 'static', keyboard: false, animated: true, ignoreBackdropClick: true, initialState: { title: 'Create User', config: "{ backdrop: 'static' }", } }); } newSubCategory() { this.modalRef2 = this.modalService.show(NewSubCategoryComponent, { backdrop: 'static', keyboard: false, animated: true, ignoreBackdropClick: true, initialState: { title: 'New SubCategory', config: "{ backdrop: 'static' }", } }); } locationCode(){ this.bsModalRef = this.modalService.show(CreateLocationComponent, { backdrop: 'static', keyboard: false, animated: true, ignoreBackdropClick: true, initialState: { title: 'Create Location', config: "{ backdrop: 'static' }", } }); } taxes(){ this.bsModalRef = this.modalService.show(CreateTaxesComponent, { backdrop: 'static', keyboard: false, animated: true, ignoreBackdropClick: true, initialState: { config: "{ backdrop: 'static' }", } }); } createAccount(){ this.bsModalRef = this.modalService.show(CreateAccountComponent, { backdrop: 'static', keyboard: false, animated: true, ignoreBackdropClick: true, initialState: { config: "{ backdrop: 'static' }", title: 'Create Account' } }); } keywordsDisplay(){ this.bsModalRef = this.modalService.show(SearchKeywordsComponent, { backdrop: 'static', keyboard: false, animated: true, ignoreBackdropClick: true, initialState: { config: "{ backdrop: 'static' }" } }); } }