GroupBy Filter in AngularJS - javascript

I have an array of timeline which I want to divide in groups per date (dd/MM/YYYY). I was trying make my own "groupBy" without any library (which I really prefer), but I got no success. So I decided to search for a library that does it and I found this: angular-filter, so now I'm trying to use it.
The problem is that I can't figure out what I'm doing wrong, I followed this example and created my JS Bin to ilustrate my situation. It always says the format date is wrong, why?
By the way, the expected result is:
Date: 17/06/2016
Timeline item: an e-mail edited
Timeline item: an e-mail deleted
Timeline item: an e-mail edited
Date: 18/06/2016
Timeline item: an e-mail added
Timeline item: an e-mail added

Filters in Angular are called many times, not just once. So during the first digest, your created_at values are converted to D/M/Y format. Then, when during the next digest Angular call your filters again, it tries to create a date with already converted value (i.e. new Date('18/06/2016')). So you get an Invalid date as a result.
The solution is to convert the dates once in the controller before assigning them to the view and omit the map: ... filter.
See the updated jsbin.

Related

AngularJS/HTML input week format error

I'm using AngularJS to for user to choose week from a input week tag, but there is something bizarre qbout the format.
I've read that the format should be yyyy-W##, and I do this already, but angularJS still gives me this error:
Error: [ngModel:datefmt] Expected `2015-W51` to be a date
http://errors.angularjs.org/1.4.8/ngModel/datefmt?p0=2015-W51
and this is my tag:
<input type="week" ng-if="header.type==='week'" ng-model="entry[header.className]" ng-change="vos.fieldSelectionChanged(field_id,entry.record_id)"/>
So as you see, the input type is week, here, I'm using this tag inside of a ng-repeat, so I'm loading the data from the entry[] array, and the week loaded is 2015-W51.
So please tell me what I'm doing wrong , is there a best practice using this tag with AngularJS?
Thanks !
Edit 1 - more code
I've found this:
http://codepen.io/empirefox/pen/MYyoao
It demonstrates how to use input week with a date, but the problem is that I don't have the data as dates.
And at the right part of the page, you have this :
$scope.value = new Date(2013, 0, 3);
Change it to this :
$scope.value = "2015-W20";
And it gives me the same error. So if we can solve this one, I think we can also solve the problem on my page.
Angular uses native Date object to handle all its datetime-related inputs, but unfortunately Date instances does not have any methods to handle week numbers. It would be the best solution to stick with moment.js.
Coercion from string to ng-model-enabled value (in controller etc.):
$scope.value = moment("2015-W20").toDate();
Coercion from ng-model-enabled value to string (in form submit handler etc.):
moment($scope.value).format("YYYY-[W]WW"); // returns "2015-W20"

Trello Api: list all cards for a given date range considering last activity date of the card in Trello?

I need to list all the cards for a given date range in Trello. I know that I can use "since" and "before" as arguments. BUT I don't know which date would consider this filter. I need it to be the "dateLastActivity" of the card. So, the question is, "Which date is using Since and Before arguments to do the search? Is there a way to list the cards that I need for a given date range considering dateLastActivity?" ... Thanks in advance.
The since and before arguments to the api call shown below look at the date a card was created. I tested this and found that only cards that were created since '2015-07-30' were returned, even though there was activity on other cards on the same board.
https://api.trello.com/1/board/[board id]/cards?fields=name,labels,url,idShort,idList,dateLastActivity&since=2015-07-30&key=[key]&token=[token]
I have the same requirement to only gather cards using dateLastActivity in a certain date range but found it wasn't supported. I also tried the actions_since argument, but this only affects what actions appear in the result set linked to the card. It won't filter out cards. My workaround has been to get all cards and then in my program filter out the ones I don't need by comparing a date range to dateLastActivity.

Importing data from a javascript table(?) to excel

