I'm trying to get a list of objects from an API request, add their property "loglevel to my store and show it in an existing table, linking these loglevels to each "jobId" but I'm having trouble doing so. I want it to request once when opening the page so that the values are up to date with the database. This is my model:
Ext.define('U4.fundamentals.backgroundjobs.model.BackgroundJobsMonitoringModel', {
extend: 'Ext.data.Model',
fields: [
{ name: 'jobId', type: 'string', mapping: 'jobId'},
{ name: 'taskId', type: 'string', mapping: 'lastTaskRun.taskId'},
{ name: 'updatedAt', type: 'date', mapping: 'lastTaskRun.updatedAt'},
{ name: 'status', type: 'string', mapping: 'lastTaskRun.status'},
{ name: 'canRunOnDemand', type: 'boolean', defaultValue: true },
{ name: 'icon', persist: false },
{ name: 'logLevel', type: 'int'}
]});
This is my api request config in the store:
proxy: {
type: 'rest',
api: {
read: U4.getApiPath('server-jobs'),
run: U4.getApiPath('server-jobs'),
kill: U4.getApiPath('server-jobs/{jobId}/{taskId}/kill'),
config: U4.getApiPath('server-jobs-configuration/loglevel/{jobId}'),
async: U4.getApiPath('server-jobs-configuration/loglevel')
},
sendConfigTaskRequest3: function () {
var me = this;
return new Promise(function (resolve, reject) {
Ext.Ajax.request({
url: U4.data.proxy.UrlTemplate.replaceParameters({}, me.proxy.api.async),
method: 'GET',
success: function (data) {
resolve(data);
},
failure: function (data) {
reject(data);
}
});
});
}
The request doesn't take any arguments since it's a getallasync method.
I've tried setting up a function in the controller and calling it through render and afterrender listener but it did not work so far:
onConfigTaskRequestSuccess: function (grid, response) {
var me = this;
var store = grid.getStore();
store.sendConfigTaskRequest3()
.then(function (response) {
var data = Ext.decode(response.responseText); // Decode the response
// Loop through the data and set the LogLevel property for each row in the store
Ext.each(data, function (item) {
var record = store.findRecord('jobId', item.JobId); // Find the record in the store based on the jobId
if (record) {
record.set('logLevel', item.LogLevel); // Set the LogLevel property of the record
}
});
})
.catch(function (error) {
// Handle errors here
});
},
Any help would be appreciated.
Update #1: This example of a dependant rendering on the render for 'jobId' column and 'loglevel' column does exactly what I want but it makes the same request for each row. If you could tell me a way to only make one request to the API and achieve the same results it would be perfect because I really cannot send this as it is with so man requests each time I open the page. This is the renderer on jobId:
renderer: function (value, metaData, record, rowIndex, colIndex, store, view) {
Ext.defer(function () {
var promise = store.sendConfigTaskRequest3();
return new Promise(function (resolve, reject) {
promise.then(function (response) {
var data = Ext.decode(response.responseText);
Ext.each(data, function (item) {
var record = store.findRecord('jobId', item.jobId); // Find the record in the store based on the jobId
if (record) {
console.log("record log", item.jobId, item.logLevel);
record.set('logLevel', item.logLevel); // Set the LogLevel property of the record
console.log(record.get('logLevel'), "RECORD LOG");
resolve(true);
}
});
}).catch(function (error) {
reject(error);
})
});
}, 1500);
return value;
}
Renderer which depends on jobId renderer (loglevel):
{
text: 'LowSignal',
flex: 1,
dataIndex: 'logLevel',
renderer: function (value, metaData, record, rowIndex, colIndex, store, view) {
if (value === 0) {
return '<div class="u4f-backgroundjobs-alert-icon" style="height: 20px; width: 20px; margin:0px 43.33%" title="Full Log Activated!"></div>';
} else {
return 'Loading...';
}
},
align: 'center',
draggable: false,
resizable: false,
}