Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dianabarsan committed Nov 22, 2023
1 parent 725a24c commit 737cd58
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 26 deletions.
24 changes: 12 additions & 12 deletions api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 30 additions & 7 deletions webapp/src/ts/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { AnalyticsActions } from '@mm-actions/analytics';
import { TrainingCardsService } from '@mm-services/training-cards.service';
import { OLD_REPORTS_FILTER_PERMISSION } from '@mm-modules/reports/reports-filters.component';
import { OLD_ACTION_BAR_PERMISSION } from '@mm-components/actionbar/actionbar.component';
import {show} from "jsverify";

const SYNC_STATUS = {
inProgress: {
Expand Down Expand Up @@ -93,6 +94,7 @@ export class AppComponent implements OnInit, AfterViewInit {
unreadCount = {};
useOldActionBar = false;
initialisationComplete = false;
trainingCardFormId = false;

constructor (
private dbSyncService:DBSyncService,
Expand Down Expand Up @@ -428,30 +430,51 @@ export class AppComponent implements OnInit, AfterViewInit {
}

private subscribeToStore() {
combineLatest(
combineLatest([
this.store.select(Selectors.getReplicationStatus),
this.store.select(Selectors.getAndroidAppVersion),
this.store.select(Selectors.getCurrentTab),
this.store.select(Selectors.getPrivacyPolicyAccepted),
this.store.select(Selectors.getShowPrivacyPolicy),
this.store.select(Selectors.getSelectMode),
).subscribe(([
]).subscribe(([
replicationStatus,
androidAppVersion,
currentTab,
privacyPolicyAccepted,
showPrivacyPolicy,
selectMode,
]) => {
this.replicationStatus = replicationStatus;
this.androidAppVersion = androidAppVersion;
this.currentTab = currentTab;

this.selectMode = selectMode;
});

combineLatest([
this.store.select(Selectors.getPrivacyPolicyAccepted),
this.store.select(Selectors.getShowPrivacyPolicy),
this.store.select(Selectors.getTrainingCardFormId)
]).subscribe(([
privacyPolicyAccepted,
showPrivacyPolicy,
trainingCardFormId,
]) => {
this.showPrivacyPolicy = showPrivacyPolicy;
this.privacyPolicyAccepted = privacyPolicyAccepted;
this.selectMode = selectMode;
this.trainingCardFormId = trainingCardFormId;
this.displayTrainingCards();
});
}

private displayTrainingCards() {
if (this.showPrivacyPolicy && !this.privacyPolicyAccepted) {
return;
}
if (!this.trainingCardFormId) {
return;
}

this.trainingCardsService.displayTrainingCards();
}

private async subscribeToSideFilterStore() {
const isDisabled = !this.sessionService.isAdmin() && await this.authService.has(OLD_REPORTS_FILTER_PERMISSION);

Expand Down
15 changes: 8 additions & 7 deletions webapp/src/ts/services/training-cards.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,27 @@ export class TrainingCardsService {
return;
}

const routeSnapshot = this.routeSnapshotService.get();
if (routeSnapshot?.data?.hideTraining) {
return;
}

try {
const firstChronologicalTrainingCard = await this.getFirstChronologicalForm(xForms);
if (!firstChronologicalTrainingCard) {
return;
}

this.globalActions.setTrainingCardFormId(firstChronologicalTrainingCard.code);
this.modalService.show(TrainingCardsComponent);

} catch (error) {
console.error('Training Cards :: Error showing modal.', error);
return;
}
}

displayTrainingCards() {
const routeSnapshot = this.routeSnapshotService.get();
if (routeSnapshot?.data?.hideTraining) {
return;
}
this.modalService.show(TrainingCardsComponent);
}

private async getFirstChronologicalForm(xForms) {
const userCtx = this.sessionService.userCtx();
const trainingCards = this.getAvailableTrainingCards(xForms, userCtx) || [];
Expand Down

0 comments on commit 737cd58

Please sign in to comment.