nitc :: CmdList :: defaultinit
nitc :: CmdList :: print_list
nitc :: commands_http $ CmdList :: http_init
Init the command from an HTTPRequestnitc $ CmdList :: init_command
init_command
is used to factorize the sorting and pagination of results
nitc :: commands_parser $ CmdList :: parser_init
Initialize the command from the CommandParser datanitc :: json_commands $ CmdList :: to_json
Return a JSON Serializable representation ofself
results
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
nitc :: DocCommand :: cmd_filter
Return a new filter for that command execution.nitc :: DocCommand :: defaultinit
nitc :: CmdList :: defaultinit
core :: Object :: defaultinit
nitc :: DocCommand :: execute
nitc :: DocCommand :: filter=
ModelFilter to apply if anynitc :: DocCommand :: http_init
Init the command from an HTTPRequestcore :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Object :: native_class_name
The class name of the object in CString format.core :: Object :: output_class_name
Display class name on stdout (debug only).nitc :: DocCommand :: parser_init
Initialize the command from the CommandParser datanitc :: CmdList :: print_list
nitc :: DocCommand :: to_json
Return a JSON Serializable representation ofself
results
nitc :: CmdCatalogContributing
Retrieve the packages contributed by a person
# A command that returns a list of results
abstract class CmdList
super DocCommand
# Type of result
type ITEM: Object
# Limit the items in the list
var limit: nullable Int = null is optional, writable
# Page to display
var page: nullable Int = null is optional, writable
# Total number of ret
var count: nullable Int = null is optional, writable
# Total number of pages
var max: nullable Int = null is optional, writable
# Comparator used to sort the list
var sorter: nullable Comparator = null is writable
# Items in the list
var results: nullable Array[ITEM] = null is writable
# `init_command` is used to factorize the sorting and pagination of results
#
# See `init_results` for the result list initialization.
redef fun init_command do
var res = super
if not res isa CmdSuccess then return res
res = init_results
if not res isa CmdSuccess then return res
sort
paginate
return res
end
# Initialize the `results` list
#
# This method must be redefined by CmdList subclasses.
fun init_results: CmdMessage do return new CmdSuccess
# Sort `mentities` with `sorter`
fun sort do
var results = self.results
if results == null then return
var sorter = self.sorter
if sorter == null then return
sorter.sort(results)
end
# Paginate the results
#
# This methods keeps only a subset of `results` depending on the current `page` and the
# number of elements to return set by `limit`.
#
# The `count` can be specified when `results` does not contain all the results.
# For example when the results are already limited from a DB statement.
fun paginate do
var results = self.results
if results == null then return
var limit = self.limit
if limit == null then return
var page = self.page
if page == null or page <= 0 then page = 1
var count = self.count
if count == null then count = results.length
var max = count / limit
if max == 0 then
page = 1
max = 1
else if page > max then
page = max
end
var lstart = (page - 1) * limit
var lend = limit
if lstart + lend > count then lend = count - lstart
self.results = results.subarray(lstart, lend)
self.max = max
self.limit = limit
self.page = page
self.count = count
end
end
src/doc/commands/commands_base.nit:217,1--306,3
redef class CmdList
redef fun parser_init(mentity_name, options) do
var opt_page = options.opt_int("page")
if opt_page != null then page = opt_page
var opt_limit = options.opt_int("limit")
if opt_limit != null then limit = opt_limit
return super
end
end
src/doc/commands/commands_parser.nit:291,1--299,3
redef class CmdList
fun print_list(list_title: nullable String, list_items: nullable Array[MEntity], no_color: nullable Bool) do
if list_title != null then
if no_color == null or not no_color then
print list_title.bold
else
print list_title
end
print ""
end
if list_items != null and list_items.not_empty then
for mentity in list_items do
print mentity.cs_list_item(no_color)
print ""
end
else
print "None."
end
end
end
src/doc/term/term.nit:108,1--127,3