Trello Manatee - How to filter cards in a list by Date (since and before) - manatee.trello

I want to fetch cards by date, for example:
list.Cards.Filter(CardFilter.Closed).Since("someDate").toList()
but there is no extension for cards like actions.

There is a Filter () overload that takes start and end dates.
Edit 1
This is wrong. I was thinking action collections. I'll check the API and come back.
Edit 2
As per the Trello docs there is no "get cards by date" function. However, there are a couple ways to do this:
By creation date
list.Cards.Filter(CardFilter.Closed)
.Where(c => c.CreationDate >= someDate);
By last modified date
list.Cards.Filter(CardFilter.Closed)
.Where(c => c.LastActivity >= someDate);
Also, remember that you can get cards for lists (as you're doing and above) as well as all of the cards for an entire board.
Edit 3
Manatee.Trello v1.16.0 provides this functionality as a new overload of the Filter() extension method on the ReadOnlyCardCollection object. You can use it like this:
list.Cards.Filter(new DateTime(2017,1,1), null);
to get all cards in a list that were created after 1 Jan 2017. The other parameter is an end date.

Related

How can I get all Actions for a Board using Trello's Rest API?

I want to get all the actions for a board, but Trello limits the results to 1000. I understand the correct way to deal with this is to paginate. I've tried both before and page as keywords:
Basic Call:
https://api.trello.com/1/board/[boardID]/
?key=[key]&token=[token]
&actions=commentCard&actions_limit=1000
Alternatives:
Before:
https://api.trello.com/1/board/[boardID]/
?key=[key]&token=[token]
&actions=commentCard&actions_limit=1000&
before=[oldest_returned_action's_date]
Page:
https://api.trello.com/1/board/[boardID]/
?key=[key]&token=[token]
&actions=commentCard&actions_limit=1000&
page=[page_number]
The result never varies --- I always get back [limit] number of actions, and they're always the same no matter the call. I checked the dates in what was returned and they certainly don't respect the before parameter. I even tried lowering the limit to make sure I wasn't trying to return more than I possessed. The problem persists.
How can I correctly get all actions for a Trello board?
Actions are in reverse chronological order (newest-to-oldest), so to page through the actions on a board, you would use something like:
curl "https://api.trello.com/1/boards/${BOARD_ID}/actions/?key=${TRELLO_API_KEY}&token=${TRELLO_TOKEN}&limit=1000"
then, from the last element of the array returned by the the above, select the date or id and pass that as the before parameter in the next call, e.g.:
curl "https://api.trello.com/1/boards/${BOARD_ID}/actions/?key=${TRELLO_API_KEY}&token=${TRELLO_TOKEN}&limit=1000&before=${DATE_OR_ID_OF_LAST_ACTION}"
and repeat, passing in either the id or date of the last action as the subsequent before parameter.
References:
Paging
Board Actions
Actions Nested Resource

Creating custom widgets for ruby gem dashing.io - Or combining widgets elements

I'm working with the dashing ruby gem and I would really like to combine elements of the graph and number widgets. I would like all elements of the graph and include the up/down percentage arrow from the number widget.
I've never done much work with ruby and I understand there are a few files within the widget that might need to be changed.
I've setup a few nice widgets and I'm using a job to pull data from a redis db to populate. I've added the following to the graph.html page:
<p class="change-rate">
<i data-bind-class="arrow"></i><span data-bind="difference"></span>
</p>
This has no effect, and I'm sure that I'm missing something in one of the many files that makes this all work.
Your on the right track, and I've actually put together something very similar but in order to complete what you are trying to do you need to send data to your two new data binds, which would be done with your jobs file and the graph.coffee file.
I'm not sure how exactly you're getting your graph data from redis to your jobs erb file but you will want to setup a couple new variables, for the example I have used nowNumber and lastNumber. These will be the number that the valuation is performed on.
jobs/jobname.erb
send_event('graph', points: points, current: nowNumber, last: lastNumber )
If you print this out you will get something like this:
{:points=>[{:x=>6, :y=>64}, {:x=>5, :y=>62}, {:x=>4, :y=>56}], :current=>57, :last=>64}
Tweak your graph/graph.coffee file:
# The following 6 lines aren't needed for your solution, but if you wanted to take advantage of 'warning', 'danger', and 'ok' status classes (changes background color and flashes), just feed your send_event with 'status: [one of the three status names]
if data.status
# clear existing "status-*" classes
$(#get('node')).attr 'class', (i,c) ->
c.replace /\bstatus-\S+/g, ''
# add new class
$(#get('node')).addClass "status-#{data.status}"
#accessor 'difference', ->
if #get('last')
last = parseInt(#get('last'))
current = parseInt(#get('current'))
if last != 0
diff = Math.abs(Math.round((current - last) / last * 100))
"#{diff}%"
else
""
# Picks the direction of the arrow based on whether the current value is higher or lower than the last
#accessor 'arrow', ->
if #get('last')
if parseInt(#get('current')) > parseInt(#get('last')) then 'icon-arrow-up' else 'icon-arrow-down'

Odoo / Postgres: Concatenate rows value until condition = true

I'm creating a new view for a customized PoS module for my restaurant. It's a specific view for kitchen, already filtered to show just kitchen's related items of a PoS order.
Now I would like to show a particular series of product with the name starting with "#" in a field populated by a function side by side with the "standard" products. In fact I'm speaking of a set of instructions coded as products to be available on PoS and to suit my needs I decided to create kitchen instructions as a product (service). In my PoS there are 3 categories that are not products but instructions (ADD, SUBTRACT, ADDITIONAL NOTE).
A typical order will show as:
Product Quantity
[1007] Pom. Secchi 1
# + Búfala 1
# - Mussarela 1
[2002] Nutella banana 1
# + Mussarela 1
What I would like to archive is a view like:
Product Note Quantity
[1007] Pom. Secchi # + Búfala # - Mussarela 1
[2002] Nutella banana # + Mussarela 1
I need to select just the strings starting with the "#" between two internal code starting with "[code]" and this is the hard thing to do. I don't need to delete the values I "move" because I need the stock view when I print the receipt.
I will call this function using python (and psycopg2 on postgresql 9.4) with on_change or extending the workflow when an order is marked as "paid". I don't think if doing it directly in Python is viable.
I've tried with string_agg(,) but with bad results.
Any tips about what should be the correct path to start coding? Thanks.

Rails 4: complex search form to filter a model through various relationships

I'm working on some reporting/analytics for a site. The goal is to filter to a group of #loans that I query from the DB and run analytics against. The desire is to use the DB to grab the filtered #loans, run metrics against those records, and then return the metrics to display on the page.
The relationships are not very complex but what I'm doing feels like it is:
Model relationships
# loan.rb
belongs_to :loan_category
belongs_to :loan_type
belongs_to :partner
# loan_category.rb
has_many :loans
# loan_type.rb
has_many :loans
# partner.rb
has_many :loans
belongs_to :company
# company.rb
has_many :partners
Filter form
I'm treating reports as a resource since users can save filters as a saved_report.
A user filters by 2 given criteria:
what type of report they want (partner, company, loan_category, loan_type), accomplished by selecting ONLY one of the four (ie, filter by parter ID#3, or loan_type ID#6, but never more than one)
date range (from, to)
At first it seems fairly trivial, until I start trying to implement this. The issue is that the various situations must be accounted for:
need an overview report that ONLY filters by date range (basically a dashboard page), so that if a user does NOT select any report type and only provides dates, you display the overview report
need to filter by provided type (partner, company, loan_category, loan_type) AND date range
need to allow users to save a filter as a saved_report to quickly filter by the criteria when they select that report
I'm trying to accomplish this in a pretty ugly fashion. These examples will demonstrate what I mean:
/reports => overview report, default to current month
/reports?from=2014-01-01 => overview report, from given date to current day
/reports/3 => a saved_report, which COULD filter by any of the four (partner, company, loan_category, loan_type) and a date range
/reports/partner?partner_id=3 => using params[:id] in a hackish fashion, my controller code knows I want to filter by a given partner
/reports/loan_type?loan_type_id=7&from=2014-01-01&to=2014-01-31 => again using params[:id] I know to filter by a given loan_type with a specified date range
This leads to some very ugly controller code:
Reports controller
# always overview report; just filter by specified date range
def index
# Dummy code to show what I'm doing...
#loans = Loan.where(created_at >= params[:from]).where(created_at <= params[:to])
# ...use #loans to calculate metrics for report...
end
def show
is_saved_report = false
#saved_report = nil
# feels very "hackish" to do this...
case params[:id]
when "partner"
#loans = Loan.where(partner_id: params[:partner_id])
when "company"
#loans = Loan.includes(:partner).where(partner.company_id: params[:company_id])
when "loan_category"
#loans = Loan.where(loan_category_id: params[:loan_category_id])
when "loan_type"
#loans = Loan.where(loan_type_id: params[:loan_type_id])
else
# if none of the 4 "keywords" was used, assume it's a saved_report ID
is_saved_report = true
#saved_report = SavedReport.find(params[:id])
# grab filters from #saved_report and use them to run ANOTHER case statement...
end
# add date range filters
if is_saved_report == true
#loans.where(created_at >= #saved_report.from).where(created_at <= #saved_report.to)
else
#loans.where(created_at >= params[:from]).where(created_at <= params[:to])
end
# at this point, should have filtered list of #loans to run metrics on
#total_loans = #loans.size
# ...have to have more conditionals to display metrics for specific type of report...
end
As you can see, the code gets VERY UGLY very quickly. There has to be a better way of approaching this. I simply cannot think of a cleaner solution. I've been working on this problem so long now that I'm not thinking clearly on it.
I'm open to any suggestions or thoughts on this situation. Something that at first seemed trivial is becoming a bit of a nightmare.

Search for a date between given ranges - Lotus

I have been trying to work out what is the best way to search for gather all of the documents in a database that have a certain date.
Originally I was trying to use FTsearch or search to move through a document collection, but I changed over to processing a view and associated documents.
My first question is what is the easiest way to spin through a set of documents and find if a date stored in the documents is greater than or less than a specified date?
So, to continue working I implemented the following code.
If (doc.creationDate(0) > cdat(parm1))
And (doc.creationDate(0) < CDat(parm2)) then
...
end if
but the results are off
Included! Date:3/12/10 11:07:08 P1:3/1/10 P2: 3/5/10
Included! Date:3/13/10 9:15:09 P1:3/1/10 P2: 3/5/10
Included! Date:3/17/10 16:22:07P1:3/1/10 P2: 3/5/10
You can see that the date stored in the doc is not between P1 and P2. BUT! it does limit the documents with a date less than P1 correctly. So I won't get a result for a document with a date less than 3/1/10
If there isn't a better way than the if statement, can someone help me understand why the two examples from above are included?
Hi you can try something like this:
searchStr = {(Form = "yourForm" & ((#Created > [} & parm1 & {]) & (#Created < [} & parm2 & {])))}
Set docCollection = currentDB.Search(searchStr, Nothing, 0)
If(docCollection.Count > 0)Then
'do your stuff with the collection returned
End If
Carlos' response is pretty good.
If you have a lot of documents, you can also use a full-text search which will is much faster. The method call is very similar (db.ftsearch(), online help can be found here).
The standard DB Search method operates in the same way as view index updates, so it can get a little slow if you have thousands of documents to search through.
Just make sure you enable full text index for your database in the database properties, (last tab).
Syntax on this approach is very similar, this link provides a good reference for FTsearch. Using Carlos' syntax, you can substitute FTSearch and searchStr assignment for faster searching.