What you need is actually a "control" (like "if" and "foreach"), not a
"function". The existing controls are here:
http://static.simile.mit.edu/exhibit/api-2.0/scripts/data/controls.js
Your "filter" control will look something like this:
Exhibit.Controls["filter"] = {
f: function(
args,
roots,
rootValueTypes,
defaultRootName,
database
) {
var collection = args[0].evaluate(roots, rootValueTypes,
defaultRootName, database);
var oldValue = roots["value"];
var oldValueType = rootValueTypes["value"];
var results = new Exhibit.Set();
rootValueTypes["value"] = collection.valueType;
collection.forEachValue(function(element) {
roots["value"] = element;
var collection2 = args[1].evaluate(roots,
rootValueTypes, defaultRootName, database);
if (collection2.size > 0 && collection2.contains("true")) {
results.add(element);
}
});
roots["value"] = oldValue;
rootValueTypes["value"] = oldValueType;
return new Exhibit.Expression._Collection(results,
collection.valueType);
}
};
Then you need an "and" function:
Exhibit.Functions["and"] = {
f: function(args) {
var r = true;
for (var i = 0; r && i < args.length; i++) {
r = r && args[i].contains(true);
}
return new Exhibit.Expression._Collection([ r ], "boolean");
}
};
Finally you need to declare the appropriate collections:
<div ex:role="collection" ex:itemTypes="Build" id="all-builds"></div>
<div ex:role="collection"
id="browser-trunk-builds"
ex:baseCollectionID="all-builds"
ex:expression="filter(value, and(.app = 'browser', .tree =
'trunk'))"></div>
(I'll add these control and function into the API later on.)
David
Axel Hecht wrote:
> That worked, somewhat.
>
> The downside of this approach is that it still lists the full count of
> items that are in the original collection, so, in my case, I can't do
> a "32 of 47", as it reports some "32 of 59".
> To us, the "we missed out on 15" is valuable information.
>
> I failed to create a filter function, I started, but basically died on
> the fact that the arguments of the functions are passed as values, and
> not expressions, so I can't apply an expression to my value set or
> something. I guess to get filtered collections, we really have to hack
> that into the collection logic.
>
> Axel
>
> 2008/2/1, David Huynh <[EMAIL PROTECTED]>:
>
>> Hi Axel,
>>
>> The easiest way is to add some facets with predefined selections:
>>
>> <div ex:role="collection" ex:itemTypes="Build" id="builds"></div>
>> <div style="display: none;">
>> <div ex:role="facet" ex:collectionID="builds"
>> ex:expression=".app"
>> ex:selection="browser"
>> ex:scroll="false"></div>
>>
>> <div ex:role="facet" ex:collectionID="builds"
>> ex:expression=".tree"
>> ex:selection="trunk"
>> ex:scroll="false"></div>
>> </div>
>>
>> David
>>
>>
>> Axel Hecht wrote:
>>
>>> Hi,
>>>
>>> I have another breed of my l10n builds exhibits, and I'm struggling
>>> with the following task:
>>>
>>> I have builds for two trees, and (possibly) two applications. I
>>> managed to filter the items based on type, and I even got a
>>> ex:expression sub-collection going. My items look somewhat like
>>>
>>> {
>>> "items": [
>>> {
>>> "locale": "bn-IN",
>>> "app": "browser",
>>> "tree": "incubator",
>>> "result": "success",
>>> "label": "bn-IN",
>>> "type": "Build",
>>> "id":
>>> "linux-langpack/incubator/browser/bn-IN"
>>> },
>>> {
>>> "locale": "it",
>>> "app": "browser",
>>> "tree": "trunk",
>>> "result": "success",
>>> "label": "it",
>>> "type": "Build",
>>> "id": "linux-langpack/trunk/browser/it"
>>> }
>>> ]
>>> }
>>>
>>> and what I want, in semi-XPath speak is ".[.app = 'browser'][.tree =
>>> 'trunk'].
>>>
>>> The treat is, I'm using the main json file for other exhibits, too, in
>>> which I actually want all builds, but this is for release tracking,
>>> and only a subset of that actually matter.
>>>
>>> I tried
>>>
>>> <div ex:role="collection" ex:itemTypes="Build" id="builds"></div>
>>> <div ex:role="collection" ex:expression=".tree = 'trunk'"
>>> ex:baseCollectionID="builds"></div>
>>>
>>> but that yielded only 'true' and 'false' to be in the collection,
>>> which maps to what I though the code would do.
>>>
>>> Any suggestions? Or is my way to go to just implement a function that
>>> does what I want?
>>>
>>> Axel
>>> _______________________________________________
>>> General mailing list
>>> [email protected]
>>> http://simile.mit.edu/mailman/listinfo/general
>>>
>>>
>> _______________________________________________
>> General mailing list
>> [email protected]
>> http://simile.mit.edu/mailman/listinfo/general
>>
>>
> _______________________________________________
> General mailing list
> [email protected]
> http://simile.mit.edu/mailman/listinfo/general
>
_______________________________________________
General mailing list
[email protected]
http://simile.mit.edu/mailman/listinfo/general