diff --git a/server/src/uds/REST/documentation.py b/server/src/uds/REST/documentation.py index 5bdc06db0..69346a84a 100644 --- a/server/src/uds/REST/documentation.py +++ b/server/src/uds/REST/documentation.py @@ -53,36 +53,24 @@ logger = logging.getLogger(__name__) @dataclasses.dataclass class HelpMethodInfo: method: str - params: list[str] text: str - @property - def methods(self) -> typing.Generator[str, None, None]: - for param in self.params: - if param == '': - yield self.method - else: - if (self.method + ' ')[0] == '-': - yield f'<{param}>/{self.method[1:]}' - elif self.method: - yield f'{self.method}/<{param}>' - else: - yield f'<{param}>' - def __str__(self) -> str: - return ', '.join(self.methods) + return f'{self.method}: {self.text}' def __repr__(self) -> str: return self.__str__() class HelpMethod(enum.Enum): - ITEM = HelpMethodInfo('', ['uuid'], 'Retrieves an item by its UUID') - LOG = HelpMethodInfo('-' + consts.rest.LOG, ['uuid'], 'Retrieves the log of an item') - OVERVIEW = HelpMethodInfo(consts.rest.OVERVIEW, [''], 'General Overview of all items (a list') - TABLEINFO = HelpMethodInfo(consts.rest.TABLEINFO, [''], 'Table visualization information (types, etc..)') - TYPES = HelpMethodInfo(consts.rest.TYPES, ['', 'type'], 'Types information') - GUI = HelpMethodInfo(consts.rest.GUI, ['', 'type'], 'GUI information') + ITEM = HelpMethodInfo('', 'Retrieves an item by its UUID') + LOG = HelpMethodInfo(f'/{consts.rest.LOG}', 'Retrieves the log of an item') + OVERVIEW = HelpMethodInfo(consts.rest.OVERVIEW, 'General Overview of all items (a list') + TABLEINFO = HelpMethodInfo(consts.rest.TABLEINFO, 'Table visualization information (types, etc..)') + TYPES = HelpMethodInfo(consts.rest.TYPES, 'Retrieves a list of types available') + TYPES_TYPE = HelpMethodInfo(f'{consts.rest.TYPES}/', 'Retrieves a type information') + GUI = HelpMethodInfo(consts.rest.GUI, 'GUI information') + GUI_TYPES = HelpMethodInfo(f'{consts.rest.GUI}/', 'GUI Types information') @dataclasses.dataclass @@ -112,13 +100,24 @@ class Documentation(View): methods = [ HelpMethod.OVERVIEW, HelpMethod.GUI, - HelpMethod.TABLEINFO, + HelpMethod.GUI_TYPES, HelpMethod.TYPES, + HelpMethod.TYPES_TYPE, + HelpMethod.TABLEINFO, HelpMethod.ITEM, HelpMethod.LOG, ] elif node.kind == types.rest.HelpNode.HelpNodeType.DETAIL: - methods = [] + methods = [ + HelpMethod.OVERVIEW, + HelpMethod.GUI, + HelpMethod.GUI_TYPES, + HelpMethod.TYPES, + HelpMethod.TYPES_TYPE, + HelpMethod.TABLEINFO, + HelpMethod.ITEM, + HelpMethod.LOG, + ] else: methods = [] diff --git a/server/src/uds/REST/model/detail.py b/server/src/uds/REST/model/detail.py index d98461753..fc3a3f15e 100644 --- a/server/src/uds/REST/model/detail.py +++ b/server/src/uds/REST/model/detail.py @@ -144,6 +144,52 @@ class DetailHandler(BaseModelHandler): r = self._check_is_custom_method(self._args[0], parent) if r is not consts.rest.NOT_FOUND: return r + + match self._args[0]: + case consts.rest.OVERVIEW: + if num_args == 1: + return self.get_items(parent, None) + raise self.invalid_request_response() + case consts.rest.TYPES: + if num_args == 1: + types_ = self.get_types(parent, None) + logger.debug('Types: %s', types_) + return types_ + elif num_args == 2: + return self.get_types(parent, self._args[1]) + raise self.invalid_request_response() + case consts.rest.TABLEINFO: + if num_args == 1: + return self.process_table_fields( + self.get_title(parent), + self.get_fields(parent), + self.get_row_style(parent), + ) + raise self.invalid_request_response() + case consts.rest.GUI: + if num_args in (1, 2): + if num_args == 1: + gui = self.get_processed_gui(parent, '') + else: + gui = self.get_processed_gui(parent, self._args[1]) + return sorted(gui, key=lambda f: f['gui']['order']) + raise self.invalid_request_response() + case consts.rest.LOG: + if num_args == 2: + return self.get_logs(parent, self._args[1]) + raise self.invalid_request_response() + case _: + # try to get id + if num_args == 1: + return self.get_items(parent, process_uuid(self._args[0])) + + # Maybe a custom method? + r = self._check_is_custom_method(self._args[1], parent, self._args[0]) + if r is not None: + return r + + # Not understood, fallback, maybe the derived class can understand it + return self.fallback_get() if num_args == 1: match self._args[0]: diff --git a/server/src/uds/templates/uds/modern/documentation.html b/server/src/uds/templates/uds/modern/documentation.html index 3dabb25ad..55035e20e 100644 --- a/server/src/uds/templates/uds/modern/documentation.html +++ b/server/src/uds/templates/uds/modern/documentation.html @@ -13,6 +13,20 @@ +
@@ -31,15 +45,14 @@ {% if h.methods %}
{% for m in h.methods %} - {% for mm in m.value.methods %} -
{{ h.path }}/{{ mm }}
- {% endfor %} +
{{ h.path }}/{{ m.value.method }} : {{ m.value.text }}
{% endfor %}
+ {% else %} +
{{ h.path }} : {{ h.text }}
{% endif %}
{% endfor %} -