PDA

View Full Version : Must read JSON, convert string to INT, re-load Grid w/ data and output to progressBar



pwelby
15 Nov 2010, 10:37 PM
okay, I have a Grid that shows how far along in the steps for creating a build of a project by doing a read of a JSON store. One of the columns in the Grid has a Progress Bar. In order to show the progress of the steps for building a project, I need to update this progress bar. It needs to read an integer to create its output, but the only values I am getting are flags from the service call. I am getting 4 sets of flags starting from - UFS_START_DATE. If a flag comes back as 'Y" then I need to convert it to a 'percentage' INT to output in the GRID's progressBar. If there is an 'error' passed and the flag reads 'Y' for the error then the string for the actual error will be found in the STATUS value. I need to also figure out how to output this error message (if there is one) either over, under or on top of the progress Bar.

Here is an example of the JSON I am reading:


{"success":true,"message":[{"ID":"55","BUILD_ID":"718","HOST":"qsd8650-lab10","USERNAME":"pwelby","P4_SERVER":"ASWP401:1666","P4_TICKET":"3F61A451728B19F1A86321AA1EABD134","CSPEC_NAME":"paul_3_qsd8650-lab10","CSPEC_ROOT":"c:\\builds\\paul_3","PLF_NAME":"MSM8x60_BMP.plf","BUILD_PATH":"AMSS\\products\\8660\\oem\\bsp\\build","BUILD_COMMAND":"build oemsa BUILD_ID=AAABQNBA BUILD_VER=0016","BUILD_MODE":"build","UFS_START_DATE":null,"UFS_END_DATE":null,"IS_UFS_ERROR":"N","IS_SYNCFILE_WRITTEN":"N","IS_SYNCFILE_ERROR":"N","BUILD_START_DATE":null,"BUILD_END_DATE":null,"IS_BUILD_FINISHED":"N","IS_ERROR":"N","STATUS":null,"IS_USERFILE_WRITTEN":"N","IS_USERFILE_ERROR":"N"},{"ID":"57","BUILD_ID":"750","HOST":"qsd8650-lab10","USERNAME":"pwelby","P4_SERVER":"ASWP401:1666","P4_TICKET":"3F61A451728B19F1A86321AA1EABD134","CSPEC_NAME":"paul_3_qsd8650-lab10","CSPEC_ROOT":"c:\\builds\\paul_3","PLF_NAME":"MSM8x60_BMP.plf","BUILD_PATH":"AMSS\\products\\8660\\oem\\bsp\\build","BUILD_COMMAND":"build oemsa BUILD_ID=AAABQNBA BUILD_VER=0016","BUILD_MODE":"build","UFS_START_DATE":null,"UFS_END_DATE":null,"IS_UFS_ERROR":"N","IS_SYNCFILE_WRITTEN":"Y","IS_SYNCFILE_ERROR":"N","BUILD_START_DATE":null,"BUILD_END_DATE":null,"IS_BUILD_FINISHED":"N","IS_ERROR":"N","STATUS":null,"IS_USERFILE_WRITTEN":"N","IS_USERFILE_ERROR":"N"},{"ID":"60","BUILD_ID":"797","HOST":"qsd8650-lab10","USERNAME":"c_qingw","P4_SERVER":"ASWP401:1666","P4_TICKET":"7DF8AA8618CE1BC9D6EAF06A7BEF6190","CSPEC_NAME":"lab10","CSPEC_ROOT":"c:\\tools\\AAABQNBA","PLF_NAME":"MSM8x60_BMP.plf","BUILD_PATH":"AMSS\\products\\8660\\oem\\bsp\\build","BUILD_COMMAND":"build oemsa BUILD_ID=AAABQNBA BUILD_VER=0017","BUILD_MODE":"build","UFS_START_DATE":null,"UFS_END_DATE":null,"IS_UFS_ERROR":"N","IS_SYNCFILE_WRITTEN":"N","IS_SYNCFILE_ERROR":"N","BUILD_START_DATE":null,"BUILD_END_DATE":null,"IS_BUILD_FINISHED":"N","IS_ERROR":"N","STATUS":null,"IS_USERFILE_WRITTEN":"N","IS_USERFILE_ERROR":"N"}]}
Here is an example of the store I am using. I was thinking about using the "listeners" for 'userListStore.on' but then I was not sure how to add the converted data back to the JSON to be read by the grid... and then how to 're-read' the Store in the grid to output the converted INT for the ProgressBar to show the output in the progress bar


