ORO CRM datagrid refresh after inline edit failed by missing parameter - datagrid

I have a datagrid:
datagrids:
gates-under-location-grid:
inline_editing:
enable: true
extended_entity_name: Entity\Gate
source:
type: orm
query:
select:
- g
- l
- ancestor.id as ancestorId
- ancestor.name as ancestorName
from:
- { table: Entity\Gate, alias: g }
join:
left:
- { join: g.locations, alias: l }
inner:
- { join: Entity\LocationClosure, alias: lc, conditionType: WITH, condition: 'l.id=lc.descendant' }
- { join: Entity\Location, alias: ancestor, conditionType: WITH, condition: 'ancestor=:rootLocation'}
where:
and:
- lc.ancestor=:rootLocation
bind_parameters:
rootLocation: ~
hints:
- HINT_TRANSLATABLE
columns:
name:
label: 'gate.datagrid.field.name'
align: left
locations:
label: 'gate.datagrid.field.locations'
align: left
data_name: locations
data: locations
type: twig
template: Partials/Datagrid/Gate:locations_cell_in_gate_under_location_grid.html.twig
frontend_type: html
inline_editing:
behaviour: enable_selected
editor:
view: oroform/js/app/views/editor/related-id-select-editor-view
view_options:
value_field_name: locations.name
placeholder: 'placeholder'
autocomplete_api_accessor:
class: oroentity/js/tools/entity-select-search-api-accessor
entity_name: Entity\Location
search_handler_name: locations
value_field_name: id
field_name: name
label_field_name: name
properties:
id: ~
view_link:
type: url
route: gate_view
params: [ id ]
update_link:
type: url
route: gate_update
params: [ id ]
sorters:
columns:
name: { data_name: g.name }
default:
name: ASC
filters:
columns:
name:
type: string
data_name: g.name
actions:
view:
type: navigate
label: 'common.grid.details'
link: view_link
icon: eye
update:
type: navigate
label: 'common.grid.edit'
icon: edit
link: update_link
options:
entityHint: 'gate.datagrid.entityhint'
export: true
entity_pagination: true
routerEnabled: false
The location cell editor template is in the locations_cell_in_gate_under_location_grid.html file:
{% import 'OroUIBundle::macros.html.twig' as UI %}
<span class="inline-actions-element">
{% for location in value %}
<span class="tags-container">
<a href="#" title="{{ location.name }}" class="tags-container__tag-entry">
<span>
{{ location.name }}
</span>
</a>
</span>
{% endfor %}
<span class="inline-actions-element_actions inline-actions-element_wrapper" data-role="container">
{{ UI.clientButton({
'dataUrl': path('gate_locations_update',
{
'gateId': record.rootEntity.id,
'locationId': record.getValue('ancestorId')
}),
'aCss': 'inline-actions-btn inline-actions-btn--size-s',
'iCss': 'fa-pencil',
'dataId': record.rootEntity.id,
'title' : 'Edit'|trans,
'label' : 'Edit'|trans,
'widget' : {
'type' : 'dialog',
'multiple' : false,
'reload-grid-name' : 'gates-under-location-grid',
'options' : {
'alias': 'gate_locations_update_dialog',
'stateEnabled': false,
'dialogOptions' : {
'title' : 'gate.datagrid.under_location.locations_edit_widget.title'|trans,
'allowMaximize': false,
'allowMinimize': false,
'width': 600,
'modal': true,
},
},
},
}) }}
</span>
Controller action is the following:
/**
* Shows editForm, or updates Gate with given ID
*
* #Route("/locations-edit/gate/{gateId}/location/{locationId}", name="gate_locations_update", requirements={"gateId"="\d+","locationId"="\d+"})
* #Template("Gate:locations_update.html.twig")
* #ParamConverter("gate", class="Entity\Gate", options={"id" = "gateId"})
* #ParamConverter("location", class="Entity\Location", options={"id" = "locationId"})
*
* #param Request $request
* #param Gate $gate
* #param Location $location
*
* #return array|RedirectResponse
*/
public function updateLocationsAction(Request $request, Gate $gate, Location $location)
{
$form = $this->get('form.factory')
->create(GateLocationsType::class, $gate, ['attr' => ['rootLocation' => $location]]);
return $this->get('oro_form.update_handler')
->update(
$gate,
$form,
$this->get('translator')->trans('common.processes.successful_saved'),
$request
);
}
I wanted to refresh the cell after inline edit, but since i didn't find any chance, it would be good to refresh whole datagrid.
The problem is with this solution, after cell data stored, i got the Data loading failed, try reloading the page. If the issue appears again please contact your administrator. message, and it's logged in the log file:
request.CRITICAL: Uncaught PHP Exception Oro\Bundle\DataGridBundle\Exception\InvalidArgumentException: "Cannot bind datasource parameter "rootLocation", there is no datagrid parameter with path "rootLocation"." at vendor/oro/platform/src/Oro/Bundle/DataGridBundle/Datasource/Orm/ParameterBinder.php line 164 {"exception":"[object] (Oro\\Bundle\\DataGridBundle\\Exception\\InvalidArgumentException(code: 0): Cannot bind datasource parameter \"rootLocation\", there is no datagrid parameter with path \"rootLocation\". at app/vendor/oro/platform/src/Oro/Bundle/DataGridBundle/Datasource/Orm/ParameterBinder.php:164, Symfony\\Component\\PropertyAccess\\Exception\\NoSuchPropertyException(code: 0): The key \"rootLocation\" does exist in an array. at app/vendor/oro/platform/src/Oro/Component/PropertyAccess/PropertyAccessor.php:435)"} []
I tried to add the parameters, but these efforts didn't affected on the error.
Could somebody help, how to pass the rootLocation parameter for the refresh?
Thanks in advance!

