What should be used for the writer config of a LABKEY.ext.Store (Ext3 version)

LabKey Support Forum (Inactive)
What should be used for the writer config of a LABKEY.ext.Store (Ext3 version) Leo Dashevskiy  2013-07-03 12:20
Status: Closed
 
to be able to update the Labkey data base tables with changes made to this store?

Thanks.
-Leo
 
 
Ben Bimber responded:  2013-07-03 13:07
Hi Leo,

If you're talking about the tables exposed via LabKey, then it should work out of the box. You will need to call commit() on the store to actually save your changes. I believe there is an auto-commit option in the sotre config, but you'd need to check the docs.
 
Leo Dashevskiy responded:  2013-07-03 13:32
Ok, Ben, thanks. I see commitChanges(), but no commit(). I tried also using save(), but that did not work.
commitChanges() though at least reacts, but does throw an error at the moment about the primary key column not being unique...
 
Ben Bimber responded:  2013-07-03 13:36
yes, sorry - the method's name is commitChanges():

https://www.labkey.org/download/clientapi_docs/javascript-api/symbols/LABKEY.ext.Store.html

that error seems to suggest it's working. i think the next thing to investigate is what you're trying to save. are you doing an insert or update?
 
Leo Dashevskiy responded:  2013-07-03 14:21
I am trying to do an update, but it looks like it's doing an insert instead...

I have an EditorGridPanel, its data being driven by a Labkey's store.
I double click a cell and modify its contents, click else where, the editor goes away and the cell is marked as 'dirty'/modified with a small red rectangle in the top left corner, then I have a button and its handler calls the commitChanges() on that store...

Could not save changes due to the following error:
ERROR: duplicate key value violates unique constraint "pk_qatasklist"
  Detail: Key (qaid, container)=(1, d200e809-e4ad-102f-b2d1-1f5d89162b6e) already exists.

I see there is a config option 'editable' for LABKEY.ext.EditorGridPanel - I am currently using the Ext.grid.EditorGridPanel, would using the Labkey one provide additional benefits, does it play nicer with the Labkey's store?

To partially answer my own question about the benefits of Labkey's EditorGridPanel - immediate benefit is that it seems to offer paging out-of-the-box (though, I am getting some other errors with it)
 
Leo Dashevskiy responded:  2013-07-03 14:47
So for that first use case of mine the error was 400.

