0

I'm trying to do something fun: I'd like to send the record changes from one client to another and have the second client updated to show these changes. Basically collaborative viewing. The second client is disabled from making changes, he can only watch.

Simple fields like strings, numbers, checkboxes, etc. are easy, that worked right away.

The references are the problem. If I have a combo that uses another model as it's source, I am unable to update it on the second client.

I tried setting just the id, then the entire referenced object, I tried various set options, but simply no dice.

The record does change, I see that the data is updated, I was even able to manually modify the _ reference attributes, but the UI keeps showing the old values for those fields.

Is there a way to send the record from one client to another and have the other client just take over all values and display them in the UI? (it would be better to send just the changes, but I'd be very happy if I could get it to work with the entire record)

EDIT: I'm using SailsJS with socket.io, so the p2p connection is not the issue.

I'm getting the data like this:

var data = record.getData(true);
broadcastRecord(data);

And on the other side I tried:

record.set(data);

A code example for the receiving side would be appreciated, if anyone has an ide how to solve this...

Predrag Stojadinović
  • 3,439
  • 6
  • 34
  • 52
  • It is quite easy to send a record from one client to another, once you have the p2p connection set up and running. As you already found out, this works well for text and numbers and whatever you can store in a record. However, the things you mention seem not to be part of a record. So, what exactly are you trying to send? – Alexander Aug 25 '17 at 10:10
  • I added more information in the original post. The data I am talking about is part of the record, but is not part of the records data. The referenced user is not found in record.data.user but in record._user where the entire user document is contained, I don't know why, but that's how it is. When I do data=record.getData(); then data.user is empty. However, record.getData(true); returns data.user containing the mongodb user collection id of the user document. – Predrag Stojadinović Aug 25 '17 at 13:11
  • `record.getData(true)` returns the associations, so that's why your reference data is in there... in order to update the user data, either you could bind to it directly, or you'd have to do `record.user().set('fieldName', fieldValue)`. In Ext JS 6.5, there's a [`loadData`](http://docs.sencha.com/extjs/6.5.1/classic/Ext.data.Model.html#static-method-loadData) method that might be useful for you, but that creates an entirely new model... it's easy to backport to 6.2. – incutonez Aug 25 '17 at 13:18
  • Right, all that is on the source side, my problem is on the receiving side. I am able to extract the data, but I am unable to update the model on the receiving side, such that it is reflected in the UI. – Predrag Stojadinović Aug 26 '17 at 14:49

1 Answers1

0

I think your problem is related to associations and comboboxes.

Let's say you have a model User with a field group that references model Group, and that you have a User form with a Group combobox.

In the receiver client, you are probably getting only the group id. record.set(data) updates the bound combobox calling setValue(groupId).

This setValue will try to find the corresponding record inside its store, but it won't ask server-side for that record. Instead, it will create a new record with the passed id (showing an empty combobox).

If possibile, you can set remoteFilter:false to the store and queryMode:'local' on the combobox and preload all the data from that store.

Otherwise, I think you'll have to override the combobox setValue method to get the record remotely.

fradal83
  • 2,002
  • 1
  • 10
  • 9