14 Commits

Author SHA1 Message Date
John Lyon-Smith
a3b20d8ac1 Reduce sensitivity 2018-05-31 13:38:28 -07:00
John Lyon-Smith
519bc1c50b Version 1.2.0-20180531.0 2018-05-31 11:16:42 -07:00
John Lyon-Smith
71e1816173 Added wait modals everywhere. Reduce required distance to item 2018-05-31 11:15:53 -07:00
John Lyon-Smith
9e55320a21 Fixing base route issues. Fix map scrolling issues on iOS 2018-05-31 07:20:29 -07:00
John Lyon-Smith
62876c94c9 Version 1.1.3-20180529.0 2018-05-29 13:09:48 -07:00
John Lyon-Smith
5e00b0dd23 Correct fix for background location services 2018-05-29 12:49:51 -07:00
John Lyon-Smith
fb8545110c Revert to location when in use 2018-05-29 12:44:38 -07:00
John Lyon-Smith
323d047903 Version 1.1.2-20180529.0 2018-05-29 07:55:59 -07:00
John Lyon-Smith
9ec1e689eb Production settings 2018-05-29 07:55:29 -07:00
John Lyon-Smith
bbd259f989 Version 1.1.1-20180528.0 2018-05-28 16:13:55 -07:00
John Lyon-Smith
f07c61c3b5 Remove autobind decorator. Fix bugs in AR view 2018-05-28 16:12:20 -07:00
John Lyon-Smith
eb3649547a Update for new snap-tool 2018-05-28 12:23:53 -07:00
John Lyon-Smith
5d339a695e Remove activities when deleting work item 2018-05-25 15:58:17 -07:00
John Lyon-Smith
c53d7339fb Version 1.1.0-20180525.0 2018-05-25 14:55:36 -07:00
44 changed files with 1844 additions and 1527 deletions

View File

@@ -6,7 +6,6 @@
"development": { "development": {
"plugins": [ "plugins": [
"transform-react-jsx-source", "transform-react-jsx-source",
"transform-decorators-legacy"
] ]
} }
} }

View File

@@ -8,7 +8,7 @@
</configuration> </configuration>
</facet> </facet>
</component> </component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true"> <component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" /> <excludeFolder url="file://$MODULE_DIR$/.gradle" />

154
mobile/android/app/app.iml Normal file
View File

@@ -0,0 +1,154 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
<option name="GRADLE_PROJECT_PATH" value=":app" />
</configuration>
</facet>
<facet type="android" name="Android">
<configuration>
<option name="SELECTED_BUILD_VARIANT" value="debug" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<afterSyncTasks>
<task>generateDebugSources</task>
</afterSyncTasks>
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager">
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/check-manifest" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaPrecompile" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/prebuild" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/splits-support" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/reports" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Gradle: com.android.support:support-fragment-25.0.0" level="project" />
<orderEntry type="library" name="Gradle: com.facebook.fresco:fbcore-1.3.0" level="project" />
<orderEntry type="library" name="Gradle: com.google.android.exoplayer:exoplayer-r2.2.0" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:support-media-compat-25.0.0" level="project" />
<orderEntry type="library" name="Gradle: com.facebook.fresco:drawee-1.3.0" level="project" />
<orderEntry type="library" name="Gradle: com.facebook.fresco:imagepipeline-okhttp3-1.3.0" level="project" />
<orderEntry type="library" name="Gradle: artifacts:arcore_client" level="project" />
<orderEntry type="library" name="Gradle: com.parse.bolts:bolts-tasks:1.4.0@jar" level="project" />
<orderEntry type="library" name="Gradle: com.squareup.okio:okio:1.13.0@jar" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:appcompat-v7-25.0.0" level="project" />
<orderEntry type="library" name="Gradle: com.amazonaws:aws-android-sdk-ddb:2.2.22@jar" level="project" />
<orderEntry type="library" name="Gradle: com.google.code.gson:gson:2.2.4@jar" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:animated-vector-drawable-25.0.0" level="project" />
<orderEntry type="library" name="Gradle: com.facebook.fresco:fresco-1.3.0" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:support-compat-25.0.0" level="project" />
<orderEntry type="library" name="Gradle: com.google.code.findbugs:jsr305:3.0.0@jar" level="project" />
<orderEntry type="library" name="Gradle: org.webkit:android-jsc-r174650" level="project" />
<orderEntry type="library" name="Gradle: com.amazonaws:aws-android-sdk-s3:2.2.22@jar" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:support-core-utils-25.0.0" level="project" />
<orderEntry type="library" name="Gradle: javax.inject:javax.inject:1@jar" level="project" />
<orderEntry type="library" name="Gradle: com.amazonaws:aws-android-sdk-core:2.2.22@jar" level="project" />
<orderEntry type="library" name="Gradle: com.facebook.soloader:soloader-0.1.0" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:support-core-ui-25.0.0" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:support-vector-drawable-25.0.0" level="project" />
<orderEntry type="library" name="Gradle: com.facebook.fbui.textlayoutbuilder:textlayoutbuilder-1.0.0" level="project" />
<orderEntry type="library" name="Gradle: com.facebook.fresco:imagepipeline-base-1.3.0" level="project" />
<orderEntry type="library" name="Gradle: com.squareup.okhttp3:okhttp:3.6.0@jar" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:support-v4-25.0.0" level="project" />
<orderEntry type="library" name="Gradle: com.facebook.fbui.textlayoutbuilder:staticlayout-proxy:1.0@jar" level="project" />
<orderEntry type="library" name="Gradle: artifacts:react_viro" level="project" />
<orderEntry type="library" name="Gradle: com.facebook.react:react-native-0.55.4" level="project" />
<orderEntry type="library" name="Gradle: com.google.protobuf.nano:protobuf-javanano:3.0.0-alpha-7@jar" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:support-annotations:25.0.1@jar" level="project" />
<orderEntry type="library" name="Gradle: com.amazonaws:aws-android-sdk-cognito:2.2.22@jar" level="project" />
<orderEntry type="library" name="Gradle: com.amazonaws:aws-android-sdk-cognitoidentityprovider:2.2.22@jar" level="project" />
<orderEntry type="library" name="Gradle: com.squareup.okhttp3:okhttp-urlconnection:3.6.0@jar" level="project" />
<orderEntry type="library" name="Gradle: artifacts:viro_renderer" level="project" />
<orderEntry type="library" name="Gradle: com.amazonaws:aws-android-sdk-ddb-mapper:2.2.22@jar" level="project" />
<orderEntry type="library" name="Gradle: artifacts:gvr_common" level="project" />
<orderEntry type="library" name="Gradle: com.facebook.fresco:imagepipeline-1.3.0" level="project" />
<orderEntry type="module" module-name="react-native-fs" />
<orderEntry type="module" module-name="react-native-maps" />
<orderEntry type="module" module-name="react-native-image-resizer" />
<orderEntry type="module" module-name="react-native-image-picker" />
<orderEntry type="library" name="Gradle: android-android-27" level="project" />
</component>
</module>

View File

@@ -101,8 +101,8 @@ android {
applicationId "com.deightonar" applicationId "com.deightonar"
minSdkVersion 24 minSdkVersion 24
targetSdkVersion 27 targetSdkVersion 27
versionCode 5 versionCode 10
versionName "1.0.2" versionName "1.2.0"
ndk { ndk {
abiFilters "armeabi-v7a", "x86" abiFilters "armeabi-v7a", "x86"
} }

View File

@@ -1,7 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.deightonar" package="com.deightonar"
android:versionCode="5" android:versionCode="10"
android:versionName="1.0.2"> android:versionName="1.2.0">
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/> <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

View File

@@ -140,6 +140,11 @@
TargetAttributes = { TargetAttributes = {
13B07F861A680F5B00A75B9A = { 13B07F861A680F5B00A75B9A = {
DevelopmentTeam = 523GZPCZ3X; DevelopmentTeam = 523GZPCZ3X;
SystemCapabilities = {
com.apple.BackgroundModes = {
enabled = 1;
};
};
}; };
}; };
}; };

View File

@@ -2,8 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>NSMicrophoneUsageDescription</key> <key>NSLocationAlwaysUsageDescription</key>
<string>$(PRODUCT_NAME) camera use</string> <string>$(PRODUCT_NAME) background location use</string>
<key>CFBundleDevelopmentRegion</key> <key>CFBundleDevelopmentRegion</key>
<string>en</string> <string>en</string>
<key>CFBundleDisplayName</key> <key>CFBundleDisplayName</key>
@@ -19,11 +19,11 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>APPL</string> <string>APPL</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.0.2</string> <string>1.2.0</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>20180518.0</string> <string>20180531.0</string>
<key>LSRequiresIPhoneOS</key> <key>LSRequiresIPhoneOS</key>
<true/> <true/>
<key>NSAppTransportSecurity</key> <key>NSAppTransportSecurity</key>
@@ -33,8 +33,16 @@
</dict> </dict>
<key>NSCameraUsageDescription</key> <key>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME) camera use</string> <string>$(PRODUCT_NAME) camera use</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>$(PRODUCT_NAME) location use</string>
<key>NSMicrophoneUsageDescription</key>
<string>$(PRODUCT_NAME) camera use</string>
<key>NSPhotoLibraryUsageDescription</key> <key>NSPhotoLibraryUsageDescription</key>
<string>$(PRODUCT_NAME) photo use</string> <string>$(PRODUCT_NAME) photo use</string>
<key>UIBackgroundModes</key>
<array>
<string>location</string>
</array>
<key>UILaunchStoryboardName</key> <key>UILaunchStoryboardName</key>
<string>LaunchScreen</string> <string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key> <key>UIRequiredDeviceCapabilities</key>
@@ -46,8 +54,6 @@
<string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string> <string>UIInterfaceOrientationPortraitUpsideDown</string>
</array> </array>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>$(PRODUCT_NAME) location use</string>
<key>UIViewControllerBasedStatusBarAppearance</key> <key>UIViewControllerBasedStatusBarAppearance</key>
<false/> <false/>
</dict> </dict>

