KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Need some help with the Dashboard Notification #3301

Open Eugene opened this topic on on May 24 - 9 comments

Eugene commented on May 24

Hi, guys

I am a bit confused how to use the Notification in the Dashboard.

For example I have a FlexView (below is a part of code)

'step2' => function ($params) {
                        ...
//and somewhere here I understood that something is wrong with my data, for example,
// and want to show the alert to my user and after he closes it I want to change the view. 
//If Everything is ok I wish to continue with my usual content 
                        
                return [
                            Panel::create()->type('primary')->header('<b>Step 2: File Information</b>')->sub([
...

So what is the best way to do it?

Eugene commented on May 24

This approach partially works:

'step2' => function ($params) {
                       
                        if (something is wrong) {
               //     $this->widget('FileImportFlexView')->showView('step1');
                            return [
                                Alert::danger('Error happened', 'Opps')
                            ];
                        }else{
                            return[
                                //usual content
                                   ]            
                }        


I can see the Alert but if I add $this->widget('FileImportFlexView')->showView('step1'); before return I get an error about Duplicate name of widget [SalesSummaryUploader] (it is a part of the view step1)

KoolReport commented on May 24

Alert or Note are returned in any server-side action to show something to user. For example, you create a button with actionSubmit, when the user click to button, the actionSubmit will be triggered at server-side, there you can process action or data, and if something wrong, you can return an Alert. Dashboard will send to client-side pop up content to alert user.

Alert and Note are not widget that you should add directly to content.

In your case, I have not fully understood your intention yet. May be you can provide more context, what you want to complete, some illustration, some code so that I can understand more the situation.

Eugene commented on May 25

Well,

  1. I use FlexView named FileImportFlexView

  2. the initial view (step1) has SalesSummaryUploader widget extended FileUploader - it works fine and when the file has uploaded it changes the view to the step2

  3. In step2 function I check something in the uploaded file. If something is wrong I want to show the alert and return to the step1. If everything ok I want to show step2 content.

I try to do it like this

'step2' => function ($params) {
                       
                        if (something is wrong) {
                 $this->widget('FileImportFlexView')->showView('step1');
                            return [
                                Alert::danger('Error happened', 'Opps')
                            ];
                        }else{
                            return[
                                //usual step2 content
                                   ]            
                }        

but get the error about Duplicate name of widget [SalesSummaryUploader]

I understand that maybe I do something wrong with the Alert but it works (the error is generated by showView so without it I can see the Alert).

If I still do something wrong what should I do If I wish to show the alert not after user action but depends on the internal logic?

And how to return to the first view?

Eugene commented on May 28

up

KoolReport commented on May 28

HI Eugene,

The issue of duplicate widgets is happens when FlexView is in the step 1, it receives command to change view to step 2 but then immediately change back to step 1, the loading of step 1 will be duplicated.

You can rearrange abit. Instead of checking the validity in step 2, you can check them right away in step 1. If something went wrong, you show error there (it could be a simple red text or pop-up modal) until everything is right, then you move the step 2.

Now, let me know if you want to show a modal pop-up to show error or a simple text to show error in step 1, I will provide you a pseudo-code for that.

Eugene commented on May 28

Yes please I will need the modal on my next step.

KoolReport commented on May 29

Here comes the code:

use koolreport\dashboard\containers\Html;
use koolreport\dashboard\notifications\Alert;
use koolreport\dashboard\widgets\FlexView;
use koolreport\dashboard\inputs\FileUploader;

class MyBoard extends Dashboard
{
	protected function content()
	{
		return [
			FlexView::create("myFlexView")
			->viewOptions([
				"step1"=>function($params){
					return [
						FileUploader::create("myFileUploader")
						->registerEvent("AllFileHandled",function($params){
							/**
							 * Do your checking files and data here
							 * since all files have been uploaded and
							 * available.
							 * If something wrong, we will register ActionPerformed
							 * event to access the Response to output error message
							 * with Alert notification.
							 * If nothing wrong, we will show the next view. The
							 * step 2 will show with error clean and does not need
							 * to check again.
							 */
							if($someThingWrong) {
								$this->registerEvent("ActionPerformed",function($params){
									$response = $params["response"];
									$response->show(Alert::danger("Your error message"));
								});
							} else {
								$this->sibling("myFlexView")->showView("step2");
							}
						})
					];
				},
				"step2"=>function($params){
					return [
						Html::div("Everything is fine"),
					];
				},
			])
		];
	}
}

Hope that helps.

Eugene commented on May 29

Thank you.

But what if I want to show a Modal with more complex content that is not a fix and depends on the result of the check.

KoolReport commented on May 29

You can do this:

$response->show(
    Alert::create()
    ->type("danger")
    ->title("Error")
    ->sub([
        //Complex content here
        Html::p("Developer does not know what error is, but it happens, bear yourself, I show you some unnecessarily things here just to divert your attention from the error, wish you strength to endure."),
        LineChart::create("whatADumpChart")
    ])
);

The Alert is actually derived from Modal but automatically added with OK button at footer so you do not need to do it by yourself.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

Dashboard