Skip to content

Commit c74798e

Browse files
authored
docs for ExApp UI (#175)
During the release there was a deadline and there was no time for documentation - fixing it now. Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
1 parent 4ea6581 commit c74798e

File tree

7 files changed

+143
-20
lines changed

7 files changed

+143
-20
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ docs html:
66
rm -rf docs/_build
77
$(MAKE) -C docs html
88

9+
.PHONY: links
10+
links:
11+
$(MAKE) -C docs links
12+
913
.PHONY: help
1014
help:
1115
@echo "Welcome to NC_PY_API development. Please use \`make <target>\` where <target> is one of"

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ The **Nextcloud** class functions as a standard Nextcloud client,
4646
enabling you to make API requests using a username and password.
4747

4848
On the other hand, the **NextcloudApp** class is designed for creating applications for Nextcloud.<br>
49-
It uses the [AppAPI](https://github.com/cloud-py-api/app_api) to allow
50-
applications to impersonate users through a separate authentication mechanism.
49+
It uses [AppAPI](https://github.com/cloud-py-api/app_api) to provide additional functionality allowing
50+
applications have their own graphical interface, fulfill requests from different users,
51+
and everything else that is necessary to implement full-fledged applications.
5152

5253
Both classes offer most of the same APIs,
5354
but NextcloudApp has a broader selection since applications typically require access to more APIs.

docs/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ SPHINXOPTS =
77
SPHINXBUILD = sphinx-build
88
SOURCEDIR = .
99
BUILDDIR = _build
10+
LINKCHECKDIR = _build/linkcheck
1011

1112
# Put it first so that "make" without argument is like "make help".
1213
help:
@@ -22,3 +23,7 @@ github:
2223
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
2324
%: Makefile
2425
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
26+
27+
.PHONY: links
28+
links:
29+
@$(SPHINXBUILD) -b linkcheck "$(SOURCEDIR)" "$(LINKCHECKDIR)" $(ALLSPHINXOPTS)

docs/NextcloudApp.rst

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@ The API will not fail, and in such cases, it will simply re-register without err
3737
If any error prevents your application from functioning, you should provide a brief description in the return instead
3838
of an empty string, and log comprehensive information that will assist the administrator in addressing the issue.
3939

40+
Dockerfile
41+
----------
42+
43+
We decided to keep all the examples and applications in the same format as the usual PHP applications for Nextcloud.
44+
45+
.. code-block::
46+
47+
ADD cs[s] /app/css
48+
ADD im[g] /app/img
49+
ADD j[s] /app/js
50+
ADD l10[n] /app/l10n
51+
ADD li[b] /app/lib
52+
53+
This code from dockerfile copies folders of app if they exists to the docker container.
54+
55+
**nc_py_api** will automatically mount ``css``, ``img``, ``js``, ``l10n`` folders to the FastAPI.
56+
57+
.. note:: If you do not want automatic mount happen, pass ``map_app_static=False`` to ``set_handlers``.
58+
4059
Debugging
4160
---------
4261

@@ -54,6 +73,7 @@ Here they are:
5473

5574
* APP_ID - ID of the application.
5675
* APP_PORT - Port on which application listen for the requests from the Nextcloud.
76+
* APP_HOST - "0.0.0.0"/"127.0.0.1"/other host value.
5777
* APP_SECRET - Shared secret between Nextcloud and Application.
5878
* APP_VERSION - Version of the application.
5979
* AA_VERSION - Version of the AppAPI.
@@ -67,17 +87,17 @@ After launching your application, execute the following command in the Nextcloud
6787
6888
php occ app_api:app:register YOUR_APP_ID manual_install --json-info \
6989
"{\"appid\":\"YOUR_APP_ID\",\"name\":\"YOUR_APP_DISPLAY_NAME\",\"daemon_config_name\":\"manual_install\",\"version\":\"YOU_APP_VERSION\",\"secret\":\"YOUR_APP_SECRET\",\"host\":\"host.docker.internal\",\"scopes\":{\"required\":[2, 10, 11],\"optional\":[30, 31, 32, 33]},\"port\":SELECTED_PORT,\"protocol\":\"http\",\"system_app\":0}" \
70-
--force-scopes
90+
--force-scopes --wait-finish
7191
7292
You can see how **nc_py_api** registers in ``scripts/dev_register.sh``.
7393

7494
It's advisable to write these steps as commands in a Makefile for quick use.
7595

7696
Examples for such Makefiles can be found in this repository:
7797
`Skeleton <https://github.com/cloud-py-api/nc_py_api/blob/main/examples/as_app/skeleton/Makefile>`_ ,
78-
`TalkBot <https://github.com/cloud-py-api/nc_py_api/blob/main/examples/as_app/talk_bot/Makefile>`_
98+
`TalkBot <https://github.com/cloud-py-api/nc_py_api/blob/main/examples/as_app/talk_bot/Makefile>`_ ,
7999
`ToGif <https://github.com/cloud-py-api/nc_py_api/blob/main/examples/as_app/to_gif/Makefile>`_ ,
80-
`nc_py_api <https://github.com/cloud-py-api/nc_py_api/blob/main/scripts/dev_register.sh>`_
100+
`UiExample <https://github.com/cloud-py-api/nc_py_api/blob/main/examples/as_app/ui_example/Makefile>`_
81101

82102
During the execution of `php occ app_api:app:register`, the **enabled_handler** will be called
83103

@@ -201,6 +221,6 @@ into a standard :py:class:`~nc_py_api.files.FsNode` class that describes the fil
201221
In the **convert_video_to_gif** function, a standard conversion using ``OpenCV`` from a video file to a GIF image occurs,
202222
and since this is not directly related to working with NextCloud, we will skip this for now.
203223

204-
**ToGif** example `full source <https://github.com/cloud-py-api/nc_py_api/blob/main/examples/as_app/to_gif/src/main.py>`_ code.
224+
**ToGif** example `full source <https://github.com/cloud-py-api/nc_py_api/blob/main/examples/as_app/to_gif/lib/main.py>`_ code.
205225

206226
This chapter ends here, but the next topics are even more intriguing.

docs/NextcloudTalkBot.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@ Currently, bots have access only to three methods:
7070
All other rules and algorithms remain consistent with regular external applications.
7171

7272
Full source of bot example can be found here:
73-
`TalkBot <https://github.com/cloud-py-api/nc_py_api/blob/main/examples/as_app/talk_bot/src/main.py>`_
73+
`TalkBot <https://github.com/cloud-py-api/nc_py_api/blob/main/examples/as_app/talk_bot/lib/main.py>`_
7474

7575
Wishing success with your Nextcloud bot integration! May the force be with you!

docs/NextcloudUiApp.rst

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
Writing Nextcloud App with UI
2+
=============================
3+
4+
.. note:: It is advisable to have experience writing PHP applications for Nextcloud,
5+
since the UI of applications not written in PHP is exactly the same.
6+
7+
One of the most interesting features is the ability to register a page in the Nextcloud Top Menu.
8+
9+
Full source of UI example can be found here:
10+
`UiExample <https://github.com/cloud-py-api/nc_py_api/blob/main/examples/as_app/ui_example/lib/main.py>`_
11+
12+
Here we will simply describe in detail what happens in the example.
13+
14+
.. code-block:: python
15+
16+
if enabled:
17+
nc.ui.resources.set_initial_state(
18+
"top_menu", "first_menu", "ui_example_state", {"initial_value": "test init value"}
19+
)
20+
nc.ui.resources.set_script("top_menu", "first_menu", "js/ui_example-main")
21+
nc.ui.top_menu.register("first_menu", "UI example", "img/icon.svg")
22+
23+
**set_initial_state** is analogue of PHP ``OCP\AppFramework\Services\IInitialState::provideInitialState``
24+
25+
**set_script** is analogue of PHP ``Util::addScript``
26+
27+
There is also **set_style** (``Util::addStyle``) that can be used for CSS files and works the same way as **set_script**.
28+
29+
Backend
30+
-------
31+
32+
.. code-block:: python
33+
34+
class Button1Format(BaseModel):
35+
initial_value: str
36+
37+
38+
@APP.post("/verify_initial_value")
39+
async def verify_initial_value(
40+
_nc: typing.Annotated[NextcloudApp, Depends(nc_app)],
41+
input1: Button1Format,
42+
):
43+
print("Old value: ", input1.initial_value)
44+
return responses.JSONResponse(content={"initial_value": str(random.randint(0, 100))}, status_code=200)
45+
46+
47+
class FileInfo(BaseModel):
48+
getlastmodified: str
49+
getetag: str
50+
getcontenttype: str
51+
fileid: int
52+
permissions: str
53+
size: int
54+
getcontentlength: int
55+
favorite: int
56+
57+
58+
@APP.post("/nextcloud_file")
59+
async def nextcloud_file(
60+
_nc: typing.Annotated[NextcloudApp, Depends(nc_app)],
61+
args: dict,
62+
):
63+
print(args["file_info"])
64+
return responses.Response()
65+
66+
Here is defining two endpoints for test purposes.
67+
68+
The first is to get the current initial state of the page when the button is clicked.
69+
70+
Second one is receiving a default information about file in the Nextcloud.
71+
72+
Frontend
73+
--------
74+
75+
The frontend part is the same as the default Nextcloud apps, with slightly different URL generation since all requests are sent through the AppAPI.
76+
77+
JS Frontend part is covered by AppAPI documentation: ``to_do``
78+
79+
Important notes
80+
---------------
81+
82+
We do not call ``top_menu.unregister`` or ``resources.delete_script`` as during uninstalling of application **AppAPI** will automatically remove this.
83+
84+
.. note:: Recommended way is to manually clean all stuff and probably if it was not an example, we would call all unregister and cleanup stuff during ``disabling``.
85+
86+
87+
All resources of ExApp should be avalaible and mounted to webserver(**FastAPI** + **uvicorn** are used by default for this).
88+
89+
.. note:: This is in case you have custom folders that Nextcloud instance should have access.
90+
91+
92+
*P.S.: If you are missing some required stuff for the UI part, please inform us, and we will consider adding it.*

docs/index.rst

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,20 @@ and handle complex problems through issues.
2525
Have a great time with Python and Nextcloud!
2626

2727
.. toctree::
28-
:maxdepth: 1
29-
30-
Installation
31-
FirstSteps
32-
MoreAPIs
33-
NextcloudApp
34-
NextcloudTalkBot
35-
NextcloudTalkBotTransformers
36-
NextcloudSysApp
37-
Options
38-
reference/index.rst
39-
DevSetup
40-
benchmarks/AppAPI.rst
28+
:maxdepth: 1
29+
30+
Installation
31+
FirstSteps
32+
MoreAPIs
33+
NextcloudApp
34+
NextcloudTalkBot
35+
NextcloudTalkBotTransformers
36+
NextcloudSysApp
37+
NextcloudUiApp
38+
Options
39+
reference/index.rst
40+
DevSetup
41+
benchmarks/AppAPI.rst
4142

4243
Indices and tables
4344
==================

0 commit comments

Comments
 (0)