2638
mobile/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -3,7 +3,6 @@
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"devDependencies": { "devDependencies": {
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-react-native-stage-0": "^1.0.1", "babel-preset-react-native-stage-0": "^1.0.1",
"jest-react-native": "^18.0.0", "jest-react-native": "^18.0.0",
"react-test-renderer": "16.2.0" "react-test-renderer": "16.2.0"
@@ -18,7 +17,7 @@
"preset": "react-native" "preset": "react-native"
}, },
"dependencies": { "dependencies": {
"autobind-decorator": "^2.1.0", "auto-bind2": "^1.0.3",
"eventemitter3": "^3.1.0", "eventemitter3": "^3.1.0",
"moment": "^2.22.1", "moment": "^2.22.1",
"react": "^16.3.2", "react": "^16.3.2",

View File

@@ -1,9 +1,9 @@
import EventEmitter from "eventemitter3" import EventEmitter from "eventemitter3"
import io from "socket.io-client" import io from "socket.io-client"
import { AsyncStorage } from "react-native" import { AsyncStorage } from "react-native"
import autobind from "autobind-decorator"
import { config } from "./config" import { config } from "./config"
import RNFS from "react-native-fs" import RNFS from "react-native-fs"
import { autoBind } from "auto-bind2"
const authTokenKeyName = "AuthToken" const authTokenKeyName = "AuthToken"
const backendKeyName = "Backend" const backendKeyName = "Backend"
@@ -33,7 +33,6 @@ class APIError extends Error {
} }
} }
@autobind
class API extends EventEmitter { class API extends EventEmitter {
static urls = { static urls = {
normal: "https://dar.kss.us.com/api", normal: "https://dar.kss.us.com/api",
@@ -43,6 +42,7 @@ class API extends EventEmitter {
constructor() { constructor() {
super() super()
autoBind(this)
this.user = { pending: true } this.user = { pending: true }
this._apiURL = null this._apiURL = null

View File

@@ -13,16 +13,16 @@ import {
ViroQuad, ViroQuad,
ViroConstants, ViroConstants,
} from "react-viro" } from "react-viro"
import autobind from "autobind-decorator"
import backImage from "./images/back.png" import backImage from "./images/back.png"
import { config } from "../config" import { config } from "../config"
import "url-search-params-polyfill" import "url-search-params-polyfill"
import { reactAutoBind } from "auto-bind2"
const shapes = { const shapes = {
order: { order: {
source: require("./models/hardhat_obj.obj"), source: require("./models/hardhat_obj.obj"),
resources: [require("./models/hardhat.mtl")], resources: [require("./models/hardhat.mtl")],
scale: [0.5, 0.5, 0.5], scale: [0.3, 0.3, 0.3],
}, },
complaint: { complaint: {
source: require("./models/question_obj.obj"), source: require("./models/question_obj.obj"),
@@ -47,6 +47,7 @@ const distance = (vectorA, vectorB) => {
class WorkItemSceneAR extends React.Component { class WorkItemSceneAR extends React.Component {
constructor(props) { constructor(props) {
super(props) super(props)
reactAutoBind(this)
this.state = { this.state = {
position: [0, 0, 0], position: [0, 0, 0],
@@ -57,7 +58,6 @@ class WorkItemSceneAR extends React.Component {
} }
} }
@autobind
handleLoadEnd() { handleLoadEnd() {
this.arScene.getCameraOrientationAsync().then((orientation) => { this.arScene.getCameraOrientationAsync().then((orientation) => {
return this.arScene return this.arScene
@@ -65,8 +65,11 @@ class WorkItemSceneAR extends React.Component {
.then((results) => { .then((results) => {
const { forward, position } = orientation const { forward, position } = orientation
// Default position is just one meter in front of the user // Default position is just one meter in front of the user
const defaultPosition = const defaultPosition = [
[forward[0] * 1.0, forward[1] * 1.0, forward[2]] * 1.0 forward[0] * 1.0,
forward[1] * 1.0,
forward[2] * 1.0,
]
let hitResultPosition = null let hitResultPosition = null
// Filter the hit test results based on the position. // Filter the hit test results based on the position.
@@ -110,7 +113,6 @@ class WorkItemSceneAR extends React.Component {
}) })
} }
@autobind
updateInitialRotation() { updateInitialRotation() {
this.arNode.getTransformAsync().then((retDict) => { this.arNode.getTransformAsync().then((retDict) => {
let rotation = retDict.rotation let rotation = retDict.rotation
@@ -131,7 +133,6 @@ class WorkItemSceneAR extends React.Component {
}) })
} }
@autobind
handleTrackingUpdated(state, reason) { handleTrackingUpdated(state, reason) {
if ( if (
!this.state.trackingInitialized && !this.state.trackingInitialized &&
@@ -141,12 +142,10 @@ class WorkItemSceneAR extends React.Component {
} }
} }
@autobind
handleAnchorFound() { handleAnchorFound() {
this.setState({ haveAnchor: true }) this.setState({ haveAnchor: true })
} }
@autobind
handleClick(position, source) { handleClick(position, source) {
const { workItemId } = this.props const { workItemId } = this.props
@@ -182,7 +181,7 @@ class WorkItemSceneAR extends React.Component {
innerAngle={5} innerAngle={5}
outerAngle={20} outerAngle={20}
direction={[0, -1, 0]} direction={[0, -1, 0]}
position={[0, 10, 0]} position={[0, 5, 0]}
color="#ffffff" color="#ffffff"
castsShadow={true} castsShadow={true}
shadowNearZ={0.1} shadowNearZ={0.1}
@@ -193,7 +192,7 @@ class WorkItemSceneAR extends React.Component {
trackingInitialized && trackingInitialized &&
haveAnchor && ( haveAnchor && (
<Viro3DObject <Viro3DObject
position={[0, 0, -1]} position={[0, 0, 0]}
source={shape.source} source={shape.source}
resources={shape.resources} resources={shape.resources}
scale={shape.scale} scale={shape.scale}
@@ -219,6 +218,7 @@ class WorkItemSceneAR extends React.Component {
export class ARViewer extends React.Component { export class ARViewer extends React.Component {
constructor(props) { constructor(props) {
super(props) super(props)
reactAutoBind(this)
const { search } = this.props.location const { search } = this.props.location
@@ -230,7 +230,6 @@ export class ARViewer extends React.Component {
} }
} }
@autobind
handleBackPress() { handleBackPress() {
this.props.history.replace("/") this.props.history.replace("/")
} }

View File

@@ -23,7 +23,7 @@ import {
FormStaticInput, FormStaticInput,
} from "../ui" } from "../ui"
import { MessageModal, WaitModal, ProgressModal } from "../Modal" import { MessageModal, WaitModal, ProgressModal } from "../Modal"
import autobind from "autobind-decorator" import { reactAutoBind } from "auto-bind2"
import KeyboardSpacer from "react-native-keyboard-spacer" import KeyboardSpacer from "react-native-keyboard-spacer"
import { isIphoneX } from "react-native-iphone-x-helper" import { isIphoneX } from "react-native-iphone-x-helper"
import { api } from "../API" import { api } from "../API"
@@ -86,24 +86,30 @@ export class Activity extends React.Component {
constructor(props) { constructor(props) {
super(props) super(props)
reactAutoBind(this)
this.state = { this.state = {
binder: new FormBinder({}, Activity.bindings), binder: new FormBinder({}, Activity.bindings),
waitModal: null, waitModal: null,
messageModal: null, messageModal: null,
progressModal: null, progressModal: null,
uploadPercent: 0, uploadPercent: 0,
region: config.initialRegion,
} }
this.region = null
this.isMapReady = false
this.goToRegionWhenReady = false
}
componentDidMount() {
const { search } = this.props.location const { search } = this.props.location
const params = search ? new URLSearchParams(search) : { get: () => null } const params = search ? new URLSearchParams(search) : { get: () => null }
const id = params.get("id") const id = params.get("id")
const workItemId = params.get("workItemId") const workItemId = params.get("workItemId")
const getWorkItem = (id) => { const getWorkItem = (id) => {
this.setState({ waitModal: { message: "Loading Work Item Details..." } })
api api
.getWorkItem(id) .getWorkItem(id)
.then((workItem) => { .then((workItem) => {
this.setState({ waitModal: null })
if (workItem) { if (workItem) {
const [lng, lat] = workItem.location.coordinates const [lng, lat] = workItem.location.coordinates
@@ -116,19 +122,27 @@ export class Activity extends React.Component {
}, },
Activity.bindings Activity.bindings
), ),
region: {
latitude: lat,
longitude: lng,
latitudeDelta: 0.01,
longitudeDelta: 0.01,
},
location: formatLatLng(lat, lng), location: formatLatLng(lat, lng),
dateTime: moment().format(), dateTime: moment().format(),
}) })
this.region = {
latitude: lat,
longitude: lng,
latitudeDelta: config.activityRegionDelta,
longitudeDelta: config.activityRegionDelta,
}
}
if (this.isMapReady) {
this.mapView.animateToRegion(this.region)
} else {
this.goToRegionWhenReady = true
} }
}) })
.catch((err) => { .catch((err) => {
this.setState({ this.setState({
waitModal: null,
messageModal: { messageModal: {
icon: "hand", icon: "hand",
message: "Unable to get work item details", message: "Unable to get work item details",
@@ -140,9 +154,12 @@ export class Activity extends React.Component {
} }
if (id) { if (id) {
this.setState({ waitModal: { message: "Loading Activity..." } })
api api
.getActivity(id) .getActivity(id)
.then((activity) => { .then((activity) => {
this.setState({ waitModal: null })
if (activity) { if (activity) {
this.setState({ this.setState({
binder: new FormBinder(activity, Activity.bindings), binder: new FormBinder(activity, Activity.bindings),
@@ -153,6 +170,7 @@ export class Activity extends React.Component {
}) })
.catch((err) => { .catch((err) => {
this.setState({ this.setState({
waitModal: null,
messageModal: { messageModal: {
icon: "hand", icon: "hand",
message: "Unable to get activity details", message: "Unable to get activity details",
@@ -170,7 +188,15 @@ export class Activity extends React.Component {
} }
} }
@autobind handleOnMapReady() {
if (this.goToRegionWhenReady) {
this.mapView.animateToRegion(this.region)
this.goToRegionWhenReady = false
}
this.isMapReady = true
}
handleMessageDismiss() { handleMessageDismiss() {
const back = this.state.messageModal.back const back = this.state.messageModal.back
this.setState({ messageModal: null }) this.setState({ messageModal: null })
@@ -179,7 +205,6 @@ export class Activity extends React.Component {
} }
} }
@autobind
handleBackPress() { handleBackPress() {
const { history } = this.props const { history } = this.props
@@ -190,7 +215,6 @@ export class Activity extends React.Component {
} }
} }
@autobind
handleDonePress() { handleDonePress() {
const { binder } = this.state const { binder } = this.state
let obj = binder.getModifiedBindingValues() let obj = binder.getModifiedBindingValues()
@@ -228,7 +252,6 @@ export class Activity extends React.Component {
} }
} }
@autobind
handleUploadStarted() { handleUploadStarted() {
this.setState({ this.setState({
progressModal: { message: "Uploading Photo..." }, progressModal: { message: "Uploading Photo..." },
@@ -236,7 +259,6 @@ export class Activity extends React.Component {
}) })
} }
@autobind
handleUploadProgress(uploadData) { handleUploadProgress(uploadData) {
if (this.state.progressModal) { if (this.state.progressModal) {
this.setState({ this.setState({
@@ -250,12 +272,10 @@ export class Activity extends React.Component {
} }
} }
@autobind
handleUploadEnded(successful, uploadData) { handleUploadEnded(successful, uploadData) {
this.setState({ progressModal: null }) this.setState({ progressModal: null })
} }
@autobind
handleUploadCanceled() { handleUploadCanceled() {
this.setState({ progressModal: null }) this.setState({ progressModal: null })
} }
@@ -266,7 +286,6 @@ export class Activity extends React.Component {
messageModal, messageModal,
progressModal, progressModal,
waitModal, waitModal,
region,
dateTime, dateTime,
location, location,
uploadPercent, uploadPercent,
@@ -283,7 +302,12 @@ export class Activity extends React.Component {
/> />
<ScrollView style={styles.container}> <ScrollView style={styles.container}>
<View style={styles.panel}> <View style={styles.panel}>
<BoundInput binder={binder} name="resolution" label="Resolution:" /> <BoundInput
binder={binder}
name="resolution"
label="Resolution:"
message="You must supply a resolution for the activity"
/>
</View> </View>
<View style={styles.panel}> <View style={styles.panel}>
<BoundOptionStrip <BoundOptionStrip
@@ -296,16 +320,23 @@ export class Activity extends React.Component {
]} ]}
label="Status:" label="Status:"
name="status" name="status"
message="You must supply a status for the activity"
/> />
</View> </View>
<View style={styles.panel}> <View style={styles.panel}>
<BoundInput binder={binder} name="notes" label="Notes:" /> <BoundInput
binder={binder}
name="notes"
label="Notes:"
message="You must supply notes for the activity"
/>
</View> </View>
<View style={styles.panel}> <View style={styles.panel}>
<FormStaticInput label="Date &amp; Time:" value={dateTime} /> <FormStaticInput label="Date &amp; Time:" value={dateTime} />
<FormStaticInput label="Location:" value={location} /> <FormStaticInput label="Location:" value={location} />
<View style={{ flexDirection: "column", justifyContent: "center" }}> <View style={{ flexDirection: "column", justifyContent: "center" }}>
<MapView <MapView
ref={(ref) => (this.mapView = ref)}
style={{ style={{
flexDirection: "column", flexDirection: "column",
justifyContent: "center", justifyContent: "center",
@@ -324,7 +355,8 @@ export class Activity extends React.Component {
showsScale={false} showsScale={false}
showsUserLocation showsUserLocation
cacheEnabled cacheEnabled
region={region} initialRegion={config.initialRegion}
onMapReady={this.handleOnMapReady}
/> />
<Icon <Icon
name="target" name="target"

View File

@@ -56,7 +56,11 @@ export default class App extends React.Component {
<Route exact path="/login" component={Login} /> <Route exact path="/login" component={Login} />
<Route exact path="/logout" component={Logout} /> <Route exact path="/logout" component={Logout} />
<ProtectedRoute exact path="/home" component={Home} /> <ProtectedRoute exact path="/home" component={Home} />
<ProtectedRoute exact path="/arviewer" component={ARViewer} /> <ProtectedRoute
exact
path="/arviewer"
render={(props) => <ARViewer {...props} />}
/>
<ProtectedRoute exact path="/activity" component={Activity} /> <ProtectedRoute exact path="/activity" component={Activity} />
<ProtectedRoute exact admin path="/workItem" component={WorkItem} /> <ProtectedRoute exact admin path="/workItem" component={WorkItem} />
<ProtectedRoute <ProtectedRoute

View File

@@ -17,7 +17,7 @@ import { api } from "../API"
import { BoundSwitch, BoundInput, BoundButton } from "../ui" import { BoundSwitch, BoundInput, BoundButton } from "../ui"
import KeyboardSpacer from "react-native-keyboard-spacer" import KeyboardSpacer from "react-native-keyboard-spacer"
import { versionInfo } from "../version" import { versionInfo } from "../version"
import autobind from "autobind-decorator" import { reactAutoBind } from "auto-bind2"
import { isIphoneX } from "react-native-iphone-x-helper" import { isIphoneX } from "react-native-iphone-x-helper"
import { config } from "../config" import { config } from "../config"
@@ -74,6 +74,7 @@ export class Login extends React.Component {
constructor(props) { constructor(props) {
super(props) super(props)
reactAutoBind(this)
this.state = { this.state = {
binder: new FormBinder( binder: new FormBinder(
{ email: config.defaultUser, rememberMe: true }, { email: config.defaultUser, rememberMe: true },
@@ -92,7 +93,6 @@ export class Login extends React.Component {
} }
} }
@autobind
handleLogin() { handleLogin() {
let obj = this.state.binder.getModifiedBindingValues() let obj = this.state.binder.getModifiedBindingValues()
let { history } = this.props let { history } = this.props
@@ -117,18 +117,15 @@ export class Login extends React.Component {
} }
} }
@autobind
handleMessageDismiss() { handleMessageDismiss() {
this.setState({ messageModal: null }) this.setState({ messageModal: null })
} }
@autobind
handleApiDismiss(backendName) { handleApiDismiss(backendName) {
this.setState({ apiModal: null }) this.setState({ apiModal: null })
api.backend = backendName api.backend = backendName
} }
@autobind
handleApiPress() { handleApiPress() {
this.hiddenTouchCount += 1 this.hiddenTouchCount += 1

View File

@@ -1,28 +1,35 @@
import React from 'react' import React from "react"
import { Route, Redirect } from 'react-router-native' import { Route, Redirect } from "react-router-native"
import { PropTypes } from 'prop-types' import { PropTypes } from "prop-types"
import { api } from '../API' import { api } from "../API"
import autobind from 'autobind-decorator' import { reactAutoBind, autoBind } from "auto-bind2"
export class ProtectedRoute extends React.Component { export class ProtectedRoute extends React.Component {
static propTypes = { static propTypes = {
location: PropTypes.shape({ pathname: PropTypes.string, search: PropTypes.string }), location: PropTypes.shape({
pathname: PropTypes.string,
search: PropTypes.string,
}),
admin: PropTypes.bool, admin: PropTypes.bool,
} }
@autobind constructor(props) {
super(props)
reactAutoBind(this)
}
updateComponent() { updateComponent() {
this.forceUpdate() this.forceUpdate()
} }
componentDidMount() { componentDidMount() {
api.addListener('login', this.updateComponent) api.addListener("login", this.updateComponent)
api.addListener('logout', this.updateComponent) api.addListener("logout", this.updateComponent)
} }
componentWillUnmount() { componentWillUnmount() {
api.removeListener('login', this.updateComponent) api.removeListener("login", this.updateComponent)
api.removeListener('logout', this.updateComponent) api.removeListener("logout", this.updateComponent)
} }
render(props) { render(props) {
@@ -32,7 +39,7 @@ export class ProtectedRoute extends React.Component {
return null return null
} else { } else {
if (!user._id || (this.props.admin && !user.administrator)) { if (!user._id || (this.props.admin && !user.administrator)) {
return <Redirect to='/login' /> return <Redirect to="/login" />
} else { } else {
return <Route {...this.props} /> return <Route {...this.props} />
} }

View File

@@ -13,9 +13,9 @@ import {
} from "react-native" } from "react-native"
import MapView, { Marker, Callout } from "react-native-maps" import MapView, { Marker, Callout } from "react-native-maps"
import { Icon, Header, Geolocation } from "../ui" import { Icon, Header, Geolocation } from "../ui"
import { MessageModal } from "../Modal" import { MessageModal, WaitModal } from "../Modal"
import { api } from "../API" import { api } from "../API"
import autobind from "autobind-decorator" import { reactAutoBind } from "auto-bind2"
import { ifIphoneX } from "react-native-iphone-x-helper" import { ifIphoneX } from "react-native-iphone-x-helper"
import { import {
geoDistance, geoDistance,
@@ -39,14 +39,19 @@ const neverAskForCameraKeyName = "NeverAskForCameraPermission"
export class Home extends React.Component { export class Home extends React.Component {
constructor(props) { constructor(props) {
super(props) super(props)
reactAutoBind(this)
this.state = { this.state = {
waitModal: null,
messageModal: null,
sections: [], sections: [],
showWorkItems: true, showWorkItems: true,
region: config.initialRegion,
haveCameraPermission: false, haveCameraPermission: false,
haveLocationPermission: false, haveLocationPermission: false,
currentPosition: null, currentPosition: null,
} }
this.isMapReady = false
this.goToRegionWhenReady = false
this.region = null
if (Platform.OS !== "ios") { if (Platform.OS !== "ios") {
ensurePermissions( ensurePermissions(
@@ -94,7 +99,14 @@ export class Home extends React.Component {
this.state.haveLocationPermission = true this.state.haveLocationPermission = true
this.state.haveCameraPermission = true this.state.haveCameraPermission = true
} }
}
componentDidMount() {
this.loadWorkItems()
}
loadWorkItems() {
this.setState({ waitModal: { message: "Loading Work Items..." } })
api api
.listTeams() .listTeams()
.then((list) => { .then((list) => {
@@ -102,6 +114,8 @@ export class Home extends React.Component {
return api.listWorkItemActivities() return api.listWorkItemActivities()
}) })
.then((list) => { .then((list) => {
this.setState({ waitModal: null })
list.items.forEach((item) => { list.items.forEach((item) => {
item.data.forEach((datum) => { item.data.forEach((datum) => {
const team = this.teams.find((team) => team._id === datum.team) const team = this.teams.find((team) => team._id === datum.team)
@@ -111,15 +125,23 @@ export class Home extends React.Component {
}) })
this.setState({ this.setState({
sections: list.items, sections: list.items,
region:
regionContainingPoints(
list.items.map((item) => item.coordinate),
0.02
) || this.state.region,
}) })
this.region =
regionContainingPoints(
list.items.map((item) => item.coordinate),
config.homeRegionInset
) || config.initialRegion
if (this.isMapReady) {
this.mapView.animateToRegion(this.region)
} else {
this.goToRegionWhenReady = true
}
}) })
.catch((err) => { .catch((err) => {
this.setState({ this.setState({
waitModal: null,
messageModal: { messageModal: {
icon: "hand", icon: "hand",
message: "Unable to get a list of work items, activities and teams", message: "Unable to get a list of work items, activities and teams",
@@ -129,12 +151,19 @@ export class Home extends React.Component {
}) })
} }
@autobind
handleMessageDismiss() { handleMessageDismiss() {
this.setState({ messageModal: null }) this.setState({ messageModal: null })
} }
@autobind handleOnMapReady() {
if (this.goToRegionWhenReady) {
this.mapView.animateToRegion(this.region)
this.goToRegionWhenReady = false
}
this.isMapReady = true
}
handleMarkerPress(e, sectionIndex) { handleMarkerPress(e, sectionIndex) {
if (this.sectionList) { if (this.sectionList) {
this.sectionList.scrollToLocation({ this.sectionList.scrollToLocation({
@@ -145,7 +174,6 @@ export class Home extends React.Component {
} }
} }
@autobind
handleWorkItemsListPress() { handleWorkItemsListPress() {
if (this.currentPosition) { if (this.currentPosition) {
const { coords } = this.currentPosition const { coords } = this.currentPosition
@@ -156,29 +184,30 @@ export class Home extends React.Component {
} }
} }
@autobind
handleItemSelect(activity) { handleItemSelect(activity) {
this.props.history.push(`/activity?id=${activity._id}`) this.props.history.push(`/activity?id=${activity._id}`)
} }
@autobind
handleSectionSelect(workItem) { handleSectionSelect(workItem) {
if (!this.isMapReady) {
return
}
const { latitude, longitude } = workItem.coordinate const { latitude, longitude } = workItem.coordinate
const region = {
this.region = {
latitude, latitude,
longitude, longitude,
latitudeDelta: 0.01, latitudeDelta: config.homeRegionDelta,
longitudeDelta: 0.01, longitudeDelta: config.homeRegionDelta,
} }
this.setState({ region }) this.mapView.animateToRegion(this.region)
} }
@autobind
handleLogoutPress() { handleLogoutPress() {
this.props.history.replace("/logout") this.props.history.replace("/logout")
} }
@autobind
handleGlassesPress() { handleGlassesPress() {
const { sections: workItems } = this.state const { sections: workItems } = this.state
@@ -217,24 +246,27 @@ export class Home extends React.Component {
} }
} }
@autobind
handleMyLocationPress() { handleMyLocationPress() {
if (this.currentPosition) { if (this.currentPosition && this.isMapReady) {
const coords = this.currentPosition.coords const coords = this.currentPosition.coords
this.map.animateToCoordinate({ this.mapView.animateToCoordinate({
latitude: coords.latitude, latitude: coords.latitude,
longitude: coords.longitude, longitude: coords.longitude,
}) })
} }
} }
@autobind
handleToggleWorkItemsList() { handleToggleWorkItemsList() {
this.setState({ showWorkItems: !this.state.showWorkItems }) const newShowWorkItems = !this.state.showWorkItems
this.setState({ showWorkItems: newShowWorkItems })
if (newShowWorkItems) {
this.loadWorkItems()
}
} }
@autobind
handleCalloutPress(workItem) { handleCalloutPress(workItem) {
if (api.loggedInUser.administrator) { if (api.loggedInUser.administrator) {
this.props.history.push( this.props.history.push(
@@ -245,12 +277,10 @@ export class Home extends React.Component {
} }
} }
@autobind
handlePositionUpdate(position) { handlePositionUpdate(position) {
this.currentPosition = position this.currentPosition = position
} }
@autobind
getCoordinateDistance(coordinate) { getCoordinateDistance(coordinate) {
if (this.currentPosition) { if (this.currentPosition) {
const coords = this.currentPosition.coords const coords = this.currentPosition.coords
@@ -274,8 +304,8 @@ export class Home extends React.Component {
const { const {
sections, sections,
showWorkItems, showWorkItems,
region,
messageModal, messageModal,
waitModal,
haveCameraPermission, haveCameraPermission,
haveLocationPermission, haveLocationPermission,
} = this.state } = this.state
@@ -295,7 +325,7 @@ export class Home extends React.Component {
/> />
<MapView <MapView
ref={(ref) => { ref={(ref) => {
this.map = ref this.mapView = ref
}} }}
style={[ style={[
{ {
@@ -310,7 +340,8 @@ export class Home extends React.Component {
showsIndoors={false} showsIndoors={false}
zoomControlEnabled={false} zoomControlEnabled={false}
showsMyLocationButton={false} showsMyLocationButton={false}
region={region}> initialRegion={config.initialRegion}
onMapReady={this.handleOnMapReady}>
{sections.map((workItem, index) => ( {sections.map((workItem, index) => (
<Marker <Marker
key={index} key={index}
@@ -479,6 +510,10 @@ export class Home extends React.Component {
{haveLocationPermission && ( {haveLocationPermission && (
<Geolocation onUpdate={this.handlePositionUpdate} /> <Geolocation onUpdate={this.handlePositionUpdate} />
)} )}
<WaitModal
open={!!waitModal}
message={waitModal ? waitModal.message : ""}
/>
<MessageModal <MessageModal
open={!!messageModal} open={!!messageModal}
icon={messageModal ? messageModal.icon : ""} icon={messageModal ? messageModal.icon : ""}

View File

@@ -3,7 +3,7 @@ import Modal from "react-native-modal"
import PropTypes from "prop-types" import PropTypes from "prop-types"
import { View, Text, TouchableOpacity } from "react-native" import { View, Text, TouchableOpacity } from "react-native"
import { Icon, OptionStrip } from "../ui" import { Icon, OptionStrip } from "../ui"
import autobind from "autobind-decorator" import { reactAutoBind } from "auto-bind2"
import { api } from "../API" import { api } from "../API"
export class ApiModal extends Component { export class ApiModal extends Component {
@@ -14,12 +14,12 @@ export class ApiModal extends Component {
constructor(props) { constructor(props) {
super(props) super(props)
reactAutoBind(this)
this.state = { this.state = {
value: api.backend, value: api.backend,
} }
} }
@autobind
handleButtonPress() { handleButtonPress() {
const { onDismiss } = this.props const { onDismiss } = this.props
@@ -28,7 +28,6 @@ export class ApiModal extends Component {
} }
} }
@autobind
handleValueChanged(newValue) { handleValueChanged(newValue) {
this.setState({ value: newValue }) this.setState({ value: newValue })
} }

View File

@@ -3,7 +3,7 @@ import Modal from "react-native-modal"
import PropTypes from "prop-types" import PropTypes from "prop-types"
import { View, Image, TouchableOpacity } from "react-native" import { View, Image, TouchableOpacity } from "react-native"
import { Icon } from "../ui" import { Icon } from "../ui"
import autobind from "autobind-decorator" import { reactAutoBind } from "auto-bind2"
export class ImageViewerModal extends Component { export class ImageViewerModal extends Component {
static propTypes = { static propTypes = {
@@ -12,7 +12,11 @@ export class ImageViewerModal extends Component {
onDismiss: PropTypes.func, onDismiss: PropTypes.func,
} }
@autobind constructor(props) {
super(props)
reactAutoBind(this)
}
handleButtonPress() { handleButtonPress() {
const { onDismiss } = this.props const { onDismiss } = this.props

View File

@@ -3,7 +3,7 @@ import Modal from "react-native-modal"
import PropTypes from "prop-types" import PropTypes from "prop-types"
import { View, Text, TouchableOpacity } from "react-native" import { View, Text, TouchableOpacity } from "react-native"
import { Icon } from "../ui" import { Icon } from "../ui"
import autobind from "autobind-decorator" import { reactAutoBind } from "auto-bind2"
export class MessageModal extends Component { export class MessageModal extends Component {
static propTypes = { static propTypes = {
@@ -14,7 +14,11 @@ export class MessageModal extends Component {
onDismiss: PropTypes.func, onDismiss: PropTypes.func,
} }
@autobind constructor(props) {
super(props)
reactAutoBind(this)
}
handleButtonPress() { handleButtonPress() {
if (this.props.onDismiss) { if (this.props.onDismiss) {
this.props.onDismiss() this.props.onDismiss()

View File

@@ -3,7 +3,6 @@ import Modal from "react-native-modal"
import PropTypes from "prop-types" import PropTypes from "prop-types"
import { View, Text, ActivityIndicator, TouchableOpacity } from "react-native" import { View, Text, ActivityIndicator, TouchableOpacity } from "react-native"
import { ProgressBar } from "../ui" import { ProgressBar } from "../ui"
import autobind from "autobind-decorator"
export class ProgressModal extends Component { export class ProgressModal extends Component {
static propTypes = { static propTypes = {

View File

@@ -23,7 +23,7 @@ import {
Geolocation, Geolocation,
} from "../ui" } from "../ui"
import { MessageModal, ProgressModal, WaitModal } from "../Modal" import { MessageModal, ProgressModal, WaitModal } from "../Modal"
import autobind from "autobind-decorator" import { reactAutoBind } from "auto-bind2"
import { ifIphoneX, isIphoneX } from "react-native-iphone-x-helper" import { ifIphoneX, isIphoneX } from "react-native-iphone-x-helper"
import KeyboardSpacer from "react-native-keyboard-spacer" import KeyboardSpacer from "react-native-keyboard-spacer"
import { api } from "../API" import { api } from "../API"
@@ -93,36 +93,46 @@ export class WorkItem extends React.Component {
constructor(props) { constructor(props) {
super(props) super(props)
reactAutoBind(this)
this.state = { this.state = {
binder: new FormBinder({}, WorkItem.bindings), binder: new FormBinder({}, WorkItem.bindings),
messageModal: null, messageModal: null,
waitModal: null, waitModal: null,
progressModal: null, progressModal: null,
region: config.initialRegion,
} }
this.region = null
this.isMapReady = false
this.goToRegionWhenReady = false
}
componentDidMount() {
const { search } = this.props.location const { search } = this.props.location
const params = search ? new URLSearchParams(search) : { get: () => null } const params = search ? new URLSearchParams(search) : { get: () => null }
const id = params.get("id") const id = params.get("id")
if (id) { if (id) {
this.setState({ waitModal: { message: "Loading Work Item..." } })
api api
.getWorkItem(id) .getWorkItem(id)
.then((workItem) => { .then((workItem) => {
this.setState({ waitModal: null })
if (workItem) { if (workItem) {
const [longitude, latitude] = workItem.location.coordinates const [longitude, latitude] = workItem.location.coordinates
const region = {
this.region = {
latitude, latitude,
longitude, longitude,
latitudeDelta: 0.01, latitudeDelta: config.workItemRegionDelta,
longitudeDelta: 0.01, longitudeDelta: config.workItemRegionDelta,
} }
if (this.mapView) { if (this.isMapReady) {
this.mapView.animateToRegion(region) this.mapView.animateToRegion(this.region)
} else { } else {
this.goToRegion = region this.goToRegionWhenReady = true
} }
this.setState({ this.setState({
@@ -132,6 +142,7 @@ export class WorkItem extends React.Component {
}) })
.catch((err) => { .catch((err) => {
this.setState({ this.setState({
waitModal: null,
messageModal: { messageModal: {
icon: "hand", icon: "hand",
message: "Unable to get work item details", message: "Unable to get work item details",
@@ -149,7 +160,6 @@ export class WorkItem extends React.Component {
} }
} }
@autobind
handleBackPress() { handleBackPress() {
const { history } = this.props const { history } = this.props
@@ -160,19 +170,22 @@ export class WorkItem extends React.Component {
} }
} }
@autobind
handleDonePress() { handleDonePress() {
const { binder } = this.state const { binder } = this.state
let obj = binder.getModifiedBindingValues() let obj = binder.getModifiedBindingValues()
this.setState({ waitModal: { message: "Creating Work Item..." } })
if (!obj._id) { if (!obj._id) {
api api
.createWorkItem(obj) .createWorkItem(obj)
.then((workItem) => { .then((workItem) => {
this.setState({ waitModal: null })
this.handleBackPress() this.handleBackPress()
}) })
.catch((error) => { .catch((error) => {
this.setState({ this.setState({
waitModal: null,
messageModal: { messageModal: {
icon: "hand", icon: "hand",
message: "Unable to create work item", message: "Unable to create work item",
@@ -188,6 +201,7 @@ export class WorkItem extends React.Component {
}) })
.catch((error) => { .catch((error) => {
this.setState({ this.setState({
waitModal: null,
messageModal: { messageModal: {
icon: "hand", icon: "hand",
message: "Unable to update work item", message: "Unable to update work item",
@@ -198,7 +212,6 @@ export class WorkItem extends React.Component {
} }
} }
@autobind
handleMessageDismiss() { handleMessageDismiss() {
const back = this.state.messageModal.back const back = this.state.messageModal.back
this.setState({ messageModal: null }) this.setState({ messageModal: null })
@@ -207,10 +220,16 @@ export class WorkItem extends React.Component {
} }
} }
@autobind
handleRegionChange(region) { handleRegionChange(region) {
if (!this.isMapReady) {
// On iOS we get this after setting the initial region, before the map declared as ready!
return
}
const { latitude, longitude } = region const { latitude, longitude } = region
this.region = region
if (this.latLngInput) { if (this.latLngInput) {
this.latLngInput.handleChangeText(formatLatLng(latitude, longitude)) this.latLngInput.handleChangeText(formatLatLng(latitude, longitude))
} }
@@ -226,15 +245,15 @@ export class WorkItem extends React.Component {
) )
} }
@autobind
handleOnMapReady() { handleOnMapReady() {
if (this.goToRegion && this.mapView) { if (this.goToRegionWhenReady) {
this.mapView.animateToRegion(this.goToRegion) this.mapView.animateToRegion(this.region)
this.goToRegion = null this.goToRegionWhenReady = false
} }
this.isMapReady = true
} }
@autobind
handleStartAddressLookup(latLng) { handleStartAddressLookup(latLng) {
api api
.getAddress(latLng) .getAddress(latLng)
@@ -250,7 +269,6 @@ export class WorkItem extends React.Component {
}) })
} }
@autobind
handleUploadStarted() { handleUploadStarted() {
this.setState({ this.setState({
progressModal: { message: "Uploading Photo..." }, progressModal: { message: "Uploading Photo..." },
@@ -258,7 +276,6 @@ export class WorkItem extends React.Component {
}) })
} }
@autobind
handleUploadProgress(uploadData) { handleUploadProgress(uploadData) {
if (this.state.progressModal) { if (this.state.progressModal) {
this.setState({ this.setState({
@@ -272,35 +289,36 @@ export class WorkItem extends React.Component {
} }
} }
@autobind
handleUploadEnded(successful, uploadData) { handleUploadEnded(successful, uploadData) {
this.setState({ progressModal: null }) this.setState({ progressModal: null })
this.mapView.animateToRegion(this.region)
} }
@autobind
handleUploadCanceled() { handleUploadCanceled() {
this.setState({ progressModal: null }) this.setState({ progressModal: null })
} }
@autobind
handleAddActivity() { handleAddActivity() {
if (this.props.history) { if (this.props.history) {
this.props.history.push(`/activity?workItemId=${this.state.binder._id}`) this.props.history.push(`/activity?workItemId=${this.state.binder._id}`)
} }
} }
@autobind
handlePositionUpdate(position) { handlePositionUpdate(position) {
const { coords } = position const { coords } = position
this.setState({ this.region = {
region: { latitude: coords.latitude,
latitude: coords.latitude, longitude: coords.longitude,
longitude: coords.longitude, latitudeDelta: config.workItemRegionDelta,
latitudeDelta: 0.02, longitudeDelta: config.workItemRegionDelta,
longitudeDelta: 0.02, }
},
}) if (this.isMapReady) {
this.mapView.animateToRegion(this.region)
} else {
this.goToRegionWhenReady = true
}
} }
render() { render() {
@@ -310,7 +328,6 @@ export class WorkItem extends React.Component {
waitModal, waitModal,
progressModal, progressModal,
uploadPercent, uploadPercent,
region,
} = this.state } = this.state
return ( return (
@@ -358,10 +375,11 @@ export class WorkItem extends React.Component {
rotateEnabled={false} rotateEnabled={false}
pitchEnabled={false} pitchEnabled={false}
showsUserLocation showsUserLocation
showsMyLocationButton
showsBuildings={false} showsBuildings={false}
showsTraffic={false} showsTraffic={false}
showsIndoors={false} showsIndoors={false}
region={region} initialRegion={config.initialRegion}
onRegionChange={this.handleRegionChange} onRegionChange={this.handleRegionChange}
onMapReady={this.handleOnMapReady} onMapReady={this.handleOnMapReady}
/> />

View File

@@ -10,7 +10,7 @@ import {
} from "react-native" } from "react-native"
import { Icon, Header } from "../ui" import { Icon, Header } from "../ui"
import { MessageModal } from "../Modal" import { MessageModal } from "../Modal"
import autobind from "autobind-decorator" import { reactAutoBind } from "auto-bind2"
import { SwipeListView } from "react-native-swipe-list-view" import { SwipeListView } from "react-native-swipe-list-view"
import { api } from "../API" import { api } from "../API"
import { import {
@@ -36,6 +36,7 @@ const styles = StyleSheet.create({
export class WorkItemList extends React.Component { export class WorkItemList extends React.Component {
constructor(props) { constructor(props) {
super(props) super(props)
reactAutoBind(this)
this.state = { this.state = {
messageModal: null, messageModal: null,
} }
@@ -74,12 +75,10 @@ export class WorkItemList extends React.Component {
}) })
} }
@autobind
handleItemSelect(item, ref) { handleItemSelect(item, ref) {
this.props.history.push(`/workItem?id=${item._id}`) this.props.history.push(`/workItem?id=${item._id}`)
} }
@autobind
handleItemDelete(item, ref) { handleItemDelete(item, ref) {
api api
.deleteWorkItem(item._id) .deleteWorkItem(item._id)
@@ -110,17 +109,14 @@ export class WorkItemList extends React.Component {
}) })
} }
@autobind
handleMessageDismiss() { handleMessageDismiss() {
this.setState({ messageModal: null }) this.setState({ messageModal: null })
} }
@autobind
handleDonePress() { handleDonePress() {
this.props.history.push("/workItem") this.props.history.push("/workItem")
} }
@autobind
handleBackPress() { handleBackPress() {
const { history } = this.props const { history } = this.props

View File

@@ -2,16 +2,22 @@ import React from "react"
import { Platform } from "react-native" import { Platform } from "react-native"
export const config = { export const config = {
localIPAddr: "192.168.1.175", //localIPAddr: "192.168.1.175",
//localIPAddr: "192.168.1.14", localIPAddr: "192.168.1.14",
viroAPIKey: "06F37B6A-74DA-4A83-965A-7DE2209A5C46", viroAPIKey: "06F37B6A-74DA-4A83-965A-7DE2209A5C46",
googleGeocodeAPIKey: "AIzaSyCs4JVT6gysnY5dAJ7KjVJYeykLv_xz1GI", googleGeocodeAPIKey: "AIzaSyCs4JVT6gysnY5dAJ7KjVJYeykLv_xz1GI",
googleGeocodeURL: "https://maps.googleapis.com/maps/api/geocode/json", googleGeocodeURL: "https://maps.googleapis.com/maps/api/geocode/json",
refererURL: "https://dar.kss.us.com", refererURL: "https://dar.kss.us.com",
minDistanceToItem: 20, minDistanceToItem: 20,
workItemRegionDelta: 0.005,
activityRegionDelta: 0.005,
homeRegionInset: 0.02,
homeRegionDelta: 0.005,
geocodeDelayMilliseconds: 500, geocodeDelayMilliseconds: 500,
//defaultUser: "john@lyon-smith.org", //defaultUser: "john@lyon-smith.org",
defaultUser: "", defaultUser: "",
// This region is downtown Toronto // This region is downtown Toronto
initialRegion: { initialRegion: {
latitude: 43.653908, latitude: 43.653908,
@@ -19,6 +25,7 @@ export const config = {
latitudeDelta: 0.0922, latitudeDelta: 0.0922,
longitudeDelta: 0.0421, longitudeDelta: 0.0421,
}, },
// This region is Bainbridge Island // This region is Bainbridge Island
// initialRegion: { // initialRegion: {
// latitude: 47.629536, // latitude: 47.629536,
@@ -26,5 +33,6 @@ export const config = {
// latitudeDelta: 0.0922, // latitudeDelta: 0.0922,
// longitudeDelta: 0.0421, // longitudeDelta: 0.0421,
// }, // },
// alwaysShowWorkItemInAR: true, // alwaysShowWorkItemInAR: true,
} }

View File

@@ -1,7 +1,7 @@
import React from "react" import React from "react"
import PropTypes from "prop-types" import PropTypes from "prop-types"
import { View, Text, TouchableHighlight } from "react-native" import { View, Text, TouchableHighlight } from "react-native"
import autobind from "autobind-decorator" import { reactAutoBind } from "auto-bind2"
export class BoundButton extends React.Component { export class BoundButton extends React.Component {
static propTypes = { static propTypes = {
@@ -14,6 +14,7 @@ export class BoundButton extends React.Component {
constructor(props) { constructor(props) {
super(props) super(props)
reactAutoBind(this)
const { name, binder } = this.props const { name, binder } = this.props
@@ -21,7 +22,6 @@ export class BoundButton extends React.Component {
this.state = binder.getBindingState(name) this.state = binder.getBindingState(name)
} }
@autobind
updateValue(e) { updateValue(e) {
this.setState(e.state) this.setState(e.state)
} }

View File

@@ -1,7 +1,7 @@
import React from "react" import React from "react"
import PropTypes from "prop-types" import PropTypes from "prop-types"
import { Header } from "." import { Header } from "."
import autobind from "autobind-decorator" import { reactAutoBind } from "auto-bind2"
const headerButtonShape = { const headerButtonShape = {
icon: PropTypes.string.isRequired, icon: PropTypes.string.isRequired,
@@ -19,6 +19,7 @@ export class BoundHeader extends React.Component {
constructor(props) { constructor(props) {
super(props) super(props)
reactAutoBind(this)
const { name, binder } = this.props const { name, binder } = this.props
@@ -26,7 +27,6 @@ export class BoundHeader extends React.Component {
this.state = binder.getBindingState(name) this.state = binder.getBindingState(name)
} }
@autobind
updateValue(e) { updateValue(e) {
this.setState(e.state) this.setState(e.state)
} }

View File

@@ -1,7 +1,7 @@
import React from "react" import React from "react"
import PropTypes from "prop-types" import PropTypes from "prop-types"
import { TextInput, Text, View, Platform } from "react-native" import { TextInput, Text, View, Platform } from "react-native"
import autobind from "autobind-decorator" import { reactAutoBind } from "auto-bind2"
export class BoundInput extends React.Component { export class BoundInput extends React.Component {
static propTypes = { static propTypes = {
@@ -20,11 +20,11 @@ export class BoundInput extends React.Component {
constructor(props) { constructor(props) {
super(props) super(props)
reactAutoBind(this)
const { name, binder } = this.props const { name, binder } = this.props
this.state = binder.getBindingState(name) this.state = binder.getBindingState(name)
this.handleChangeText = this.handleChangeText.bind(this)
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
@@ -33,7 +33,6 @@ export class BoundInput extends React.Component {
} }
} }
// @autobind : There seems to be a bug with using this here, so we just do it the old way
handleChangeText(newText) { handleChangeText(newText) {
const { binder, name } = this.props const { binder, name } = this.props

View File

@@ -2,7 +2,7 @@ import React from "react"
import PropTypes from "prop-types" import PropTypes from "prop-types"
import { View, Text } from "react-native" import { View, Text } from "react-native"
import { OptionStrip } from "." import { OptionStrip } from "."
import autobind from "autobind-decorator" import { reactAutoBind } from "auto-bind2"
export class BoundOptionStrip extends React.Component { export class BoundOptionStrip extends React.Component {
static propTypes = { static propTypes = {
@@ -17,10 +17,10 @@ export class BoundOptionStrip extends React.Component {
constructor(props) { constructor(props) {
super(props) super(props)
reactAutoBind(this)
this.state = props.binder.getBindingState(props.name) this.state = props.binder.getBindingState(props.name)
} }
@autobind
handleValueChanged(newValue) { handleValueChanged(newValue) {
this.setState( this.setState(
this.props.binder.updateBindingValue(this.props.name, newValue) this.props.binder.updateBindingValue(this.props.name, newValue)

View File

@@ -12,7 +12,7 @@ import {
import { Icon } from "." import { Icon } from "."
import ImagePicker from "react-native-image-picker" import ImagePicker from "react-native-image-picker"
import ImageResizer from "react-native-image-resizer" import ImageResizer from "react-native-image-resizer"
import autobind from "autobind-decorator" import { reactAutoBind } from "auto-bind2"
import { api } from "../API" import { api } from "../API"
const getScreenPortraitDimensions = () => { const getScreenPortraitDimensions = () => {
@@ -35,10 +35,8 @@ export class BoundPhotoPanel extends Component {
constructor(props) { constructor(props) {
super(props) super(props)
reactAutoBind(this)
const { name, binder } = this.props this.state = this.props.binder.getBindingState(this.props.name)
this.state = binder.getBindingState(name)
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
@@ -47,7 +45,6 @@ export class BoundPhotoPanel extends Component {
} }
} }
@autobind
handlePhotoPress(index) { handlePhotoPress(index) {
const { onUploadStarted, onUploadEnded, onUploadProgress } = this.props const { onUploadStarted, onUploadEnded, onUploadProgress } = this.props
@@ -98,7 +95,6 @@ export class BoundPhotoPanel extends Component {
) )
} }
@autobind
handleLayout(e) { handleLayout(e) {
if (!this.state.photoSize) { if (!this.state.photoSize) {
const { layout } = e.nativeEvent const { layout } = e.nativeEvent

View File

@@ -1,7 +1,7 @@
import React from "react" import React from "react"
import PropTypes from "prop-types" import PropTypes from "prop-types"
import { View, Switch, Text } from "react-native" import { View, Switch, Text } from "react-native"
import autobind from "autobind-decorator" import { reactAutoBind } from "auto-bind2"
export class BoundSwitch extends React.Component { export class BoundSwitch extends React.Component {
static propTypes = { static propTypes = {
@@ -12,10 +12,10 @@ export class BoundSwitch extends React.Component {
constructor(props) { constructor(props) {
super(props) super(props)
reactAutoBind(this)
this.state = props.binder.getBindingState(props.name) this.state = props.binder.getBindingState(props.name)
} }
@autobind
handleValueChange(newValue) { handleValueChange(newValue) {
const { binder, name } = this.props const { binder, name } = this.props
const state = binder.getBindingState(name) const state = binder.getBindingState(name)

View File

@@ -1,7 +1,6 @@
import React from "react" import React from "react"
import PropTypes from "prop-types" import PropTypes from "prop-types"
import { TextInput, Text, View, Platform } from "react-native" import { TextInput, Text, View, Platform } from "react-native"
import autobind from "autobind-decorator"
export class FormStaticInput extends React.Component { export class FormStaticInput extends React.Component {
static propTypes = { static propTypes = {

View File

@@ -1,7 +1,6 @@
import React, { Component } from "react" import React, { Component } from "react"
import { Image, View } from "react-native" import { Image, View } from "react-native"
import PropTypes from "prop-types" import PropTypes from "prop-types"
import autobind from "autobind-decorator"
export class Geolocation extends Component { export class Geolocation extends Component {
static propTypes = { static propTypes = {

View File

@@ -1,7 +1,7 @@
import React, { Component } from "react" import React, { Component } from "react"
import { View, Text, TouchableHighlight } from "react-native" import { View, Text, TouchableHighlight } from "react-native"
import PropTypes from "prop-types" import PropTypes from "prop-types"
import autobind from "autobind-decorator" import { reactAutoBind } from "auto-bind2"
export class OptionStrip extends Component { export class OptionStrip extends Component {
static propTypes = { static propTypes = {
@@ -14,12 +14,12 @@ export class OptionStrip extends Component {
constructor(props) { constructor(props) {
super(props) super(props)
reactAutoBind(this)
this.state = { this.state = {
selectedOption: this.getSelectedOption(props.options, props.value), selectedOption: this.getSelectedOption(props.options, props.value),
} }
} }
@autobind
getSelectedOption(options, value) { getSelectedOption(options, value) {
return options.find((option) => value === option.value) || null return options.find((option) => value === option.value) || null
} }
@@ -38,7 +38,6 @@ export class OptionStrip extends Component {
} }
} }
@autobind
handlePress(option) { handlePress(option) {
const { onValueChanged } = this.props const { onValueChanged } = this.props

View File

@@ -1,6 +1,6 @@
export const versionInfo = { export const versionInfo = {
version: '1.0.2', version: '1.2.0',
fullVersion: '1.0.2-20180518.0', fullVersion: '1.2.0-20180531.0',
title: 'Deighton AR System', title: 'Deighton AR System',
copyright: '© 2018, Kingston Software Solutions.', copyright: '© 2018, Kingston Software Solutions.',
supportEmail: 'support@kss.us.com', supportEmail: 'support@kss.us.com',

View File

@@ -1,6 +1,6 @@
{ {
"name": "deighton-ar", "name": "deighton-ar",
"version": "1.0.2", "version": "1.2.0",
"description": "Deighton AR Training System", "description": "Deighton AR Training System",
"main": "index.js", "main": "index.js",
"repository": { "repository": {

View File

@@ -12,7 +12,7 @@ server {
# Any route that starts with /api/ is for the backend # Any route that starts with /api/ is for the backend
location /api/ { location /api/ {
error_page 502 503 $scheme://$server_name/500.json; error_page 502 503 504 $scheme://$server_name/500.json;
proxy_pass http://127.0.0.1:3006/; proxy_pass http://127.0.0.1:3006/;
proxy_buffering off; proxy_buffering off;

View File

@@ -7,7 +7,7 @@
"start": "babel-node src/server.js", "start": "babel-node src/server.js",
"start:prod": "NODE_ENV=production node dist/server.js", "start:prod": "NODE_ENV=production node dist/server.js",
"build": "rm -rf dist && babel src -d dist -s", "build": "rm -rf dist && babel src -d dist -s",
"deploy": "rsync -vr -e ssh --exclude-from .rsync-exclude * $SNAP_DEPLOY_USER@$SNAP_DEPLOY_HOST:deighton-ar-server/ && ssh $SNAP_DEPLOY_USER@$SNAP_DEPLOY_HOST 'cd deighton-ar-server; npm install; sudo ./ops restart; sudo ./ops --test restart'", "deploy": "rsync -vr -e ssh --exclude-from .rsync-exclude * $SNAP_DEPLOY_USER_HOST:deighton-ar-server/ && ssh $SNAP_DEPLOY_USER_HOST 'cd deighton-ar-server; npm install; sudo ./ops restart; sudo ./ops --test restart'",
"test": "jest", "test": "jest",
"actor:api": "monzilla 'src/api/**/*.js:src/database/**/*.js' -- babel-node src/api/index.js", "actor:api": "monzilla 'src/api/**/*.js:src/database/**/*.js' -- babel-node src/api/index.js",
"actor:api:debug": "babel-node --inspect-brk src/api/index.js", "actor:api:debug": "babel-node --inspect-brk src/api/index.js",

View File

@@ -6,7 +6,11 @@ import { catchAll, TeamRoutes, BaseRoutes } from "."
@autobind @autobind
export class ActivityRoutes extends BaseRoutes { export class ActivityRoutes extends BaseRoutes {
constructor(container) { constructor(container) {
super(container, container.db.Activity) super({
container,
model: container.db.Activity,
nonAdmin: { listItems: true, createItem: true, getItem: true },
})
const app = container.app const app = container.app
@@ -19,6 +23,12 @@ export class ActivityRoutes extends BaseRoutes {
} }
async deleteAllActivities(req, res, next) { async deleteAllActivities(req, res, next) {
const isAdmin = !!req.user.administrator
if (!isAdmin) {
throw createError.Forbidden()
}
const Activity = this.db.Activity const Activity = this.db.Activity
const Team = this.db.Team const Team = this.db.Team

View File

@@ -3,14 +3,23 @@ import createError from "http-errors"
import autobind from "autobind-decorator" import autobind from "autobind-decorator"
import { catchAll } from "." import { catchAll } from "."
// The list of functions you can list in options.nonAdmin is:
//
// listItems
// createItem
// updateItem
// getItem
// deleteItem
@autobind @autobind
export class BaseRoutes { export class BaseRoutes {
constructor(container, model) { constructor(options) {
this.model = model const { container } = options
this.options = options
this.log = container.log this.log = container.log
this.db = container.db this.db = container.db
const basePath = "/" + model.collection.collectionName const basePath = "/" + options.model.collection.collectionName
const app = container.app const app = container.app
app app
@@ -41,7 +50,13 @@ export class BaseRoutes {
} }
async listItems(req, res, next) { async listItems(req, res, next) {
const ItemModel = this.model const isAdmin = !!req.user.administrator
if (!this.options.nonAdmin.listItems && !isAdmin) {
throw createError.Forbidden()
}
const ItemModel = this.options.model
const limit = req.query.limit || 20 const limit = req.query.limit || 20
const skip = req.query.skip || 0 const skip = req.query.skip || 0
const partial = !!req.query.partial const partial = !!req.query.partial
@@ -74,14 +89,14 @@ export class BaseRoutes {
}) })
} }
async createItem(req, res, next) { async createItem(req, res) {
const isAdmin = req.user.administrator const isAdmin = !!req.user.administrator
if (!isAdmin) { if (!this.options.nonAdmin.createItem && !isAdmin) {
return new createError.Forbidden() throw createError.Forbidden()
} }
const ItemModel = this.model const ItemModel = this.options.model
let item = new ItemModel(req.body) let item = new ItemModel(req.body)
const newItem = await item.save() const newItem = await item.save()
@@ -89,11 +104,11 @@ export class BaseRoutes {
res.json(newItem.toClient()) res.json(newItem.toClient())
} }
async updateItem(req, res, next) { async updateItem(req, res) {
const isAdmin = req.user.administrator const isAdmin = !!req.user.administrator
if (!isAdmin) { if (!this.options.nonAdmin.updateItem && !isAdmin) {
return new createError.Forbidden() throw createError.Forbidden()
} }
// Do this here because Mongoose will add it automatically otherwise // Do this here because Mongoose will add it automatically otherwise
@@ -101,11 +116,11 @@ export class BaseRoutes {
throw createError.BadRequest("No _id given in body") throw createError.BadRequest("No _id given in body")
} }
let ItemModel = this.model let ItemModel = this.options.model
let item = await ItemModel.findById(req.body._id) let item = await ItemModel.findById(req.body._id)
if (!item) { if (!item) {
return next(createError.NotFound(`Item with _id ${_id} was not found`)) throw createError.NotFound(`Item with _id ${_id} was not found`)
} }
item.merge(new ItemModel(req.body)) item.merge(new ItemModel(req.body))
@@ -115,8 +130,14 @@ export class BaseRoutes {
res.json(savedItem.toClient()) res.json(savedItem.toClient())
} }
async getItem(req, res, next) { async getItem(req, res) {
const ItemModel = this.model const isAdmin = !!req.user.administrator
if (!this.options.nonAdmin.getItem && !isAdmin) {
throw createError.Forbidden()
}
const ItemModel = this.options.model
const _id = req.params._id const _id = req.params._id
const item = await ItemModel.findById(_id) const item = await ItemModel.findById(_id)
@@ -127,14 +148,14 @@ export class BaseRoutes {
res.json(item.toClient()) res.json(item.toClient())
} }
async deleteItem(req, res, next) { async deleteItem(req, res) {
const isAdmin = req.user.administrator const isAdmin = !!req.user.administrator
if (!isAdmin) { if (!this.options.nonAdmin.deleteItem && !isAdmin) {
return new createError.Forbidden() throw createError.Forbidden()
} }
const ItemModel = this.model const ItemModel = this.options.model
const _id = req.params._id const _id = req.params._id
const item = await ItemModel.remove({ _id }) const item = await ItemModel.remove({ _id })

View File

@@ -8,7 +8,11 @@ import { catchAll, BaseRoutes } from "."
@autobind @autobind
export class TeamRoutes extends BaseRoutes { export class TeamRoutes extends BaseRoutes {
constructor(container) { constructor(container) {
super(container, container.db.Team) super({
container,
model: container.db.Team,
nonAdmin: { listItems: true, getItem: true },
})
container.app container.app
.route("/teams/status") .route("/teams/status")
@@ -19,6 +23,12 @@ export class TeamRoutes extends BaseRoutes {
} }
async getTeamStatus(req, res, next) { async getTeamStatus(req, res, next) {
const isAdmin = !!req.user.administrator
if (!isAdmin) {
throw createError.Forbidden()
}
const Team = this.db.Team const Team = this.db.Team
const Activity = this.db.Activity const Activity = this.db.Activity
let teams = await Team.find({}).exec() let teams = await Team.find({}).exec()
@@ -41,7 +51,7 @@ export class TeamRoutes extends BaseRoutes {
res.writeHead(200, { res.writeHead(200, {
"Content-Type": "application/gzip", "Content-Type": "application/gzip",
"Content-Disposition": 'attachment; filename="team-scores.gzip"', "Content-Disposition": 'attachment; filename="team-scores.json.gzip"',
}) })
readable.pipe(gzip).pipe(res) readable.pipe(gzip).pipe(res)
} }

View File

@@ -7,7 +7,11 @@ import { catchAll, BaseRoutes } from "."
@autobind @autobind
export class WorkItemRoutes extends BaseRoutes { export class WorkItemRoutes extends BaseRoutes {
constructor(container) { constructor(container) {
super(container, container.db.WorkItem) super({
container,
model: container.db.WorkItem,
nonAdmin: { listItems: true, getItem: true },
})
const app = container.app const app = container.app
app app
@@ -25,6 +29,15 @@ export class WorkItemRoutes extends BaseRoutes {
) )
} }
async deleteItem(req, res, next) {
super.deleteItem(req, res, next)
const id = req.params._id
const Activity = this.db.Activity
await Activity.remove({ workItem: id })
}
async listWorkItemActivities(req, res, next) { async listWorkItemActivities(req, res, next) {
const WorkItem = this.db.WorkItem const WorkItem = this.db.WorkItem
const aggregate = WorkItem.aggregate() const aggregate = WorkItem.aggregate()
@@ -54,6 +67,12 @@ export class WorkItemRoutes extends BaseRoutes {
} }
async deleteAllWorkItems(req, res, next) { async deleteAllWorkItems(req, res, next) {
const isAdmin = !!req.user.administrator
if (!isAdmin) {
throw createError.Forbidden()
}
const Activity = this.db.Activity const Activity = this.db.Activity
const WorkItem = this.db.WorkItem const WorkItem = this.db.WorkItem
const Team = this.db.Team const Team = this.db.Team

View File

@@ -1,6 +1,6 @@
export const versionInfo = { export const versionInfo = {
version: '1.0.2', version: '1.2.0',
fullVersion: '1.0.2-20180518.0', fullVersion: '1.2.0-20180531.0',
title: 'Deighton AR System', title: 'Deighton AR System',
copyright: '© 2018, Kingston Software Solutions.', copyright: '© 2018, Kingston Software Solutions.',
supportEmail: 'support@kss.us.com', supportEmail: 'support@kss.us.com',

View File

@@ -15,11 +15,11 @@
buildFormat: "full", buildFormat: "full",
tags: { tags: {
major: 1, major: 1,
minor: 0, minor: 2,
patch: 2, patch: 0,
build: 20180518, build: 20180531,
revision: 0, revision: 0,
sequence: 5, sequence: 10,
tz: "America/Los_Angeles", tz: "America/Los_Angeles",
title: "Deighton AR System", title: "Deighton AR System",
copyright: "© 2018, Kingston Software Solutions.", copyright: "© 2018, Kingston Software Solutions.",

View File

@@ -62,7 +62,7 @@
"scripts": { "scripts": {
"start": "node scripts/start.js", "start": "node scripts/start.js",
"build": "node scripts/build.js", "build": "node scripts/build.js",
"deploy": "rsync -vr -e ssh build/* $SNAP_DEPLOY_USER@$SNAP_DEPLOY_HOST:deighton-ar-website/", "deploy": "rsync -vr -e ssh build/* $SNAP_DEPLOY_USER_HOST:deighton-ar-website/",
"lint": "eslint --ext .js --ext .jsx src/", "lint": "eslint --ext .js --ext .jsx src/",
"lint:fix": "eslint --ext .js --ext .jsx --fix src/" "lint:fix": "eslint --ext .js --ext .jsx --fix src/"
}, },

View File

@@ -1,6 +1,6 @@
export const versionInfo = { export const versionInfo = {
version: '1.0.2', version: '1.2.0',
fullVersion: '1.0.2-20180518.0', fullVersion: '1.2.0-20180531.0',
title: 'Deighton AR System', title: 'Deighton AR System',
copyright: '© 2018, Kingston Software Solutions.', copyright: '© 2018, Kingston Software Solutions.',
supportEmail: 'support@kss.us.com', supportEmail: 'support@kss.us.com',