diff --git a/app/config.json b/app/config.json index 5023d74cb9afa0b50a481c40c00ad58f40f26416..a4bfaabb1090a05a8581523ac8859ca7115a8275 100644 --- a/app/config.json +++ b/app/config.json @@ -8,11 +8,30 @@ } }, + "gchange": { + "APP_CONFIG": { + "DUNITER_NODE": "cgeek.fr:9330", + "DUNITER_NODE_ES": "data.duniter.fr", + "NEW_ISSUE_LINK": "https://github.com/duniter/cesium/issues/new?labels=bug", + "TIMEOUT": 4000, + "DEBUG": false + } + }, + "dev": { "APP_CONFIG": { "DUNITER_NODE": "localhost:9201", "TIMEOUT": 6000, "DEBUG": true } + }, + + "dev-es": { + "APP_CONFIG": { + "DUNITER_NODE": "test-net.duniter.fr:9201", + "DUNITER_NODE_ES": "localhost:9200", + "TIMEOUT": 6000, + "DEBUG": true + } } } diff --git a/gulpfile.js b/gulpfile.js index 2888ce9993b8af87735196870b11d39136f4d774..79814626f880baf45b51f45eab4e885aeac47d38 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -40,10 +40,16 @@ var paths = { templates: ['./www/templates/**/*.html'], templatecache: ['./www/templates/**/*.html'], ng_translate: ['./www/i18n/locale-*.json'], - ng_annotate: ['./www/js/**/*.js', '!./www/js/vendor/*.js'] + ng_annotate: ['./www/js/**/*.js', '!./www/js/vendor/*.js'], + // plugins: + templatecache_plugin: ['./www/plugins/*/templates/**/*.html'], + ng_translate_plugin: ['./www/plugins/*/i18n/locale-*.json'], + ng_annotate_plugin: ['./www/plugins/*/js/**/*.js', '!./www/plugins/*/js/vendor/*.js'] }; -gulp.task('default', ['sass', 'config', 'templatecache', 'ng_translate', 'ng_annotate']); +gulp.task('default', ['sass', 'config', 'templatecache', 'ng_translate', 'ng_annotate', + 'templatecache_plugin', 'ng_translate_plugin', 'ng_annotate_plugin' +]); gulp.task('sass', function(done) { gulp.src('./scss/ionic.app.scss') @@ -66,8 +72,12 @@ gulp.task('sass', function(done) { gulp.task('watch', function() { gulp.watch(paths.sass, ['sass']); gulp.watch(paths.templatecache, ['templatecache']); - gulp.watch(paths.ng_translate, ['ng_translate']); gulp.watch(paths.ng_annotate, ['ng_annotate']); + gulp.watch(paths.ng_translate, ['ng_translate']); + // plugins: + gulp.watch(paths.templatecache_plugin, ['templatecache_plugin']); + gulp.watch(paths.ng_annotate_plugin, ['ng_annotate_plugin']); + gulp.watch(paths.ng_translate_plugin, ['ng_translate_plugin']); }); gulp.task('install', ['git-check'], function() { @@ -125,7 +135,7 @@ gulp.task('config', function (done) { }); gulp.task('templatecache', function (done) { - gulp.src('./www/templates/**/*.html') + gulp.src(paths.templatecache) .pipe(templateCache({ standalone:true, module:"cesium.templates", @@ -148,6 +158,32 @@ gulp.task('ng_translate', function() { .pipe(gulp.dest('www/dist/dist_js/app')); }); +/* -- Plugins -- */ +gulp.task('templatecache_plugin', function (done) { + gulp.src(paths.templatecache_plugin) + .pipe(templateCache({ + standalone:true, + module:"cesium.plugins.templates", + root: "plugins/" + })) + .pipe(gulp.dest('./www/dist/dist_js/plugins')) + .on('end', done); +}); + +gulp.task('ng_annotate_plugin', function (done) { + gulp.src(paths.ng_annotate_plugin) + .pipe(ngAnnotate({single_quotes: true})) + .pipe(gulp.dest('./www/dist/dist_js/plugins')) + .on('end', done); +}); + +gulp.task('ng_translate_plugin', function() { + return gulp.src(paths.ng_translate_plugin) + .pipe(ngTranslate({standalone:true, module: 'cesium.plugins.translations'})) + .pipe(gulp.dest('www/dist/dist_js/plugins')); +}); + +/* -- Web dist build -- */ gulp.task('clean:tmp', function(done) { return del([ './tmp' diff --git a/ionic.project b/ionic.project index 614a09d13bc3a564929cf819562577dcf5c3f73b..27234b0a0ddf9495249db5bdbfc4b088b149402a 100644 --- a/ionic.project +++ b/ionic.project @@ -8,8 +8,11 @@ "gulpStartupTasks": [ "sass", "templatecache", - "ng_translate", "ng_annotate", + "ng_translate", + "templatecache_plugin", + "ng_annotate_plugin", + "ng_translate_plugin", "watch" ], "defaultBrowser": "chrome", diff --git a/www/index.html b/www/index.html index 933daa740709e10bd25279f72f7f599dac29b86f..039de43d7919cd3cc68ac4ae1fc6a8d4a788ebf2 100644 --- a/www/index.html +++ b/www/index.html @@ -74,8 +74,17 @@ <script src="dist/dist_js/app/controllers.js"></script> <!-- templates --> - <script src="dist/dist_js/app/templates.js"></script> - <script src="dist/dist_js/app/translations.js"></script> + <script src="dist/dist_js/app/templates.js"></script> + <script src="dist/dist_js/app/translations.js"></script> + + <!-- Plugins --> + <script src="dist/dist_js/app/plugins.js"></script> + <script src="dist/dist_js/plugins/translations.js"></script> + <script src="dist/dist_js/plugins/templates.js"></script> + <script src="dist/dist_js/plugins/es/js/services/market-services.js"></script> + <script src="dist/dist_js/plugins/es/js/services/registry-services.js"></script> + <script src="dist/dist_js/plugins/es/js/controllers/market-controllers.js"></script> + <script src="dist/dist_js/plugins/es/js/controllers/registry-controllers.js"></script> <!-- App --> <script src="dist/dist_js/app/app.js"></script> diff --git a/www/js/app.js b/www/js/app.js index 2e5a51bbc589b4b3129356ef2017a453969dbc96..5de4c0525f7bd296268bf45c20bf7a6d9deacd44 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -5,10 +5,11 @@ // the 2nd parameter is an array of 'requires' // 'starter.controllers' is found in controllers.js angular.module('cesium', ['ionic', 'ionic-material', 'ngMessages', 'ngAnimate', 'pascalprecht.translate', 'angularMoment', 'ngApi', - 'cesium.controllers', 'cesium.templates','cesium.translations', + 'cesium.controllers', 'cesium.templates', 'cesium.translations', // removeIf(no-device) 'ngCordova', 'ionic-native-transitions', // endRemoveIf(no-device) + 'cesium.plugins' ]) .filter('formatInteger', function() { diff --git a/www/js/config.js b/www/js/config.js index 1756f746ea4e8012f5af4647a6d12e42276e09df..789dd4c78932cb1085575b118c2f6759735f455a 100644 --- a/www/js/config.js +++ b/www/js/config.js @@ -14,7 +14,7 @@ angular.module("cesium.config", []) "TIMEOUT": 4000, "DEBUG": false, "VERSION": "0.1.26", - "BUILD_DATE": "2016-07-04T15:23:49.649Z" + "BUILD_DATE": "2016-07-05T14:49:15.328Z" }) -; +; \ No newline at end of file diff --git a/www/js/plugins.js b/www/js/plugins.js index 171f96930aabc5179509d3cde5e2685cee040215..606ab299e6058b809617b8a6a53e423cd6ce3e1d 100644 --- a/www/js/plugins.js +++ b/www/js/plugins.js @@ -1,5 +1,10 @@ angular.module('cesium.plugins', [ - 'cesium.es.plugin' + 'cesium.plugins.translations', + 'cesium.plugins.templates', + 'cesium.registry.services', + 'cesium.market.services', + 'cesium.registry.controllers', + 'cesium.market.controllers' ]) ; diff --git a/www/js/services/utils-services.js b/www/js/services/utils-services.js index 5e8824583ad34fe2d12563418403dd545ade3424..a66b24fde186f255dfdb90cbad851f8c2e8590cb 100644 --- a/www/js/services/utils-services.js +++ b/www/js/services/utils-services.js @@ -4,7 +4,22 @@ angular.module('cesium.utils.services', ['ngResource']) function($ionicLoading, $ionicPopup, $translate, $q, ionicMaterialInk, ionicMaterialMotion, $window, $timeout) { 'ngInject'; - var loadingTextCache=null; + function exact(regexpContent) { + return new RegExp("^" + regexpContent + "$"); + } + + var + loadingTextCache=null, + CONST = { + MAX_HEIGHT: 400, + MAX_WIDTH: 400, + THUMB_MAX_HEIGHT: 150, + THUMB_MAX_WIDTH: 150 + }, + regex = { + IMAGE_SRC: exact("data:([A-Za-z//]+);base64,(.*)") + } + ; function alertError(err, subtitle) { return $q(function(resolve, reject) { @@ -166,27 +181,22 @@ angular.module('cesium.utils.services', ['ngResource']) return selectedText; } - function resizeImageFromFile(file) { - return $q(function(resolve, reject) { - - var reader = new FileReader(); - - reader.onload = function(event){ - var img = document.createElement("img"); - - img.onload = function(event) { + function imageOnLoadResize(resolve, reject, thumbnail) { + return function(event) { var width = event.target.width; var height = event.target.height; + var maxWidth = (thumbnail ? CONST.THUMB_MAX_WIDTH : CONST.MAX_WIDTH); + var maxHeight = (thumbnail ? CONST.THUMB_MAX_HEIGHT : CONST.MAX_HEIGHT); if (width > height) { - if (width > CONST.MAX_WIDTH) { - height *= CONST.MAX_WIDTH / width; - width = CONST.MAX_WIDTH; + if (width > maxWidth) { + height *= maxWidth / width; + width = maxWidth; } } else { - if (height > CONST.MAX_HEIGHT) { - width *= CONST.MAX_HEIGHT / height; - height = CONST.MAX_HEIGHT; + if (height > maxHeight) { + width *= maxHeight / height; + height = maxHeight; } } var canvas = document.createElement("canvas"); @@ -199,49 +209,94 @@ angular.module('cesium.utils.services', ['ngResource']) resolve(dataurl); }; + } - img.src = event.target.result; - }; + function resizeImageFromFile(file, thumbnail) { + return $q(function(resolve, reject) { if (file) { + var reader = new FileReader(); + reader.onload = function(event){ + var img = document.createElement("img"); + img.onload = imageOnLoadResize(resolve, reject, thumbnail); + img.src = event.target.result; + }; reader.readAsDataURL(file); } - else { - //reject("Not a file"); + }); } + + function resizeImageFromSrc(imageSrc, thumbnail) { + return $q(function(resolve, reject) { + var img = document.createElement("img"); + img.onload = imageOnLoadResize(resolve, reject, thumbnail); + img.src = imageSrc; }); } - function disableEffects() { - this.ink = function(){}; - - function disableMotion(baseSelector) { - return function(options) { - if (!options || !options.selector) { - options = { - selector: (baseSelector + ' .item') - }; - } - var parentsInDom = document.querySelectorAll(baseSelector); - for (var i = 0; i < parentsInDom.length; i++) { - var parent = parentsInDom[i]; - parent.className = parent.className.replace(/\banimate-[a-z- ]+\b/,''); - } + function imageFromAttachment(attachment) { + if (!attachment || !attachment._content_type || !attachment._content) { + return null; + } + var image = { + src: "data:" + attachment._content_type + ";base64," + attachment._content + }; + if (attachment._title) { + image.title = attachment._title; + } + if (attachment._name) { + image.name = attachment._name; + } + return image; + } - var itemsInDom = document.querySelectorAll(options.selector); - for (var j = 0; j < itemsInDom.length; j++) { - var child = itemsInDom[j]; - child.style.webkitTransitionDelay = "0s"; - child.style.transitionDelay = "0s"; - child.className += ' in done'; - } + function imageToAttachment(image) { + if (!image || !image.src) return null; + var match = regex.IMAGE_SRC.exec(image.src); + if (!match) return null; + var attachment = { + _content_type: match[1], + _content: match[2] }; + if (image.title) { + attachment._title = image.title; } - - this.motion.fadeSlideIn= disableMotion('.animate-fade-slide-in'); - this.motion.fadeSlideInRight = disableMotion('.animate-fade-slide-in-right'); + if (image.name) { + attachment._name = image.name; + } + return attachment; } + function disableEffects() { + this.ink = function(){}; + + function disableMotion(baseSelector) { + return function(options) { + if (!options || !options.selector) { + options = { + selector: (baseSelector + ' .item') + }; + } + var parentsInDom = document.querySelectorAll(baseSelector); + for (var i = 0; i < parentsInDom.length; i++) { + var parent = parentsInDom[i]; + parent.className = parent.className.replace(/\banimate-[a-z- ]+\b/,''); + } + + var itemsInDom = document.querySelectorAll(options.selector); + for (var j = 0; j < itemsInDom.length; j++) { + var child = itemsInDom[j]; + child.style.webkitTransitionDelay = "0s"; + child.style.transitionDelay = "0s"; + child.className += ' in done'; + } + }; + } + + this.motion.fadeSlideIn= disableMotion('.animate-fade-slide-in'); + this.motion.fadeSlideInRight = disableMotion('.animate-fade-slide-in-right'); + } + return { alert: { error: alertError, @@ -264,9 +319,29 @@ angular.module('cesium.utils.services', ['ngResource']) get: getSelectionText }, image: { - resize: resizeImageFromFile + resizeFile: resizeImageFromFile, + resizeSrc: resizeImageFromSrc, + fromAttachment: imageFromAttachment, + toAttachment: imageToAttachment } }; }) + +// See http://plnkr.co/edit/vJQXtsZiX4EJ6Uvw9xtG?p=preview +.factory('$focus', function($timeout, $window) { + 'ngInject'; + + return function(id) { + // timeout makes sure that it is invoked after any other event has been triggered. + // e.g. click events that need to run before the focus or + // inputs elements that are in a disabled state but are enabled when those events + // are triggered. + $timeout(function() { + var element = $window.document.getElementById(id); + if(element) + element.focus(); + }); + }; +}) ; diff --git a/www/js/services/wallet-services.js b/www/js/services/wallet-services.js index 9c4ede326fa23e302d11714908b0c3f95badea0f..94909c55462b1b64bed1a0bce6306956ad918800 100644 --- a/www/js/services/wallet-services.js +++ b/www/js/services/wallet-services.js @@ -528,6 +528,30 @@ angular.module('cesium.wallet.services', ['ngResource', 'ngApi', 'cesium.bma.ser }); }, + /*loadAvatar = function() { + return $q(function(resolve, reject) { + if (!Registry) { + data.avatar = null; + resolve(); + return; + } + Registry.record.avatar(data.pubkey) + .then(function(imageData) { + if (imageData) { + data.avatar = imageData; + } + else { + data.avatar = null; + } + resolve(); + }) + .catch(function(err) { + data.avatar = null; // silent ! + resolve(); + }); + }); + },*/ + loadData = function() { if (data.loaded) { return refreshData();