Skip to content

Commit

Permalink
Merge pull request #265 from RADAR-base/staging-app
Browse files Browse the repository at this point in the history
Release 0.5.10.1-alpha
  • Loading branch information
mpgxvii authored Jan 25, 2019
2 parents c30922d + 52337a9 commit 044b2e0
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 78 deletions.
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<widget android-versionCode="515" id="org.phidatalab.radar_armt" version="0.5.10-alpha" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<widget android-versionCode="516" id="org.phidatalab.radar_armt" version="0.5.10.1-alpha" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>RADAR Questionnaire</name>
<description>An application that collects active data for research.</description>
<author email="[email protected]" href="http://radar-cns.org/">RADAR-CNS</author>
Expand Down
5 changes: 0 additions & 5 deletions src/app/core/containers/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Platform } from 'ionic-angular'

import { DefaultNotificationType } from '../../../assets/data/defaultConfig'
import { SplashPageComponent } from '../../pages/splash/containers/splash-page.component'
import { ConfigService } from '../services/config.service'
import { NotificationService } from '../services/notification.service'

@Component({
Expand All @@ -18,15 +17,11 @@ export class AppComponent {
private platform: Platform,
private statusBar: StatusBar,
private splashScreen: SplashScreen,
private configService: ConfigService,
private notificationService: NotificationService
) {
this.platform.ready().then(() => {
this.statusBar.hide()
this.splashScreen.hide()
this.configService.fetchConfigState(false)
this.configService.migrateToLatestVersion()

if (DefaultNotificationType === 'LOCAL')
this.notificationService.permissionCheck()
})
Expand Down
132 changes: 70 additions & 62 deletions src/app/core/services/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'rxjs/add/operator/toPromise'

import { HttpClient } from '@angular/common/http'
import { Injectable } from '@angular/core'
import { AppVersion } from '@ionic-native/app-version'

import {
ARMTDefBranchProd,
Expand All @@ -24,76 +25,83 @@ export class ConfigService {
public http: HttpClient,
public storage: StorageService,
private schedule: SchedulingService,
private notificationService: NotificationService
private notificationService: NotificationService,
private appVersion: AppVersion
) {}

fetchConfigState(force: boolean) {
return Promise.all([
this.storage.get(StorageKeys.CONFIG_VERSION),
this.storage.get(StorageKeys.SCHEDULE_VERSION)
]).then(([configVersion, scheduleVersion]) => {
return this.pullProtocol()
.then(res => {
if (res) {
const response: any = JSON.parse(res)
if (
configVersion !== response.version ||
scheduleVersion !== response.version ||
force
) {
this.storage.set(StorageKeys.HAS_CLINICAL_TASKS, false)
const protocolFormated = this.formatPulledProcotol(
response.protocols
)
const scheduledAssessments = []
const clinicalAssessments = []
for (let i = 0; i < protocolFormated.length; i++) {
const clinical =
protocolFormated[i]['protocol']['clinicalProtocol']
if (clinical) {
this.storage.set(StorageKeys.HAS_CLINICAL_TASKS, true)
clinicalAssessments.push(protocolFormated[i])
} else {
scheduledAssessments.push(protocolFormated[i])
this.storage.get(StorageKeys.SCHEDULE_VERSION),
this.storage.get(StorageKeys.APP_VERSION),
this.appVersion.getVersionNumber()
]).then(
([configVersion, scheduleVersion, storedAppVersion, appVersion]) => {
return this.pullProtocol()
.then(res => {
if (res) {
const response: any = JSON.parse(res)
if (
configVersion !== response.version ||
scheduleVersion !== response.version ||
storedAppVersion !== appVersion ||
force
) {
this.storage.set(StorageKeys.APP_VERSION, appVersion)
this.storage.set(StorageKeys.HAS_CLINICAL_TASKS, false)
const protocolFormated = this.formatPulledProcotol(
response.protocols
)
const scheduledAssessments = []
const clinicalAssessments = []
for (let i = 0; i < protocolFormated.length; i++) {
const clinical =
protocolFormated[i]['protocol']['clinicalProtocol']
if (clinical) {
this.storage.set(StorageKeys.HAS_CLINICAL_TASKS, true)
clinicalAssessments.push(protocolFormated[i])
} else {
scheduledAssessments.push(protocolFormated[i])
}
}
}
return this.storage
.set(StorageKeys.CONFIG_VERSION, response.version)
.then(() => {
return this.storage
.set(
StorageKeys.CONFIG_CLINICAL_ASSESSMENTS,
clinicalAssessments
)
.then(() => {
console.log('Pulled clinical questionnaire')
return this.pullQuestionnaires(
StorageKeys.CONFIG_CLINICAL_ASSESSMENTS
)
})
})
.then(() => {
return this.storage
.set(StorageKeys.CONFIG_ASSESSMENTS, scheduledAssessments)
.then(() => {
console.log('Pulled questionnaire')
return this.pullQuestionnaires(
StorageKeys.CONFIG_ASSESSMENTS
return this.storage
.set(StorageKeys.CONFIG_VERSION, response.version)
.then(() => {
return this.storage
.set(
StorageKeys.CONFIG_CLINICAL_ASSESSMENTS,
clinicalAssessments
)
})
})
.then(() => this.schedule.generateSchedule(true))
.then(() => this.rescheduleNotifications())
} else {
console.log(
'NO CONFIG UPDATE. Version of protocol.json has not changed.'
)
return this.schedule.generateSchedule(false)
.then(() => {
console.log('Pulled clinical questionnaire')
return this.pullQuestionnaires(
StorageKeys.CONFIG_CLINICAL_ASSESSMENTS
)
})
})
.then(() => {
return this.storage
.set(StorageKeys.CONFIG_ASSESSMENTS, scheduledAssessments)
.then(() => {
console.log('Pulled questionnaire')
return this.pullQuestionnaires(
StorageKeys.CONFIG_ASSESSMENTS
)
})
})
.then(() => this.schedule.generateSchedule(true))
.then(() => this.rescheduleNotifications())
} else {
console.log(
'NO CONFIG UPDATE. Version of protocol.json has not changed.'
)
return this.schedule.generateSchedule(false)
}
}
}
})
.catch(e => console.log(e))
})
})
.catch(e => console.log(e))
}
)
}

rescheduleNotifications() {
Expand Down
7 changes: 4 additions & 3 deletions src/app/core/services/kafka.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class KafkaService {
}
const kafkaObject = { value: value, key: answerKey }
return this.getSpecs(task, kafkaObject, type).then(specs =>
this.createPayloadAndSend(specs)
this.cacheAnswers(specs).then(() => this.createPayloadAndSend(specs))
)
})
}
Expand Down Expand Up @@ -199,6 +199,7 @@ export class KafkaService {
})
},
error => {
this.cacheAnswers(specs)
console.error(
'Could not initiate kafka connection ' + JSON.stringify(error)
)
Expand All @@ -209,10 +210,10 @@ export class KafkaService {

cacheAnswers(specs) {
const kafkaObject = specs.kafkaObject
this.storage.get(StorageKeys.CACHE_ANSWERS).then(cache => {
return this.storage.get(StorageKeys.CACHE_ANSWERS).then(cache => {
console.log('KAFKA-SERVICE: Caching answers.')
cache[kafkaObject.value.time] = specs
this.storage.set(StorageKeys.CACHE_ANSWERS, cache)
return this.storage.set(StorageKeys.CACHE_ANSWERS, cache)
})
}

Expand Down
16 changes: 11 additions & 5 deletions src/app/core/services/storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'rxjs/add/operator/map'
import 'rxjs/add/operator/catch'

import { Injectable } from '@angular/core'
import { AppVersion } from '@ionic-native/app-version'
import { Storage } from '@ionic/storage'
import { throwError as observableThrowError } from 'rxjs'

Expand All @@ -19,7 +20,7 @@ import { Task } from '../../shared/models/task'
export class StorageService {
global: any = {}

constructor(private storage: Storage) {
constructor(private storage: Storage, private appVersion: AppVersion) {
const setStoragePromise = this.prepareStorage()
Promise.resolve(setStoragePromise)
}
Expand All @@ -33,9 +34,8 @@ export class StorageService {
createdDate,
createdDateMidnight
) {
const allKeys = this.getAllKeys()
return allKeys
.then(keys => {
return Promise.all([this.getAllKeys(), this.getAppVersion()])
.then(([keys, appV]) => {
// TODO: Find out why this is hard-coded?
if (keys.length <= 7) {
const enrolmentDateTime = new Date(createdDate)
Expand Down Expand Up @@ -79,6 +79,7 @@ export class StorageService {
new Date().getTimezoneOffset()
)
const cache = this.set(StorageKeys.CACHE_ANSWERS, {})
const appVersion = this.set(StorageKeys.APP_VERSION, appV)

return Promise.all([
pId,
Expand All @@ -93,7 +94,8 @@ export class StorageService {
utc,
cache,
enrolmentDate,
referenceDate
referenceDate,
appVersion
])
}
})
Expand Down Expand Up @@ -148,6 +150,10 @@ export class StorageService {
return this.storage.keys()
}

getAppVersion() {
return this.appVersion.getVersionNumber()
}

prepareStorage() {
return this.getAllKeys()
.then(keys => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class SettingsPageComponent {
}

loadSettings() {
const appVersionPromise = this.appVersion.getVersionNumber()
const appVersionPromise = this.storage.get(StorageKeys.APP_VERSION)
const configVersion = this.storage.get(StorageKeys.CONFIG_VERSION)
const scheduleVersion = this.storage.get(StorageKeys.SCHEDULE_VERSION)
const participantId = this.storage.get(StorageKeys.PARTICIPANTID)
Expand Down
5 changes: 4 additions & 1 deletion src/app/pages/splash/containers/splash-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ export class SplashPageComponent {

onStart() {
this.status = 'Updating notifications...'
return this.checkTimezoneChange()
this.configService.migrateToLatestVersion()
return this.configService
.fetchConfigState(false)
.then(() => this.checkTimezoneChange())
.then(() => this.notificationsRefresh())
.catch(error => {
console.error(error)
Expand Down
1 change: 1 addition & 0 deletions src/app/shared/enums/storage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export class StorageKeys {
static APP_VERSION = new StorageKeys('APP_VERSION')
static REFERENCEDATE = new StorageKeys('REFERENCEDATE')
static ENROLMENTDATE = new StorageKeys('ENROLMENTDATE')
static OAUTH_TOKENS = new StorageKeys('OAUTH_TOKENS')
Expand Down

0 comments on commit 044b2e0

Please sign in to comment.