Laravel Nova Metrics - how to show number without k - laravel-nova

I generate metrics with Laravel Nova to show sales.
The problem is that it shows me numbers like 0.50k instead of 500

To show thousands "normally" you can use the format method like this:
public function calculate(Request $request)
{
return $this->count($request, Sales::class)->format('0,0');
}

Related

Best way to show a list of complex objects and emit event int vaadin 14

For sample I have one order that my user can add one store and in each store a lot of itens:
Amazon
- cup - $ 1
- notebook - $ 3
- $ 4 Ebay
- bike - $ 10
- boat - $ 13
- $ 23
Total order: $ 27 [Button to send the order]
And in my project I have 3 components:
CartView - (show the total from order and a button)
- StoreView (show de Store name, and total)
---StoreitemView (show the item and the button to remove)
lets to the doubts:
1 - The best way to show thats lists are usingo a GRID with one ROW? some like this:
Grid<StoreView> myGrid = new Grid();
myGrid.addComponentColumn(this::createStoreView).setAutoWidth(true);
or Its best to use a for just like this:
Div myDiv = new Div();
for(Store store in StoreList){
muDiv.add(new StoreView(store);
}
2 - How can I pass event to parent? so when my user click a button at StoreItemView I need to emit that event to my CartView(passing to StorView, and go to CarView to update the values and recreate the cart)
tks
Layout
The layout depends on how many stores and items you expect. If the number is low, just looping through and adding components is a decent approach.
If you have many items, using a Grid with one column is a better approach, as all items aren't rendered at once. An even better approach might be the IronList, or since Vaadin 21 the VirtualList.
If your views are complex with a lot of components, it's a good idea to use a TemplateRenderer instead of a ComponentRenderer. If writing views in HTML instead of Java is not your cup of tea, you can keep on using the ComponentRenderer, especially if performance seems to be good.
If there are a lot of items per store, you can consider having a virtual list for the store items inside the store also. Especially if there are only a few stores.
Events
There is no correct answer here. It seems like your StoreView and StoreItemView are tightly coupled, so the communication can be tightly coupled too. For example, the StoreItemView can expose the button directly with a getRemoveButton() method.
I would use the ComponentEvent for the removal event, something like the code below. Your logic for how the StoreItemViews are created would be different, and you could add a method in the StoreView for adding the event listener. You might want to add some data to the event, too.
public class StoreView extends HorizontalLayout {
public StoreView() {
// Create your store items as you see fit
StoreItemView storeItemView = new StoreItemView();
storeItemView.getRemoveButton().addClickListener(e -> {
remove(storeItemView);
fireEvent(new StoreItemRemovedEvent(storeItemView));
});
add(storeItemView);
}
public static class StoreItemRemovedEvent extends
ComponentEvent<StoreItemView> {
public StoreItemRemovedEvent(StoreItemView source) {
super(source, false);
}
}
}
public class CartView extends VerticalLayout {
public CartView() {
StoreView storeView = new StoreView();
ComponentUtil.addListener(storeView, StoreView.StoreItemRemovedEvent.class, e ->
Notification.show("Store item removed"));
add(storeView);
}
}

Different text used of sorting and filtering

in a app, I use jQueryTablesorter, and the widget https://mottie.github.io/tablesorter/docs/example-widget-filter.html
I have two main features :
- filtering (the widget)
- sorting (default feature)
Both of these feature use textExtraction() function,
https://mottie.github.io/tablesorter/docs/#textextraction
My problem is the following :
for sorting, I would like to use computer form of a date, that is "2020-04-01"
for filtering, I would like to use human form (in French "1er avril 2020").
How can I deal with it ?
You might need to use a date library like sugar or date.js - check out this demo: https://mottie.github.io/tablesorter/docs/example-parsers-dates.html. What that library does is use the parser to convert the filter into a normalized date that will match with the date in the column. You would also need to add a filter-parsed class name to the column (ref).
I have found. I need to use a hook which modify the value parsed for filtering.
$.tablesorter.filter.types.start = function(config, data) {
data.exact = data.$cells[data.index];
data.exact = data.exact.innerText;
data.iExact = data.exact.toLowerCase();
return null;
}

Spring-data-elasticsearch: Result window is too large (index.max_result_window)

We retrieve information from Elasticsearch 2.7.0 and we allow the user to go through the results. When the user requests a high page number we get the following error message:
Result window is too large, from + size must be less than or equal to:
[10000] but was [10020]. See the scroll api for a more efficient way
to request large data sets. This limit can be set by changing the
[index.max_result_window] index level parameter
The thing is we use pagination in our requests so I don't see why we get this error:
#Autowired
private ElasticsearchOperations elasticsearchTemplate;
...
elasticsearchTemplate.queryForPage(buildQuery(query, pageable), Document.class);
...
private NativeSearchQuery buildQuery() {
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.should(QueryBuilders.boolQuery().must(QueryBuilders.termQuery(term, query.toUpperCase())));
NativeSearchQueryBuilder nativeSearchQueryBuilder = new NativeSearchQueryBuilder().withIndices(DOC_INDICE_NAME)
.withTypes(indexType)
.withQuery(boolQueryBuilder)
.withPageable(pageable);
return nativeSearchQueryBuilder.build();
}
I don't understand the error because we retreive pageable.size (20 elements) everytime... Do you have any idea why we get this?
Unfortunately, Spring data elasticsearch even when paging results searchs for a much larger result window in the elasticsearch. So you have two options, the first is to change the value of this parameter.
The second is to use the scan / scroll API, however, as far as I understand, in this case the pagination is done manually, as it is used for infinite sequential reading (like scrolling your mouse).
A sample:
List<Pessoa> allItens = new ArrayList<>();
String scrollId = elasticsearchTemplate.scan(build, 1000, false, Pessoa.class);
Page<Pessoa> page = elasticsearchTemplate.scroll(scrollId, 5000L, Pessoa.class);
while (true) {
if (!page.hasContent()) {
break;
}
allItens.addAll(page.getContent());
page = elasticsearchTemplate.scroll(scrollId, 5000L, Pessoa.class);
}
This code, shows you how to read ALL the data from your index, you have to get the requested page inside scrolling.

Prestashop convertPrice doesn't convert price

Using Prestashop 1.6.1.4
The theme function
{convertPrice price=$total}
Add the current currency sign but doesn't actually convert the to the chosen currency.
I followed the debugger to function (classes/Product.php, line 3034):
public static function convertPrice($params, &$smarty)
{
return Tools::displayPrice($params['price'], Context::getContext()->currency);
}
Which is strange since the convertPrice eventually calls displayPrice while Tools::convertPrice(...) is the function that convert the currency (but doesn't add the currency sign).
So I change it to :
return Tools::displayConvertPrice($params['price'], Context::getContext()->currency);
and added to Tools.php
public function displayConvertPrice($price, $currency)
{
return Tools::displayPrice(Tools::convertPrice($price, $currency), $currency);
}
My question:
Is it a bug or that I'm missing something?
Who knows what the devs wanted with that but there is a smarty function
{convertAndFormatPrice price=$total}
which does what you want.
You can open /config/smarty.config.inc.php and you'll see all prestashop functions registered in smarty smartyRegisterFunction(yada yada).
Use
{toolsConvertPrice price=$total}
this works for me on PS 1.6.1.12.

How to receive updates to the Twitter social graph?

I just got some crazy ideas for analyzing the Twitter social graph (i.e., representing follow-relations as the edges of a graph). Interestingly, the Twitter API provides methods for creating the graph. It is possible to read out a static snapshot of the social graph, whereas Twitter is a very dynamic network. It would be great if one could dynamically update the graph. So my question is: Is there any way to get notified by Twitter when anyone starts or stops to follow anyone?
I believe that the documentation you linked to would definitely mention that.
I'm quite certain that you need to do your own follower-list checking, and compare results on a regular basis.
I do this if someone follows me or not and how many followers they have and i generate this chart
public function existsFriendship($username,$friend)
{
try
{
if ($this->twitter->existsFriendship($username, $friend))
return true;
}
catch(Exception $e)
{
$this->debug($e->getMessage());
}
}
for the chart generation i use pchart.
in smarty template the code looks like this;
include("pChart/pData.class");
include("pChart/pChart.class"); ![alt text][1]
// Initialise the graph
$Test = new pChart(700,230);
$Test->setFontProperties("Fonts/tahoma.ttf",13);
$Test->setGraphArea(40,30,680,200);
$Test->drawGraphArea(252,252,252,TRUE);
$Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);
$Test->drawGrid(4,TRUE,230,230,230,70);
// Draw the line graph
$Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());
$Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);
// Finish the graph
$Test->setFontProperties("Fonts/tahoma.ttf",12);
$Test->drawLegend(45,35,$DataSet->GetDataDescription(),255,255,255);
$Test->setFontProperties("Fonts/tahoma.ttf",12);
$Test->drawTitle(60,22,"Twitter Graph",50,50,50,585);
$example = $Test->Render("templates/example1.png");
$smarty->assign("example",$example);
$smarty->display('index.tpl');
finaly the result
alt text http://img691.imageshack.us/img691/6749/example1k.png

Resources