diff --git a/www/js/services/wallet-services.js b/www/js/services/wallet-services.js index dc704cd2de2bb2ad081d8d3e0ffedb3b38410d3d..b1f9b5aa0683396a14aaacf7e1daa150428a4222 100644 --- a/www/js/services/wallet-services.js +++ b/www/js/services/wallet-services.js @@ -699,8 +699,17 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se // Clean existing events cleanEventsByContext('requirements'); + var finished = false; + + $timeout(function() { + if (!finished) UIUtils.loading.update({template: "COMMON.LOADING_WAIT"}); + }, 2000); // Get requirements - return csWot.loadRequirements(data, withCache); + return csWot.loadRequirements(data, withCache) + .then(function(res) { + finished = true; + return res; + }); }, loadTxAndSources = function(fromTime) { @@ -2011,7 +2020,7 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se }, getChildWalletById = function(id) { - return (id !== 'default') && _.find(data.children|| [], function(child) {return child.id === id;}) || undefined; + return (id !== 'default') && _.find(data.children|| [], function(child) {return child.id === +id;}) || undefined; }, getChildWalletByPubkey = function(pubkey) { @@ -2028,11 +2037,10 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se newChildInstance = function() { // Return max(id) + 1 - var walletId =Â (data.children && data.children.reduce(function(res, wallet) { + var walletId =Â (data.children || []).reduce(function(res, wallet) { return Math.max(res, wallet.id); - }, 0) || data.childrenCount || 0 )+ 1; - var childrenWallet = service.instance(walletId, BMA); - return childrenWallet; + }, 0) + 1; + return service.instance(walletId, BMA); }, getAllChildrenWallet = function() { diff --git a/www/plugins/es/js/services/like-services.js b/www/plugins/es/js/services/like-services.js index 8d0b489c796ae1f89701a20dad4ba8e9603294f4..b622ae722b240a8b1cba8eca4e94dcccab18a456 100644 --- a/www/plugins/es/js/services/like-services.js +++ b/www/plugins/es/js/services/like-services.js @@ -4,29 +4,30 @@ angular.module('cesium.es.like.services', ['ngResource', 'cesium.services', .factory('esLike', function($q, csWallet, esHttp) { 'ngInject'; + + var constants = { + KINDS: ['LIKE', 'ABUSE'] + }; + function EsLike(index, type) { - var - raw = { + var that = this; + that.raw = { getSearch: esHttp.get('/like/record/_search?_source=false&q=:q'), searchBaseQueryString: 'index:{0} AND type:{1} AND id:'.format(index, type), postSearch: esHttp.post("/like/record/_search"), postRecord: esHttp.record.post('/{0}/{1}/:id/_like'.format(index, type)), removeRecord: esHttp.record.remove('like', 'record') - }, - constants = { - KINDS: ['LIKE', 'ABUSE'] - } - ; + }; function getLikeIds(id, options) { options = options ||Â {}; options.kind = options.kind ||Â 'LIKE'; - var queryString = raw.searchBaseQueryString + id; + var queryString = that.raw.searchBaseQueryString + id; if (options.kind) queryString += ' AND kind:' + options.kind.toUpperCase(); if (options.issuer) queryString += ' AND issuer:' + options.issuer; - return raw.getSearch({q: queryString}) + return that.raw.getSearch({q: queryString}) .then(function(res) { return (res && res.hits && res.hits.hits || []).map(function(hit) { return hit._id; @@ -48,7 +49,7 @@ angular.module('cesium.es.like.services', ['ngResource', 'cesium.services', if (options.comment) record.comment = options.comment; if (angular.isDefined(options.level)) record.level = options.level; - return raw.postRecord(record, options); + return that.raw.postRecord(record, options); } function toggleLike(id, options) { @@ -82,7 +83,7 @@ angular.module('cesium.es.like.services', ['ngResource', 'cesium.services', function removeLike(id, options) { if (!id) throw new Error("Missing 'id' argument"); - return raw.removeRecord(id, options); + return that.raw.removeRecord(id, options); } function countLike(id, options) { @@ -111,7 +112,7 @@ angular.module('cesium.es.like.services', ['ngResource', 'cesium.services', request._source = ["issuer"]; } - return raw.postSearch(request) + return that.raw.postSearch(request) .then(function(res) { var hits = res && res.hits; var result = { @@ -138,7 +139,6 @@ angular.module('cesium.es.like.services', ['ngResource', 'cesium.services', return { index: index, type: type, - constants: constants, toggle: toggleLike, add: addLike, remove: removeLike, @@ -147,6 +147,7 @@ angular.module('cesium.es.like.services', ['ngResource', 'cesium.services', } return { + constants: constants, instance: EsLike }; })