Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 KB | None | 0 0
  1. export class FilterBarComponent implements OnInit, OnDestroy {
  2. filterParam: any = filterDataObject;
  3. buttonStatus: boolean;
  4. @Output() eventClicked: EventEmitter<boolean> = new
  5. EventEmitter<boolean>();
  6.  
  7.  
  8. constructor(private sharedService: SharedDataService) {
  9. this.buttonStatus = false;
  10. }
  11. ngOnInit() {
  12.  
  13. }
  14. onClick(event: boolean): void {
  15. this.buttonStatus = true; // this.buttonStatus = !event :to toggle the
  16. status of the button between true and false
  17. this.eventClicked.emit(this.buttonStatus);
  18. this.sharedService.updateTableView(this.buttonStatus);
  19. this.removeEmptyValueFromFilterParam(this.filterParam);
  20. this.sharedService.updatedDataSelection
  21. (this.removeEmptyValueFromFilterParam(this.filterParam));
  22. }
  23.  
  24. // To remove the empty params from the request
  25. removeEmptyValueFromFilterParam(obj: any) {
  26. this.filterParam = {};
  27. Object.keys(obj).forEach((prop) => {
  28. if (obj[prop] !== '') { this.filterParam[prop] = obj[prop]; }
  29. });
  30. return this.filterParam;
  31. }
  32.  
  33. ngOnDestroy() {
  34. this.buttonStatus = !this.buttonStatus;
  35.  
  36. }
  37.  
  38. }
  39.  
  40. export class LogsTableComponent implements OnInit, AfterViewInit,
  41. OnDestroy {
  42. @Input() clicked: boolean;
  43. private subscription: Subscription;
  44. filtredLogs: Ilogs[];
  45. filterParamCriteria: any;
  46. subscribed: boolean = false;
  47. constructor(private logsService: HttpClientTestService, private
  48. sharedService: SharedDataService) {
  49. }
  50.  
  51.  
  52. ngOnInit() {
  53. this.getLogs();
  54. }
  55.  
  56. ngAfterViewInit() {
  57. }
  58.  
  59. getLogs() {
  60. if (this.isEmpty(this.filterParamCriteria) > 0) {
  61. this.getLogsWithQueryFilter();
  62. } else {
  63. this.getLogsWithoutParam();
  64. }
  65.  
  66. }
  67.  
  68. getLogsWithoutParam() {
  69. this.filtredLogs = [];
  70. this.logsService.getLogsWithoutParam().subscribe((res) => {
  71. this.filtredLogs = res;
  72. console.log(res);
  73. },
  74. err => {
  75. return console.error(err);
  76. }
  77. );
  78.  
  79. }
  80.  
  81. getLogsWithQueryFilter() {
  82. this.filtredLogs = [];
  83.  
  84. this.logsService.getLogsWithQueryParam
  85. (this.filterParamCriteria).subscribe((res) => {
  86. this.filtredLogs = res;
  87. console.log(res);
  88. },
  89. err => {
  90. return console.error(err);
  91. }
  92. );
  93.  
  94. }
  95.  
  96. getFilterParamCriteria() {
  97. this.subscription = this.sharedService.data$.subscribe(filterParam => {
  98. if (filterParam) {
  99. console.log('get filter param');
  100. this.filterParamCriteria = filterParam;
  101. if (this.isEmpty(this.filterParamCriteria) > 0) {
  102. console.log(this.isEmpty(this.filterParamCriteria));
  103. this.subscribed = true;
  104. console.log(this.subscribed);
  105. console.log(this.filterParamCriteria);
  106. }
  107.  
  108. } else {
  109. this.filterParamCriteria = {};
  110. this.subscribed = false;
  111. }
  112. return this.filterParamCriteria;
  113. });
  114. }
  115.  
  116. isEmpty(obj) {
  117. return Object.keys(obj).length;
  118. }
  119.  
  120.  
  121. getShowTableView() {
  122. this.subscription =
  123. this.sharedService.data$_showTable.subscribe(showTable =>
  124. {
  125. if (showTable) {
  126. console.log('get show table ');
  127. this.clicked = showTable;
  128. console.log(this.clicked);
  129. } else {
  130. this.clicked = !showTable;
  131.  
  132. }
  133. });
  134. }
  135.  
  136. ngOnDestroy() {
  137. this.subscription.unsubscribe();
  138.  
  139. }
  140. }
  141.  
  142. const FILITER_DATA = {};
  143. const SHOWTABL_FLAG = false;
  144. @Injectable({
  145. providedIn: 'root'
  146. })
  147. export class SharedDataService {
  148.  
  149. private filterStore = new BehaviorSubject(FILITER_DATA);
  150.  
  151. private showTable = new BehaviorSubject(SHOWTABL_FLAG);;
  152.  
  153. data$: Observable<any> = this.filterStore.asObservable();
  154.  
  155. data$_showTable: Observable<any> = this.showTable.asObservable();
  156. constructor() { }
  157.  
  158. updatedDataSelection(data: any) {
  159. this.filterStore.next(data);
  160. }
  161.  
  162. updateTableView(data: any) {
  163. this.showTable.next(data);
  164. }
  165. }
  166.  
  167. ERROR TypeError: "can't convert undefined to object"
  168. isEmpty logs-table.component.ts:85
  169. getLogs logs-table.component.ts:30
  170. ngOnInit logs-table.component.ts:23
  171.  
  172. filterParamCriteria: any = {};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement