Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export class FilterBarComponent implements OnInit, OnDestroy {
- filterParam: any = filterDataObject;
- buttonStatus: boolean;
- @Output() eventClicked: EventEmitter<boolean> = new
- EventEmitter<boolean>();
- constructor(private sharedService: SharedDataService) {
- this.buttonStatus = false;
- }
- ngOnInit() {
- }
- onClick(event: boolean): void {
- this.buttonStatus = true; // this.buttonStatus = !event :to toggle the
- status of the button between true and false
- this.eventClicked.emit(this.buttonStatus);
- this.sharedService.updateTableView(this.buttonStatus);
- this.removeEmptyValueFromFilterParam(this.filterParam);
- this.sharedService.updatedDataSelection
- (this.removeEmptyValueFromFilterParam(this.filterParam));
- }
- // To remove the empty params from the request
- removeEmptyValueFromFilterParam(obj: any) {
- this.filterParam = {};
- Object.keys(obj).forEach((prop) => {
- if (obj[prop] !== '') { this.filterParam[prop] = obj[prop]; }
- });
- return this.filterParam;
- }
- ngOnDestroy() {
- this.buttonStatus = !this.buttonStatus;
- }
- }
- export class LogsTableComponent implements OnInit, AfterViewInit,
- OnDestroy {
- @Input() clicked: boolean;
- private subscription: Subscription;
- filtredLogs: Ilogs[];
- filterParamCriteria: any;
- subscribed: boolean = false;
- constructor(private logsService: HttpClientTestService, private
- sharedService: SharedDataService) {
- }
- ngOnInit() {
- this.getLogs();
- }
- ngAfterViewInit() {
- }
- getLogs() {
- if (this.isEmpty(this.filterParamCriteria) > 0) {
- this.getLogsWithQueryFilter();
- } else {
- this.getLogsWithoutParam();
- }
- }
- getLogsWithoutParam() {
- this.filtredLogs = [];
- this.logsService.getLogsWithoutParam().subscribe((res) => {
- this.filtredLogs = res;
- console.log(res);
- },
- err => {
- return console.error(err);
- }
- );
- }
- getLogsWithQueryFilter() {
- this.filtredLogs = [];
- this.logsService.getLogsWithQueryParam
- (this.filterParamCriteria).subscribe((res) => {
- this.filtredLogs = res;
- console.log(res);
- },
- err => {
- return console.error(err);
- }
- );
- }
- getFilterParamCriteria() {
- this.subscription = this.sharedService.data$.subscribe(filterParam => {
- if (filterParam) {
- console.log('get filter param');
- this.filterParamCriteria = filterParam;
- if (this.isEmpty(this.filterParamCriteria) > 0) {
- console.log(this.isEmpty(this.filterParamCriteria));
- this.subscribed = true;
- console.log(this.subscribed);
- console.log(this.filterParamCriteria);
- }
- } else {
- this.filterParamCriteria = {};
- this.subscribed = false;
- }
- return this.filterParamCriteria;
- });
- }
- isEmpty(obj) {
- return Object.keys(obj).length;
- }
- getShowTableView() {
- this.subscription =
- this.sharedService.data$_showTable.subscribe(showTable =>
- {
- if (showTable) {
- console.log('get show table ');
- this.clicked = showTable;
- console.log(this.clicked);
- } else {
- this.clicked = !showTable;
- }
- });
- }
- ngOnDestroy() {
- this.subscription.unsubscribe();
- }
- }
- const FILITER_DATA = {};
- const SHOWTABL_FLAG = false;
- @Injectable({
- providedIn: 'root'
- })
- export class SharedDataService {
- private filterStore = new BehaviorSubject(FILITER_DATA);
- private showTable = new BehaviorSubject(SHOWTABL_FLAG);;
- data$: Observable<any> = this.filterStore.asObservable();
- data$_showTable: Observable<any> = this.showTable.asObservable();
- constructor() { }
- updatedDataSelection(data: any) {
- this.filterStore.next(data);
- }
- updateTableView(data: any) {
- this.showTable.next(data);
- }
- }
- ERROR TypeError: "can't convert undefined to object"
- isEmpty logs-table.component.ts:85
- getLogs logs-table.component.ts:30
- ngOnInit logs-table.component.ts:23
- filterParamCriteria: any = {};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement