From 89966a75b8e8e8ed70f9ef3f6969e1756f304fd0 Mon Sep 17 00:00:00 2001 From: blavenie <benoit.lavenier@e-is.pro> Date: Mon, 23 Oct 2017 14:27:37 +0200 Subject: [PATCH] [fix] set profile location to null (need by ES node synchro) [enh doc search: add button to remove a doc, is owner --- www/js/config.js | 2 +- www/plugins/es/i18n/locale-fr-FR.json | 1 + .../es/js/controllers/document-controllers.js | 31 ++++++++++++------- .../es/js/controllers/profile-controllers.js | 2 +- .../es/js/services/document-services.js | 31 ++++++++++++++++--- www/plugins/es/js/services/http-services.js | 12 +++++-- .../es/templates/document/item_document.html | 7 +++++ .../es/templates/document/lookup_form.html | 1 + .../es/templates/registry/edit_record.html | 2 -- 9 files changed, 66 insertions(+), 23 deletions(-) diff --git a/www/js/config.js b/www/js/config.js index 2221ba57..7cf7dfe5 100644 --- a/www/js/config.js +++ b/www/js/config.js @@ -70,7 +70,7 @@ angular.module("cesium.config", []) } }, "version": "0.18.3", - "build": "2017-10-20T17:44:25.876Z", + "build": "2017-10-20T18:07:51.522Z", "newIssueUrl": "https://github.com/duniter/cesium/issues/new?labels=bug" }) diff --git a/www/plugins/es/i18n/locale-fr-FR.json b/www/plugins/es/i18n/locale-fr-FR.json index 36ff7cc5..34cdb2f6 100644 --- a/www/plugins/es/i18n/locale-fr-FR.json +++ b/www/plugins/es/i18n/locale-fr-FR.json @@ -426,6 +426,7 @@ "HEADER_ISSUER": "Emetteur", "HEADER_RECIPIENT": "Destinataire", "READ": "Lu", + "BTN_REMOVE": "Supprimer ce document", "POPOVER_ACTIONS": { "TITLE": "Actions", "REMOVE_ALL": "Supprimer ces documents..." diff --git a/www/plugins/es/js/controllers/document-controllers.js b/www/plugins/es/js/controllers/document-controllers.js index f16187b5..f2274f6c 100644 --- a/www/plugins/es/js/controllers/document-controllers.js +++ b/www/plugins/es/js/controllers/document-controllers.js @@ -126,10 +126,17 @@ function ESDocumentLookupController($scope, $ionicPopover, $location, $timeout, return UIUtils.alert.confirm('DOCUMENT.CONFIRM.REMOVE_ALL') .then(function(confirm) { - if (confirm) { - return esDocument.removeAll($scope.search.results) - .catch(UIUtils.onError('DOCUMENT.ERROR.REMOVE_ALL_FAILED')); - } + if (!confirm) return; + UIUtils.loading.show(); + return esDocument.removeAll($scope.search.results) + .then(function() { + $scope.search.loading = false; + return $timeout(function() { + UIUtils.toast.show('DOCUMENT.INFO.REMOVED'); // toast + return $scope.load(); + }, 1000 /*waiting propagation*/); + }) + .catch(UIUtils.onError('DOCUMENT.ERROR.REMOVE_ALL_FAILED')); }); }; @@ -139,14 +146,14 @@ function ESDocumentLookupController($scope, $ionicPopover, $location, $timeout, UIUtils.alert.confirm('DOCUMENT.CONFIRM.REMOVE') .then(function(confirm) { - if (confirm) { - esDocument.remove(doc) - .then(function () { - $scope.search.results.splice(index,1); // remove from messages array - UIUtils.toast.show('DOCUMENT.INFO.REMOVED'); - }) - .catch(UIUtils.onError('MESSAGE.ERROR.REMOVE_FAILED')); - } + if (!confirm) return; + return esDocument.remove(doc) + .then(function () { + $scope.search.results.splice(index,1); // remove from messages array + $scope.$broadcast('$$rebind::rebind'); // notify binder + UIUtils.toast.show('DOCUMENT.INFO.REMOVED'); // toast + }) + .catch(UIUtils.onError('MESSAGE.ERROR.REMOVE_FAILED')); }); }; diff --git a/www/plugins/es/js/controllers/profile-controllers.js b/www/plugins/es/js/controllers/profile-controllers.js index 1a572d1b..3ca009ad 100644 --- a/www/plugins/es/js/controllers/profile-controllers.js +++ b/www/plugins/es/js/controllers/profile-controllers.js @@ -225,7 +225,7 @@ function ESViewEditProfileController($scope, $rootScope, $q, $timeout, $state, $ // Workaround for old data if (formData.position) { - delete formData.position; + formData.position = null; } if (formData.geoPoint && formData.geoPoint.lat && formData.geoPoint.lon) { formData.geoPoint.lat = parseFloat(formData.geoPoint.lat); diff --git a/www/plugins/es/js/services/document-services.js b/www/plugins/es/js/services/document-services.js index 24bf8ece..7270bf18 100644 --- a/www/plugins/es/js/services/document-services.js +++ b/www/plugins/es/js/services/document-services.js @@ -20,7 +20,8 @@ angular.module('cesium.es.document.services', ['ngResource', 'cesium.platform', }, fields = { commons: ["issuer", "pubkey", "hash", "time", "recipient", "nonce", "read_signature"], - peer: ["*"] + peer: ["*"], + movement: ["*"] }, raw = { search: esHttp.post('/:index/:type/_search'), @@ -64,7 +65,7 @@ angular.module('cesium.es.document.services', ['ngResource', 'cesium.platform', function search(options) { options = options || {}; - if (options.type == 'peer') { + if (options.type == 'movement') { if (!options.sort) { options.sort = 'stats.medianTime:desc'; } @@ -80,10 +81,32 @@ angular.module('cesium.es.document.services', ['ngResource', 'cesium.platform', ]; options._source = fields.peer; options.getTimeFunction = function(doc) { - return doc.stats && doc.stats.medianTime; + doc.time = doc.stats && doc.stats.medianTime; + return doc.time; }; } } + else if (options.type == 'movement') { + if (!options.sort) { + options.sort = 'medianTime:desc'; + } + else { + var sortParts = options.sort.split(':'); + var side = sortParts.length > 1 ? sortParts[1] : 'desc'; + + options.sort = [ + {'medianTime': { + order: side + }} + ]; + options._source = fields.movement; + options.getTimeFunction = function(doc) { + doc.time = doc.medianTime; + return doc.time; + }; + } + } + if (!options || !options.index || !options.type) throw new Error('Missing mandatory options [index, type]'); var request = { @@ -141,7 +164,7 @@ angular.module('cesium.es.document.services', ['ngResource', 'cesium.platform', } function remove(document) { - if (document || !document.index || !document.type || !document.id) return; + if (!document || !document.index || !document.type || !document.id) return $q.reject('Could not remove document: missing mandatory fields'); return esHttp.record.remove(document.index, document.type)(document.id); } diff --git a/www/plugins/es/js/services/http-services.js b/www/plugins/es/js/services/http-services.js index 4de5bf99..74654c41 100644 --- a/www/plugins/es/js/services/http-services.js +++ b/www/plugins/es/js/services/http-services.js @@ -258,6 +258,9 @@ angular.module('cesium.es.http.services', ['ngResource', 'ngApi', 'cesium.servic delete obj.signature; delete obj.hash; obj.issuer = walletData.pubkey; + if (!obj.version) { + obj.version = 2; + } // Fill tags if (options.tagFields) { @@ -268,11 +271,13 @@ angular.module('cesium.es.http.services', ['ngResource', 'ngApi', 'cesium.servic return CryptoUtils.util.hash(str) .then(function(hash) { - return CryptoUtils.sign(str, walletData.keypair) + return CryptoUtils.sign(hash, walletData.keypair) .then(function(signature) { obj.hash = hash; obj.signature = signature; - return postRequest(obj, params) + str = '{"hash":"' + hash + '","signature":"' + signature + '",' + + str.substring(1); + return postRequest(str, params) .then(function (id){ return id; }); @@ -288,6 +293,7 @@ angular.module('cesium.es.http.services', ['ngResource', 'ngApi', 'cesium.servic .then(function(walletData) { var obj = { + version: 2, index: index, type: type, id: id, @@ -297,7 +303,7 @@ angular.module('cesium.es.http.services', ['ngResource', 'ngApi', 'cesium.servic var str = JSON.stringify(obj); return CryptoUtils.util.hash(str) .then(function (hash) { - return CryptoUtils.sign(str, walletData.keypair) + return CryptoUtils.sign(hash, walletData.keypair) .then(function (signature) { obj.hash = hash; obj.signature = signature; diff --git a/www/plugins/es/templates/document/item_document.html b/www/plugins/es/templates/document/item_document.html index b2698d1e..9f5eaf60 100644 --- a/www/plugins/es/templates/document/item_document.html +++ b/www/plugins/es/templates/document/item_document.html @@ -28,6 +28,13 @@ </div> <div class="col"> + <a + ng-if=":rebind:login && doc.pubkey==$root.walletData.pubkey" + ng-click="remove($index)" + class="gray pull-right" + title="{{'DOCUMENT.LOOKUP.BTN_REMOVE'|translate}}"> + <i class="ion-trash-a"></i> + </a> <h3 ng-if=":rebind:doc.recipient"> <a ui-sref="app.wot_identity({pubkey: doc.recipient.pubkey, uid: doc.recipient.uid})"> <span class="gray"> diff --git a/www/plugins/es/templates/document/lookup_form.html b/www/plugins/es/templates/document/lookup_form.html index b0d2f504..c940bdd6 100644 --- a/www/plugins/es/templates/document/lookup_form.html +++ b/www/plugins/es/templates/document/lookup_form.html @@ -67,6 +67,7 @@ <div class=" pull-right hidden-xs hidden-sm"> <a class="button button-text button-small ink" + ng-if="login" ng-click="showActionsPopover($event)"> {{'DOCUMENT.LOOKUP.BTN_ACTIONS' | translate}} <i class="icon ion-arrow-down-b"></i> diff --git a/www/plugins/es/templates/registry/edit_record.html b/www/plugins/es/templates/registry/edit_record.html index 9660fecc..278641dc 100644 --- a/www/plugins/es/templates/registry/edit_record.html +++ b/www/plugins/es/templates/registry/edit_record.html @@ -112,8 +112,6 @@ </div> </div> - <div class="item item-divider" translate>REGISTRY.LOCATION_DIVIDER</div> - <!-- position --> <ng-include src="'plugins/es/templates/common/edit_position.html'"></ng-include> -- GitLab