From 708c0aa3543f3ba36bdef604f24dbaee9d0dceb5 Mon Sep 17 00:00:00 2001 From: BinarySandia04 Date: Mon, 14 Oct 2024 20:02:53 +0200 Subject: [PATCH] Doc update --- backend/services/api.js | 1 + client/src/services/Api.js | 2 +- documentation/docs/.vuepress/config.js | 6 +- documentation/docs/client/api.md | 155 +++++++++++++++++++++++ documentation/docs/client/test.md | 41 ------ documentation/docs/plugin/plugin.json.md | 1 + documentation/docs/server/api.md | 1 + documentation/docs/server/test.md | 1 - 8 files changed, 162 insertions(+), 46 deletions(-) create mode 100644 documentation/docs/client/api.md delete mode 100644 documentation/docs/client/test.md create mode 100644 documentation/docs/plugin/plugin.json.md create mode 100644 documentation/docs/server/api.md delete mode 100644 documentation/docs/server/test.md diff --git a/backend/services/api.js b/backend/services/api.js index 15ed2dd7..7c2d682d 100644 --- a/backend/services/api.js +++ b/backend/services/api.js @@ -133,6 +133,7 @@ class BackendModule { return this.#_router; } + // Creates a model for the Module createModel(name, schema){ return new BackendModel(name, `${this.#_plugin.package}/${this.#_id}`, schema); } diff --git a/client/src/services/Api.js b/client/src/services/Api.js index 1ff24d28..5b662db0 100644 --- a/client/src/services/Api.js +++ b/client/src/services/Api.js @@ -65,7 +65,7 @@ class ClientApi { return `${this.#_plugin.package}/${name}`; } - createWindow(type, data){ + createWindow(type, data = {id: type}){ _Windows.CreateWindow(type, data); } diff --git a/documentation/docs/.vuepress/config.js b/documentation/docs/.vuepress/config.js index 5344a505..b90c5794 100644 --- a/documentation/docs/.vuepress/config.js +++ b/documentation/docs/.vuepress/config.js @@ -30,18 +30,18 @@ export default defineUserConfig({ text: "Plugin", prefix: "plugin/", collapsable: true, - children: ['/client/test'] + children: ['/plugin/plugin.json'] }, { text: "Client API", prefix: "client/", collapsable: true, - children: ['/client/test'] + children: ['/client/api'] }, { text: "Server API", prefix: "server/", - children: ['/server/test'] + children: ['/server/api'] } ] } diff --git a/documentation/docs/client/api.md b/documentation/docs/client/api.md new file mode 100644 index 00000000..1ff7e817 --- /dev/null +++ b/documentation/docs/client/api.md @@ -0,0 +1,155 @@ +# Client Api + +## ClientApi + +The ClientApi object is used for interacting with everything related to the Dragonroll client. It is passed to the `Main` function at the entrypoint defined in the [plugin.json](/plugin/plugin.json) file + + +### createView + +Creates a [ClientView](#clientview) object from a Vue view defined inside the `client/views` folder + +#### Parameters + +| Property | Type | Required | Description | +| -------- | ---- | -------- | ----------- | +| ``path`` | String | yes | The path relative from `client/views` to the Vue view without the `.vue` extension | + +### Returns + +| Type | Description | +| ---- | ----------- | +| [ClientView](#clientview) | The new created view | + +#### Example + +```js +// Supposing that we have /your-plugin-root/client/views/Calculator.vue +let calculatorView = Api.createView('Calculator'); +``` + +### createModule + +Creates a [ClientModule](#clientmodule). The module needs to be later registered with the [registerModule](#registermodule) method to be loaded by Dragonroll. See [creating a module]() + +#### Parameters + +| Property | Type | Required | Description | +| -------- | ---- | -------- | ----------- | +| ``id`` | String | yes | The identifier of the new module | + +#### Returns + +| Type | Description | +| ---- | ----------- | +| [ClientModule](#clientmodule) | The new ClientModule | + +#### Example + +```js +let dndModule = Api.createModule('dnd-5e'); +dndModule.title = "Dungeons & Dragons 5e"; +dndModule.description = "Dungeons & Dragons Fifth edition module"; +dndModule.version = "1.0"; +dndModule.color = "#e92026"; +dndModule.icon = "icon.png"; +``` + +### createWindow + +This method instances a new window from an already registered one. You can also pass custom parameters inside this method and then read them from your view. + +#### Parameters + +| Property | Type | Required | Description | +| -------- | ---- | -------- | ----------- | +| ``type`` | String ([WindowType]()) | yes | The type of the new window | +| ``data`` | Object ([WindowData]()) | no | Aditional data for the created window | + +#### Example + +```js +let databaseWindow = Api.registerWindow('database', Api.createView('Database')); + +// Opens the database window +Api.createWindow(databaseWindow, { + id: 'my-database-window', + title: "My Database", + custom: [ + { + data: "This is custom data" + } + ] +}) +``` + +### clearWindow + +Clears the window with the specified id + +#### Parameters + +| Property | Type | Required | Description | +| -------- | ---- | -------- | ----------- | +| ``id`` | String | yes | The id of the window to clear | + +#### Example + +```js +Api.createWindow(databaseWindow, { + id: 'my-database-window', + title: "My Database", + close: () => { + // When the close button is pressed, clear the window + Api.clearWindow('my-database-window'); + } +}) +``` + + +### registerModule + +Registers an already created [module](#clientmodule) to Dragonroll + +#### Parameters + +| Property | Type | Required | Description | +| -------- | ---- | -------- | ----------- | +| ``module`` | [ClientModule](#clientmodule) | yes | The module to register | + +#### Example + +```js +let dndModule = Api.createModule('dnd-5e'); +... +api.registerModule(dndModule); +``` + +### registerWindow + +Registers a new window to Dragonroll and returns the registered id + +#### Parameters + +| Property | Type | Required | Description | +| -------- | ---- | -------- | ----------- | +| ``name`` | String | yes | The name of the new window | +| ``view`` | [ClientView](#clientview) | yes | The view that contains the window | + +#### Returns + +| Type | Description | +| ---- | ----------- | +| String ([WindowType](#windowpath)) | The registered type of window | + +#### Example + +```js +let databaseWindow = Api.registerWindow('database', Api.createView('Database')); +``` + +### router + +### socket + +## ClientModule \ No newline at end of file diff --git a/documentation/docs/client/test.md b/documentation/docs/client/test.md deleted file mode 100644 index e309c384..00000000 --- a/documentation/docs/client/test.md +++ /dev/null @@ -1,41 +0,0 @@ -# Updating a resource - -## Request - -- HTTP Method: `PUT` -- Content Type: `application/json` -- URL: `http://example.com/users/{id}` - -## Parameters - -| Property | Type | Required | Description | -| -------- | ---- | -------- | ----------- | -| ``name`` | String | false | The name of the user. | -| ``age`` | Number | false | The age of the user. | - -## Request example - -``` js -fetch('http://example.com/users/1', { - method: 'PUT', - body: JSON.stringify({ - name: 'John Doe', - age: 27, - }), - headers: { - 'Content-type': 'application/json', - }, -}) - .then((response) => response.json()) - .then((json) => console.log(json)); -``` - -## Response example - -``` JSON -{ - "id": 1, - "name": "John Doe", - "age": 27 -} -``` \ No newline at end of file diff --git a/documentation/docs/plugin/plugin.json.md b/documentation/docs/plugin/plugin.json.md new file mode 100644 index 00000000..1bb4fb54 --- /dev/null +++ b/documentation/docs/plugin/plugin.json.md @@ -0,0 +1 @@ +# plugin.json \ No newline at end of file diff --git a/documentation/docs/server/api.md b/documentation/docs/server/api.md new file mode 100644 index 00000000..bbb80218 --- /dev/null +++ b/documentation/docs/server/api.md @@ -0,0 +1 @@ +# ServerApi \ No newline at end of file diff --git a/documentation/docs/server/test.md b/documentation/docs/server/test.md deleted file mode 100644 index 9022d488..00000000 --- a/documentation/docs/server/test.md +++ /dev/null @@ -1 +0,0 @@ -# Server test \ No newline at end of file