Skip to content

Commit

Permalink
Add support to scan QR codes directly from the app
Browse files Browse the repository at this point in the history
This requires support for one new plugin and one new permission (CAMERA)
  • Loading branch information
shankari committed Mar 21, 2018
1 parent 8baba60 commit 34fdc65
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
6 changes: 6 additions & 0 deletions config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@
</plugin>
<plugin name="edu.berkeley.eecs.emission.cordova.auth" spec="https://github.com/e-mission/cordova-jwt-auth.git" />
<preference name="SplashShowOnlyFirstTime" value="false" />
<plugin name="phonegap-plugin-barcodescanner" spec="^7.1.0">
<variable name="ANDROID_SUPPORT_V4_VERSION" value="27.+" />
<edit-config file="*-Info.plist" mode="merge" target="NSCameraUsageDescription">
<string>To scan the barcode for the study</string>
</edit-config>
</plugin>
<engine name="ios" spec="^4.5.4" />
<engine name="android" spec="^6.4.0" />
</widget>
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@
},
"edu.berkeley.eecs.emission.cordova.auth": {},
"cordova-plugin-whitelist": {},
"edu.berkeley.eecs.emission.cordova.transitionnotify": {}
"edu.berkeley.eecs.emission.cordova.transitionnotify": {},
"phonegap-plugin-barcodescanner": {
"ANDROID_SUPPORT_V4_VERSION": "27.+"
}
}
},
"dependencies": {
Expand Down Expand Up @@ -63,6 +66,7 @@
"fs-extra": "^5.0.0",
"ionic-plugin-keyboard": "~2.2.1",
"klaw-sync": "^3.0.2",
"phonegap-plugin-barcodescanner": "^7.1.0",
"phonegap-plugin-push": "~1.9.2"
}
}
1 change: 1 addition & 0 deletions www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="lib/moment/min/moment.min.js"></script>
<script src="lib/moment-timezone/builds/moment-timezone-with-data.min.js"></script>
<script src="lib/string.startsWith/src/string.startsWith.js"></script>
<script src="lib/angular-cookies/angular-cookies.min.js"></script>
<script src="lib/angularLocalStorage/dist/angularLocalStorage.min.js"></script>

Expand Down
29 changes: 26 additions & 3 deletions www/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,36 @@ angular.module('emission.controllers', ['emission.splash.updatecheck',
.controller('DashCtrl', function($scope) {})

.controller('SplashCtrl', function($scope, $state, $interval, $rootScope,
UpdateCheck, PushNotify,
LocalNotify) {
$ionicPlatform, $ionicPopup, UpdateCheck, LocalNotify) {
console.log('SplashCtrl invoked');
// alert("attach debugger!");
// PushNotify.startupInit();
console.log('SplashCtrl invoke finished');
})

$ionicPlatform.ready(function() {
$scope.scanEnabled = true;
});

$scope.scanCode = function() {
if (!$scope.scanEnabled) {
$ionicPopup.alert({template: "plugins not yet initialized, please retry later"});
} else {
cordova.plugins.barcodeScanner.scan(
function (result) {
if (result.format == "QR_CODE" &&
result.cancelled == false &&
result.text.substring(0,11) == "emission://") {
handleOpenURL(result.text);
} else {
$ionicPopup.alert({template: "invalid study reference "+result.text});
}
},
function (error) {
$ionicPopup.alert({template: "Scanning failed: " + error});
});
}
}; // scanCode
}) // controller


.controller('ChatsCtrl', function($scope, Chats) {
Expand Down
5 changes: 5 additions & 0 deletions www/templates/study-text.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@
<div class="intro-space"></div>
</div>
</ion-content>
<ion-footer-bar class="no-bgColor" id="intro-footer">
<button ng-enabled="scanEnabled" class="button button-block button-outline button-positive" ng-click="scanCode()">
Scan now
</button>
</ion-footer-bar>

0 comments on commit 34fdc65

Please sign in to comment.