Skip to content

Commit

Permalink
Merge branch 'mobile-development' into USH-1513
Browse files Browse the repository at this point in the history
  • Loading branch information
Angamanga authored Dec 18, 2024
2 parents cb81dc3 + 41079ae commit 522e4c9
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { Component, EventEmitter, Input, OnInit, Output, forwardRef } from '@angular/core';
import { FilterControl, FilterControlOption } from '@models';
import { CategoriesService, CategoryInterface, SavedsearchesService } from '@mzima-client/sdk';
import {
apiHelpers,
CategoriesService,
CategoryInterface,
SavedsearchesService,
} from '@mzima-client/sdk';
import { AlertService, NetworkService, SessionService, ToastService } from '@services';
import { searchFormHelper, getDeploymentAvatarPlaceholder } from '@helpers';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
Expand Down Expand Up @@ -198,31 +203,33 @@ export class FilterComponent implements ControlValueAccessor, OnInit {
}

private getCategories(): void {
this.categoriesService.get().subscribe({
next: (response) => {
const mainCategories = response?.results.filter((c: CategoryInterface) => !c.parent_id);
this.options = mainCategories?.map((category: CategoryInterface) => ({
checked: this.value.has(category.id),
value: category.id,
label: String(category.tag),
color: getDeploymentAvatarPlaceholder(String(category.tag)),
options: category.children.length
? category.children.map((cat: CategoryInterface) => ({
value: cat.id,
label: cat.tag,
checked: this.value.has(cat.id),
}))
: null,
isDropDownOpen: category.children.length ? false : null,
}));
this.isOptionsLoading = false;
},
error: (err) => {
if (err.message.match(/Http failure response for/)) {
setTimeout(() => this.getCategories(), 5000);
}
},
});
this.categoriesService
.getCategories({ only: apiHelpers.ONLY.TAG_ID_PARENTID_CHILDREN })
.subscribe({
next: (response) => {
const mainCategories = response?.results.filter((c: CategoryInterface) => !c.parent_id);
this.options = mainCategories?.map((category: CategoryInterface) => ({
checked: this.value.has(category.id),
value: category.id,
label: String(category.tag),
color: getDeploymentAvatarPlaceholder(String(category.tag)),
options: category.children.length
? category.children.map((cat: CategoryInterface) => ({
value: cat.id,
label: cat.tag,
checked: this.value.has(cat.id),
}))
: null,
isDropDownOpen: category.children.length ? false : null,
}));
this.isOptionsLoading = false;
},
error: (err) => {
if (err.message.match(/Http failure response for/)) {
setTimeout(() => this.getCategories(), 5000);
}
},
});
}

public getObjectKeysCount(obj: any): number {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const enum EventType {
RefreshSurveysCounters = 'REFRESH_SURVEYS_COUNTERS',
StopExportPolling = 'STOP_EXPORT_POLLING',
ExportDone = 'EXPORT_DONE',
StatusChange = 'STATUS_CHANGE',
}

export interface BusEvent<T = any> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ export class PostHeadComponent extends BaseComponent implements OnInit {
underReview() {
this.postsService.updateStatus(this.post.id, PostStatus.Draft).subscribe((res) => {
this.post = res.result;
this.statusChanged.emit();
this.eventBusService.next({
type: EventType.StatusChange,
payload: this.post,
});
});
}

Expand All @@ -81,7 +84,10 @@ export class PostHeadComponent extends BaseComponent implements OnInit {
if (postHelpers.isAllRequiredCompleted(post)) {
this.postsService.updateStatus(this.post.id, PostStatus.Published).subscribe((res) => {
this.post = res.result;
this.statusChanged.emit();
this.eventBusService.next({
type: EventType.StatusChange,
payload: this.post,
});
});
} else {
this.showMessage(this.translate.instant('notify.post.unfinished_post_task'), 'error', 5000);
Expand All @@ -100,7 +106,10 @@ export class PostHeadComponent extends BaseComponent implements OnInit {
archive() {
this.postsService.updateStatus(this.post.id, PostStatus.Archived).subscribe((res) => {
this.post = res.result;
this.statusChanged.emit();
this.eventBusService.next({
type: EventType.StatusChange,
payload: this.post,
});
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Component, Input, OnInit } from '@angular/core';
import { PostPropertiesInterface, PostResult } from '@mzima-client/sdk';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { EventBusService, EventType } from '@services';

@UntilDestroy()
@Component({
selector: 'app-post-metadata',
templateUrl: './post-metadata.component.html',
Expand All @@ -10,8 +13,18 @@ export class PostMetadataComponent implements OnInit {
@Input() post: PostResult | PostPropertiesInterface;
author: string;

constructor(private eventBusService: EventBusService) {}

ngOnInit(): void {
this.getUsername();
this.eventBusService
.on(EventType.StatusChange)
.pipe(untilDestroyed(this))
.subscribe({
next: (post) => {
if (post.id === this.post.id) this.post = post;
},
});
}

private getUsername(): void {
Expand Down

0 comments on commit 522e4c9

Please sign in to comment.