Skip to content

Commit

Permalink
[WIP] Get barcode response from input camera photo and OCR Cloud Visi…
Browse files Browse the repository at this point in the history
…on text output - ref #66
  • Loading branch information
macintoshhelper committed May 8, 2017
1 parent d136df1 commit 329ba75
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 41 deletions.
42 changes: 22 additions & 20 deletions client-src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,34 +96,36 @@ document.querySelector('.visa-img').addEventListener('click', (/* event */) => {
document.getElementById('cardCamera').click();
});

const camera = document.getElementById('cardCamera');
const cardCamera = document.getElementById('cardCamera');
// const frame = document.getElementById('frame');
let token = '';

const scanCamera = (route, targetDestination, file) => {
makeRequest('POST', 'card', (err, res) => {
if (err) {
return console.error(err);
}
const responseObj = JSON.parse(res);
token = responseObj.token;

return makeRequest('GET', `${targetDestination}?ajax=true`, (routeErr, cartRes) => {
if (routeErr) {
return console.error(routeErr);
}
cardCamera.addEventListener('change', (cardEvent) => {
makeRequest('POST', '/card', (err, res) => {
if (err) return console.error(err);

const data = JSON.parse(res);
if (!token) token = data.token;

return makeRequest('GET', '/cart?ajax=true', (cartErr, cartRes) => {
if (cartErr) return console.error(cartErr);

document.getElementById('outerContainer').innerHTML = cartRes;

const itemCamera = document.getElementById('itemCamera');
itemCamera.addEventListener('change', (e) => {
scanCamera(targetDestination, e.target.files[0]);

itemCamera.addEventListener('change', (itemEvent) => {
makeRequest('POST', '/add-item', (itemErr, itemRes) => {
if (itemErr) return console.error(itemErr);

const itemData = JSON.parse(itemRes);

return console.log({ itemData });
}, itemEvent.target.files[0], ['Authorization', token]);
});

return window.history.pushState(null, null, targetDestination);
return window.history.pushState(null, null, '/cart');
}, null, ['Authorization', token]);
}, file, token);
};

camera.addEventListener('change', (e) => {
scanCamera('/card', '/cart', e.target.files[0]);
}, cardEvent.target.files[0]);
});
41 changes: 21 additions & 20 deletions public/assets/js/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/assets/js/main.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 329ba75

Please sign in to comment.