diff --git a/docs/docassets/images/alfrescocorerestapi_children.png b/docs/docassets/images/alfrescocorerestapi_children.png new file mode 100644 index 0000000000..3354d522dd Binary files /dev/null and b/docs/docassets/images/alfrescocorerestapi_children.png differ diff --git a/docs/docassets/images/alfrescocorerestapi_nodesdata.png b/docs/docassets/images/alfrescocorerestapi_nodesdata.png new file mode 100644 index 0000000000..d9569bf3aa Binary files /dev/null and b/docs/docassets/images/alfrescocorerestapi_nodesdata.png differ diff --git a/docs/tutorials/README.md b/docs/tutorials/README.md index c3efeffc1c..2323e20c2e 100644 --- a/docs/tutorials/README.md +++ b/docs/tutorials/README.md @@ -22,4 +22,5 @@ The tutorials are graded as follows: | [**Using components**](using-components.md) | Beginner | There are three different ways to use, extend and configure an ADF component: configuration properties, event listeners, and content projection / HTML extensions. In this tutorial you will see a practical example of each approach using the Login component. | | [**Customizing the Login component**](customising-login.md) | Intermediate | In this tutorial you will learn how to customize the [\`Login\` component](https://alfresco.github.io/adf-component-catalog/components/LoginComponent.html) following the [technical documentation](https://alfresco.github.io/adf-component-catalog/components/LoginComponent.html). The task will be very simple. See the documentation for further details about customizing this component, along with examples. | | [**Working with a Data Table**](working-with-data-table.md) | Intermediate | In this tutorial you will learn how to populate a [\`DataTable\` component](https://alfresco.github.io/adf-component-catalog/components/DataTableComponent.html) with custom data from a generic back-end service or third party API. As an example we are going to use data from one of the available services on Alfresco Content Services. However, the procedure is much the same if want to use an Alfresco Process Services endpoint or a third party API. | -| [**Working with the Nodes API Service**](working-with-nodes-api-service.md) | Intermediate | In this tutorial you will learn how to use the NodesApiService, to interact with your instance of Alfresco Content Services without consuming directly the REST endpoints. | +| [**Working with the Nodes API Service**](working-with-nodes-api-service.md) | Intermediate | In this tutorial you will learn how to use the `NodesApiService` into an Angular application, to interact with your instance of Alfresco Content Services without consuming directly the REST endpoints. | +| [**Working with the Nodes using the JS API**](working-with-nodes-js-api.md) | Intermediate | In this tutorial you will learn how to use the `AlfrescoCoreRestApi` into a JavaScript application, to interact with your instance of Alfresco Content Services without consuming directly the REST endpoints. | diff --git a/docs/tutorials/working-with-nodes-js-api.md b/docs/tutorials/working-with-nodes-js-api.md new file mode 100644 index 0000000000..490cd9248b --- /dev/null +++ b/docs/tutorials/working-with-nodes-js-api.md @@ -0,0 +1,147 @@ +# Working with Nodes using the JS API + +In this tutorial you will learn how to use the [`AlfrescoCoreRestApi`](https://github.com/Alfresco/alfresco-js-api/tree/master/src/alfresco-core-rest-api) in some practical examples developed to show how to interact with your instance of Alfresco Content Services, without consuming directly the REST endpoints. With this approach the `AlfrescoCoreRestApi` is used as an abstraction layer, defining one of the core services of the [`alfresco-api-js`](https://github.com/Alfresco/alfresco-js-api) library. + +## Preparing the development environment + +To focus the description on the `AlfrescoCoreRestApi`, in this tutorial we are going to develop using the [Alfresco JavaScript application](./creating-javascript-app-using-alfresco-js-api.html). If you don't have it already available into your development environment, check the *how-to* description into the [dedicated tutorial](./creating-javascript-app-using-alfresco-js-api.html). + +## About the `AlfrescoCoreRestApi` + +Before any development, let's introduce the `AlfrescoCoreRestApi` class. For further details about its implementation, check the documentation [here](https://github.com/Alfresco/alfresco-js-api/tree/master/src/alfresco-core-rest-api). As you can see, the available methods are in "*1 to 1*" relation with the REST endpoints and services of Alfresco Content Services. This makes the development easier and clean, and enables the developer to a full access to the Alfresco Content Services REST API. + +Starting from the most basic [Alfresco JavaScript application](./creating-javascript-app-using-alfresco-js-api.html), the `AlfrescoCoreRestApi` class can be accessed with the following command. + + this.alfrescoJsApi.core + +## Retrieving the children of a node + +As a first example of usage of the `AlfrescoCoreRestApi` class, let's retrieve the children of the root node, identified by the `-root-` alias. As described in the official documentation the method `getNodeChildren` should be used as described below. For this purpose edit the `index.html` file and as follow and replace the JavaScript source code for the login call. + + ... + this.alfrescoJsApi.login('admin', 'admin').then(function (data) { + + this.alfrescoJsApi.core.childAssociationsApi.getNodeChildren('-root-', {}).then( + + function (data) { + + var divElement = document.getElementById("result"); + + for (var i = 0; i < data.list.entries.length; i++) { + + console.log(data.list.entries[i]); + + var textElement = document.createTextNode( + data.list.entries[i].entry.name + + " (" + + data.list.entries[i].entry.id + + ")" + ); + var paragraphElement = document.createElement("p"); + paragraphElement.appendChild(textElement); + divElement.appendChild(paragraphElement); + } + }, + function (error) { console.error(error); }); + + }, function (error) { + console.error(error); + }); + ... + +Then replace the HTML body as follows. + +
+ + + +Once done, save and deploy the source code as described [here](./creating-javascript-app-using-alfresco-js-api.html), executing the following command from the `my-js-app` folder into a terminal. + + docker cp ../my-js-app