A custom controller is not a recommended way to handle the inline editing in the datagrid.
Please follow the official documentation on Creating editable data grid cells in OroPlatform applications.
Also, there is a general reference on inline editing in the OroPlatform datagrids, where you can find the documentation about all the existing inline editor options. You can use one of them, instead of implementing the custom one, or you can use it as a base for creating your own editor.

Related

How to remove active class of previously selected list item on selecting new one in angular

I want to remove the active class of list item which I had set intentionally active so when the page load I want this list item to remain active using routerLinkActive="active". I want to disable this active class when I select the other items of list in angular
I tried using ngClass but didn't worked as expected. How can this be done without using jquery?
<ul class="nav">
<li routerLinkActive="active" *ngFor="let menuItem of menuItems" [ngClass]="{'active': selectedItem == menuItem}" (click)="listClick($event, menuItem)">
<a class="nav-link" [routerLink]="[menuItem.path]">
<p>{{ menuItem.title }}</p>
</a>
</li>
</ul>
declare interface RouteInfo {
path: String,
title: String,
class: String
}
export const ROUTES: RouteInfo[] = [
{ path: '', title: 'Dashboard', class: '' },
{ path: '/vessel', title: 'Vessel Details', class: '' },
{ path: '/arrival', title: 'Arrival Details', class: ''},
{ path: '/stock', title: 'StockYard', class: ''},
{ path: '/cargo', title: 'Cargo Details', class: '' },
{ path: '/other', title: 'Others', class: ''}
];
menuItems: any[];
selectedItem= false;
listClick(event, newValue) {
console.log(newValue);
this.selectedItem = !this.selectedItem;
}
The intentionally setted active class should be disabled when other list items are clicked.
I see what your trying to do now. You shouldn't need to use ngClass or the click event. Angular will check to see if the active route matches the routerLink path. If it does, the class specified in ActiveRouterLink is added.
It's hard to solve your issue without knowing what you are seeing but try adding [routerLinkActiveOptions]="{exact: true} to the li element.

Dropdown created by EasyAdmin Bundle not closing on select

I am creating a backend to my Symfony4.2 site using the easyadmin bundle. in the new/edit form created for my entities it creates a dropdown to select from. However, in chrome and firefox these dropdowns are not behaving as expected. When I click on them it shows the options but it does not close if I select an option or click away from the dropdown menu. It works okay on Safari and Edge.
Here is the easyadmin.yaml
easy_admin:
#Global Settings
site_name: 'Physics Quiz SIte'
design:
assets:
favicon: '/build/images/favicon.ba133a8b.ico'
# this is the default form theme used by backends
form_theme: '#EasyAdmin/form/bootstrap_4.html.twig'
# these custom templates are applied to all entities
brand_color: '#1ABC9C'
menu:
- { label: 'Public Homepage', route: 'homepage', icon: 'home' }
- { entity: 'User', icon: 'user' }
- { entity: 'QuestionType' }
- { entity: 'Question' }
- { entity: 'Quiz' }
show:
max_results: 10
list:
actions:
- { name: 'edit', icon: 'pencil'}
- { name: 'delete', icon: 'trash'}
# allow deleting multiple items at once ...
batch_actions: ['delete']
# List the entity class name you want to manage
entities:
Quiz:
class: App\Entity\Quiz
form:
fields:
- property: 'quizname'
label: 'Quiz Name'
- property: 'course'
type: 'entity'
type_options:
expanded: false
multiple: false
This is the relevant page source that is created:
<div class="col-12 ">
<div class="form-group field-entity">
<label class="form-control-label required" for="quiz_course">Course</label>
<div class="form-widget">
<select id="quiz_course" name="quiz[course]" data-widget="select2" class="form-control">
<option value="1">Year 10 Physics</option>
<option value="2">Year 11 Physics</option>
</select>
</div>
</div>
</div>
and here are the scripts that may be relevant.
<script src="/bundles/easyadmin/select2/i18n/en.js"></script>
<script type="text/javascript">
$(function() {
// Select2 widget is only enabled for the <select> elements which
// explicitly ask for it
function init() {
$('form select[data-widget="select2"]').select2({
theme: 'bootstrap',
language: 'en'
});
}
$(document).on('easyadmin.collection.item-added', init);
init();
});
</script>
Here is a picture of the rendered dropdown:
This was a bug introduced in version 2.1.2.
https://github.com/EasyCorp/EasyAdminBundle/issues/2715
There was a new release 2.1.3 that fixes the problem.

