Author: ygrego Date: 2015-04-10 21:08:56 +0000 (Fri, 10 Apr 2015) New Revision: 1151 Url: http://forge.nuiton.org/projects/sandbox/repository/revisions/1151 Log: Implementation of methods "orderBy", "_removeConstraints", "_removeOrdering" and "_removeQuery". Modified: oipf/js/impl/model/MetadataSearch.js Modified: oipf/js/impl/model/MetadataSearch.js =================================================================== --- oipf/js/impl/model/MetadataSearch.js 2015-04-10 15:11:31 UTC (rev 1150) +++ oipf/js/impl/model/MetadataSearch.js 2015-04-10 21:08:56 UTC (rev 1151) @@ -137,6 +137,7 @@ channels: [], ratings: [] }; + this._ordering = []; }, /* @@ -286,6 +287,68 @@ } return new Query(field, comparison, value); + }, + + /* + * Description: + * Set the order in which results SHOULD be returned in future. + * Any existing search results SHALL not be re-ordered. Subsequent calls + * to orderBy() will apply further levels of ordering within the order + * defined by previous calls. + * For example: + * orderBy("ServiceName", true); + * orderBy("PublishedStart", true); + * will cause results to be ordered by service name and then by start time + * for results with the same channel number. + * + * Arguments: + * -field: The name of the field by which results SHOULD be sorted. + * A value of null indicates that any currently-set order SHALL be cleared + * and the default sort order should be used. + * + * -ascending: Flag indicating whether the results SHOULD + * be returned in ascending or descending order. + */ + orderBy: function(field, ascending) { + var parameters = arguments; + if (parameters.length != 2) { + throw new TypeError + ("Excessive number of arguments."); + } + + if ((!(typeof field === "string") && + field && + Number.isInteger(field)) || + !(typeof ascending === "boolean")) { + throw new TypeError("This function cannot be called with these arguments."); + } + + if (this._ordering) { + this._ordering.push({ + field: field, + ascending: ascending + }); + } + + }, + + _removeConstraints: function() { + + var keys = Object.keys(this._constraints); + for (var i = 0, l = keys.length; i < l; i + 1) { + var constraint = this._constraints[keys[i]]; + if (constraint instanceof Array) { + constraint.length = 0; + } + } + }, + + _removeQuery: function() { + this._currentQuery = null; + }, + + _removeOrdering: function() { + this._ordering = null; } }); \ No newline at end of file
participants (1)
-
ygregoï¼ users.nuiton.org