Skip to content

Commit

Permalink
Merge pull request #328 from irceline/BELAIR-167
Browse files Browse the repository at this point in the history
BELAIR-168
  • Loading branch information
bieblebrox authored May 31, 2024
2 parents e6c433e + c605ef4 commit 18edcec
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/app/v2/screens/main-screen/main-screen.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ <h5>{{ 'v2.screens.main-screen.view-details' | translate }}</h5>

</div>

<!-- THIS AREADY COMMENT OUT BEFORE -->
<!-- THIS ALREADY COMMENT OUT BEFORE -->
<!-- <app-horizontal-cards-slider [data]="slidesData"></app-horizontal-cards-slider> -->
</ng-container>
</div>
Expand Down
57 changes: 44 additions & 13 deletions src/app/v2/screens/main-screen/main-screen.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class MainScreenComponent implements OnInit {
locations: UserLocation[] = [];

// belAqi data
belAqiForCurrentLocation: BelAqiIndexResult[] = [];
belAqiForCurrentLocation!: BelAqiIndexResult[];
// @ts-ignore
currentActiveIndex: BelAqiIndexResult;

Expand Down Expand Up @@ -104,7 +104,7 @@ export class MainScreenComponent implements OnInit {
];

// keep track of loading status
detailDataLoadig = false;
detailDataLoading = false;

detailData: DataPoint[] = [];
// @ts-ignore
Expand Down Expand Up @@ -135,7 +135,7 @@ export class MainScreenComponent implements OnInit {
public router: Router,
public alertCtrl: AlertController,
public navCtrl: NavController,
private generalNotificationSrvc: GeneralNotificationService,
private generalNotificationSrvc: GeneralNotificationService
// private splashScreen: SplashScreen
) {
this.registerBackButtonEvent();
Expand Down Expand Up @@ -196,6 +196,7 @@ export class MainScreenComponent implements OnInit {
}, error => {
console.error('Error occured while fetching the bel aqi indicies');
if (loadFinishedCb) { loadFinishedCb(); }
this.showErrorAlert()
});
} else {
// @ts-ignore
Expand All @@ -206,10 +207,16 @@ export class MainScreenComponent implements OnInit {
}

private async updateDetailData(loadFinishedCb?: () => any) {
this.detailDataLoadig = true;
this.detailDataLoading = true;

// let currentBelAqi = this.belAqiForCurrentLocation.find(e => e.valueDate === ValueDate.CURRENT);
let currentBelAqi = this.belAqiForCurrentLocation.find(e => e.valueDate === this.currentActiveIndex?.valueDate);
let currentActiveIndex = ValueDate.CURRENT;
if (this.currentActiveIndex) {
if (typeof this.currentActiveIndex.valueDate != 'undefined') {
currentActiveIndex = this.currentActiveIndex.valueDate;
}
}

let currentBelAqi = this.belAqiForCurrentLocation.find(e => e.valueDate === currentActiveIndex);
// if current is not available
if (currentBelAqi === undefined && this.belAqiForCurrentLocation.length > 0) {
currentBelAqi = this.belAqiForCurrentLocation[0];
Expand Down Expand Up @@ -243,15 +250,16 @@ export class MainScreenComponent implements OnInit {
color: this.belAqiService.getLightColorForIndex(value.index),
label: this.belAqiService.getLabelForIndex(value.index)
};
})
});

this.detailedPhenomenona.forEach(dph => {
forkJoin([
this.modelledValueService.getCurrentValue(this.userSettingsService.selectedUserLocation, dph.phenomenon),
this.modelledValueService.getValueByDate(this.userSettingsService.selectedUserLocation, dph.phenomenon, currentActiveIndex),
this.annulMeanValueService.getLastValue(this.userSettingsService.selectedUserLocation, dph.phenomenon)
]).subscribe(
res => {
if (res[0] != null) {
const idx = this.detailData.findIndex(e => e.substance === dph);
const entry = {
location: this.userSettingsService.selectedUserLocation,
currentValue: Math.round(res[0].value),
Expand All @@ -265,7 +273,6 @@ export class MainScreenComponent implements OnInit {
evaluation: this.belAqiService.getLabelForIndex(res[0].index),
color: this.belAqiService.getLightColorForIndex(res[0].index)
};
const idx = this.detailData.findIndex(e => e.substance === dph);
if (idx > -1) {
// @ts-ignore
this.detailData[idx] = entry;
Expand All @@ -274,7 +281,7 @@ export class MainScreenComponent implements OnInit {
this.detailData.push(entry);
}
}
this.detailDataLoadig = false;
this.detailDataLoading = false;
if (loadFinishedCb) { loadFinishedCb(); }
},
error => {
Expand All @@ -295,19 +302,21 @@ export class MainScreenComponent implements OnInit {
if (this.platform.is('ios')) {
this.contentHeight =
this.platform.height() - this.drawerOptions.handleHeight - 106;
this.iosPadding = 50;
} else {
this.contentHeight =
this.platform.height() - this.drawerOptions.handleHeight - 56;
}
this.screenHeight = this.platform.height();

if (this.platform.is('ios')) this.iosPadding = 50;

this.generalNotificationSrvc.$active.pipe(first()).subscribe(async (res) => {
if (!res) {
const asked = await this.generalNotificationSrvc.getAskedEnableNotif()
if (!asked || asked === '') setTimeout(() => this.showPushNotifAlert(), 3000)
}
})

this.belAqiService.$activeIndex.subscribe(newIndex => {
if (newIndex) {
this.updateDetailData();
Expand Down Expand Up @@ -339,8 +348,9 @@ export class MainScreenComponent implements OnInit {
}

openDetails(selectedDataPoint: DataPoint) {
this.activeSlideIndex = ValueDate.CURRENT;
this.detailActive = true;
if (this.detailDataLoading) {
this.activeSlideIndex = ValueDate.CURRENT;
}
this.detailPoint = selectedDataPoint;
this.modelledValueService.getValueTimeline(
this.userSettingsService.selectedUserLocation,
Expand All @@ -360,6 +370,9 @@ export class MainScreenComponent implements OnInit {
valueDate: e.valueDate,
location: this.userSettingsService.selectedUserLocation,
}));

this.detailActive = true;
this.detailSlide?.slideTo(this.activeSlideIndex);
});
}

Expand Down Expand Up @@ -418,4 +431,22 @@ export class MainScreenComponent implements OnInit {
});
await alert.present();
}

async showErrorAlert() {
const alert = await this.alertCtrl.create({
header: this.translateService.instant('error-modal.title'),
message: this.translateService.instant('error-modal.no-network-connection'),
buttons: [
{
text: this.translateService.instant('error-modal.back-to-app'),
role: 'confirm',
handler: () => {
this.updateDetailData()
},
},
],
});

await alert.present();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export class ModelledValueService extends ValueProvider {
if (typeof value != 'undefined') {
observer.next({
value,
index: this.categorize(value, phenomenon),
index: this.categorize_pf(value, phenomenon),
date: moment(timeparam),
valueDate: valueDate
});
Expand Down

0 comments on commit 18edcec

Please sign in to comment.