import { Component, OnInit, Input, OnChanges, Output, EventEmitter } from '@angular/core'; import { FileManagementService } from './file-management.service'; import { NgbDropdownConfig } from '@ng-bootstrap/ng-bootstrap'; @Component({ selector: 'lib-file-management', templateUrl: './file-management.component.html', styleUrls: ['./file-management.component.css'] }) export class FileManagementComponent implements OnInit, OnChanges { @Input() fileSummaryDataSource; @Input() uploadFileDataSource; @Input() discussionForum; @Input() breadCrumbs; @Input() hierarchyList = []; @Input() backgroundContent = ''; @Input() repositoryUrl = ''; @Input() presentView; @Output() addFile = new EventEmitter(); @Output() editFile = new EventEmitter(); @Output() deleteFile = new EventEmitter(); @Output() filterData = new EventEmitter(); _opened = true; sidebar3Opened = true; fileSummaryData: any; selectedFile: any; constructor(private service: FileManagementService, private config: NgbDropdownConfig) { config.autoClose = 'outside'; } ngOnInit() { const c = document.getElementById('sidebar3'); c.firstElementChild.classList.remove('ml-0'); c.firstElementChild.classList.add('ml-25'); } ngOnChanges(changes) { if (changes && changes.hierarchyList && changes.hierarchyList.currentValue !== changes.hierarchyList.previousValue) { this.hierarchyList = changes.hierarchyList.currentValue; } if (changes && changes.fileSummaryDataSource && changes.fileSummaryDataSource.currentValue !== changes.fileSummaryDataSource.previousValue) { this.fileSummaryDataSource = changes.fileSummaryDataSource.currentValue; if (this.fileSummaryDataSource.filter && this.fileSummaryDataSource.filters.length > 0) { this.fileSummaryDataSource.filters.forEach(ele => { this.service.getAPIs(ele.apiLink).subscribe((res: any) => { ele.values = res; this.fileSummaryData = Object.assign({}, this.fileSummaryDataSource); }, error => { console.log(error); }); }); } else { this.fileSummaryData = Object.assign({}, this.fileSummaryDataSource); } } if (changes && changes.breadCrumbs && changes.breadCrumbs.currentValue !== changes.breadCrumbs.previousValue) { this.breadCrumbs = changes.breadCrumbs.currentValue; } if (changes && changes.uploadFileDataSource && changes.uploadFileDataSource.currentValue !== changes.uploadFileDataSource.previousValue) { this.uploadFileDataSource = changes.uploadFileDataSource.currentValue; } if (changes && changes.presentView) { if (changes.presentView.firstChange) { this.changeView('home'); } else { this.changeView(changes.presentView.currentValue); } } } _toggleSidebar() { this._opened = !this._opened; if (this.sidebar3Opened) { const c = document.getElementById('sidebar3'); if (!(this._opened)) { c.firstElementChild.classList.remove('ml-25'); c.firstElementChild.classList.add('ml-0'); } else { c.firstElementChild.classList.remove('ml-0'); c.firstElementChild.classList.add('ml-25'); } } } changeView(e) { this.presentView = e; const c = document.getElementById('sidebar3'); if (this.presentView === 'uploadFile') { c.firstElementChild.classList.remove('ml-25'); c.firstElementChild.classList.add('ml-0'); } else { c.firstElementChild.classList.remove('ml-0'); c.firstElementChild.classList.add('ml-25'); } } setFile(e) { this.presentView = 'uploadFile'; this.selectedFile = e; const c = document.getElementById('sidebar3'); c.firstElementChild.classList.remove('ml-25'); c.firstElementChild.classList.add('ml-0'); } openFile(file) { window.open(this.repositoryUrl + file, '_blank'); } submitRequest(e, action) { if (action === 'add') { this.addFile.emit(e); } else if (action === 'edit') { this.editFile.emit(e); } else if (action === 'delete') { this.deleteFile.emit(e); } } selectionChanged(event, item, id) { if (item) { if (event) { if (item.multiSelect) { item.selectedFilters.push(id); } else if (!item.multiSelect) { item.selectedFilters = [id]; } } else if (!event) { item.selectedFilters.splice(item.selectedFilters.findIndex(x => x === id), 1); } const obj = {}; // obj[item.name] = item.selectedFilters; this.hierarchyList.forEach(ele => { if (ele && ele.selectedFilters.length > 0) { obj[ele.name] = ele.selectedFilters; } }); this.filterData.emit(obj); } } isChecked(id, selectedFilters) { if (selectedFilters.length > 0 && selectedFilters.findIndex(x => x === id) >= 0) { return true; } else { return false; } } }