From 2ef44f1dde0323cb3f17a4b6bedfd843baae9227 Mon Sep 17 00:00:00 2001 From: blavenie <benoit.lavenier@e-is.pro> Date: Thu, 2 Nov 2017 12:36:55 +0100 Subject: [PATCH] Page: update "total" when adding/deleting a comment Page: Display pubkey --- .../es/js/controllers/common-controllers.js | 5 +- .../es/js/controllers/registry-controllers.js | 79 +++++++++++-------- .../es/js/services/comment-services.js | 5 +- .../es/templates/registry/view_record.html | 25 +++--- 4 files changed, 62 insertions(+), 52 deletions(-) diff --git a/www/plugins/es/js/controllers/common-controllers.js b/www/plugins/es/js/controllers/common-controllers.js index 035787f4..0b0d5d49 100644 --- a/www/plugins/es/js/controllers/common-controllers.js +++ b/www/plugins/es/js/controllers/common-controllers.js @@ -219,7 +219,9 @@ function ESCommentsController($scope, $filter, $state, $focus, UIUtils) { $scope.focusNewComment(); return $scope.service.save($scope.id, $scope.comments, comment); }) - + .then(function() { + $scope.comments.total++; + }) .catch(UIUtils.onError('REGISTRY.ERROR.FAILED_SAVE_COMMENT')); }; @@ -259,6 +261,7 @@ function ESCommentsController($scope, $filter, $state, $focus, UIUtils) { $scope.remove = function(comment) { if (!comment) {return;} comment.remove(); + $scope.comments.total--; }; $scope.reply = function(parent) { diff --git a/www/plugins/es/js/controllers/registry-controllers.js b/www/plugins/es/js/controllers/registry-controllers.js index 64f942fd..d774b00b 100644 --- a/www/plugins/es/js/controllers/registry-controllers.js +++ b/www/plugins/es/js/controllers/registry-controllers.js @@ -465,44 +465,44 @@ function ESRegistryRecordViewController($scope, $rootScope, $state, $q, $timeout $scope.load = function(id, anchor) { $scope.loading = true; - esRegistry.record.load(id) - .then(function (data) { - $scope.id= data.id; - $scope.formData = data.record; - console.log($scope.formData); - $scope.canEdit = csWallet.isUserPubkey($scope.formData.issuer); - $scope.issuer = data.issuer; - // avatar - $scope.avatar = $scope.formData.avatar; - $scope.avatarStyle= $scope.formData.avatar && {'background-image':'url("'+$scope.avatar.src+'")'}; - UIUtils.loading.hide(); - $scope.loading = false; - // Set Motion (only direct children, to exclude .lazy-load children) - $scope.motion.show({selector: '.list > .item, .list > ng-if > .item'}); - }) - .catch(function(err) { - // Retry (ES could have error) - if (!$scope.secondTry) { - $scope.secondTry = true; - $q(function() { - $scope.load(id); - }, 100); - } - else { + return $q.all([ + esRegistry.record.load(id) + .then(function (data) { + $scope.id= data.id; + $scope.formData = data.record; + console.log($scope.formData); + $scope.canEdit = csWallet.isUserPubkey($scope.formData.issuer); + $scope.issuer = data.issuer; + // avatar + $scope.avatar = $scope.formData.avatar; + $scope.avatarStyle= $scope.formData.avatar && {'background-image':'url("'+$scope.avatar.src+'")'}; + + UIUtils.loading.hide(); $scope.loading = false; - if (err && err.ucode === 404) { - UIUtils.toast.show('REGISTRY.ERROR.RECORD_NOT_EXISTS'); - $state.go('app.registry_lookup'); + // Set Motion (only direct children, to exclude .lazy-load children) + $scope.motion.show({selector: '.list > .item, .list > ng-if > .item'}); + }) + .catch(function(err) { + // Retry (ES could have error) + if (!$scope.secondTry) { + $scope.secondTry = true; + $q(function() { + $scope.load(id); + }, 100); } else { - UIUtils.onError('REGISTRY.ERROR.LOAD_RECORD_FAILED')(err); + $scope.loading = false; + if (err && err.ucode === 404) { + UIUtils.toast.show('REGISTRY.ERROR.RECORD_NOT_EXISTS'); + $state.go('app.registry_lookup'); + } + else { + UIUtils.onError('REGISTRY.ERROR.LOAD_RECORD_FAILED')(err); + } } - } - }); + }), - // Continue loading other data - $timeout(function() { // Load pictures esRegistry.record.picture.all({id: id}) .then(function(hit) { @@ -514,17 +514,26 @@ function ESRegistryRecordViewController($scope, $rootScope, $state, $q, $timeout // Set Motion if ($scope.pictures.length > 0) { $scope.motion.show({ - selector: '.lazy-load .item.card-gallery, .lazy-load .item', + selector: '.lazy-load .item.card-gallery', startVelocity: 3000 }); } }) .catch(function() { $scope.pictures = []; - }); + }), // Load other data (from child controller) - $scope.$broadcast('$recordView.load', id, esRegistry.record.comment); + $timeout(function() { + return $scope.$broadcast('$recordView.load', id, esRegistry.record.comment); + }) + ]) + .then(function() { + // Display items in technical parts + $scope.motion.show({ + selector: '.lazy-load .item', + startVelocity: 3000 + }); // scroll (if comment anchor) if (anchor) $timeout(function() { diff --git a/www/plugins/es/js/services/comment-services.js b/www/plugins/es/js/services/comment-services.js index 6f98c450..b81154f1 100644 --- a/www/plugins/es/js/services/comment-services.js +++ b/www/plugins/es/js/services/comment-services.js @@ -169,12 +169,15 @@ angular.module('cesium.es.comment.services', ['ngResource', 'cesium.services', delete data.mapById[comment.id]; // Send deletion request if (csWallet.isUserPubkey(comment.issuer)) { - exports.raw.remove(comment.id) + return exports.raw.remove(comment.id) .catch(function(err){ console.error(err); throw new Error('MARKET.ERROR.FAILED_REMOVE_COMMENT'); }); } + else { + return $q.reject("User is not the comment issuer"); + } }; }; diff --git a/www/plugins/es/templates/registry/view_record.html b/www/plugins/es/templates/registry/view_record.html index a1ef5ddc..c73d6de1 100644 --- a/www/plugins/es/templates/registry/view_record.html +++ b/www/plugins/es/templates/registry/view_record.html @@ -94,7 +94,7 @@ <h2 trust-as-html="formData.description"></h2> </ion-item> - <ion-item> + <ion-item ng-if="formData.category || formData.address"> <h4 ng-if="formData.category"> <span class="gray" translate>REGISTRY.VIEW.CATEGORY</span> <a class="positive" ng-if="formData.category" ui-sref="app.registry_lookup({category:formData.category.id})"> @@ -126,25 +126,20 @@ </ion-item> </ng-if> + <!-- pubkey --> + <div class="item item-icon-left item-text-wrap ink" + ng-if="formData.pubkey" + copy-on-click="{{::formData.pubkey}}"> + <i class="icon ion-key"></i> + <span translate>REGISTRY.EDIT.RECORD_PUBKEY</span> + <h4 class="dark">{{::formData.pubkey}}</h4> + </div> + <div class="lazy-load"> <!-- pictures --> <ng-include src="'plugins/es/templates/common/view_pictures.html'"></ng-include> - - <span class="item item-divider" ng-if="formData.pubkey"> - <span translate>REGISTRY.TECHNICAL_DIVIDER</span> - </span> - - <!-- pubkey --> - <div class="item item-icon-left item-text-wrap ink" - ng-if="formData.pubkey" - copy-on-click="{{::formData.pubkey}}"> - <i class="icon ion-key"></i> - <span translate>REGISTRY.EDIT.RECORD_PUBKEY</span> - <h4 class="dark">{{::formData.pubkey}}</h4> - </div> - <!-- comments --> <ng-include src="'plugins/es/templates/common/view_comments.html'"></ng-include> </div> -- GitLab