From 413e7bce9121cacb0335e00f08de4c8dde3f4222 Mon Sep 17 00:00:00 2001 From: blavenie <benoit.lavenier@e-is.pro> Date: Fri, 18 Mar 2016 18:14:03 +0100 Subject: [PATCH] - Add config.json to manage build environment - Hide loading after login on Registry & Market - Add compilation doc on README.md - Upgrade dependencies for nodejs 5 --- README.md | 37 +++++++++++++++++++ app/config.json | 29 +++++++++++++++ gulpfile.js | 43 +++++++++++++++++++++- ionic.project | 4 ++ package.json | 10 +++-- www/css/{style.css => cesium.css} | 0 www/css/{market.css => cesium.market.css} | 0 www/index.html | 13 ++++--- www/js/app.js | 3 -- www/js/config.js | 19 ++++++++++ www/js/controllers/home-controllers.js | 12 +++++- www/js/controllers/market-controllers.js | 4 ++ www/js/controllers/registry-controllers.js | 3 ++ www/js/services.js | 1 + www/js/services/bma-services.js | 10 ++--- www/js/services/market-services.js | 7 ++-- www/js/services/registry-services.js | 13 ++----- www/templates/home.html | 4 +- www/templates/menu.html | 4 +- 19 files changed, 179 insertions(+), 37 deletions(-) create mode 100644 app/config.json rename www/css/{style.css => cesium.css} (100%) rename www/css/{market.css => cesium.market.css} (100%) create mode 100644 www/js/config.js diff --git a/README.md b/README.md index d1ced1ae6..bf86f8c39 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,40 @@ Try it at: http://cesium.ucoin.io +## Developer + +To contribute and compile cesium, you will have to: + + - Installing [mvn](https://github.com/creationix/nvm) +``` + wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash +``` + + - Configure NodeJS to use a version 5: +``` + nvm install 5 +``` + + - Installing other build dependencies: +``` + sudo apt-get install build-essential +``` + + - Getting source and installing project dependencies: +``` + git clone https://www.github.com/ucoin-io/cesium.git + cd cesium + npm install +``` + + - Compiling and running application +``` + gulp & ionic serve +``` + + - To build on another environment : + - Add your environment config into `app/config.json` + - Run compitaltion using option `--env`: +``` + gulp default --env <your_env_name> +``` diff --git a/app/config.json b/app/config.json new file mode 100644 index 000000000..3c318c1f6 --- /dev/null +++ b/app/config.json @@ -0,0 +1,29 @@ +{ + "default": { + "APP_CONFIG": { + "UCOIN_NODE": "metab.ucoin.io" + } + }, + + "prod-ucoin-io": { + "APP_CONFIG": { + "UCOIN_NODE": "metab.ucoin.io" + } + }, + + "prod-ucoin-fr": { + "APP_CONFIG": { + "UCOIN_NODE": "metab.ucoin.fr" + } + }, + + "dev-eis": { + "APP_CONFIG": { + "UCOIN_NODE": "metab.ucoin.fr", + "UCOIN_NODE_WS": "metab.ucoin.fr:9201", + "UCOIN_NODE_ES": "localhost:9200" + } + + } + +} \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index 3efdfc0a1..001a3b939 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,3 +1,5 @@ +'use strict'; + var gulp = require('gulp'); var gutil = require('gulp-util'); var bower = require('bower'); @@ -6,12 +8,17 @@ var sass = require('gulp-sass'); var minifyCss = require('gulp-minify-css'); var rename = require('gulp-rename'); var sh = require('shelljs'); +var ngConstant = require('gulp-ng-constant'); +var fs = require("fs"); +var argv = require('yargs').argv; +var header = require('gulp-header'); var paths = { - sass: ['./scss/**/*.scss'] + sass: ['./scss/**/*.scss'], + config: ['./app/config.json'] }; -gulp.task('default', ['sass']); +gulp.task('default', ['sass', 'config']); gulp.task('sass', function(done) { gulp.src('./scss/ionic.app.scss') @@ -29,6 +36,7 @@ gulp.task('sass', function(done) { gulp.task('watch', function() { gulp.watch(paths.sass, ['sass']); + //gulp.watch(paths.config, ['config']); }); gulp.task('install', ['git-check'], function() { @@ -50,3 +58,34 @@ gulp.task('git-check', function(done) { } done(); }); + +gulp.task('config', function (done) { + var allConfig = JSON.parse(fs.readFileSync('./app/config.json', 'utf8')); + + // Determine which environment to use when building config. + var env = argv.env || 'default'; + var config = allConfig[env]; + + if(!config) { + gutil.log(gutil.colors.red("=> Could not load `" + env + "` environment!")); + return done(); + } + + gutil.log(gutil.colors.green("Building `www/js/config.js` for `" + env + "` environment...")); + + config['APP_CONFIG']['VERSION'] = JSON.parse(fs.readFileSync('./package.json', 'utf8')).version; + config['APP_CONFIG']['BUILD_DATE'] = (new Date()).toJSON(); + + return ngConstant({ + name: 'cesium.config', + constants: config, + stream: true, + dest: 'config.js' + }) + // Add a warning header + .pipe(header("/******\n* !! WARNING: This is a generated file !!\n*\n* PLEASE DO NOT MODIFY DIRECTLY\n*\n* => Changes should be done on file 'app/config.json'.\n******/\n\n")) + // Writes into file www/js/config.js + .pipe(rename('config.js')) + .pipe(gulp.dest('www/js')) + ; +}); \ No newline at end of file diff --git a/ionic.project b/ionic.project index e5e281461..45fe93342 100644 --- a/ionic.project +++ b/ionic.project @@ -4,5 +4,9 @@ "watchPatterns": [ "www/**/*", "!www/lib/**/*" + ], + "gulpStartupTasks": [ + "sass", + "watch" ] } diff --git a/package.json b/package.json index ed7b43c40..bc34f90ce 100644 --- a/package.json +++ b/package.json @@ -4,15 +4,19 @@ "description": "A webapp client for uCoin network", "dependencies": { "gulp": "^3.5.6", - "gulp-sass": "^1.3.3", "gulp-concat": "^2.2.0", "gulp-minify-css": "^0.3.0", - "gulp-rename": "^1.2.0" + "gulp-rename": "^1.2.0", + "gulp-sass": "^2.2.0", + "node-sass": "^3.3.3" }, "devDependencies": { "bower": "^1.3.3", + "shelljs": "^0.3.0", "gulp-util": "^2.2.14", - "shelljs": "^0.3.0" + "gulp-ng-constant": "^1.1.0", + "yargs": "^4.3.1", + "gulp-header": "^1.7.1" }, "cordovaPlugins": [ "cordova-plugin-device", diff --git a/www/css/style.css b/www/css/cesium.css similarity index 100% rename from www/css/style.css rename to www/css/cesium.css diff --git a/www/css/market.css b/www/css/cesium.market.css similarity index 100% rename from www/css/market.css rename to www/css/cesium.market.css diff --git a/www/index.html b/www/index.html index 05e8edd52..66cba6d0d 100644 --- a/www/index.html +++ b/www/index.html @@ -5,13 +5,11 @@ <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> <title></title> - <link href="lib/ionic/css/ionic.css" rel="stylesheet"> - <link href="css/style.css" rel="stylesheet"> - <link href="css/market.css" rel="stylesheet"> + <link href="css/cesium.css" rel="stylesheet"> + <link href="css/cesium.market.css" rel="stylesheet"> - <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above - <link href="css/ionic.app.css" rel="stylesheet"> - --> + <!-- compiled css output --> + <link href="css/ionic.app.min.css" rel="stylesheet"> <!-- ionic/angularjs js --> <script src="lib/ionic/js/ionic.bundle.js"></script> @@ -34,6 +32,9 @@ <!-- cordova script (this will be a 404 during development) --> <script src="cordova.js"></script> + <!-- config --> + <script src="js/config.js"></script> + <!-- services --> <script src="js/services/crypto-services.js"></script> <script src="js/services/utils-services.js"></script> diff --git a/www/js/app.js b/www/js/app.js index c06b42d84..95371216f 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -78,7 +78,6 @@ angular.module('cesium', ['ionic', 'ngMessages', 'pascalprecht.translate', 'cesi }; }) - .run(function($ionicPlatform) { $ionicPlatform.ready(function() { // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard @@ -92,6 +91,4 @@ angular.module('cesium', ['ionic', 'ngMessages', 'pascalprecht.translate', 'cesi } }); }) - - ; diff --git a/www/js/config.js b/www/js/config.js new file mode 100644 index 000000000..222a49881 --- /dev/null +++ b/www/js/config.js @@ -0,0 +1,19 @@ +/****** +* !! WARNING: This is a generated file !! +* +* PLEASE DO NOT MODIFY DIRECTLY +* +* => Changes should be done on file 'app/config.json'. +******/ + +angular.module("cesium.config", []) + +.constant("APP_CONFIG", { + "UCOIN_NODE": "metab.ucoin.fr", + "UCOIN_NODE_WS": "metab.ucoin.fr:9201", + "UCOIN_NODE_ES": "localhost:9200", + "VERSION": "0.0.1", + "BUILD_DATE": "2016-03-18T17:08:53.353Z" +}) + +; \ No newline at end of file diff --git a/www/js/controllers/home-controllers.js b/www/js/controllers/home-controllers.js index 34d490c1a..3c9bb7580 100644 --- a/www/js/controllers/home-controllers.js +++ b/www/js/controllers/home-controllers.js @@ -184,7 +184,7 @@ function LoginController($scope, $ionicModal, Wallet, CryptoUtils, UIUtils, $q, }; } -function HomeController($scope, $ionicSlideBoxDelegate, $ionicModal, $state, BMA, UIUtils, $q, $timeout, Wallet, CryptoUtils, $ionicSideMenuDelegate) { +function HomeController($scope, $ionicSlideBoxDelegate, $ionicModal, $state, $ionicSideMenuDelegate, UIUtils, $q, $timeout, CryptoUtils, BMA, Wallet, Registry, APP_CONFIG) { // With the new view caching in Ionic, Controllers are only called // when they are recreated or on app start, instead of every page change. @@ -202,6 +202,16 @@ function HomeController($scope, $ionicSlideBoxDelegate, $ionicModal, $state, BMA $scope.accountData = {}; $scope.accountForm = {}; + var nodeWithES = APP_CONFIG.UCOIN_NODE_ES != "undefined" && APP_CONFIG.UCOIN_NODE_ES != null; + $scope.options = { + market: { + enable: nodeWithES + }, + registry: { + enable: nodeWithES + } + }; + // Called to navigate to the main app $scope.cancel = function() { $scope.newAccountModal.hide(); diff --git a/www/js/controllers/market-controllers.js b/www/js/controllers/market-controllers.js index 9150d5937..e0e7d3743 100644 --- a/www/js/controllers/market-controllers.js +++ b/www/js/controllers/market-controllers.js @@ -250,8 +250,12 @@ function MarketRecordEditController($scope, $ionicModal, Wallet, Market, UIUtils .then(function(walletData) { $scope.walletData = walletData; if ($state.stateParams && $state.stateParams.id) { // Load by id + UIUtils.loading.show(); $scope.load($state.stateParams.id); } + else { + UIUtils.loading.hide(); + } }); }); diff --git a/www/js/controllers/registry-controllers.js b/www/js/controllers/registry-controllers.js index 1bbd3af02..719c75a0f 100644 --- a/www/js/controllers/registry-controllers.js +++ b/www/js/controllers/registry-controllers.js @@ -254,6 +254,9 @@ function RegistryRecordEditController($scope, $ionicModal, Wallet, Registry, UIU if ($state.stateParams && $state.stateParams.id) { // Load by id $scope.load($state.stateParams.id); } + else { + UIUtils.loading.hide(); + } }); }); diff --git a/www/js/services.js b/www/js/services.js index dd892437d..650bb8320 100644 --- a/www/js/services.js +++ b/www/js/services.js @@ -1,4 +1,5 @@ angular.module('cesium.services', [ + 'cesium.config', 'cesium.bma.services', 'cesium.crypto.services', 'cesium.utils.services', diff --git a/www/js/services/bma-services.js b/www/js/services/bma-services.js index 924da438f..1f76f4351 100644 --- a/www/js/services/bma-services.js +++ b/www/js/services/bma-services.js @@ -1,8 +1,9 @@ //var Base58, Base64, scrypt_module_factory = null, nacl_factory = null; -angular.module('cesium.bma.services', ['ngResource']) +angular.module('cesium.bma.services', ['ngResource', + 'cesium.config']) -.factory('BMA', function($http, $q) { +.factory('BMA', function($http, $q, APP_CONFIG) { function BMA(server, wsServer) { if (wsServer == "undefined" || wsServer == null) { @@ -132,9 +133,8 @@ angular.module('cesium.bma.services', ['ngResource']) } } } - var service = BMA('metab.ucoin.fr', 'metab.ucoin.fr:9201'); - //var service = BMA('192.168.0.28:9201'); - //var service = BMA('metab.ucoin.io'); + + var service = BMA(APP_CONFIG.UCOIN_NODE, APP_CONFIG.UCOIN_NODE_WS); service.instance = BMA; return service; }) diff --git a/www/js/services/market-services.js b/www/js/services/market-services.js index b8efc1f26..c4203383b 100644 --- a/www/js/services/market-services.js +++ b/www/js/services/market-services.js @@ -1,6 +1,6 @@ -angular.module('cesium.market.services', ['ngResource', 'cesium.services']) +angular.module('cesium.market.services', ['ngResource', 'cesium.services', 'cesium.config']) -.factory('Market', function($http, $q, CryptoUtils) { +.factory('Market', function($http, $q, CryptoUtils, APP_CONFIG) { function Market(server, wsServer) { @@ -210,8 +210,7 @@ angular.module('cesium.market.services', ['ngResource', 'cesium.services']) } } - var service = Market('localhost:9200'); - //var service = ES('metab.ucoin.fr:9288'); + var service = Market(APP_CONFIG.UCOIN_NODE_ES); service.instance = Market; return service; diff --git a/www/js/services/registry-services.js b/www/js/services/registry-services.js index 9d2b3c786..245201b2e 100644 --- a/www/js/services/registry-services.js +++ b/www/js/services/registry-services.js @@ -1,15 +1,11 @@ angular.module('cesium.registry.services', ['ngResource', 'cesium.services']) -.factory('Registry', function($http, $q, CryptoUtils) { +.factory('Registry', function($http, $q, CryptoUtils, APP_CONFIG) { - function Registry(server, wsServer) { + function Registry(server) { var categories = []; - if (wsServer == "undefined" || wsServer == null) { - wsServer = server; - } - function processError(reject, data) { if (data != null && data.message != "undefined" && data.message != null) { reject(data.ucode + ": " + data.message); @@ -210,10 +206,9 @@ angular.module('cesium.registry.services', ['ngResource', 'cesium.services']) } } - var service = Registry('localhost:9200'); - //var service = ES('metab.ucoin.fr:9288'); - + var service = Registry(APP_CONFIG.UCOIN_NODE_ES); service.instance = Registry; + return service; }) ; diff --git a/www/templates/home.html b/www/templates/home.html index 13ca7be65..9ab3740f7 100644 --- a/www/templates/home.html +++ b/www/templates/home.html @@ -13,9 +13,9 @@ <h1 translate>HOME.WELCOME</h1> <h2 translate>HOME.MESSAGE</h2> - <a ui-sref="app.registry_lookup" class="button button-block button-stable icon icon-left ion-person-stalker" translate>HOME.BTN_REGISTRY</a> + <a ui-sref="app.registry_lookup" class="button button-block button-stable icon icon-left ion-person-stalker" ng-if="options.registry.enable" translate>HOME.BTN_REGISTRY</a> - <a ui-sref="app.market_lookup" class="button button-block button-stable icon icon-left ion-bag" translate>HOME.BTN_MARKET</a> + <a ui-sref="app.market_lookup" class="button button-block button-stable icon icon-left ion-bag" ng-if="options.market.enable" translate>HOME.BTN_MARKET</a> <a ui-sref="app.explore_currency" class="button button-block button-stable icon icon-left ion-ios-world-outline" translate>HOME.BTN_CURRENCIES</a> diff --git a/www/templates/menu.html b/www/templates/menu.html index 870b4bd6d..8ce11c3fb 100644 --- a/www/templates/menu.html +++ b/www/templates/menu.html @@ -15,10 +15,10 @@ <ion-item menu-close href="#/app/home"> <span translate>MENU.HOME</span> </ion-item> - <ion-item menu-close href="#/app/registry"> + <ion-item menu-close href="#/app/registry" ng-if="options.registry.enable"> <span translate>MENU.REGISTRY</span> </ion-item> - <ion-item menu-close href="#/app/market"> + <ion-item menu-close href="#/app/market" ng-if="options.market.enable"> <span translate>MENU.MARKET</span> </ion-item> <ion-item menu-close href="#/app/currency"> -- GitLab