ncssar / sartopo_python

Python calls for the caltopo / sartopo API -- SUPERCEDED by caltopo_python
GNU General Public License v3.0
16 stars 2 forks source link

allow minimal json when editing existing objects #16

Closed caver456 closed 3 years ago

caver456 commented 3 years ago

currently, several default hardcodes are used in the addArea/LineAssignment functions. This means that you need to specify all of these values if you only want to edit one property.

Hopefully the API can deal with minimal json; if all properties must be specified, then modifying just one property would be a three-part operation: read the current values, do the minimal edit to the json, then write it all back again. That could all be done by the downstream tool, but that's not optimal.

caver456 commented 3 years ago

The API does need a full json set. Tried editing an existing assignment, letter=AA number=101, by only specifying 'number' in the properties table, and it deleted the letter. No problem, can accommodate this in sartopo_python such that you can still make a call to e.g. addAssignment(,{properties:{'number':111}}) and it will merge the edit with the existing json before sending the full post request. To be safe, inside addAssignment, whenever id is specified, it should first send one request (GET) to get the entire json for that object, then build the modified json, then send a second request (POST) with the full json.

caver456 commented 3 years ago

But, sending minimal json does preserve marker attributes:

SENDING POST to 'http://localhost:8080/api/v1/map/RRR2/Marker/37a02465-f8b6-4973-8f01-06ff4cf84ddf': { "json": "{\"geometry\": {\"coordinates\": [-120.02, 39.02]}, \"id\": \"37a02465-f8b6-4973-8f01-06ff4cf84ddf\"}" }

So, need to do a better test for assignments...

caver456 commented 3 years ago

Ok - looks like you can edit the geometry table without needing to specify the properties table, in which case the properties table remains untouched; but, if you edit one item in the properties table, then all other properties values get clobbered. So, we need to get the entire properties table.

As further evidence of this, watching the network traffic when you edit one field in an area assignment in the GUI shows that the geometry table is not sent but the entire properties table is sent:

json: {"type":"Feature","id":"64acc33f-464d-47d0-9b5c-37f2aee81044","properties":{"number":"123","letter":"ZZ","folderId":null,"operationalPeriodId":"85359845-371e-4d2f-9cc8-18ffea736684","resourceType":"DOG","teamSize":"3","priority":"HIGH","responsivePOD":"LOW","unresponsivePOD":"LOW","cluePOD":"LOW","description":"","previousEfforts":"asfd","transportation":"asf","timeAllocated":"0","primaryFrequency":"","secondaryFrequency":"","preparedBy":"","gpstype":"TRACK","status":"DRAFT","class":"Assignment"}}

The web page doesn't seem to do an additional request to populate the dialog when you hit the edit button; it just counts on its internal DOM of everything, built by the 'since' requests which happen every 2 seconds (on caltopo-desktop 4210). So this code will have to take appropriate steps to populate the entire properties table before editing.

caver456 commented 3 years ago

Options for obtaining the full properties json: 1 - maintain a full 'since' database as part of the sartopoSession object; the full json can be retrieved using the id that the edit function is called with 2 - pass the full properties json as an argument to the edit function(s) 3 - do the GET-merge-POST all within the edit function, as in the previous comment

1 is probably overkill. 2 and 3 can be accommodated with an 'existingJson' argument to the edit function: if None, then the edit function performs 3.

caver456 commented 3 years ago

Going with option 1) (maintain a full database using 'since' requests - just like a web browser does) since there is no API request to just get the json of a specific object. See #17 (sync with a sartopo map).

caver456 commented 3 years ago

now that sync is done (#17) - this issue involves writing some helper functions that accept a subset of properties and merge with the synced data (SartopoSession.mapData) to send to the server. Could write general edit function/s e.g. editObject that accept a geometry dict and/or a 'possibly incomplete' properties dict which may only have a few properties in it; could also write more specific edit functions e.g. editAssignmentNumber.