diff --git a/doc/fr/development_tutorial-04-add_plugin.md b/doc/fr/development_tutorial-04-add_plugin.md index 76ccc63491411dbfa2c538bafe3fb1d26b0e8d09..24e4603ca1ea9579250d7b5feb045b26039fc069 100644 --- a/doc/fr/development_tutorial-04-add_plugin.md +++ b/doc/fr/development_tutorial-04-add_plugin.md @@ -226,7 +226,7 @@ __Objectif :__ L'objectif est d'apprendre à ajouter une nouvelle page (un nouve ### Activation du plugin (en version `02`) -Editez le fichier `www/index.html` pour activer cette fois le plugin en version 2 : +Editez le fichier `www/index.html` pour activer cette fois le plugin en version `02` (remettre en commentaire la version précédente): ```html <script src="dist/dist_js/plugins/rml9/plugin-02-add_view.js"></script> ``` @@ -535,18 +535,41 @@ A vous de jouer, afin de remplacer par du contenu dynamique ! -## Niveau XVII : Etendre un service +## Niveau XVII : Etendre les services __Objectif :__ Nous allons voir comment étendre le fonctionnement du code présent dans les services. ### Activation du plugin (en version `05`) +Editez le fichier `www/index.html` pour activer cette fois le plugin en version `05` : +``` + <script src="dist/dist_js/plugins/rml9/plugin-05-service_api.js"></script> +``` + +### Se repérer dans le code + +Dans le code du plugin, observez notamment les lignes suivantes : +``` +// [NEW] Add a RML9 service, that listen some Cesium events + .factory('rml9Service', function($rootScope, csWallet, csWot) { + 'ngInject'; + var exports = {}; -TODO + // [NEW] add listeners on Cesium services + csWallet.api.data.on.login($rootScope, function(walletData, deferred){ + console.log('[RML9] Successfull login. Wallet data:', walletData); + // IMPORTANT: this is required, because of async call of extension + deferred.resolve(); + }, this); + (...) + + return exports; + }); +``` ## Niveau XVIII : Etendre les paramètres @@ -555,9 +578,13 @@ __Objectif :__ Nous allons voir comment étendre les paramètres de Cesium, en y ### Activation du plugin (en version `06`) -Dans le code du plugin (fichier `www/plugins/rml9/plugin-06-settings`) observez notamment cette partie : +Dans le code du plugin (fichier `www/plugins/rml9/plugin-06-settings`). -```js +### Se repérer dans le code + +Observez notamment cette partie du code du plugin : + +``` .controller('Rml9ButtonCtrl', function($scope, UIUtils, csSettings) { 'ngInject'; diff --git a/www/index.html b/www/index.html index 8865cada473545f2af6bfecf9dfd534ad292d334..f7a330e1ac49e1ddc62689c81f0a36ecb6243e9c 100644 --- a/www/index.html +++ b/www/index.html @@ -181,7 +181,7 @@ <!--<script src="dist/dist_js/plugins/rml9/plugin-02-add_view.js"></script>--> <!--<script src="dist/dist_js/plugins/rml9/plugin-03-file_export.js"></script>--> <!--script src="dist/dist_js/plugins/rml9/plugin-04-chart.js"></script--> - <!--<script src="dist/dist_js/plugins/rml9/plugin-06-service_api.js"></script>--> + <!--<script src="dist/dist_js/plugins/rml9/plugin-05-service_api.js"></script>--> <!--<script src="dist/dist_js/plugins/rml9/plugin-06-settings.js"></script>--> <!--<script src="dist/dist_js/plugins/rml9/plugin-final.js"></script>--> diff --git a/www/js/config.js b/www/js/config.js index 49a7f8e818c8b3f1886b34daae96ee4fb470c591..e28fc7fe468ca6364340bc0c387e59a6d2a78062 100644 --- a/www/js/config.js +++ b/www/js/config.js @@ -47,11 +47,14 @@ angular.module("cesium.config", []) "certSent": true, "certReceived": true } - } + }, + "rml9": { + enable: true + } }, "version": "0.12.7", "build": "2017-05-31T14:31:24.792Z", "newIssueUrl": "https://github.com/duniter/cesium/issues/new?labels=bug" }) -; \ No newline at end of file +; diff --git a/www/plugins/rml9/plugin-05-service_api.js b/www/plugins/rml9/plugin-05-service_api.js index 7aa169c40ac4e38f1feb59bfc100e0e694e32150..ff5f1efa3c2557c47d6b1330f09da9f683f12380 100644 --- a/www/plugins/rml9/plugin-05-service_api.js +++ b/www/plugins/rml9/plugin-05-service_api.js @@ -1,75 +1,42 @@ angular.module('cesium.rml9.plugin', ['cesium.services']) - .config(function($stateProvider, PluginServiceProvider, csConfig) { + .config(function(PluginServiceProvider, csConfig) { 'ngInject'; var enable = csConfig.plugins && csConfig.plugins.rml9; if (enable) { - - PluginServiceProvider - - // Extension de la vue d'une identité: ajout d'un bouton - .extendState('app.wot_identity', { - points: { - 'buttons': { - templateUrl: "plugins/rml9/templates/04-button.html", - controller: 'Rml9ButtonCtrl' - } - } - }) - - // Extension de 'Mes opérations' : insertion d'un bouton - .extendState('app.view_wallet_tx', { - points: { - 'buttons': { - templateUrl: "plugins/rml9/templates/04-button.html", - controller: 'Rml9ButtonCtrl' - } - } - }); - - // [NEW] Ajout d'une entrée dans les paramètres générale - PluginServiceProvider.extendState('app.settings', { - points: { - 'plugins': { - templateUrl: "plugins/rml9/templates/04-settings_item.html" - } - } - }); + // [NEW] Will force to load this RML9 service + PluginServiceProvider.registerEagerLoadingService('rml9Service'); } }) - // Manage events from the plugin button - .controller('Rml9ButtonCtrl', function($scope, UIUtils, - // [NEW] Service d'accès aux paramètres - csSettings) { + // [NEW] Add a RML9 service, that listen some Cesium events + .factory('rml9Service', function($rootScope, csWallet, csWot) { 'ngInject'; + var exports = {}; - // [NEW] A simple helper method - function isEnable(settings) { - return settings.plugins && settings.plugins.rml9 && settings.plugins.rml9.enable; - } + console.log('[RML9] Starting rml9Service service...'); - // [NEW] Nouvelle variable stockée dans le contexte de la page - $scope.enable = isEnable(csSettings.data); + // [NEW] add listeners on Cesium services + csWallet.api.data.on.login($rootScope, function(walletData, deferred){ + console.log('[RML9] Successfull login. Wallet data:', walletData); - // [NEW] Rafraichir cette variable à chaque changement dans les paramètres - csSettings.api.data.on.changed($scope, function(settings) { - console.debug("[RML9] Detect changes in settings!"); + // IMPORTANT: this is required, because of async call of extension + deferred.resolve(); + }, this); - $scope.enable = isEnable(settings); - console.debug("[RML9] RML9 plugin enable: " + $scope.enable); - }); + csWot.api.data.on.load($rootScope, function(idty, deferred){ + console.log('[RML9] Loading a wot identity: ', idty); + deferred.resolve(); + }, this); + csWot.api.data.on.search($rootScope, function(searchText, datas, pubkeyAtributeName, deferred){ + console.log('[RML9] Searching on Wot registry, using [searchText,datas]: ', searchText, datas); + deferred.resolve(); + }, this); - // Click event on button - $scope.onButtonClick = function() { - console.debug("[RML9] call function onButtonClick()"); - UIUtils.toast.show("Fine, this plugin works !"); - }; + return exports; }); - -