EasyAdmin Bundle - Symfony

I work with EasyAdmin and I don't know how to add an image in list view.
I would like to add next to the prices two pictures (simply 2 logos) with a link to the website in question. The admin can click on logo A or B who redirect to the website.
I can insert my links with entiy's priority (Interface with links).
.
Here is my code:
app/config/config.yml
list:
fields:
- { property: 'low_amz', label: 'Amazon' }
- { property: 'url_amz', label: 'Amz', type: 'url' }
- { property: 'low_pm', label: 'PriceMinister' }
- { property: 'url_pm', label: 'Pm', type: 'url' }
But how I replace these link's value with my images. The images are stocked in local.
With my thumbnails, it works:
- { property: 'urlPdtImg', type: 'image', label: ' ' }
But in my case, I want just to change the value "string" in img. Of course, this does not work:
- { property: 'url_pm', label: 'Pm', type: 'url', base_path: '/img/Amazon.svg' }}
EasyAdmin Bundle 1.17.12
Symfony 3.4
Have a nice day.
Here are my files:
File config.yml:
- { property: 'url_amz', label: ' ', type: 'url', template: 'easy_admin/fields/_url1.html.twig' }
File _url.html.twig
<a href="{{ value }}">
<img src="{{ asset('Img/PM.svg') }}" alt="Amazon logo" style="height: 30px;"/>
Result

Sonata admin bundle : Accessing the child edit route from an embed admin class

