Backpack Laravel chart widget - laravel-backpack

I am using a backpack widget to add charts to my admin panels in order to show a graphical representation of data. but I want my charts to be bigger size but I can't find a way..

You can resize a Chart widget like any other Backpack widget, using the optional wrapper attribute:
'wrapper' => [
'class' => 'col-12', // customize the class on the parent element (wrapper)
'style' => 'border-radius: 10px;',
]

Related

How to access backpack fields on custom (non-CRUD) page?

I've made a custom page in backpack admin panel. This page is non-CRUD (not related to any model). There are several forms on it, with date pickers, select inputs, etc. So I'am trying to find a way to use backpack fields to create these date pickers and select inputs. Because it seems to be awkward to embed custom js-controls into the project, as Backpack already has appropriate fields.
The only solution I came up with, is to create a crud controller for random model, disable all operations except create, use create operation view as custom page (backpack fields are available this way), and finally override store() method - to prevent creating new model entry in DB.
So, is there a proper way to access backpack fields on custom (non-CRUD) page?
Backpack 4.x fields aren't meant to be used outside CRUDs, but you can do that.
Option A
At their core, Backpack fields are just Blade views, so you can load them using the Blade helper #include(). Just make sure to pass along all variables that the blade file needs. I believe in 99% of the fields that will be a $field and a $crud variable, so this will work:
#php
// set the CRUD model to something (anything)
// but ideally it'd be the model of the entity that has the form
$crud = app()->make('crud');
$crud->setModel(\App\Models\Monster::class);
#endphp
#include('crud::fields.number', [
'crud' => $crud,
'field' => [
'name' => 'price',
'label' => 'Price',
'prefix' => '$'
]
])
This way, you only load the bits you actually want (the inputs), without the overhead of a CrudController. You can point the form to your custom controller and do the saving yourself. What you need to pass for a $field above is a Backpack field definition in array form.
This way is super-simple, but it has a big downside if you ask me. The field definition has to be 100% correct and complete, you lose all the magic and assumption logic that Backpack usually does to make your life easier when you add field using addField(). That's why in most cases I think it's more convenient to go with Option B.
Option B
Instead of manually loading all each field Blade view, add them using addField(), then load all of them just like Backpack does it in the Create or Update operation:
#php
$crud = app()->make('crud');
$crud->setModel(\App\Models\Monster::class);
$crud->addField([
'name' => 'price',
'label' => 'Price',
'prefix' => '$'
]);
#endphp
<form method="post">
#include('crud::form_content', [ 'fields' => $crud->fields(), 'action' => 'create' ])
</form>
The above will produce an output like this:
The benefit of this second option is that you can "forget" to mention stuff in the field definition and Backpack will assume it, you can use the fluent syntax, you can use most Backpack features, really...

Laravel backpack Customized fields are not working for Edit and Update methods

I'm using backpack in my project. I’ve created a customized fields that is dropdown and select box. In one blade file I’m displaying two fields based on dropdown selection I’ll display the options for select box. So everything is working fine somehow Edit and update is working for these customized field. any idea how to achieve this? Thanks in advance
In one blade file I've written these two customized fields code. so based on dropdown selection I'll pull up the options for next select box. Tried to override existed backpack files for this model. but no luck.
'label' => "Professors",
'type' => "selectProfessors",
'name' => 'professor_id',
'entity' => 'professor',
'attribute' => "name",
'model' => Professor::class,
'options' => (function ($query) {
return $query->where('professor_id', '=', backpack_user()
->professor_id)
->get();
}),
It is not working only for edit and update. for creating and deleting working as expected.

Flex Relate field value is blank in List of Sub Panel

