diff --git a/README.md b/README.md index d1ced1ae63fa246c0d503c627ed734ad5dab6921..bf86f8c394e6f5eb611514f662ab4aa2509d4f0a 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 0000000000000000000000000000000000000000..3c318c1f69e7f25474840a3ff180b7fe5a3f2f93 --- /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 3efdfc0a155bfeca424e5ef5a7d75c4b145def99..001a3b939206e4e20acd235515f6cef34a57d555 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 e5e2814615e65b65776eb19601dea3ce03408069..45fe9334234dffc405265ebdc58702a8cd75e093 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 ed7b43c4075bd3162618d7381878e0adc66e5538..bc34f90ce6ba7b57f3b142a939e697540c7abf41 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 05e8edd5272b4495f8f4d26c40036d853ae94217..66cba6d0ddfccdb4b3ffca1734adc36048c51fa7 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 c06b42d84c766c3bbe67875e694bc86d074b795e..95371216f77ef00587c81b09294f20ad3e0b258d 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 0000000000000000000000000000000000000000..222a49881073027652e077e0c63979f56d5c0389 --- /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 34d490c1a8e597d63586393ca97f72eea6c10fce..3c9bb7580335a7fb8505bb376a5fe9eed29a1c47 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 9150d59372a0f48d3e67d8613c94b5f10924e660..e0e7d37437ac16f52eeb061cf1292021a0026126 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 1bbd3af02a7c0ebe670c18b50efe3eafff57dfaf..719c75a0fe87c052c4b18a7c1860d713b67804a7 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 dd892437dc92e0ea919773f0a6ab50a9d8d31bdc..650bb8320419e8dfbff7c1f83fe591a1a8accb6a 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 924da438f1e080392301cb4e7a2ed8c15cc75840..1f76f4351cfcd7007d7658b00994f69b363032f5 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 b8efc1f26ac348be84753d9d72e66d044c6e0239..c4203383b04d2c33f8b41a47221e76b8d2820eac 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 9d2b3c786e94590bf9ecc24d131990837cbadf0a..245201b2ec62774023ca8317f2019c3713a08f59 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 13ca7be65629efda027b4eb69934beb53ab30071..9ab3740f7eb026708165bdd9a3432bdb2717775c 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 870b4bd6d41fdb549c1097dc76c55b2c2c5cd855..8ce11c3fbcf6b9f9399967de29420c85c982759b 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">