I'm trying to import data For a large number of dates from here: https://demanda.ree.es/movil/peninsula/demanda/tablas/2014-11-03/2
Once/if that's possible I want to automate it so it retrieves the data for a given set of dates. Say, entire 2013.
I can't find anything in the webpage source that would give a hint as to from where the data is retrieved from. I've tried importing the data both using:
Data/From Web: Gets javascript error
Open/ Other web locations: Just retrieves a worksheet filled with grey cells, no data.
Thanks for any help!
Use the following links:
https://demanda.ree.es/WSvisionaMovilesPeninsulaRest/resources/maxMinPeninsula?callback=angular.callbacks._0&curva=DEMANDA&fecha=2013-01-01
https://demanda.ree.es/WSvisionaMovilesPeninsulaRest/resources/prevProgPeninsula?callback=angular.callbacks._1&curva=DEMANDA&fecha=2013-01-01
https://demanda.ree.es/WSvisionaMovilesPeninsulaRest/resources/demandaGeneracionPeninsula?callback=angular.callbacks._2&curva=DEMANDA&fecha=2013-01-01
https://demanda.ree.es/WSvisionaMovilesPeninsulaRest/resources/coeficientesCO2?callback=angular.callbacks._3&curva=DEMANDA&fecha=2013-01-01
Use the "fecha" parameter to set the date. It seems it is not possible to get the whole year at once so you should iterate the calls to that link and change "fecha" to 2013-01-02, 2013-01-03, etc. for each month.
Muchas gracias #miguel-febres! It now works more or less*. Where did you find the links from? :)
It runs some 10-20 loops and returns an address error, upon which I just start the macro again and it works... strange.
Sub Macro1()
Application.DisplayAlerts = False
Do
Workbooks.OpenText Filename:="https://demanda.ree.es/WSvisionaMovilesPeninsulaRest/resources/demandaGeneracionPeninsula?callback=angular.callbacks._2&curva=DEMANDA&fecha=" & ActiveCell.Value & ""
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Windows("Spain").Activate
ActiveCell.Offset(1, 0).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
'close table
Windows("demandaGeneracionPeninsula").Activate
ActiveWindow.Close
ActiveCell.Offset(-1, 1).Activate
Loop Until ActiveCell.Value = ""
End Sub
Now I just have to parse the results.. :)

What is the proper format to specify only new items with eBay's API?

I'm using the url format to parse eBays database, and I can't seem to figure out the correct way to filter items for a specific condition, as the condition histogram instructions aren't very clear. My current code is below.
<script src=http://svcs.ebay.com/services/search/FindingService/v1?SECURITY-APPNAME=*APIKEY GOES HERE*&OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=JSON&callback=_cb_findItemsByKeywords&REST-PAYLOAD&sortOrder=PricePlusShippingLowest&itemFilter(0).name=MaxPrice&itemFilter(0).value=500.00&itemFilter(0).paramName=Currency&itemFilter(0).paramValue=USD&itemFilter(1).name=MinPrice&itemFilter(1).value=200.00&itemFilter(1).paramName=Currency&itemFilter.name=ListingType&itemFilter.value=FixedPrice&itemFilter(1).paramValue=USD&keywords=iphone%205%2016gb%20unlocked&paginationInput.entriesPerPage=6>
</script>
Check Item Filter Type in the Ebay API. It has an Enumeration Value of Condition which has an Allowed Text Value of New.

jqPlot Graph "TypeError"

In my Firebug, it is showing me:
TypeError: this[r]._ticks[0] is undefined
But in my JS Array, the items are well constructed. Should not be the data problem.
So, as i said it should not be the data problem. The mystery is:
The problem is not consistent, just that SOMETIME JUST GOT WHOLE BLANK.
I have multiple log ranges (e.g, Show 1 week, Show 1 day, Show 1 hour), then sometime some got BLANK like now and at the same time, graphs are OK in some time ranges. And next time, this range got OK and next range got problem. (With this same code, same data)
I am super sure all my Array Rooms are filled with respective data inside. (I got no blank or corrupted array rooms)
I'm outta idea already :S
Please help.
I have the same problem this day, and resoled this by hard coding the second array value is number but not string type. You can do this simply in php code: $output["1"]=(double)$var, then try to use json_encode to output the data.
Here is the difference example:
valid array format:
var data=[[['2014-01', 2],['2014-02',5.12],['2014-03',13.1],['2014-04',33.6],['2014-05',85.9],['2014-06',219.9],['2014-07',39.9],['2014-08',99.9]]];
invalid array format:
var data=[[["2014-02","1920.97"],["2014-03","2040.92"],["2014-04","1704.52"],["2014-05","1630.88"],["2014-06","207.43"]]]
Use parseFloat(var) or parseInt(var) before passing data to the graph.
Where var is your variable or value which you are passing to graph.

Categories