diff --git a/www/plugins/rml9/plugin-07-add_map.js b/www/plugins/rml9/plugin-07-add_map.js index fedea1d353f98a84446bec810d9c5314efadbe7d..2ad9198a0ffd84f332955337ab468a8c3d81b092 100644 --- a/www/plugins/rml9/plugin-07-add_map.js +++ b/www/plugins/rml9/plugin-07-add_map.js @@ -7,26 +7,25 @@ angular.module('cesium.rml9.plugin', ['cesium.services']) var enable = csConfig.plugins && csConfig.plugins.rml9; if (enable) { - // Extension de la vue d'une identité: ajout d'un bouton PluginServiceProvider + + // Extension de la vue d'une identité: ajout d'un bouton .extendState('app.wot_identity', { points: { 'buttons': { - templateUrl: "plugins/rml9/templates/01-button.html", - controller: 'Rml9ButtonCtrl' + templateUrl: "plugins/rml9/templates/07-button.html" } } - }); - - // Extension de 'Mes opérations' : insertion d'un bouton - PluginServiceProvider.extendState('app.view_wallet_tx', { - points: { - 'buttons': { - templateUrl: "plugins/rml9/templates/01-button.html", - controller: 'Rml9ButtonCtrl' + }) + + // Extension de 'Mes opérations' : insertion d'un bouton + .extendState('app.view_wallet_tx', { + points: { + 'buttons': { + templateUrl: "plugins/rml9/templates/07-button.html" + } } - } - }); + }); // [NEW] Ajout d'une nouvelle page #/app/rml9 $stateProvider @@ -34,7 +33,7 @@ angular.module('cesium.rml9.plugin', ['cesium.services']) url: "/rml9/:pubkey", views: { 'menuContent': { - templateUrl: "plugins/rml9/templates/02-view.html", + templateUrl: "plugins/rml9/templates/07-view.html", controller: 'Rml9ViewCtrl' } } @@ -43,44 +42,50 @@ angular.module('cesium.rml9.plugin', ['cesium.services']) }) - // Manage events from the plugin button - .controller('Rml9ButtonCtrl', function($scope, $state) { + // [NEW] Manage events from the page #/app/rml9 + .controller('Rml9ViewCtrl', function($scope) { 'ngInject'; - // Manage click event, on the plugin button - $scope.onButtonClick = function() { - - // [Get the public key, from the page context ($scope.formData) - var pubkey = $scope.formData.pubkey; - if (!pubkey) return; - console.debug("[RML9] call method onButtonClick() on pubkey: " + pubkey); + $scope.map = { + center: { + lat: 37.26, + lng: 138.86, + zoom: 4 + }, + defaults: { + scrollWheelZoom: false + } + }; - // [NEW] Open the RML9 view (#/app/rml9) - $state.go('app.rml9', {pubkey: pubkey}); + var data = { + "type": "Feature", + "geometry": { + "type": "Point", + "coordinates": [125.6, 10.1] + }, + "properties": { + "name": "Dinagat Islands" + } }; - }) - // [NEW] Manage events from the page #/app/rml9 - .controller('Rml9ViewCtrl', function($scope, csTx) { - 'ngInject'; + + $scope.map.geojson ={ + data: data, + style: { + fillColor: "green", + weight: 2, + opacity: 1, + color: 'white', + dashArray: '3', + fillOpacity: 0.7 + } + }; // [NEW] When opening the view $scope.$on('$ionicView.enter', function(e, state) { console.log("[RML9] Opening the view..."); - // [NEW] Get the pubkey (from URL params) and store it in the page context ($scope) - $scope.pubkey = (state && state.stateParams && state.stateParams.pubkey); - if (!$scope.pubkey) return; - - // [NEW] Create some data to display - // Load account TX data - csTx.load($scope.pubkey) // <- appel au service csTx - .then(function(result) { - console.log(result); // Allow to discover data structure - if (result && result.tx && result.tx.history) { - $scope.items = result.tx.history; - } - }); + }); }); diff --git a/www/plugins/rml9/plugin-final.js b/www/plugins/rml9/plugin-final.js index c0e154ee0b44cfe38287fada9efacf4c8b050619..1efc71ae081ede469754f248a4c8cbc588c5e40e 100644 --- a/www/plugins/rml9/plugin-final.js +++ b/www/plugins/rml9/plugin-final.js @@ -31,7 +31,7 @@ angular.module('cesium.rml9.plugin', ['cesium.services']) .extendState('app.settings', { points: { 'plugins': { - templateUrl: "plugins/rml9/templates/04-settings_item.html" + templateUrl: "plugins/rml9/templates/06-settings_item.html" } } }); @@ -42,7 +42,7 @@ angular.module('cesium.rml9.plugin', ['cesium.services']) url: "/rml9/:pubkey", views: { 'menuContent': { - templateUrl: "plugins/rml9/templates/03-view_with_button.html", + templateUrl: "plugins/rml9/templates/final-view.html", controller: 'Rml9ViewCtrl' } } @@ -52,9 +52,7 @@ angular.module('cesium.rml9.plugin', ['cesium.services']) }) // [NEW] Manage events from the page #/app/rml9 - .controller('Rml9ViewCtrl', function($scope, csTx, - // [NEW] declare an AngularJS plugin, useful to create file - FileSaver) { + .controller('Rml9ViewCtrl', function($scope, csTx, FileSaver, gpColor) { 'ngInject'; // When opening the view @@ -71,7 +69,14 @@ angular.module('cesium.rml9.plugin', ['cesium.services']) console.log(result); // Allow to discover data structure if (result && result.tx && result.tx.history) { $scope.items = result.tx.history; - $scope.items = result && result.tx && result.tx.history || []; + + // Charts data + $scope.inputChart = $scope.computeChartData(_.filter(result.tx.history, function(tx) { + return tx.amount > 0; + })); + $scope.outputChart = $scope.computeChartData(_.filter(result.tx.history, function(tx) { + return tx.amount < 0; + })); } // [NEW] store the account balance @@ -90,19 +95,46 @@ angular.module('cesium.rml9.plugin', ['cesium.services']) if (!result || !result.tx || !result.tx.history) return; // no TX - // TODO: replace this ! - // You can choose any format (CSV, TXT, JSON, ...) and test it ! - var content = [ - "Hello Libre World !\n", - "Cesium rock's !\n" - ]; + var headers = ['time', 'issuer', 'amount', 'comment']; + var content = result.tx.history.reduce(function(res, tx){ + return res.concat([ + tx.time, + tx.pubkey, + (''+tx.amount/100).replace('.',','), + tx.comment + ].join(';') + '\n'); + }, [headers.join(';') + '\n']); var file = new Blob(content, {type: 'text/plain; charset=utf-8'}); - var filename = $scope.pubkey+'-history.txt'; + var filename = $scope.pubkey+'-history.csv'; FileSaver.saveAs(file, filename); }); }; + + // Load chart data: received amount by pubkey + $scope.computeChartData = function(txArray) { + + // Sum TX amount, with a group by pubkey + var sumByPubkeys = {}; + _.forEach(txArray, function (tx) { + sumByPubkeys[tx.pubkey] = sumByPubkeys[tx.pubkey] || { + label: tx.uid || tx.pubkey, + sum: 0 + }; + sumByPubkeys[tx.pubkey].sum += tx.amount; + }); + + // Get values (from the map), then sort (desc) on sum + var sumItems = _.sortBy(_.values(sumByPubkeys), 'sum').reverse(); + + // Return arrays expected by angular-chart + return { + data: _.pluck(sumItems, 'sum'), + labels: _.pluck(sumItems, 'label'), + colors: gpColor.scale.custom(sumItems.length) + }; + }; }); diff --git a/www/plugins/rml9/templates/07-button.html b/www/plugins/rml9/templates/07-button.html index 7891a7b26e6b5ec7834019e1bccde41ea6d3a4bb..52bbfd3002f796c4c15ccbf9823fbd03319e6255 100644 --- a/www/plugins/rml9/templates/07-button.html +++ b/www/plugins/rml9/templates/07-button.html @@ -1,9 +1,6 @@ -<!-- [NEW] Display only if plugin is enable --> - - <!-- Button: call a method from the state controller --> - <button ng-if="enable" class="button button-balanced button-small-padding icon ion-android-archive" - ng-click="onButtonClick()" - title="{{'RML9.BTN_SWOW_TX' | translate}}"> - </button> - +<!-- Button: Open a view, using `ui-sref` attribute --> +<button class="button button-balanced button-small-padding icon ion-android-archive" + ui-sref="app.rml9({pubkey: formData.pubkey})" + title="{{'RML9.BTN_SWOW_TX' | translate}}"> +</button> diff --git a/www/plugins/rml9/templates/07-view.html b/www/plugins/rml9/templates/07-view.html index 8d52ce5eeb152e1ddc52047d6acc422973293d8a..af4e7f5d6f66e8757127a3ef9e5aca9e5a69a968 100644 --- a/www/plugins/rml9/templates/07-view.html +++ b/www/plugins/rml9/templates/07-view.html @@ -1,26 +1,2 @@ -<ion-view left-buttons="leftButtons"> - <ion-nav-title> - {{'RML9.VIEW.TITLE' | translate}} - </ion-nav-title> - <ion-content> - <div class="list"> - - <!-- the pubkey --> - <div class="item"> - {{'COMMON.PUBKEY'|translate}} - <div class="badge">{{pubkey|formatPubkey}}</div> - </div> - - <!-- a text divider--> - <div class="item item-divider">{{'RML9.VIEW.DIVIDER'|translate:{pubkey: pubkey} }}</div> - - <!-- iterate on each TX --> - <div class="item" ng-repeat="item in items"> - <h3>{{item.time|formatDate}}</h3> - <h4>{{item.pubkey|formatPubkey}}</h4> - <div class="badge">{{item.amount|formatAmount}}</div> - </div> - </div> - </ion-content> -</ion-view> + <leaflet id="map-geojson" center="map.center" geojson="map.geojson"></leaflet>