//build Host store
var hostListStore = new Ext.data.JsonStore({
url : 'application/models/build/host/list_svc.php',
root : 'message',
fields : [
{name: 'ID', type: 'int'},
'BUILD_ID',
'HOST',
'USERNAME',
'P4_SERVER',
'P4_TICKET',
'CSPEC_NAME',
'CSPEC_ROOT',
'PLF_NAME',
'BUILD_PATH',
'BUILD_COMMAND',
'BUILD_MODE',

'IS_SYNCFILE_WRITTEN', // phase 1 (25)
'IS_SYNCFILE_ERROR',

'UFS_START_DATE', // phase 2 (50)
'UFS_END_DATE', // (60)
'IS_UFS_ERROR',

'IS_USERFILE_WRITTEN', // phase 3 (70)
'IS_USERFILE_ERROR',

'BUILD_START_DATE', // phase 4 (80)
'BUILD_END_DATE', // (100)
'IS_BUILD_FINISHED',
'IS_ERROR',

'STATUS',
{name: 'PROGRESS', type: 'int'}
],
method : 'GET'

});
hostListStore.on('load',
function(dataStore,records,options) {

if (records.length > 0) {
// phase 1
var isw = records[0].get('IS_SYNCFILE_WRITTEN');
if (isw == 'Y') {
top.progress_val = 25;
}

var ise = records[0].get('IS_SYNCFILE_ERROR');
if (ise == 'Y') {
top.progress_error = records[0].get('STATUS');
}

// phase 2
var usd = records[0].get('UFS_START_DATE');
if (usd != '') {
top.progress_val = 50;
}

var ued = records[0].get('UFS_END_DATE');
if (ued != '') {
top.progress_val = 60;
}

var iufse = records[0].get('IS_UFS_ERROR');
if (iufse == 'Y') {
top.progress_error = records[0].get('STATUS');
}

// phase 3
var iuw = records[0].get('IS_USERFILE_WRITTEN');
if (iuw == 'Y') {
top.progress_val = 70;
}

var iue = records[0].get('IS_USERFILE_ERROR');
if (iue == 'Y') {
top.progress_error = records[0].get('STATUS');
}
// else {
// return;
// }

// phase 4
var bsd = records[0].get('BUILD_START_DATE');
if (bsd != '') {
top.progress_val = 80;
}

var ued = records[0].get('BUILD_END_DATE');
if (ued != '') {
top.progress_val = 100;
}

var i_e = records[0].get('IS_ERROR');
if (i_e == 'Y') {
top.progress_error = records[0].get('STATUS');
}

}
},this);
And here is the code I am using in the Grid:



// HostList column model
var hostListColumnModel = new Ext.grid.ColumnModel([
{header : "Username", dataIndex: 'USERNAME'},
//{header : "ID", dataIndex: 'ID'},
{header : "Build ID", dataIndex: 'BUILD_ID'},
{header : "Host", dataIndex: 'HOST'},
{header : "Is build finished?", dataIndex: 'IS_BUILD_FINISHED'},
{header : "Is there an error?", dataIndex: 'IS_ERROR'},
statusColumn
]);

//Build Host listing
var theGrid = new Ext.grid.GridPanel({
title : 'Hosts and User builds',
store : hostListStore,
autoScroll : true,
loadMask : true,
height : 600,
plugins : [ statusColumn ],
overflow : scroll,
cm : hostListColumnModel,
sm : new Ext.grid.RowSelectionModel({ singleSelect: true }),
clicksToEdit : 1,
tbar: [{
xtype : 'combo',
store: new Ext.data.ArrayStore({
id: 0,
fields: [
'myId',
'displayText'
],
data: [[1,'qsd8650-lab9'], [2,'qsd8650-lab10'], [3,'qsd8650-lab11']]
}),
text : 'Host',
valueField : 'myId',
displayField : 'displayText',
typeAhead : true,
triggerAction : 'all',
lazyRender : true,
anchor : '100%',
mode : 'local',
emptyText : 'Select a Host...',
listeners : {
'select' : {
scope : this,
fn : function (combo, record) {

// get vars
var selectedHost = record.get('displayText');
top.selectedHost = selectedHost;

// Change the title to Hosts Listing
theGrid.setTitle('Listing for Host: \'' + selectedHost + '\'');

//call getStatus timer
getBuildHostStatus.init(selectedHost);

}
} // eo 'select'
} // eo listeners

},'-',{
xtype : 'button',
text : 'My Builds',
style : 'padding: 0px 10px 0px 0px',
id : 'myBuildsListingBtn',
handler : function() {

////Change the title to - My Listing
theGrid.setTitle('My builds listing');

// call getStatus timer
getBuildMyStatus.init();

}
},{
xtype : 'tbfill'
},{
xtype : 'button',
text : 'Refresh',
style : 'padding: 0px 10px 0px 0px',
id : 'refreshButton',
handler : function() {
// reload store on click
theGrid.getStore().reload();
}
}],

viewConfig: {
forceFit: true,
beforeRender : function() {
PROGRESS == 75;
}
// afterRender : function(){
// this.constructor.prototype.afterRender.apply(this, arguments);
// this.grid.autoSizeColumn(4);
// this.grid.autoSizeColumn(5);
//test
// }
}
});

