faustinoaq changed the topic of #amber to: Welcome to Amber Framework community! | https://amberframework.org | Developer happiness, productivity and bare metal performance | GH: https://github.com/amberframework | Docs: https://docs.amberframework.org | Gitter: https://gitter.im/amberframework/amber | IRC Logger: https://irclog.whitequark.org/amber | Amber::Server.start
<FromGitter> <nsuchy> I mean I was just gonna make a bootstrap pagination list based on the size of the array and bundle the methods into Amber::ECR::Pagination or something
<FromGitter> <nsuchy> Endless scrolling sounds tricky
_whitelogger has joined #amber
_whitelogger has joined #amber
_whitelogger has joined #amber
_whitelogger has joined #amber
feepbot has quit [Ping timeout: 268 seconds]
feepbot has joined #amber
<FromGitter> <nsuchy> `Transaction.where(customer_balance_id: balance_id).count`
<FromGitter> <nsuchy> I have this query
<FromGitter> <nsuchy> but .count does not return an int64
<FromGitter> <nsuchy> it returns `Granite::Query::Executor::MultiValue(Transaction, Int64)`
<FromGitter> <nsuchy> Is there a way to get a count of the number of rows from my query
<FromGitter> <Blacksmoke16> add a `.select` or `.run`
<FromGitter> <Blacksmoke16> think that should do it
<FromGitter> <nsuchy> if I add .select afterwards it'll run my query?
<FromGitter> <Blacksmoke16> yes
<FromGitter> <nsuchy> `Error: undefined method 'run' for Granite::Query::Builder(Transaction)`
<FromGitter> <Blacksmoke16> `Transaction.where(customer_balance_id: balance_id).count.to_i`
<FromGitter> <Blacksmoke16> try that
<FromGitter> <nsuchy> ```code paste, see link``` [https://gitter.im/amberframework/amber?at=5df66ed9c6ce6027ebc7d1f6]
<FromGitter> <Blacksmoke16> ☝️ December 15, 2019 12:35 PM (https://gitter.im/amberframework/amber?at=5df66ecadbf24d0becf4dce9)
<FromGitter> <nsuchy> that doesn't work either
<FromGitter> <Blacksmoke16> whats the error?
<FromGitter> <nsuchy> ```code paste, see link``` [https://gitter.im/amberframework/amber?at=5df66f92e47fb31eb7b90f99]
<FromGitter> <Blacksmoke16> what happens if you replace `to_i` with `run`
<FromGitter> <nsuchy> it builds, next problem it's not an i64 ⏎ ⏎ ```code paste, see link``` [https://gitter.im/amberframework/amber?at=5df6700a7ce7ea1e358c56fa]
<FromGitter> <Blacksmoke16> `.as(Int64)`?
<FromGitter> <nsuchy> that works
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <nsuchy> ```code paste, see link``` [https://gitter.im/amberframework/amber?at=5df672972bca3016aa855171]
<FromGitter> <nsuchy> This is how I ended up doing pagination (ignore the label for now)
<FromGitter> <nsuchy> ```code paste, see link``` [https://gitter.im/amberframework/amber?at=5df672b2dbf24d0becf4fa92]
<FromGitter> <nsuchy> this is still being worked on, it's a list of customer transactions
<FromGitter> <nsuchy> only thing pagination needs is a page count
<FromGitter> <nsuchy> you'll have to tell Granite how many skips to run using offset (btw @Blacksmoke16 can I add a psuedomethod named skip, it makes more sense than offset, it can literally pass the data to the offset method, it'd be nice activerecord style method)
<FromGitter> <nsuchy> I have ⏎ ⏎ ``` page_number = 0 unless page_number = params[:page_number].to_i64``` ⏎ ⏎ But still get the error `The page_number param was not found, make sure is typed correctly.` if I don't send the param [https://gitter.im/amberframework/amber?at=5df67c3042784416abf198e3]
<FromGitter> <nsuchy> Is there any way around this or will I have to update my links to include a page number
<FromGitter> <Blacksmoke16> is it a query param?
<FromGitter> <Blacksmoke16> id also add buttons to go to the first/last pages
<FromGitter> <nsuchy> yeah
<FromGitter> <nsuchy> it's a query param
<FromGitter> <nsuchy> so its not always included
<FromGitter> <nsuchy> so I want it to be option
<FromGitter> <nsuchy> if amber supports it
<FromGitter> <Blacksmoke16> `page_number = param[:page].try &.to_i64 || 0`
<FromGitter> <nsuchy> that works
<FromGitter> <Blacksmoke16> Mhm
<FromGitter> <nsuchy> ```code paste, see link``` [https://gitter.im/amberframework/amber?at=5df690a6c6ce6027ebc8b48f]
<FromGitter> <nsuchy> This can now handle more than 10 pages without it becoming a mess
<FromGitter> <nsuchy> @drujensen this seems pretty generic to me. The user needs to provide the following information: a page_count variable and support using ?page_number in the query. Then on the Granite/ORM side they will need to add a limiter and keep in mind the page number to know how many rows to skip. That's not really an issue for the pagination library to worry about though
<FromGitter> <nsuchy> Think I could add it as a PR to Amber so there's built in pagination to the view engine
<FromGitter> <nsuchy> Even if it was just a new partial added to the default generator
<FromGitter> <Blacksmoke16> just make it `page`
<FromGitter> <Blacksmoke16> as the query param
<FromGitter> <Blacksmoke16> `page` and `per_page`
<FromGitter> <Blacksmoke16> with sane defaults would be 💯
<FromGitter> <Blacksmoke16> like default `page` to 1 and 10/100/1000 per page?
<FromGitter> <nsuchy> 100 seems like a lot of scrolling
<FromGitter> <Blacksmoke16> oh wait this is for the front end isnt it
<FromGitter> <Blacksmoke16> 10/15 maybe then
<FromGitter> <nsuchy> yeah
<FromGitter> <nsuchy> not a REST API where 100/1000/etc would be ine
<FromGitter> <Blacksmoke16> even c ould have a dropdown that allows you to change it like most sites do
<FromGitter> <Blacksmoke16> yea
<FromGitter> <nsuchy> include these things in the comments on my PR
<FromGitter> <nsuchy> code examples prefered
<FromGitter> <nsuchy> For a dropdown I'm worried a bit as it requires users to make even more changes to their ganite/orm code (changing the limit)
<FromGitter> <nsuchy> This also adds a security concern unless the user knows what they're doing
<FromGitter> <nsuchy> For example someone could change the limit to 1,000,000,000 and spam requests to overhwelm the ORM
<FromGitter> <nsuchy> it would then mean users not only need to configure an extra param but they have to make sure the value is sane
<FromGitter> <nsuchy> so I'm worried about that
<FromGitter> <nsuchy> Also does bootstrap have a pretty dropdown
<FromGitter> <nsuchy> I don't know how design works so I let MDBootstrap make my projects seem more impressive than they actually are lol
<FromGitter> <Blacksmoke16> well i would assume there would be either a static list of options or a max value
<FromGitter> <nsuchy> The user input gets passed to the limit option OR is used to select a static value
<FromGitter> <nsuchy> I guess you could do ⏎ ⏎ ```code paste, see link``` [https://gitter.im/amberframework/amber?at=5df69f4fe47fb31eb7ba51ee]
<FromGitter> <nsuchy> The problem really goes back to this is up to the user to implement
<FromGitter> <nsuchy> Inexperienced coders might not think of adding a limit or choose to ignore it if it's not handled for them as it takes up additional development time and they don't see the security benefits
<FromGitter> <Blacksmoke16> im not sure i agree on not doing something just so inexperienced devs dont have to think
<FromGitter> <Blacksmoke16> the implementation would just have to be an upper limit, with a dropdown that has like 10, 20, 50 in it or something
<FromGitter> <Blacksmoke16> i.e. pagination should accept any between min and max
<FromGitter> <Blacksmoke16> but the dropdown is there just as a shortcut
<FromGitter> <Blacksmoke16> i dont really care either way, just my 2 cents...
<FromGitter> <nsuchy> but it's bad if a miscoded dropdown list resulted in the entire app being breached
<FromGitter> <nsuchy> it's the reality of many PHP apps that don't use ORMs
<FromGitter> <nsuchy> they forget to escape / limit inputs
<FromGitter> <nsuchy> and the apps get hacked
<FromGitter> <nsuchy> let's not make our framework resemble the problems of PHP
<FromGitter> <Blacksmoke16> right so make it optional, or have a configurable default?
<FromGitter> <Blacksmoke16> worst case here is the current behavior no?
<FromGitter> <Blacksmoke16> where all the results get returned versus being paginated
<FromGitter> <nsuchy> I mean, right now all the pagination element does is track the current page and build an element based on the page count
<FromGitter> <drujensen> @nsuchy Just saw this PR. Is this you? https://github.com/amberframework/amber/pull/1170
<FromGitter> <nsuchy> what you do database wise is up to you
<FromGitter> <nsuchy> yes, I changed my github username
<FromGitter> <nsuchy> seperating work stuff from personal life
<FromGitter> <drujensen> gotcha. :-)
<FromGitter> <nsuchy> so currently it's up to the developer to choose a limit and implement and all that
<FromGitter> <nsuchy> they can still make a bad decision, adding the dropdown might encourage it, I'm not convinced providing a choice is necessary, let the user choose a reasonable default, whether that's 10, 100, 1000, or anything
<FromGitter> <Blacksmoke16> that would be the mvp route
<FromGitter> <drujensen> I agree.
<FromGitter> <nsuchy> but uh adding the _pagination partial would at least reduce the amount of work devs need to do when using amber
<FromGitter> <nsuchy> there is not a pagination shard at this point
<FromGitter> <nsuchy> I could make one but I don't think we need a dedicated shard when a good partial can do the same thing
<FromGitter> <nsuchy> the user just needs to make sure two variables exist and do some counting in the controller
<FromGitter> <drujensen> nope. It makes sense to add this to our default templates imo
<FromGitter> <nsuchy> yeah that's the goal of my PR
<FromGitter> <nsuchy> I might need help with the slang template later on
<FromGitter> <nsuchy> I've never used it and prefer HTML with variables
<FromGitter> <nsuchy> I'm old school like that lol
_whitelogger has joined #amber