Skip to content

Commit 1669e53

Browse files
authored
Merge pull request totaljs#585 from totaljs/v2.9.1
v2.9.1
2 parents b7294ca + 368409d commit 1669e53

7 files changed

Lines changed: 62 additions & 15 deletions

File tree

builders.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2894,6 +2894,15 @@ ErrorBuilder.prototype.push = function(name, error, path, index, prefix) {
28942894
if (error === null || (!name && !error))
28952895
return this;
28962896

2897+
// Status code
2898+
if (error > 0) {
2899+
this.status = error;
2900+
error = '@';
2901+
} else if (path > 0) {
2902+
this.status = path;
2903+
path = undefined;
2904+
}
2905+
28972906
if (!error)
28982907
error = '@';
28992908

changes.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
======= 2.9.1 (HOTFIX)
2+
3+
- added: `controller.throw409()`, `req.throw409()`
4+
- added: new view aliases: `@{R.something}` for `repository`, `@{M.something}` for `model` and `@{G.something}` for `global`
5+
6+
- updated: `ErrorBuilder.push()` supports `.push(name, status_code)` or `.push(name, error, status_code)`
7+
8+
- fixed: sitemap language auto-setting
9+
- fixed: NoSQL: `builder.paginate()` a problem with zero limit (default limit will be `maxlimit`)
10+
- fixed: NoSQL number filtering
11+
- fixed: localization of ErrorBuilder in controllers
12+
113
======= 2.9.0
214

315
- added: `WebSocketClient`

index.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,12 +1874,12 @@ F.web = F.route = function(url, funcExecute, flags, length, language) {
18741874
if (type === 'string') {
18751875
viewname = funcExecute;
18761876
funcExecute = (function(name, sitemap, language) {
1877-
if (language && !this.language)
1878-
this.language = language;
18791877
var themeName = U.parseTheme(name);
18801878
if (themeName)
18811879
name = prepare_viewname(name);
18821880
return function() {
1881+
if (language && !this.language)
1882+
this.language = language;
18831883
sitemap && this.sitemap(sitemap.id, language);
18841884
if (name[0] === '~')
18851885
this.themeName = '';
@@ -11564,6 +11564,10 @@ Controller.prototype.content = function(body, type, headers) {
1156411564
res.options.code = self.status || 200;
1156511565

1156611566
if (body instanceof ErrorBuilder) {
11567+
11568+
if (self.language && !body.resourceName)
11569+
body.resourceName = self.language;
11570+
1156711571
var tmp = body.output(true);
1156811572
if (body.contentType)
1156911573
res.options.type = body.contentType;
@@ -11783,6 +11787,15 @@ Controller.prototype.throw404 = Controller.prototype.view404 = function(problem)
1178311787
return controller_error_status(this, 404, problem);
1178411788
};
1178511789

11790+
/**
11791+
* Throw 409 - Conflict.
11792+
* @param {String} problem Description of problem (optional)
11793+
* @return {Controller}
11794+
*/
11795+
Controller.prototype.throw409 = Controller.prototype.view409 = function(problem) {
11796+
return controller_error_status(this, 409, problem);
11797+
};
11798+
1178611799
/**
1178711800
* Throw 500 - Internal Server Error.
1178811801
* @param {Error} error
@@ -15160,6 +15173,12 @@ function extend_response(PROTO) {
1516015173
return this.$throw();
1516115174
};
1516215175

15176+
PROTO.throw409 = function(problem) {
15177+
this.options.code = 409;
15178+
problem && (this.options.problem = problem);
15179+
return this.$throw();
15180+
};
15181+
1516315182
PROTO.throw431 = function(problem) {
1516415183
this.options.code = 431;
1516515184
problem && (this.options.problem = problem);

internal.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,7 +1951,7 @@ function view_parse(content, minify, filename, controller) {
19511951
if (RELEASE)
19521952
builder = builder.replace(/(\+\$EMPTY\+)/g, '+').replace(/(\$output=\$EMPTY\+)/g, '$output=').replace(/(\$output\+=\$EMPTY\+)/g, '$output+=').replace(/(\}\$output\+=\$EMPTY)/g, '}').replace(/(\{\$output\+=\$EMPTY;)/g, '{').replace(/(\+\$EMPTY\+)/g, '+').replace(/(>'\+'<)/g, '><').replace(/'\+'/g, '');
19531953

1954-
var fn = '(function(self,repository,model,session,query,body,url,global,helpers,user,config,functions,index,output,cookie,files,mobile,settings){var get=query;var post=body;var theme=this.themeName;var language=this.language;var sitemap=this.repository.$sitemap;var cookie=function(name){return controller.req.cookie(name);};' + (functions.length ? functions.join('') + ';' : '') + 'var controller=self;' + builder + ';return $output;})';
1954+
var fn = '(function(self,repository,model,session,query,body,url,global,helpers,user,config,functions,index,output,cookie,files,mobile,settings){var get=query;var post=body;var G=F.global;var R=this.repository;var M=model;var theme=this.themeName;var language=this.language;var sitemap=this.repository.$sitemap;var cookie=function(name){return self.req.cookie(name)};' + (functions.length ? functions.join('') + ';' : '') + 'var controller=self;' + builder + ';return $output;})';
19551955
try {
19561956
fn = eval(fn);
19571957
} catch (e) {
@@ -2029,6 +2029,9 @@ function view_prepare(command, dynamicCommand, functions, controller) {
20292029
case '!isomorphic':
20302030
return '$STRING(' + command + ')';
20312031

2032+
case 'M':
2033+
case 'R':
2034+
case 'G':
20322035
case 'model':
20332036
case 'repository':
20342037
case 'get':
@@ -2039,12 +2042,10 @@ function view_prepare(command, dynamicCommand, functions, controller) {
20392042
case 'user':
20402043
case 'config':
20412044
case 'controller':
2042-
return view_is_assign(command) ? 'self.$set(' + command + ')' : '$STRING(' + command + ').encode()';
2045+
return view_is_assign(command) ? ('self.$set(' + command + ')') : ('$STRING(' + command + ').encode()');
20432046

20442047
case 'body':
2045-
if (view_is_assign(command))
2046-
return 'self.$set(' + command + ')';
2047-
return command.lastIndexOf('.') === -1 ? 'output' : '$STRING(' + command + ').encode()';
2048+
return view_is_assign(command) ? ('self.$set(' + command + ')') : command.lastIndexOf('.') === -1 ? 'output' : ('$STRING(' + command + ').encode()');
20482049

20492050
case 'files':
20502051
case 'mobile':
@@ -2066,6 +2067,9 @@ function view_prepare(command, dynamicCommand, functions, controller) {
20662067
case 'functions':
20672068
return '$STRING(' + command + ').encode()';
20682069

2070+
case '!M':
2071+
case '!R':
2072+
case '!G':
20692073
case '!controller':
20702074
case '!repository':
20712075
case '!get':

nosql.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2142,22 +2142,22 @@ DatabaseBuilder.prototype.compare_string = function(json, index) {
21422142
break;
21432143
case 2: // number
21442144
if (filter.operator === '=') {
2145-
if (filter.value.toString() !== value)
2145+
if (filter.value !== +value)
21462146
allow = false;
21472147
} else if (filter.operator === '!=') {
21482148
if (filter.value.toString() === value)
21492149
allow = false;
21502150
} else if (filter.operator === '>') {
2151-
if (filter.value < +value)
2151+
if (+value <= filter.value)
21522152
allow = false;
21532153
} else if (filter.operator === '<') {
2154-
if (filter.value > +value)
2154+
if (+value >= filter.value)
21552155
allow = false;
21562156
} else if (filter.operator === '>=') {
2157-
if (filter.value <= +value)
2157+
if (+value < filter.value)
21582158
allow = false;
21592159
} else if (filter.operator === '<=') {
2160-
if (filter.value >= +value)
2160+
if (+value > filter.value)
21612161
allow = false;
21622162
} else
21632163
return; // >, < is not supported for strings
@@ -2573,6 +2573,9 @@ DatabaseBuilder.prototype.paginate = function(page, limit, maxlimit) {
25732573
if (maxlimit && limit2 > maxlimit)
25742574
limit2 = maxlimit;
25752575

2576+
if (!limit2)
2577+
limit2 = maxlimit;
2578+
25762579
this.$skip = page2 * limit2;
25772580
this.$take = limit2;
25782581
return this;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"name": "luoage",
8585
"email": "luoage@msn.cn"
8686
}],
87-
"version": "2.9.0",
87+
"version": "2.9.1-4",
8888
"homepage": "http://www.totaljs.com",
8989
"bugs": {
9090
"url": "https://github.com/totaljs/framework/issues",

test/views/a.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
@{prev('/a/1/')}
2121
@{canonical('/a/a-b-c/')}
2222
@{head('//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js')}
23-
#tag-encode@{repository.tag}#
23+
#tag-encode@{R.tag}#
2424
#tag-raw@{!repository.tag}#
2525
#helper-fn-@{helper('fn', 'A')}#
2626
#readonly@{readonly(true)}#
@@ -29,7 +29,7 @@
2929
#disabled@{disabled(true)}#
3030
#resource@{resource('name')}#
3131
#options-empty@{options(repository.optionsEmpty, 'B')}#
32-
#options@{options(repository.options, 'C', 'k', 'v')}#
32+
#options@{options(R.options, 'C', 'k', 'v')}#
3333
#view-toggle@{viewToggle(false, 'b')}#
3434
#view@{view('current/b', 'model')}#
3535
#routejs-@{routeScript('p.js')}#

0 commit comments

Comments
 (0)