Maybe I want too much from the Dashboard and FlexView... sorry for the long read
I remember your suggestion to check the validity of the files right after it uploaded (in the AllFileHandled event) but it is not only just checking - I need to get some data from the file to use it on the second screen. So I decided to create my own widget with the logic inside to put it on the second screen and that will get the information from the file and show it.
The widget generally works until I want to press the button. At this moment I met with the same problem.The FlexView first construct its current view but my widget needs the file name that for unknown reason is not available more but also it is difficult to understand for me why the FlexView want to repeat everything that was already done including the logic in my widget. It is useless at this step as for me...
Below I will show a part of my code (it is not PHP correct because I show you just to explain what I try to do )but I am not sure it is possible to do at all. FlexView looks not so flex... :-(
So my code:
FlexView board file
:
...
'step1' => function ($params) {
return [
...
FileUploader::create('SalesSummaryUploader')
...
->registerEvent('FileHandling', function ($params) {
$this->params(['savedFileName' => dirname($_SERVER['DOCUMENT_ROOT']) . '/storage/' . $params['file'] ['name']]);
return true;
})
...
];
},
//Now I have my file name in $this->params(['savedFileName'])
'step2' => function ($params) {
$bigFileInformationWidget = BigFileInformationWidget::create()
->fileName($this->params('savedFileName'))
;
//Why I do like this - because I want to have access to this object later it also does not work (see below) but it is the second problem
return [
Panel::create()->type('primary')->header('<b>Step 2: File Information</b>')->sub([
Row::create([
$bigFileInformationWidget, //it works and I can see the content from the file generated by my widget)
]),
Html::div()->class('row')->sub([
Html::div()->class('col d-flex justify-content-between')->sub([
Html::span('You can continue only if you see no errors above'),
Html::div()->sub([
Inline::create()->sub([
//The issue happens when I click any of this button. FlexView tries to construct this current view but 'savedFileName' parameter is not set at this moment ( I dont know why because it was set and the wizard could generate the content)
Button::create('BackButton')
->type('secondary')
->text('Back')
->action('submit', function ($request, $response) {
$this->widget('FileImportFlexView')->showView('step1');
}),
Button::create('NextButton')
->type('primary')
->text('Next')
->action('submit', function ($request, $response) {
$this->widget('FileImportFlexView')->showView('step1');
})->disabled($bigFileInformationWidget->getDataError()), //It also does not work because it looks like this part executed before the real value of dataError will be calculated by widget so it always return the default one
bigFileInformationWidget file:
class BigFileInformationWidget extends Widget
{
protected array $tableContent;
protected bool $dataError= false;
protected function beforeOnCreated()
{
parent::beforeOnCreated();
$this->props([
'fileName' => null,
]);
}
protected function onInit()
{
$excel = new ExcelProcessing($this->_fileName());
$result = $excel->getExcel();
...
$this->dataError = ... //I set dataError depends on the result;
$this->tableContent = [
//content for widgets view
];
}
public function getDataError(){
return $this->dataError;
}
protected function render()
{
if ($this->_hidden() === true) {
return null;
$content = '<div id="fileInformationWidget">';
.... content generation
return $content;
}
}
If you have any ideas how to solve my problems please share with me