theGrid.getSelectionModel().on('rowselect',
function(sm, rowIdx, r) {
var myDetails = r.data;
var buildId = myDetails.BUILD_ID, HOST = myDetails.HOST, USERNAME = myDetails.USERNAME, P4_SERVER = myDetails.P4_SERVER,
P4_TICKET = myDetails.P4_TICKET, CSPEC_NAME = myDetails.CSPEC_NAME, CSPEC_ROOT = myDetails.CSPEC_ROOT, PLF_NAME = myDetails.PLF_NAME,
BUILD_PATH = myDetails.BUILD_PATH, BUILD_COMMAND = myDetails.BUILD_COMMAND, BUILD_MODE = myDetails.BUILD_MODE,
UFS_START_DATE = myDetails.UFS_START_DATE, UFS_END_DATE = myDetails.UFS_END_DATE, IS_UFS_ERROR = myDetails.IS_UFS_ERROR,
IS_SYNCFILE_WRITTEN = myDetails.IS_SYNCFILE_WRITTEN, IS_SYNCFILE_ERROR = myDetails.IS_SYNCFILE_ERROR,
BUILD_START_DATE = myDetails.BUILD_START_DATE, BUILD_END_DATE = myDetails.BUILD_END_DATE, IS_BUILD_FINISHED = myDetails.IS_BUILD_FINISHED,
IS_ERROR = myDetails.IS_ERROR, STATUS = myDetails.STATUS, IS_USERFILE_WRITTEN = myDetails.IS_USERFILE_WRITTEN,
IS_USERFILE_ERROR = myDetails.IS_USERFILE_ERROR;


Ext.Msg.alert('Response Details',
'<br>Build ID: ' + buildId +
'<br>Host: ' + HOST +
'<br>Username: ' + USERNAME +
'<br>P4 Server: ' + P4_SERVER +
'<br>P4 Ticket: ' + P4_TICKET +
'<br>CSPEC Name: ' + CSPEC_NAME +
'<br>CSPEC Root: ' + CSPEC_ROOT +
'<br>PLF Name: ' + PLF_NAME +
'<br>Build path: ' + BUILD_PATH +
'<br>Build command: ' + BUILD_COMMAND +
'<br>Build mode: ' + BUILD_MODE +
'<br>' +
'<br>Syncfile written? ' + IS_SYNCFILE_WRITTEN +
'<br>Syncfile error? ' + IS_SYNCFILE_ERROR +
'<br>' +
'<br>UFS Start date: ' + UFS_START_DATE +
'<br>UFS End date: ' + UFS_END_DATE +
'<br>UFS Error? ' + IS_UFS_ERROR +
'<br>' +
'<br>Is userfile written? ' + IS_USERFILE_WRITTEN +
'<br>Is userfile error? '+ IS_USERFILE_ERROR +
'<br>' +
'<br>Build Start date: ' + BUILD_START_DATE +
'<br>Build End date: ' + BUILD_END_DATE +
'<br>Build Finished? ' + IS_BUILD_FINISHED +
'<br>Is there an Error? ' + IS_ERROR +
'<br>' +
'<br>Status: ' + STATUS
);
}
);

hostListStore.load({
params : {
mode: 'all',
host: this.host
}
});

I wish there was an easier way to do this, but unfortunately I need to work with the data the way it is.
Can anyone help me to find a good solution to create this output in the Grid's ProgressBar??