Created ngXosHelper lib
diff --git a/xos/core/xoslib/ngXosLib/README.md b/xos/core/xoslib/ngXosLib/README.md
index 65f3529..f1d5018 100644
--- a/xos/core/xoslib/ngXosLib/README.md
+++ b/xos/core/xoslib/ngXosLib/README.md
@@ -30,6 +30,22 @@
>_NOTE before adding libraries please discuss it to avoid this file to became huge_
+### Helpers
+
+XOS comes with an helper library that is automatically loaded in the Django template.
+
+To use it, add `xos.helpers` to your required modules:
+
+```
+angular.module('xos.myView', [
+ 'xos.helpers'
+])
+```
+
+It will automatically ad a `token` to all your request, eventually you can take advantage of some other services:
+
+- **NoHyperlinks Interceptor**: will add a `?no_hyperlinks=1` to your request, to tell Django to return ids instead of links.
+
### Yo Xos
We have created a [yeoman](http://yeoman.io/) generator to help you scaffolding views.
diff --git a/xos/core/xoslib/ngXosLib/generator-xos/app/templates/gulp/server.js b/xos/core/xoslib/ngXosLib/generator-xos/app/templates/gulp/server.js
index 2ffbade..907dd19 100644
--- a/xos/core/xoslib/ngXosLib/generator-xos/app/templates/gulp/server.js
+++ b/xos/core/xoslib/ngXosLib/generator-xos/app/templates/gulp/server.js
@@ -39,7 +39,8 @@
server: {
baseDir: options.src,
routes: {
- '/api': options.api
+ '/api': options.api,
+ '/xosHelpers': options.helpers
},
middleware: function(req, res, next){
if(req.url.indexOf('no_hyperlinks') !== -1){
@@ -75,7 +76,8 @@
inject(
gulp.src([
options.tmp + '**/*.js',
- options.api + '*.js'
+ options.api + '*.js',
+ options.helpers + '**/*.js'
])
.pipe(angularFilesort()),
{
diff --git a/xos/core/xoslib/ngXosLib/generator-xos/app/templates/gulpfile.js b/xos/core/xoslib/ngXosLib/generator-xos/app/templates/gulpfile.js
index 94aa335..948a99d 100644
--- a/xos/core/xoslib/ngXosLib/generator-xos/app/templates/gulpfile.js
+++ b/xos/core/xoslib/ngXosLib/generator-xos/app/templates/gulpfile.js
@@ -9,6 +9,7 @@
tmp: 'src/.tmp',
dist: 'dist/',
api: '../../ngXosLib/api/',
+ helpers: '../../ngXosLib/xosHelpers/',
static: '../../static/', // this is the django static folder
dashboards: '../../dashboards/' // this is the django html folder
};
diff --git a/xos/core/xoslib/ngXosLib/generator-xos/app/templates/src/js/main.js b/xos/core/xoslib/ngXosLib/generator-xos/app/templates/src/js/main.js
index 728394a..9a7bb98 100644
--- a/xos/core/xoslib/ngXosLib/generator-xos/app/templates/src/js/main.js
+++ b/xos/core/xoslib/ngXosLib/generator-xos/app/templates/src/js/main.js
@@ -12,6 +12,7 @@
'ngRoute',
'ngCookies',
'ngLodash',
+ 'xos.helpers',
'xos.xos'
])
.config(($interpolateProvider, $routeProvider, $resourceProvider) => {
@@ -28,29 +29,11 @@
.otherwise('/');
})
-// TODO move this in xos.service module
.config(function($httpProvider){
// add X-CSRFToken header for update, create, delete (!GET)
$httpProvider.interceptors.push('SetCSRFToken');
+ $httpProvider.interceptors.push('NoHyperlinks');
})
-.factory('SetCSRFToken', function($cookies){
- return {
- request: function(request){
-
- // if request is not HTML
- if(request.url.indexOf('.html') === -1){
- request.url += '?no_hyperlinks=1';
- }
-
- if(request.method !== 'GET'){
- // request.headers['X-CSRFToken'] = $cookies.get('csrftoken');
- request.headers['X-CSRFToken'] = $cookies.get('xoscsrftoken');
- }
- return request;
- }
- };
-})
-// ENDTODO
.directive('usersList', function(xos){
return {
restrict: 'E',
diff --git a/xos/core/xoslib/ngXosLib/gulp/ngXosHelpers.js b/xos/core/xoslib/ngXosLib/gulp/ngXosHelpers.js
new file mode 100644
index 0000000..cc68513
--- /dev/null
+++ b/xos/core/xoslib/ngXosLib/gulp/ngXosHelpers.js
@@ -0,0 +1,16 @@
+var gulp = require('gulp');
+var uglify = require('gulp-uglify');
+var concat = require("gulp-concat");
+var ngAnnotate = require('gulp-ng-annotate');
+var angularFilesort = require('gulp-angular-filesort');
+
+module.exports = function(options){
+ gulp.task('helpers', function(){
+ return gulp.src([options.xosHelperSource + '**/*.js'])
+ .pipe(angularFilesort())
+ .pipe(concat('ngXosHelpers.js'))
+ .pipe(ngAnnotate())
+ .pipe(uglify())
+ .pipe(gulp.dest(options.ngXosVendor));
+ });
+};
\ No newline at end of file
diff --git a/xos/core/xoslib/ngXosLib/gulpfile.js b/xos/core/xoslib/ngXosLib/gulpfile.js
index d693457..25bf8fa 100644
--- a/xos/core/xoslib/ngXosLib/gulpfile.js
+++ b/xos/core/xoslib/ngXosLib/gulpfile.js
@@ -4,7 +4,8 @@
var wrench = require('wrench');
var options = {
- ngXosVendor: '../static/js/vendor/' //save here the minfied vendor file, this is automatically loaded in the django page
+ ngXosVendor: '../static/js/vendor/', //save here the minfied vendor file, this is automatically loaded in the django page
+ xosHelperSource: './xosHelpers/'
};
wrench.readdirSyncRecursive('./gulp')
diff --git a/xos/core/xoslib/ngXosLib/package.json b/xos/core/xoslib/ngXosLib/package.json
index 5239a41..f6f1391 100644
--- a/xos/core/xoslib/ngXosLib/package.json
+++ b/xos/core/xoslib/ngXosLib/package.json
@@ -18,7 +18,9 @@
},
"devDependencies": {
"gulp": "^3.9.0",
+ "gulp-angular-filesort": "^1.1.1",
"gulp-concat": "^2.6.0",
+ "gulp-ng-annotate": "^1.1.0",
"gulp-uglify": "^1.4.2",
"wiredep": "^3.0.0-beta",
"wrench": "^1.5.8"
diff --git a/xos/templates/admin/base.html b/xos/templates/admin/base.html
index 1187d35..04ec651 100644
--- a/xos/templates/admin/base.html
+++ b/xos/templates/admin/base.html
@@ -22,6 +22,7 @@
<!-- ngXosLib -->
<script src="{% static 'js/vendor/ngXosVendor.js' %}"></script>
+ <script src="{% static 'js/vendor/ngXosHelpers.js' %}"></script>
<script src="{% static 'js/xosApi.js' %}"></script>
<script type="text/javascript">var Suit = { $: $.noConflict() }; if (!$) $ = Suit.$; </script>