Skip to content

Commit

Permalink
Merge pull request #800 from RADAR-base/release-0.7.2-alpha
Browse files Browse the repository at this point in the history
Release 0.7.2 alpha
  • Loading branch information
mpgxvii committed Oct 15, 2019
2 parents af04414 + 426cc79 commit 28b08b9
Show file tree
Hide file tree
Showing 44 changed files with 832 additions and 607 deletions.
73 changes: 60 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![BCH compliance](https://bettercodehub.com/edge/badge/RADAR-base/RADAR-Questionnaire?branch=master)](https://bettercodehub.com/)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/03ec17f46bf147278bc71242a769af88)](https://www.codacy.com/app/yatharthranjan89/RADAR-Questionnaire?utm_source=github.com&utm_medium=referral&utm_content=RADAR-base/RADAR-Questionnaire&utm_campaign=Badge_Grade)

Hybrid mobile application to actively capture data for the RADAR-Base Platform.
A hybrid mobile application to actively capture data for the RADAR-Base Platform.

## Note

Expand Down Expand Up @@ -38,17 +38,27 @@ To run the application in the browser use:
$ ionic serve
```

## Fix CSS
## Guidelines

Use the following command to sort, format and fix common css problems:

```
$ yarn fix:css
```

Use the following command before commiting to fix all common styling and sorting problems:

```
$ yarn fix:all
```

## Platforms

In order to add platforms to target, you must install the required SDKs.

### Android

To add the Android platform. You need to have the [Android SDK](https://developer.android.com/studio/index.html) pre installed. This step also adds the plugins listed in `config.xml` to the project.
To add the Android platform, you need to have the [Android SDK](https://developer.android.com/studio/index.html) pre installed. This step also adds the plugins listed in `config.xml` to the project.

```
$ ionic cordova platform add android
Expand All @@ -66,7 +76,36 @@ Run the app in an Android emulator:
$ ionic cordova emulate android
```

## Firebase remote config
### iOS

To add the iOS platform, you need to have [XCode](https://apps.apple.com/us/app/xcode/id497799835?mt=12) pre installed.

```
$ ionic cordova platform add ios
```

Run the app in an iOS device:

```
$ ionic cordova run ios
```

## Firebase

If using Firebase for notifications, analytics, or remote config, [create your Firebase project](https://console.firebase.google.com/). Then, add your iOS or Android app to the Firebase project. Once added, please download the app's `google-service.json` file (for Android) and `GoogleService-Info.plist` (for iOS), and add it to the root directory.

### Remote Notifications

If using FCM pull notifications instead of the local ones, please specify the FCM sender id (as mentioned in FCM settings) in `src/assets/data/defaultConfig.ts` and the default notification type to FCM (this is already the default value).

```ts
export const FCMPluginProjectSenderId = 'your-sender-id'
export const DefaultNotificationType = 'FCM'
```

In order for notifications to be sent, you must run your own app server. It is part of the [RADAR-base stack](https://github.com/RADAR-base/RADAR-Docker/), and specific docs can be found [here](https://github.com/RADAR-base/RADAR-Docker/tree/dev/dcompose-stack/firebase-app-server).

### Remote Config

Certain values can be overriden using Firebase Remote Config. Specifically, the following variables are supported:

Expand All @@ -81,28 +120,36 @@ Certain values can be overriden using Firebase Remote Config. Specifically, the
| `kafka_specification_url` | URL of the Kafka topic specification | <https://api.github.com/repos/RADAR-base/radar-schemas/contents/specifications/active/aRMT_1.4.3.yml?ref=master> |
| `platform_instance` | Title of RADAR Base / platform instance | `RADAR-CNS` |

### Analytics

In order to personalize Firebase events, certain user properties must be added to the Firebase console. Specifically, the following user properties are supported:

| Property | Description |
| ----------------- | ----------------------------------------------------------------- |
| `subjectId` | Custom identifier for the user |
| `humanReadableId` | Human readable identifier for the user |
| `baseUrl` | Custom identifier for the base URL of the project |
| `projectId` | Custom identifier for the project that a user belongs to |
| `sourceId` | Custom identifier for the source the application is registered as |
| `enrolmentDate` | Enrolment date of the user |

Further details on the events that are already logged, default events, and default user properties can be found on the [RADAR Base wiki pages](https://radar-base.atlassian.net/wiki/spaces/RAD/pages/905707521/Firebase+Analytics).

## Other Config Options

Copy `src/assets/data/secret.ts.template` to `src/assets/data/secret.ts` and add the following configuration -

```ts
// The client secret for OAuth authorisation with the Management Portal
export const DefaultSourceProducerAndSecretExport: string = 'aRMT:<aRMT-secret>'
export const DefaultSourceProducerAndSecretExport = 'aRMT:<aRMT-secret>'
```

In `src/assets/data/defaultConfig.ts` the following settings can be changed:

If using FCM pull notifications instead of the local ones, please specify the FCM sender id (as mentioned in FCM settings) in `src/assets/data/defaultConfig.ts`. Don't forget to add the app's `google-services.json` (Android) or `GoogleService-Info.plist` (iOS) file to the root of your project.

```ts
export const FCMPluginProjectSenderId: string = 'your-sender-id'
```

The Default endpoint of where the RADAR-base platform is hosted.

```ts
export const DefaultEndPoint: string =
'https://your-hosted-radar-platform-base-url/'
export const DefaultEndPoint = 'https://your-hosted-radar-platform-base-url/'
```

Also change the Default Github source details where the questionnaire scheduling protocols and questionnaire schemas are hosted.
Expand Down
4 changes: 3 additions & 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="537" id="org.phidatalab.radar_armt" ios-CFBundleIdentifier="org.phidatalab.radar-armt" version="0.7.1.1-alpha" xmlns:android="http://schemas.android.com/apk/res/android">
<widget android-versionCode="538" id="org.phidatalab.radar_armt" ios-CFBundleIdentifier="org.phidatalab.radar-armt" version="0.7.2-alpha" xmlns:android="http://schemas.android.com/apk/res/android">
<name>RADAR Questionnaire</name>
<description>An application that collects active data for research.</description>
<author email="radar-base@kcl.ac.uk" href="http://radar-base.org/">RADAR-Base</author>
Expand All @@ -12,6 +12,7 @@
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<allow-navigation href="*" />
<icon src="resources/android/icon/drawable-xhdpi-icon.png" />
<preference name="DisallowOverscroll" value="true" />
<preference name="BackgroundColor" value="0xff6d9aa5" />
Expand Down Expand Up @@ -127,6 +128,7 @@
<plugin name="cordova-plugin-camera" spec="^4.0.3" />
<plugin name="cordova-plugin-local-notification" spec="^0.9.0-beta.3" />
<plugin name="cordova-plugin-app-version" spec="^0.1.9" />
<plugin name="cordova-plugin-network-information" spec="^2.0.2" />
<plugin name="phonegap-plugin-mobile-accessibility" spec="^1.0.5" />
<plugin name="cordova-media-with-compression" spec="^2.1.2" />
<plugin name="cordova-plugin-file" spec="^6.0.1" />
Expand Down
58 changes: 30 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,28 @@
"@angular/forms": "^7.2.13",
"@angular/router": "^7.2.13",
"@auth0/angular-jwt": "^3.0.0",
"@ionic-native/android-permissions": "^5.14.0",
"@ionic-native/app-version": "^5.14.0",
"@ionic-native/background-mode": "^5.14.0",
"@ionic-native/barcode-scanner": "^5.14.0",
"@ionic-native/core": "^5.14.0",
"@ionic-native/device": "^5.14.0",
"@ionic-native/dialogs": "^5.14.0",
"@ionic-native/file": "^5.14.0",
"@ionic-native/firebase": "^5.14.0",
"@ionic-native/globalization": "^5.14.0",
"@ionic-native/insomnia": "^5.14.0",
"@ionic-native/keyboard": "^5.14.0",
"@ionic-native/local-notifications": "^5.14.0",
"@ionic-native/mobile-accessibility": "5.14.0",
"@ionic-native/splash-screen": "^5.14.0",
"@ionic-native/status-bar": "^5.14.0",
"@ionic-native/vibration": "^5.14.0",
"@ionic-native/web-intent": "^5.14.0",
"@ionic-native/android-permissions": "^5.15.0",
"@ionic-native/app-version": "^5.15.0",
"@ionic-native/background-mode": "^5.15.0",
"@ionic-native/barcode-scanner": "^5.15.0",
"@ionic-native/core": "^5.15.0",
"@ionic-native/device": "^5.15.0",
"@ionic-native/dialogs": "^5.15.0",
"@ionic-native/file": "^5.15.0",
"@ionic-native/firebase": "^5.15.0",
"@ionic-native/globalization": "^5.15.0",
"@ionic-native/insomnia": "^5.15.0",
"@ionic-native/keyboard": "^5.15.0",
"@ionic-native/local-notifications": "^5.15.0",
"@ionic-native/mobile-accessibility": "5.15.0",
"@ionic-native/splash-screen": "^5.15.0",
"@ionic-native/status-bar": "^5.15.0",
"@ionic-native/vibration": "^5.15.0",
"@ionic-native/web-intent": "^5.15.0",
"@ionic/storage": "^2.2.0",
"angular-svg-round-progressbar": "^3.0.1",
"autoprefixer": "^9.6.1",
"avsc": "^5.4.13",
"autoprefixer": "^9.6.4",
"avsc": "^5.4.14",
"base64-js": "^1.3.1",
"browserify": "^16.3.0",
"com-darryncampbell-cordova-plugin-intent": "^1.1.4",
Expand All @@ -92,7 +92,7 @@
"cordova-plugin-insomnia": "^4.3.0",
"cordova-plugin-ionic-keyboard": "^2.2.0",
"cordova-plugin-local-notification": "^0.9.0-beta.3",
"cordova-plugin-network-information": "git+https://github.com/apache/cordova-plugin-network-information.git",
"cordova-plugin-network-information": "^2.0.2",
"cordova-plugin-splashscreen": "^5.0.3",
"cordova-plugin-statusbar": "^2.4.3",
"cordova-plugin-vibration": "^3.1.1",
Expand All @@ -109,8 +109,9 @@
"phonegap-plugin-barcodescanner": "^8.1.0",
"phonegap-plugin-mobile-accessibility": "^1.0.5",
"rxjs": "^6.5.3",
"semver": "^6.3.0",
"uuid": "^3.3.3",
"yaml": "^1.7.0",
"yaml": "^1.7.1",
"zone.js": "~0.8.26"
},
"devDependencies": {
Expand All @@ -122,8 +123,8 @@
"@angular/platform-browser-dynamic": "^7.2.13",
"@angular/platform-server": "^7.2.13",
"@ionic/app-scripts": "^3.2.4",
"@types/jasmine": "^3.4.1",
"@types/jasminewd2": "^2.0.7",
"@types/jasmine": "^3.4.4",
"@types/jasminewd2": "^2.0.8",
"@types/node": "^12.7.8",
"codelyzer": "^5.1.2",
"eslint": "^6.5.1",
Expand All @@ -132,7 +133,7 @@
"import-sort-parser-babylon": "^6.0.0",
"import-sort-parser-typescript": "^6.0.0",
"import-sort-style-module": "^6.0.0",
"ionic": "^5.4.1",
"ionic": "^5.4.2",
"jasmine": "^3.5.0",
"jasmine-core": "^3.5.0",
"jasmine-spec-reporter": "^4.2.1",
Expand Down Expand Up @@ -160,15 +161,15 @@
"rxjs-compat": "^6.5.3",
"rxjs-tslint": "0.1.5",
"stylefmt": "^6.0.3",
"stylelint": "^11.0.0",
"stylelint": "^11.1.1",
"stylelint-config-standard": "^19.0.0",
"tslint": "^5.20.0",
"tslint-angular": "^3.0.2",
"tslint-config-prettier": "^1.15.0",
"tslint-config-standard": "^8.0.1",
"typescript": "~3.1.6",
"watchify": "^3.11.1",
"webpack": "^4.41.0",
"webpack": "^4.41.1",
"webpack-sources": "^1.4.3"
},
"cordova": {
Expand Down Expand Up @@ -207,7 +208,8 @@
"cordova-plugin-androidx-adapter": {},
"cordova-plugin-background-mode-fixes": {},
"com-darryncampbell-cordova-plugin-intent": {},
"cordova-plugin-ionic-keyboard": {}
"cordova-plugin-ionic-keyboard": {},
"cordova-plugin-network-information": {}
}
},
"ionic_enable_lint": false
Expand Down
10 changes: 8 additions & 2 deletions src/app/core/services/config/config.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { HttpClient, HttpHandler } from '@angular/common/http'
import { TestBed } from '@angular/core/testing'
import { Platform } from 'ionic-angular'
import { PlatformMock } from 'ionic-mocks'

import {
AppConfigServiceMock,
Expand All @@ -17,12 +20,12 @@ import { LocalizationService } from '../misc/localization.service'
import { LogService } from '../misc/log.service'
import { NotificationService } from '../notifications/notification.service'
import { ScheduleService } from '../schedule/schedule.service'
import { AnalyticsService } from '../usage/analytics.service'
import { AppConfigService } from './app-config.service'
import { ConfigService } from './config.service'
import { ProtocolService } from './protocol.service'
import { QuestionnaireService } from './questionnaire.service'
import { SubjectConfigService } from './subject-config.service'
import { AnalyticsService } from '../usage/analytics.service';

describe('ConfigService', () => {
let service
Expand All @@ -43,7 +46,10 @@ describe('ConfigService', () => {
provide: AnalyticsService,
useClass: FirebaseAnalyticsServiceMock
},
{ provide: LogService, useClass: LogServiceMock }
{ provide: LogService, useClass: LogServiceMock },
HttpClient,
HttpHandler,
{ provide: Platform, useClass: PlatformMock }
]
})
)
Expand Down
43 changes: 38 additions & 5 deletions src/app/core/services/config/config.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import { HttpClient } from '@angular/common/http'
import { Injectable } from '@angular/core'
import { Platform } from 'ionic-angular'
import * as ver from 'semver'

import { DefaultNotificationRefreshTime } from '../../../../assets/data/defaultConfig'
import {
DefaultAppId,
DefaultAppVersion,
DefaultAppleAppStoreAppURL,
DefaultGooglePlaystoreAppURL,
DefaultNotificationRefreshTime,
DefaultPackageName
} from '../../../../assets/data/defaultConfig'
import {
ConfigEventType,
NotificationEventType
} from '../../../shared/enums/events'
import { User } from '../../../shared/models/user'
import { parseVersion } from '../../../shared/utilities/parse-version'
import { TaskType } from '../../../shared/utilities/task-type'
import { KafkaService } from '../kafka/kafka.service'
import { LocalizationService } from '../misc/localization.service'
Expand All @@ -30,7 +41,9 @@ export class ConfigService {
private kafka: KafkaService,
private localization: LocalizationService,
private analytics: AnalyticsService,
private logger: LogService
private logger: LogService,
private http: HttpClient,
private platform: Platform
) {}

fetchConfigState(force?: boolean) {
Expand All @@ -45,6 +58,7 @@ export class ConfigService {
this.subjectConfig
.getEnrolmentDate()
.then(d => this.appConfig.init(d))
this.checkForAppUpdates()
if (newProtocol)
return this.updateConfigStateOnProtocolChange(newProtocol)
if (newAppVersion)
Expand All @@ -54,7 +68,7 @@ export class ConfigService {
if (newNotifications) return this.rescheduleNotifications(false)
})
.catch(e => {
this.sendConfigChangeEvent(ConfigEventType.ERROR)
this.sendConfigChangeEvent(ConfigEventType.ERROR, '', '', e.message)
throw e
})
}
Expand Down Expand Up @@ -130,6 +144,24 @@ export class ConfigService {
})
}

checkForAppUpdates() {
const playstoreURL = this.platform.is('ios')
? DefaultAppleAppStoreAppURL + DefaultAppId
: DefaultGooglePlaystoreAppURL + DefaultPackageName
return Promise.all([
this.http
.get(playstoreURL, { responseType: 'text' })
.toPromise()
.then(res => parseVersion(res))
.catch(e => DefaultAppVersion),
this.appConfig.getAppVersion()
]).then(([playstoreVersion, currentVersion]) => {
if (ver.gt(playstoreVersion, currentVersion))
throw new Error(ConfigEventType.APP_UPDATE_AVAILABLE)
return
})
}

checkParticipantEnrolled() {
return this.subjectConfig
.getParticipantLogin()
Expand Down Expand Up @@ -243,10 +275,11 @@ export class ConfigService {
}
}

sendConfigChangeEvent(type, previous?, current?) {
sendConfigChangeEvent(type, previous?, current?, error?) {
this.analytics.logEvent(type, {
previous: String(previous),
current: String(current)
current: String(current),
error: String(error)
})
}

Expand Down
Loading

0 comments on commit 28b08b9

Please sign in to comment.