Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix QR code scanner #28

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ module.exports = function(grunt) {
}
},
vendors: {
src: ['public/src/js/ios-imagefile-megapixel/megapix-image.js', 'public/lib/qrcode-generator/js/qrcode.js', 'public/src/js/jsqrcode/grid.js', 'public/src/js/jsqrcode/version.js', 'public/src/js/jsqrcode/detector.js', 'public/src/js/jsqrcode/formatinf.js', 'public/src/js/jsqrcode/errorlevel.js', 'public/src/js/jsqrcode/bitmat.js', 'public/src/js/jsqrcode/datablock.js', 'public/src/js/jsqrcode/bmparser.js', 'public/src/js/jsqrcode/datamask.js', 'public/src/js/jsqrcode/rsdecoder.js', 'public/src/js/jsqrcode/gf256poly.js', 'public/src/js/jsqrcode/gf256.js', 'public/src/js/jsqrcode/decoder.js', 'public/src/js/jsqrcode/qrcode.js', 'public/src/js/jsqrcode/findpat.js', 'public/src/js/jsqrcode/alignpat.js', 'public/src/js/jsqrcode/databr.js', 'public/lib/momentjs/min/moment.min.js', 'public/lib/moment/lang/es.js', 'public/lib/zeroclipboard/ZeroClipboard.min.js'],
src: ['public/src/js/ios-imagefile-megapixel/megapix-image.js', 'public/lib/qrcode-generator/js/qrcode.js', 'public/src/js/jsqrcode/grid.js', 'public/src/js/jsqrcode/version.js', 'public/src/js/jsqrcode/detector.js', 'public/src/js/jsqrcode/formatinf.js', 'public/src/js/jsqrcode/errorlevel.js', 'public/src/js/jsqrcode/bitmat.js', 'public/src/js/jsqrcode/datablock.js', 'public/src/js/jsqrcode/bmparser.js', 'public/src/js/jsqrcode/datamask.js', 'public/src/js/jsqrcode/rsdecoder.js', 'public/src/js/jsqrcode/gf256poly.js', 'public/src/js/jsqrcode/gf256.js', 'public/src/js/jsqrcode/decoder.js', 'public/src/js/jsqrcode/qrcode.js', 'public/src/js/jsqrcode/findpat.js', 'public/src/js/jsqrcode/alignpat.js', 'public/src/js/jsqrcode/databr.js', 'public/lib/momentjs/min/moment.min.js', 'public/lib/moment/lang/es.js', 'public/lib/zeroclipboard/ZeroClipboard.min.js', 'public/src/js/d3/d3.min.js'],
dest: 'public/js/vendors.js'
},
angular: {
src: ['public/lib/angular/angular.min.js', 'public/lib/angular-resource/angular-resource.min.js', 'public/lib/angular-route/angular-route.min.js', 'public/lib/angular-qrcode/qrcode.js', 'public/lib/angular-animate/angular-animate.min.js', 'public/lib/angular-bootstrap/ui-bootstrap.js', 'public/lib/angular-bootstrap/ui-bootstrap-tpls.js', 'public/lib/angular-ui-utils/ui-utils.min.js', 'public/lib/ngprogress/build/ngprogress.min.js', 'public/lib/angular-gettext/dist/angular-gettext.min.js', 'public/lib/angular-moment/angular-moment.min.js', 'public/lib/angular-ui-router/release/angular-ui-router.js'],
src: ['public/lib/angular/angular.min.js', 'public/lib/angular-resource/angular-resource.min.js', 'public/lib/angular-route/angular-route.min.js', 'public/lib/angular-qrcode/qrcode.js', 'public/lib/angular-animate/angular-animate.min.js', 'public/lib/angular-bootstrap/ui-bootstrap.js', 'public/lib/angular-bootstrap/ui-bootstrap-tpls.js', 'public/lib/angular-ui-utils/ui-utils.min.js', 'public/lib/ngprogress/build/ngprogress.min.js', 'public/lib/angular-gettext/dist/angular-gettext.min.js', 'public/lib/angular-moment/angular-moment.min.js', 'public/lib/angular-ui-router/release/angular-ui-router.js', 'public/lib/angular-d3/angular-d3.min.js'],
dest: 'public/js/angularjs-all.js'
},
main: {
Expand Down
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"angular-ui-utils": "~0.1.1",
"angular-gettext": "~2.3.10",
"angular-moment": "~1.2.0",
"angular-ui-router": "~1.0.6"
"angular-ui-router": "~1.0.6",
"angular-d3": "~0.1.1"
}
}
2 changes: 1 addition & 1 deletion public/css/main.min.css

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions public/js/main.min.js

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions public/src/css/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -912,3 +912,41 @@ fieldset[disabled] .btn-info:hover {
color: #cfe3f4;
background-color: transparent;
}

