You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Project management tools, such as our Kanban, are highly sought after by businesses of all sizes. Considering this, it is important to provide a seamless user experience for multiple users. Our new feature allows users to efficiently manage the same cards on the Kanban board in real-time, without the need for page reloads. As a result, end-users can collaborate and stay up-to-date with one another's actions, enhancing productivity and overall satisfaction.
94
+
95
+
To implement a multiuser backend, you need to get authorization on the server before the Kanban initialization. For this, you can create the `login(url: string)` function:
96
+
97
+
~~~js {}
98
+
constlogin= (url) => {
99
+
var token =sessionStorage.getItem("login-token");
100
+
if (token) {
101
+
returnPromise.resolve(token);
102
+
}
103
+
104
+
returnfetch(url +"/login?id=1")
105
+
.then(raw=>raw.text())
106
+
.then(token=> {
107
+
sessionStorage.setItem("login-token", token);
108
+
return token;
109
+
});
110
+
};
111
+
~~~
112
+
113
+
This function only simulates authorization, and all users will be authorized with an ID of 1. After successful authorization, the server sends a token that needs to be used in every subsequent request to the server. To automate the token sending, the `RestDataProvider.setHeaders()` function is used. This function adds custom headers to the requests. By default, our server stores the token in the `"Remote-Token":<value>` header:
-`handlers` - the client handlers that handle server events
170
+
-`events` - the object that connects to the server and listens for all incoming events
171
+
-`RemoteEvents.on(handlers)` - applies client handlers to server events
172
+
173
+
After integrating the multiuser backend into your app, you can simplify collaboration between users and enable them to keep track of any changes via the UI in a real time.
174
+
175
+
### Example
176
+
177
+
The snippet below shows how to configure the multiuser backend to track changes of other users in a real time:
You can define your own logic for handling server events. For this purpose, you need to pass the **handlers** object to the `RemoteEvents.on(handlers)` method. The **handlers** object should have the following structure:
184
+
185
+
~~~js {}
186
+
{
187
+
"cards":cardsHandler:function(obj:any),
188
+
"columns": columnsHandler: function(obj: any),
189
+
"rows": rowsHandler: function(obj: any),
190
+
}
191
+
~~~
192
+
193
+
When any change occurs on the server, it returns the name of the modified element. These names can vary depending on the server logic.
194
+
195
+
The data updated on the client side will be placed in the **obj** argument of the `function(obj: any)`function. To specify an operation, there is a `type: string` field. It can take the following values:
196
+
197
+
- For **cards**: `"add-card"`, `"update-card"`, `"delete-card"`, `"move-card"`
198
+
- For **columns**: `"add-column"`, `"update-column"`, `"delete-column"`, `"move-column"`
199
+
- For **rows**: `"add-row"`, `"update-row"`, `"delete-row"`, `"move-row"`
200
+
201
+
In the following code snippet you can see the implementation details:
202
+
203
+
~~~js {}
204
+
// initialize kanban
205
+
const kanbanInstance = new kanban.Kanban(...);
206
+
const restProvider = new kanban.RestProvider(url);
The `RestDataProvider.getIDResolver()` method returns a function that is necessary to synchronize client IDs with server IDs. When a new object (*card/column/row*) is created on the client side, the resulting object will have a temporary ID and a corresponding server ID in the store. The `idResolver()` function allows synchronizing the client ID with the server ID. This function has the following format: `idResolver(id: TID, type: number)`
238
+
239
+
The `type` argument is the type of model that takes the following values:
240
+
241
+
- `CardID` - 1,
242
+
- `RowID` - 2,
243
+
- `ColumnID` - 3
244
+
245
+
To prevent the request from being sent to the server, you need to use the `skipProvider: true` flag when calling the `kanbanInstance.api.exec()` method.
246
+
247
+
And the final step is to apply custom handlers to the server events. In this way you can create your own server event handlers.
0 commit comments