In sonata it is possible to export list views to different file formats e.g. excel, pdf or csv ...
This export is based on the database query running in the background. It does not consider that maybe a template is manipulating the output in the list view. For example if a timestamp is saved in the database and this field is added via
$listMapper->add('testdate', 'date', ['format' => 'y-m-d'])
on the listview its correct displayed as "2017-10-01" but in the export there is something like "2489489289" in this column...
Another example: if i render a custom column representing a state based on different properties of the current object, the state column will never appear in the exported file.
Maybe a possible solution to me could be to override the admin controller and add a custom callback function to render the export file manual.
But here is one big problem:
I have to implement the whole logic for showing the columns in the expected format also in the exporting callback function.
Is there an elegant way to achieve this? What i actually want is an export of the current list view "as it is" and not based on the database query in the background ...
Thanks
You can add what fields you want to export or you can add functions and do your own logic for fields instead of field getters in getExportFields() method of your Admin class, read more here.
I have it like this in Admin:
public function getExportFields()
{
return array(
$this->trans('export.createdAt') => 'CreatedAtForExport',
$this->trans('export.OfferPage') => 'OfferPageNameForExport'
);
}
and in my Entity I have:
class Entity
{
public function getCreatedAtForExport()
{
return $this->createdAt->format('d.m.Y H:i');
}
public function getOfferPageNameForExport()
{
return $this->isOfferPage ? 'OfferPage' : 'CalcPage';
}
}
Related
I am trying to implement a search filter in my application which uses react/redux using redux-search. The first gotcha I get is when I try to add the store enhancer as in the example.
// Compose :reduxSearch with other store enhancers
const enhancer = compose(
applyMiddleware(...yourMiddleware),
reduxSearch({
// Configure redux-search by telling it which resources to index for searching
resourceIndexes: {
// In this example Books will be searchable by :title and :author
books: ['author', 'title']
},
// This selector is responsible for returning each collection of searchable resources
resourceSelector: (resourceName, state) => {
// In our example, all resources are stored in the state under a :resources Map
// For example "books" are stored under state.resources.books
return state.resources.get(resourceName)
}
})
)
I understand evarything up to the resourceSelector, when I tried to get a deep dive into the example to see how it works but I can barely see how they are generated and the last line returns an error, Cannot read property 'get' of undefined
My state object looks like this
state: {
//books is an array of objects...each object represents a book
books:[
//a book has these properties
{name, id, author, datePublished}
]
}
Any help from anyone who understands redux-search is helpful
If this line:
return state.resources.get(resourceName)
Is causing this error:
Cannot read property 'get' of undefined
That indicates that state.resources is not defined. And sure enough, your state doesn't define a resources attribute.
The examples were written with the idea in mind of using redux-search to index many types of resources, eg:
state: {
resources: {
books: [...],
authors: [...],
// etc
}
}
The solution to the issue you've reported would be to either:
A: Add an intermediary resources object (if you think you might want to index other things in the future and you like that organization).
B: Replace state.resources.get(resourceName) with state[resourceName] or similar.
I'm trying to sort a list of products from highest to lowest. The file json has been uploaded to firebase.
TypeError: Cannot read property 'query' of undefined
thats the error i'm receiving.
My model is called "product" and it has the price attribute
Here is the code:
sortHigh: ['product.price'],
actions:{
sortHigh(product) {
sortedProducts: Ember.computed.sort('product', 'sortHigh')
return this.store.query('product').sortHigh('price');
}
}
HTML {{action 'sortHigh'}}Highest Price
By default store is available only in route and controller. If you want to access store in any other place, then you need to inject to get it.
store: Ember.inject.service()
Let's say I have an initial state in my redux application that looks like this:
{
themeParks : []
}
And theme park objects are stored in a MongoDB or wherever like this:
{
ParkName : "Disney World",
NumberOfRides : 25
}
My app fetches (via ajax) and displays the theme parks on load, and lets me do CRUD operations to add / remove / edit theme parks.
My question is, what is the best point in the application to merge in new properties that I will need, that are related to UI changes and need to be included in the state? For example, at some point I need to add an "editing" boolean property to each theme park, so they look like this:
{
ParkName : "Disney World",
NumberOfRides : 25,
editing : false
}
This "editing" flag needs to be a property of each theme park object, to provide the ability to have multiple theme parks in an editable state while using the application, is that correct? Obviously I don't want or need to store this flag in my database schema as it only relates to UI operations.
My first guess would be to include such logic within my .then function after successful return of the data, like this, but I'm not sure:
let ajax = new AjaxHanlder();
let promise = ajax.DoGet('/path/to/api-endpoint');
promise.then((themeParks) => {
themeParks.map((themePark, i) => {
themePark.editing = false;
});
dispatch({type : LOAD_THEME_PARKS, payload : themeParks});
});
Also, is there a convention for providing a definition of the theme park object before it is loaded, since the initial state is an empty array and has no knowledge of it?
Thanks in advance for any insight on this, as I attempt to advance my knowledge of redux design patterns :-)
I recommend adding the editing property to your LOAD_THEME_PARKS reducer. For example, part of your LOAD_THEME_PARKS reducer could look like:
case LOAD_THEME_PARKS:
return {
...state,
themeParks: action.payload.map(park => park.editing = false)
};
I have a collection called "Products". I want to access and change an attribute called "screenShots" inside the collection.
This code didn't work with me
screenshotsURLS: function(sshots) {
check(sshots, [String]);
Products.update({},{$set:{screenShots:sshots}});
console.log(sshots);
}
when i console.log the sshots, i can see that the array exists, but the update function isn't working
how do i set the screenShots attribute inside the Product collection to whatever value passed in "screenshotsURLS" function?
For that you have to update the mongodb document.
THis is how you can update the doc in meteor.
collectionName.update(
<query>,
<update>,
{
upsert: <boolean>,
multi: <boolean>,
writeConcern: <document>
}
)
In your your case collectionName is Products and field is screenShots.
So for doing this. Your query will be
sshots
Products.update({},{$set:{screenShots:sshots}}) (Be careful this will update all of your doc)
For selecting doc update use the query like.
Products.update({name:'yourProductName'},{$set:{screenShots:sshots}})
For more about update a please check this link.
In RavenDB I can store objects of type Products and Categories and they will automatically be located in different collections. This is fine.
But what if I have 2 logically completely different types of products but they use the same class? Or instead of 2 I could have a generic number of different types of products. Would it then be possible to tell Raven to split the product documents up in collections, lets say based on a string property available on the Product class?
Thankyou in advance.
EDIT:
I Have created and registered the following StoreListener that changes the collection for the documents to be stored on runtime. This results in the documents correctly being stored in different collections and thus making a nice, logically grouping of the documents.
public class DynamicCollectionDefinerStoreListener : IDocumentStoreListener
{
public bool BeforeStore(string key, object entityInstance, RavenJObject metadata)
{
var entity = entityInstance as EntityData;
if(entity == null)
throw new Exception("Cannot handle object of type " + EntityInstance.GetType());
metadata["Raven-Entity-Name"] = RavenJToken.FromObject(entity.TypeId);
return true;
}
public void AfterStore(string key, object entityInstance, RavenJObject metadata)
{
}
}
However, it seems I have to adjust my queries too in order to be able to get the objects back. My typical query of mine used to look like this:
session => session.Query<EntityData>().Where(e => e.TypeId == typeId)
With the 'typeId' being the name of the new raven collections (and the name of the entity type saved as a seperate field on the EntityData-object too).
How would I go about quering back my objects? I can't find the spot where I can define my collection at runtime prioring to executing my query.
Do I have to execute some raw lucene queries? Or can I maybe implement a query listener?
EDIT:
I found a way of storing, querying and deleting objects using dynamically defined collections, but I'm not sure this is the right way to do it:
Document store listener:
(I use the class defined above)
Method resolving index names:
private string GetIndexName(string typeId)
{
return "dynamic/" + typeId;
}
Store/Query/Delete:
// Storing
session.Store(entity);
// Query
var someResults = session.Query<EntityData>(GetIndexName(entity.TypeId)).Where(e => e.EntityId == entity.EntityId)
var someMoreResults = session.Advanced.LuceneQuery<EntityData>(GetIndexName(entityTypeId)).Where("TypeId:Colors AND Range.Basic.ColorCode:Yellow)
// Deleting
var loadedEntity = session.Query<EntityData>(GetIndexName(entity.TypeId)).Where(e =>
e.EntityId == entity.EntityId).SingleOrDefault();
if (loadedEntity != null)
{
session.Delete<EntityData>(loadedEntity);
}
I have the feeling its getting a little dirty, but is this the way to store/query/delete when specifying the collection names runtime? Or do I trap myself this way?
Stephan,
You can provide the logic for deciding on the collection name using:
store.Conventions.FindTypeTagName
This is handled statically, using the generic type.
If you want to make that decision at runtime, you can provide it using a DocumentStoreListner