/* d3 tree Visualization*/

.node circle {
fill: #444;
stroke: #fff;
stroke-width: 1.5px;
}

.node {
font: 10px sans-serif;
}

.link {
fill: none;
stroke: #ccc;
stroke-width: 1.5px;
}

.value {
font-weight:bold;
fill:#008de4;
}

.node .unspentTx {
fill: #8a8a8a;
}

.node .spentTx {
fill: #0478c3;
cursor: pointer;
}

.link {
stroke: lightsteelblue;
stroke-width: 2.5px;
fill-opacity: 0;
}
3 changes: 2 additions & 1 deletion public/src/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ angular.module('insight',[
'insight.status',
'insight.connection',
'insight.currency',
'insight.messages'
'insight.messages',
'd3'
]);

angular.module('insight.system', []);
Expand Down
1 change: 1 addition & 0 deletions public/src/js/controllers/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ angular.module('insight.system').controller('HeaderController',
});

$rootScope.isCollapsed = true;
$rootScope.cameraQRScannerAvailable = true;
});
45 changes: 42 additions & 3 deletions public/src/js/controllers/scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,36 @@ angular.module('insight.system').controller('ScannerController',
}
};

navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
//navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
$scope.getUserMediaNew = false;
$scope.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
if (typeof $scope.getUserMedia === 'undefined' ) {
$scope.getUserMediaNew = true;
$scope.getUserMedia = navigator.mediaDevices;
} else {
if (typeof $scope.getUserMedia.getUserMedia === 'undefined' ) {
$scope.getUserMediaNew = true;
$scope.getUserMedia = navigator.mediaDevices;
}
}
if (typeof $scope.getUserMedia === 'undefined' ) {
//disable menu button
$rootScope.cameraQRScannerAvailable = false;
} else {
$rootScope.cameraQRScannerAvailable = true;
}
var MediaStream = window.MediaStream;
if (typeof MediaStream === 'undefined' && typeof webkitMediaStream !== 'undefined') {
MediaStream = webkitMediaStream;
}
//cross-browser stream.stop (chrome and new firefox)
if (typeof MediaStream !== 'undefined' && !('stop' in MediaStream.prototype)) {
MediaStream.prototype.stop = function() {
this.getVideoTracks().forEach(function(track) {
track.stop();
});
};
}
window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL;

$scope.isMobile = isMobile.any();
Expand Down Expand Up @@ -88,7 +117,11 @@ angular.module('insight.system').controller('ScannerController',
};

var _successCallback = function(stream) {
video.src = (window.URL && window.URL.createObjectURL(stream)) || stream;
if ($scope.getUserMediaNew) {
video.srcObject = stream
} else {
video.src = (window.URL && window.URL.createObjectURL(stream)) || stream;
}
localMediaStream = stream;
video.play();
setTimeout(_scan, 1000);
Expand All @@ -106,6 +139,7 @@ angular.module('insight.system').controller('ScannerController',

var _videoError = function(err) {
console.log('Video Error: ' + JSON.stringify(err));
$rootScope.cameraQRScannerAvailable = false;
_scanStop();
};

Expand All @@ -119,6 +153,10 @@ angular.module('insight.system').controller('ScannerController',
.triggerHandler('change')
.triggerHandler('submit');
};

$scope.global.modalInstance.result.then(function(){}, function(){
_scanStop();
});

$scope.cancel = function() {
_scanStop();
Expand All @@ -142,7 +180,8 @@ angular.module('insight.system').controller('ScannerController',
canvas.height = 225;
context.clearRect(0, 0, 300, 225);

navigator.getUserMedia({video: true}, _successCallback, _videoError);
//navigator.getUserMedia({video: true}, _successCallback, _videoError);
$scope.getUserMedia.getUserMedia({video: true}).then(_successCallback).catch(_videoError);
}
}, 500);
});
Expand Down
93 changes: 57 additions & 36 deletions public/src/js/controllers/search.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
'use strict';

