Merge pull request #5327 from gabrielbazan7/feat/addLoadingAmazon

manual loading and some details fixes
This commit is contained in:
Gustavo Maximiliano Cortez 2016-12-23 13:09:27 -03:00 committed by GitHub
commit 833b98ac21
5 changed files with 56 additions and 85 deletions

View file

@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('amazonController',
function($scope, $timeout, $ionicModal, $log, lodash, amazonService, platformInfo, externalLinkService, popupService, gettextCatalog) {
function($scope, $timeout, $ionicModal, $log, $ionicScrollDelegate, lodash, amazonService, platformInfo, externalLinkService, popupService, ongoingProcess) {
$scope.network = amazonService.getEnvironment();
@ -12,7 +12,7 @@ angular.module('copayApp.controllers').controller('amazonController',
var initAmazon = function() {
amazonService.getPendingGiftCards(function(err, gcds) {
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err);
popupService.showAlert('Error', err);
return;
}
$scope.giftCards = lodash.isEmpty(gcds) ? null : gcds;
@ -24,7 +24,7 @@ angular.module('copayApp.controllers').controller('amazonController',
claimCode: $scope.cardClaimCode
});
if (lodash.isEmpty(card)) {
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Card not found'));
popupService.showAlert('Error', 'Card not found');
return;
}
$scope.openCardModal(card);
@ -34,18 +34,29 @@ angular.module('copayApp.controllers').controller('amazonController',
};
$scope.updatePendingGiftCards = lodash.debounce(function() {
ongoingProcess.set('updatingGiftCards', true);
amazonService.getPendingGiftCards(function(err, gcds) {
if (lodash.isEmpty(gcds)) {
$timeout(function() {
ongoingProcess.set('updatingGiftCards', false);
}, 1000);
}
$timeout(function() {
$scope.giftCards = gcds;
$scope.giftCards = lodash.isEmpty(gcds) ? null : gcds;
$scope.$digest();
});
var index = 0;
lodash.forEach(gcds, function(dataFromStorage) {
if (++index == Object.keys(gcds).length) {
$timeout(function() {
ongoingProcess.set('updatingGiftCards', false);
}, 1000);
}
if (dataFromStorage.status == 'PENDING') {
$log.debug("creating gift card");
amazonService.createGiftCard(dataFromStorage, function(err, giftCard) {
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err);
popupService.showAlert('Error', err);
return;
}
if (giftCard.status != 'PENDING') {
@ -65,13 +76,14 @@ angular.module('copayApp.controllers').controller('amazonController',
$log.debug("Saving new gift card");
amazonService.getPendingGiftCards(function(err, gcds) {
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err);
popupService.showAlert('Error', err);
return;
}
$scope.giftCards = gcds;
$scope.giftCards = lodash.isEmpty(gcds) ? null : gcds;
$timeout(function() {
$scope.$digest();
});
$ionicScrollDelegate.resize();
}, 10);
});
});
} else $log.debug("pending gift card not available yet");
@ -80,7 +92,9 @@ angular.module('copayApp.controllers').controller('amazonController',
});
});
}, 1000);
}, 1000, {
'leading': true
});
$scope.openCardModal = function(card) {
$scope.card = card;
@ -92,8 +106,8 @@ angular.module('copayApp.controllers').controller('amazonController',
$scope.amazonCardDetailsModal.show();
});
$scope.$on('UpdateAmazonList', function(event) {
initAmazon();
$scope.$on('modal.hidden', function() {
$scope.updatePendingGiftCards();
});
};

View file

@ -783,6 +783,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
invoiceUrl: $scope.paypro.url,
invoiceTime: giftCardInvoiceTime
};
ongoingProcess.set('creatingGiftCard', true);
debounceCreate(count, dataSrc, onSendStatusChange);
}
}, onSendStatusChange);
@ -795,7 +796,6 @@ angular.module('copayApp.controllers').controller('confirmController', function(
});
var debounceCreateGiftCard = function(count, dataSrc, onSendStatusChange) {
amazonService.createGiftCard(dataSrc, function(err, giftCard) {
$log.debug("creating gift card " + count);
if (err) {
@ -830,6 +830,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
}
amazonService.savePendingGiftCard(newData, null, function(err) {
ongoingProcess.set('creatingGiftCard', false);
$log.debug("Saving new gift card with status: " + newData.status);
$scope.amazonGiftCard = newData;
});

View file

@ -1,18 +1,22 @@
'use strict';
angular.module('copayApp.controllers').controller('amazonCardDetailsController', function($scope, $log, $timeout, bwcError, amazonService, lodash, ongoingProcess, popupService, gettextCatalog, externalLinkService) {
angular.module('copayApp.controllers').controller('amazonCardDetailsController', function($scope, $log, $timeout, $ionicScrollDelegate, bwcError, amazonService, lodash, ongoingProcess, popupService, externalLinkService) {
$scope.cancelGiftCard = function() {
ongoingProcess.set('Canceling gift card...', true);
ongoingProcess.set('cancelingGiftCard', true);
amazonService.cancelGiftCard($scope.card, function(err, data) {
ongoingProcess.set('Canceling gift card...', false);
ongoingProcess.set('cancelingGiftCard', false);
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), bwcError.msg(err));
popupService.showAlert('Error', bwcError.msg(err));
return;
}
$scope.card.cardStatus = data.cardStatus;
$timeout(function() {
$ionicScrollDelegate.resize();
$ionicScrollDelegate.scrollTop();
}, 10);
amazonService.savePendingGiftCard($scope.card, null, function(err) {
$scope.$emit('UpdateAmazonList');
$scope.refreshGiftCard();
});
});
};
@ -21,23 +25,34 @@ angular.module('copayApp.controllers').controller('amazonCardDetailsController',
amazonService.savePendingGiftCard($scope.card, {
remove: true
}, function(err) {
$scope.$emit('UpdateAmazonList');
$scope.cancel();
});
};
$scope.refreshGiftCard = function() {
ongoingProcess.set('updatingGiftCard', true);
amazonService.getPendingGiftCards(function(err, gcds) {
if (lodash.isEmpty(gcds)) {
$timeout(function() {
ongoingProcess.set('updatingGiftCard', false);
}, 1000);
}
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err);
popupService.showAlert('Error', err);
return;
}
var index = 0;
lodash.forEach(gcds, function(dataFromStorage) {
if (++index == Object.keys(gcds).length) {
$timeout(function() {
ongoingProcess.set('updatingGiftCard', false);
}, 1000);
}
if (dataFromStorage.status == 'PENDING' && dataFromStorage.invoiceId == $scope.card.invoiceId) {
$log.debug("creating gift card");
amazonService.createGiftCard(dataFromStorage, function(err, giftCard) {
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), bwcError.msg(err));
popupService.showAlert('Error', bwcError.msg(err));
return;
}
if (!lodash.isEmpty(giftCard)) {
@ -46,7 +61,6 @@ angular.module('copayApp.controllers').controller('amazonCardDetailsController',
amazonService.savePendingGiftCard(newData, null, function(err) {
$log.debug("Saving new gift card");
$scope.card = newData;
$scope.$emit('UpdateAmazonList');
$timeout(function() {
$scope.$digest();
});