var modelbuilder: ModelBuilder
# The JSON API does not filter anything by default.
- #
- # So we can cache the model view.
- var view: ModelView
+ var filter: nullable ModelFilter
# Catalog to pass to handlers.
- var catalog: Catalog is noinit
-
- # Build the catalog
- #
- # This method should be called at nitweb startup.
- # TODO move to nitweb
- fun build_catalog do
- var catalog = new Catalog(modelbuilder)
- # Compute the poset
- for p in view.mpackages do
- var g = p.root
- assert g != null
- modelbuilder.scan_group(g)
-
- catalog.deps.add_node(p)
- for gg in p.mgroups do for m in gg.mmodules do
- for im in m.in_importation.direct_greaters do
- var ip = im.mpackage
- if ip == null or ip == p then continue
- catalog.deps.add_edge(p, ip)
- end
- end
- end
- # Build the catalog
- for mpackage in view.mpackages do
- catalog.package_page(mpackage)
- catalog.git_info(mpackage)
- catalog.mpackage_stats(mpackage)
- end
- self.catalog = catalog
- end
+ var catalog: Catalog
end
# Specific handler for the nitweb API.
var config: NitwebConfig
# Find the MEntity ` with `full_name`.
- fun find_mentity(model: ModelView, full_name: nullable String): nullable MEntity do
+ fun find_mentity(full_name: nullable String): nullable MEntity do
if full_name == null then return null
- var mentity = model.mentity_by_full_name(full_name.from_percent_encoding)
+ var mentity = config.model.mentity_by_full_name(full_name.from_percent_encoding, config.filter)
if mentity == null then return null
- if config.view.accept_mentity(mentity) then return mentity
+
+ var filter = config.filter
+ if filter == null or filter.accept_mentity(mentity) then return mentity
return null
end
res.api_error(400, "Expected mentity full name")
return null
end
- var mentity = find_mentity(config.view, id)
+ var mentity = find_mentity(id)
if mentity == null then
res.api_error(404, "MEntity `{id}` not found")
end
# URL to `self` within the JSON api.
fun api_url: String do return "/api/entity/" / full_name
+ redef fun html_url do return web_url
+
redef fun core_serialize_to(v) do
super
v.serialize_attribute("web_url", web_url)
redef var web_url = mproperty.web_url is lazy
redef var api_url = mproperty.api_url is lazy
end
+
+redef class CmdLicenseFile
+ redef var file_url is lazy do
+ var mentity = self.mentity
+ if mentity == null then return super
+ return "{mentity.web_url}/license"
+ end
+end
+
+redef class CmdContribFile
+ redef var file_url is lazy do
+ var mentity = self.mentity
+ if mentity == null then return super
+ return "{mentity.web_url}/contrib"
+ end
+end