angular.module('insight.search').controller('SearchController',
function($scope, $routeParams, $location, $timeout, Global, Block, Transaction, Address, BlockByHeight) {
function($scope, $routeParams, $location, $timeout, Global, Block, Transaction, Address, BlockByHeight, Search) {
$scope.global = Global;
$scope.loading = false;
//to avoid eval for security reasons
$scope.factories = {Block: Block, Transaction: Transaction, Address: Address, BlockByHeight: BlockByHeight};

var _badQuery = function() {
$scope.badQuery = true;
Expand All @@ -17,47 +19,66 @@ angular.module('insight.search').controller('SearchController',
$scope.q = '';
$scope.loading = false;
};

$scope.swap = function(theArray, indexA, indexB) {
var temp = theArray[indexA];
theArray[indexA] = theArray[indexB];
theArray[indexB] = temp;
};

$scope.defineSearchType = function(searchString) {
var searchArray = [
{factory: 'Block', object: 'blockHash', path: 'block/'},
{factory: 'Transaction', object:'txId', path: 'tx/'},
{factory: 'Address', object: 'addrStr', path: 'address/'},
{factory: 'BlockByHeight', object: 'blockHeight', path: 'block/'}
];
if (searchString.length == 64) {
if (!searchString.match(/^00/)) {
$scope.swap(searchArray, 0, 1);
}
} else if (searchString.length == 38 || searchString.length === 34) {
$scope.swap(searchArray, 0, 2);
}
if (isFinite(searchString)) {
$scope.swap(searchArray, 0, 3);
}
return searchArray
}

$scope.traverseSearch = function(searchTypeArray, q) {
if (searchTypeArray.length) {
var searchTypeObj = {};
searchTypeObj[searchTypeArray[0].object] = q;
var path = searchTypeArray[0].path;
$scope.factories[searchTypeArray[0].factory].get(
searchTypeObj
, function() {
$scope.searchFound = true;
_resetSearch();
$location.path(path + q);
}, function() {
$scope.traverseSearch(searchTypeArray.slice(1), q);
});
} else {
$scope.loading = false;
_badQuery();
}
}

$scope.search = function() {
var q = $scope.q;
$scope.badQuery = false;
$scope.loading = true;

Block.get({
blockHash: q
}, function() {
_resetSearch();
$location.path('block/' + q);
}, function() { //block not found, search on TX
Transaction.get({
txId: q
}, function() {
_resetSearch();
$location.path('tx/' + q);
}, function() { //tx not found, search on Address
Address.get({
addrStr: q
}, function() {
_resetSearch();
$location.path('address/' + q);
}, function() { // block by height not found
if (isFinite(q)) { // ensure that q is a finite number. A logical height value.
BlockByHeight.get({
blockHeight: q
}, function(hash) {
_resetSearch();
$location.path('/block/' + hash.blockHash);
}, function() { //not found, fail :(
$scope.loading = false;
_badQuery();
});
}
else {
$scope.loading = false;
_badQuery();
}
});
});
Search.get({
searchstr: q
}, function(res) {
$scope.traverseSearch(res.data, q);
}, function() {
//not found, allow backward compatibilty if search route not available on API
var searchTypeArray = $scope.defineSearchType(q);
$scope.traverseSearch(searchTypeArray, q);
});
};

Expand Down
Loading