I'm having some headaches trying to , i guess, remake the wheel.
In sonata admin bundle , i'm trying to make a logical navigation through all my admin entities.
Each entities are related in cascade like this : programEntity -> LevelEntity -> ExerciceEntity -> somethingEntity -> etc
From what i've read , sonata admin bundle handle ( hope this will change ) only one embed relation between a parent and a child admin class .
The fact is not very user friendly to be able to edit / list parent's children and go back to dashboard to edit / list parent 's grandchildren
I'm currently trying to make a custom route for editing a parend's child by removing the parent's path from the edit route :
http://localhost/domain/admin/acme/app/parent/4/child/3/edit
i would like to replace this url by direct one like this :
http://localhost/domain/admin/acme/app/child/3/edit
This way i would be able to access grand children from the parent 's selected child.
I tried to override generateObjectUrl and generateUrl from sonata adminClass without a success, i have also in mind to override template for each of my entities but it's not very poo oriented .
any ideas ?
i was able to find a way to resolve this :
1) override base_list_field in your own bundle ( copy the files in vendor\sonata-project\admin-bundle\Sonata\AdminBundle\Resources\views\CRUD\base_list_field.html.twig in your own bundle like acme/bundle/resources/views/CRUD )
2) modify the file to looks like this :
{#
This file is part of the Sonata package.
(c) Thomas Rabaix <thomas.rabaix#sonata-project.org>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
#}
<td class="sonata-ba-list-field sonata-ba-list-field-{{ field_description.type }}" objectId="{{ admin.id(object) }}">
{% if
field_description.options.identifier is defined
and field_description.options.route is defined
and admin.isGranted(field_description.options.route.name == 'show' ? 'VIEW' : field_description.options.route.name|upper, object)
and admin.hasRoute(field_description.options.route.name)
%}
<script type="text/javascript">
var route = "{{ admin.generateObjectUrl(field_description.options.route.name, object, field_description.options.route.parameters) }}";
var url = route.split(/(app)\//);
var tabUrl = url[2].split ( "/" );
alert ( 'test' ) ;
var new_url = '';
// case where adminclass is a child
if ( tabUrl.length == 5 )
{
new_url = url[0] + url[1] + '/' + tabUrl[2] + '/' + tabUrl[3] + '/' + tabUrl[4] ;
}
// case where adminclass is not a child
if ( tabUrl.length == 3 )
{
new_url = "{{ admin.generateObjectUrl(field_description.options.route.name, object, field_description.options.route.parameters) }}";
}
document.write( {%raw%}"<a href='"{%endraw%} + new_url + {%raw%}"'>{%endraw%}{%- block field %}{{ value }}{% endblock -%}{%raw%}</a>"{%endraw%} );
</script>
{% else %}
{{ block('field') }}
{% endif %}
if the tabUrl ( whitch is a split of the url with '/' ) find 5 results , it means that we are in adminclass embedded , otherwise it's a normal admin class listing .
the code is not very clean and optimized but it works .
3) update your config.yml
sonata_admin:
title: Bonk
title_logo: public/img/logo-admin.png
security:
handler: sonata.admin.security.handler.noop
templates:
# default global templates
layout: SonataAdminBundle::standard_layout.html.twig
ajax: SonataAdminBundle::ajax_layout.html.twig
dashboard: SonataAdminBundle:Core:dashboard.html.twig
# default actions templates, should extend a global templates
list: SonataAdminBundle:CRUD:list.html.twig
show: SonataAdminBundle:CRUD:show.html.twig
edit: SonataAdminBundle:CRUD:edit.html.twig
------>>> base_list_field: AcmeMyBundle:CRUD:base_list_field.html.twig
and
sonata_doctrine_orm_admin:
# default value is null, so doctrine uses the value defined in the configuration
entity_manager: '#doctrine.orm.entity_manager'
templates:
form:
- SonataDoctrineORMAdminBundle:Form:form_admin_fields.html.twig
filter:
- SonataDoctrineORMAdminBundle:Form:filter_admin_fields.html.twig
types:
list:
array: SonataAdminBundle:CRUD:list_array.html.twig
boolean: SonataAdminBundle:CRUD:list_boolean.html.twig
date: SonataAdminBundle:CRUD:list_date.html.twig
time: SonataAdminBundle:CRUD:list_time.html.twig
datetime: SonataAdminBundle:CRUD:list_datetime.html.twig
text: acmeMyBundle:CRUD:base_list_field.html.twig
trans: SonataAdminBundle:CRUD:list_trans.html.twig
string: acmeMyBundle:CRUD:base_list_field.html.twig
smallint: acmeMyBundle:CRUD:base_list_field.html.twig
bigint: acmeMyBundle:CRUD:base_list_field.html.twig
integer: acmeMyBundle:CRUD:base_list_field.html.twig
decimal: acmeMyBundle:CRUD:base_list_field.html.twig
identifier: acmeMyBundle:CRUD:base_list_field.html.twig
hope this will help !

Form does not display form errors in template

For my contact form no form errors are displayed.
$contact = new Contact();
$form = $this->createForm(new ContactFormType(), $contact);
/* handle contact form submission */
if ('POST' == $request->getMethod()) {
$form->bindRequest($request);
if ($form->isValid()) {
//Do something
}
}
return $this->render('MainBundle:Default:contact.html.twig', array(
'form' => $form->createView()
));
My validator
Fc\MainBundle\Entity\Contact:
properties:
firstName:
- NotBlank: ~
lastName:
- NotBlank: ~
email:
- NotBlank: ~
- Email:
checkMX: true
title:
- NotBlank: ~
message:
- NotBlank: ~
I have added a novalidate attribute to my form tag to check if my validation works. Now when I submit the form with empty data nothing happens (with correct data everything is fine), the controller identifies the form as invalid and stops further processes.
In the template I call
{{ form_errors(form) }}
But nothing is displayed. Any ideas why? I use symfony 2.1.X
Can you confirm that the validation is working with this:
if ($form->isValid()) {
//Do something
}
else
{ die('not valid') }
Is the form well posted?
Is there anything in the HTML that shows up where you call {{ form_errors(form) }} ? - it would be a CSS or JS problem if that's the case...
Have you tried to show the errors by field (there is no global error in your validation apparently):
{{ form_errors(form.firstName) }}
etc.
Remark: form.firstName works, not form.first_name. You have to follow that convention with Doctrine2/Symfony2.

Resources