in public/src/autocomplete/url_pattern_matcher.js [51:116]
cls.addEndpoint = function (pattern, endpoint) {
var c,
active_component = this.rootComponent,
endpointComponents = endpoint.url_components || {};
var partList = pattern.split("/");
_.each(partList, function (part, partIndex) {
if (part.search(/^{.+}$/) >= 0) {
part = part.substr(1, part.length - 2);
if (active_component.getComponent(part)) {
// we already have something for this, reuse
active_component = active_component.getComponent(part);
return;
}
// a new path, resolve.
if ((c = endpointComponents[part])) {
// endpoint specific. Support list
if (_.isArray(c)) {
c = new engine.ListComponent(part, c, active_component);
}
else if (_.isObject(c) && c.type === "list") {
c = new engine.ListComponent(part, c.list, active_component, c.multi_valued, c.allow_non_valid);
}
else {
console.warn("incorrectly configured url component ", part, " in endpoint", endpoint);
c = new engine.SharedComponent(part);
}
}
else if ((c = this.parametrizedComponentFactories[part])) {
// c is a f
c = c(part, active_component);
}
else {
// just accept whatever with not suggestions
c = new engine.SimpleParamComponent(part, active_component);
}
active_component = c;
}
else {
// not pattern
var lookAhead = part, s;
for (partIndex++; partIndex < partList.length; partIndex++) {
s = partList[partIndex];
if (s.indexOf("{") >= 0) {
break;
}
lookAhead += "/" + s;
}
if (active_component.getComponent(part)) {
// we already have something for this, reuse
active_component = active_component.getComponent(part);
active_component.addOption(lookAhead);
}
else {
c = new engine.ConstantComponent(part, active_component, lookAhead);
active_component = c;
}
}
}, this);
// mark end of endpoint path
new AcceptEndpointComponent(endpoint, active_component);
};