There are two modules: Customer & Top Transaction
Relationship between them: 1(Customer):Many(Top Transaction)
There is one 'Flex Relate' field in Top Transaction module.
Now I want to display that 'Flex Relate' value on sub panel list of Top Transaction module.
For that I did changes from studio->Customer->Sub-Panel->Top Transaction.
On Customer detail page under Top Transaction sub panel it's showing only header of 'Flex Relate' field & no value(values are blank).
Does anyone know solution to this?
I'm using 6.5 community edition.
Please check this link for flex relate Flex relate
Try to use relate field instead of flex related i think it will solve your problem .
I know, this is the old question, but here is the solution I have found.
Add these 2 fields in the subpanel metadata and this would show the parent/flex field properly.
However there is still an issue in that, here the target module is fixed. I will update this as soon as I find any solution to it.
Untill that, I think this is achievable in process_record hook. But, I am looking for some generic solution.
'parent_type' =>
array(
'usage' => 'query_only',
),
'parent_name' =>
array(
'width' => '10%',
'vname' => 'LBL_FLEX_RELATE',
'id' => 'parent_id',
'link' => true,
'widget_class' => 'SubPanelDetailViewLink',
'target_module' => 'AOS_Invoices',
'target_record_key' => 'parent_id',
'default' => false,
),

Rendering views inside layouts

I'm trying to use a form in my main.php layout. The form is in the view folder with views related to my newsletter model and controller.
So far I've tried to create the following widget:**
<?php
namespace app\components;
use app\models\Newsletter;
use yii\base\Widget;
use yii\helpers\Html;
class NewsletterForm extends Widget
{
public function run()
{
$model = new Newsletter;
return $this->render('_form', [
'model' => $model
]);
}
}
?>
The widget is located in: app\components\NewsletterForm.php
I have a DB model called Newsletter.php and a database table called newsletter.
There is a folder inside app\views called newsletter. This folder as the _form.php where i want the user to input name and email to receive the newsletter.
The problem is I need to load the _form in views\newsletter in the footer of main.php
When I use the widget I always get the error:
The view file does not exist: /Applications/MAMP/htdocs/beladona/components/views/_form.php
How can I render the form inside views\newsletter\ _form.php.
The form needs to render inside the footer of main.php
After extensive discussion with the OP, we decided that a widget wasn't appropriate for his use case. Widgets are intended to be independent pieces of code, capable of being re-used in different situations. All he wanted to do was render a view file from an existing MVC combination
So here is what we settled on;
Layout being used is main.php We edited this for the following;
use app\models\Newsletter;
echo $this->render('#app/views/site/_index', 'model' => new Newsletter);
This has the advantage of keeping the existing form he is using.
He then needed to specify a controller/action combination to use in the form, like this;
$form = ActiveForm::begin([
'action' => Url::to(['newsletter/create'])
]);

SugarCRM CE (6.5.x) How To Create a View Layout with Panels (not fields) in Two (Multiple) Columns (Side by Side Subpanels)

Sugar 6.5 CE
In Studio View Layout Editor (this happens to be for Cases Edit View but should apply to all view layouts) I see no way for me to move a panel into a second column to the side of another panel. This is frustrating in that many people (like myself) are using 1920 pixel width video displays these days so you get this stack of panels with extremely wide tables, way wider than necessary to display the list data of the panel.
How can I go about moving the panels into two columns like you can do when you edit the layout of the Dashboard where you can move dashlets side by side. If I have to do some coding, so be it.
Thanks in advance to anyone that can throw a bone out on this one.
(I'm NOT talking about adding columns for fields within a panel.)
Something like that can be achived through code. Studio doesn't support that.
copy modules/Cases/metadata/editviewdefs.php to custom/modules/Cases/metadata/editviewdefs.php
or edit existing custom/modules/Cases/metadata/editviewdefs.php
$viewdefs['Cases']['EditView'] = array(
'templateMeta' => array(
'form' => array(
'buttons'=>array('SAVE', 'CANCEL')
),
'maxColumns' => '2',
'useTabs' => true,
'widths' => array(
array('label' => '10', 'field' => '30'),
array('label' => '10', 'field' => '30'),
),
'panels' => array(
.
.
.
... file goes on
Here increase maxColumns and add elements in widths accordingly.
Than you have to arrange the fields in panels to match you column layout.
other optical changes can be made through 'customcode' , 'displayParams' or by javascript