I tried it elsewhere and the error I get there is 401: unauthorized (but I'm a server admin!) - how can I resolve this one?

Thanks.
-Leo
 
jeckels responded:  2013-07-03 14:50
Hi Leo,

What schema/query are you trying to update? Can you make edits to that data through the standard LabKey UI?

Thanks,
Josh
 
Leo Dashevskiy responded:  2013-07-03 15:05
Hey, Josh, I am able to go into the Schema Browser, navigate to my custom schema, then to my custom table, click 'view data', then 'edit' for a row, then change out one of the column values and then click 'submit' to make the changes.

But with the API:

User does not have permission to perform this operation

Could not save changes due to the following error:
Unauthorized

Any ideas?
 
Leo Dashevskiy responded:  2013-07-03 15:27
In addition, I stumbled across a LABKEY.user JS object:

LABKEY.user
Object {phone: null, canDelete: true, sessionid: "C9B4ABED360003B0E09310F952F17044", isSystemAdmin: true, id: 1002…}
canDelete: true
canDeleteOwn: true
canInsert: true
canUpdate: true
canUpdateOwn: true
displayName: "ldashevs@fhcrc.org"
email: "ldashevs@fhcrc.org"
id: 1002
isAdmin: true
isGuest: false
isSystemAdmin: true
phone: null
sessionid: "C9B4ABED360003B0E09310F952F17044"
__proto__: Object
 
Leo Dashevskiy responded:  2013-07-08 15:57
Does it matter, if the source of my query is 'built-in query/table' or a custom one, which does not necessarily reference all of the columns and is not necessarily driven by data from just one table...


So here is the info from "Request payload":

{"commands":[{"schemaName":"opencyto_preprocessing","queryName":"GatingSet","command":"insertWithKeys","rows":[{"values":{"Id":1,"Name":"test","Path":"/home/ldashevs/Labkey/flowFiles/HVTN080/@files/assay/0880-M-080/6edd36458d6da212026ec7676b76e6f8","Description":"description","EntityId":"d200e809-e4ad-102f-b2d1-1f5d89162b6e","Created":"2013-07-03T21:16:36.000Z","container":"d200e809-e4ad-102f-b2d1-1f5d89162b6e"},"oldKeys":{"undefined":"ext-record-2"}}]}]}

I see that the command here is not 'update', but 'insert' and I already have this row with that key present in the table, is that a problem?

Also, I see a field called 'oldKeys', but it does not seem to contain anything meaningful, is that a problem?

Thanks.
-Leo
 
Leo Dashevskiy responded:  2013-07-08 16:35
So I managed to make it so that the 'command' is now 'updateChangingKeys':

{"commands":[{"schemaName":"opencyto_preprocessing","queryName":"GatingSet","command":"updateChangingKeys","rows":[{"values":{"Id":1,"Name":"test","Path":"/home/ldashevs/Labkey/flowFiles/HVTN080/@files/assay/0880-M-080/6edd36458d6da212026ec7676b76e6f8","Description":"description","EntityId":"d200e809-e4ad-102f-b2d1-1f5d89162b6e","Created":"2013-07-03T21:16:36.000Z","container":"d200e809-e4ad-102f-b2d1-1f5d89162b6e"},"oldKeys":{"undefined":"ext-record-2"}}]}]}

Though, before calling commitChanges() on the store I had to manually go through the modified records and set their .phantom values to false:

                        new Ext.Button({
                            //disabled: true,
                            handler: function(){
                                var records = strGatingSet.getModifiedRecords();
                                Ext.each( records, function(record){
                                    record.phantom = false;
                                });
                                strGatingSet.commitChanges();
                            },
                            text: 'Update'
                        })

Still this gives my 'unathorized' 401 error.
What is there to do? Please, help!
 
jeckels responded:  2013-07-08 16:46
Hi Leo,

In one of your followups, you asked about updating a custom query. That's not supported - while some simple queries may map one-to-one with rows in a source table, most do not, and there's no way for us to know for sure if it would work. So, all custom queries are effectively read-only and you'll need to fire update/insert/delete requests against the "real" table.

Does that explain what's happening in this case?

Thanks,
Josh
 
Leo Dashevskiy responded:  2013-07-08 17:36
Is there a live example up somewhere of either LABKEY.ext.EditorGridPanel or Ext.grid.EditorGridPanel working with a Labkey's store?
 
Leo Dashevskiy responded:  2013-07-08 18:06
Thanks Josh, yeah, that makes more sense, I was wondering, how you would be able to update not-one-to-one mappings... it would be difficult if not impossible...

So I am now using the built-in query/table as the source for the store, and still I have to do the trick above with setting .phantom to false, so that not 'insert' is fired, but 'update', but now I get an error:

Could not save changes due to the following error:
Value for key field 'gsid' was null or not supplied!

where 'gsid' is the required primary key (along with the container).

I am not sure, where/how am I supposed to supply it...
 
Leo Dashevskiy responded:  2013-07-09 12:06
Here is the new

Request Payload:

{"commands":[{"schemaName":"opencyto_preprocessing","queryName":"gstbl","command":"updateChangingKeys","rows":[{"values":{"container":"bc1fd7f4-8817-1030-8a76-1f5d8916d162","gsid":2,"gsname":"1023","objlink":"/home/ldashevs/Labkey/flowFiles/RV144/@files/XML files/16875f96ef0cf8fe0bc327be33594f5f","gsdescription":"1023 desc","xmlpath":"/home/ldashevs/Labkey/flowFiles/RV144/@files/XML files/RV144 Batch 1023.xml","samplegroup":"1023 Samples","created":"2013-07-03T22:04:12.000Z"},"oldKeys":{"undefined":"ext-record-141"}}]}]}

and it does have the 'gsid' in it.

Anyone?
 
Leo Dashevskiy responded:  2013-07-09 14:19
So the exception comes up because of this 'oldKeys' data being sent. Naturally, its value being: {"undefined":"ext-record-141"} does not quite look right.

This value comes from this line of LABKEY.ext.Store:

getOldKeys : function(record) {
        var oldKeys = {};
        oldKeys[this.reader.meta.id] = record.id;
        return oldKeys;
    }

I do not have this.reader.meta.id and the record.id does not have anything meaningful in it...


this.reader.meta

Object {title: "gstbl", totalProperty: "rowCount", importTemplates: Array[1], root: "rows", description: "↵ The 'gsTbl' table contains information about generated gating sets.↵ "…}
description: "↵ The 'gsTbl' table contains information about generated gating sets.↵ "
fields: Array[8]
importMessage: null
importTemplates: Array[1]
root: "rows"
title: "gstbl"
totalProperty: "rowCount"
__proto__: Object


record

sb {phantom: false, id: "ext-record-3", data: Object, json: Object, store: LABKEY.ext.Store.Ext.extend.constructor…}
data: Object
dirty: true
id: "ext-record-3"
json: Object
modified: Object
phantom: false
saveOperationInProgress: true
store: LABKEY.ext.Store.Ext.extend.constructor
__proto__: F


So what needs to be done here, guys? Anybody?
 
Leo Dashevskiy responded:  2013-07-09 17:03
Thanks to Kevin's insight, it looks like the data base schema is such that a primary key is composed of 2 columns and this cannot be handled by Ext. Will work on refactoring that particular table in order to get this to work...
 
Leo Dashevskiy responded:  2013-07-11 12:44
After changing the table definition, so that it now has a one-column primary key, everything works!