Replies: 8 comments 4 replies
-
One question: I wonder if we really need to redirect the I'm thinking the only valid source of any request matching those paths is the live app itself. (You can't bookmark an "update observation" request... i mean you could, but it wouldn't work). If the view that creates such a request uses the new path, then everybody uses the new path. So it would seem that only paths using |
Beta Was this translation helpful? Give feedback.
-
re: no need to redirect old non-GET requests -- Yes, totally agree with you.
…On Fri, Jun 17, 2022 at 2:17 PM andrew nimmo ***@***.***> wrote:
One question: I wonder if we really need to redirect the POST/PATCH/DELETE
paths in routes.rb...
I'm thinking the only valid source of any request matching those paths is
the live app itself. (You can't bookmark an "update observation" request...
i mean you could, but it wouldn't work). If the view that creates such a
request uses the new path, then everybody uses the new path.
So it would seem that only paths using GET need redirecting...?
—
Reply to this email directly, view it on GitHub
<#1031 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAYTNNOBMURNMRGQNVCBNF3VPS6LTANCNFSM5ZDAVJCA>
.
You are receiving this because you are subscribed to this thread.Message
ID:
<MushroomObserver/mushroom-observer/repo-discussions/1031/comments/2973674
@github.com>
|
Beta Was this translation helpful? Give feedback.
-
@nimmolo: Yes, I would like to work on this? |
Beta Was this translation helpful? Give feedback.
-
@pellaea , Thank you for the explanation. Moving this also to the refactor discussion since it applies to other controllers. How about something like this, routing everything to
Question: Does the first condition (no query) partly duplicate the last? Here for RssLogs, I'd like to make the "type" param incorporate the "show_#{type}" param. I'm picturing the type param value could be something like |
Beta Was this translation helpful? Give feedback.
-
Thanks, Nimmo. (For moving into discussion. Oh shoot, is this in the
discussion now?... Ah yes, it is, good!)
re: are the first and last cases somewhat redundant? -- Yes, by necessity,
I think. The problem is the "q" parameter can expire. In that case it
should fall back on the standard, primary, "display all objects" index,
which of course is the first case.
Hmmm, just throwing this out there, you could have it instead redirect back
to the same action(!) without the "q" parameter if the query has expired.
It should happen only very rarely. And, in fact, it gives an opportunity
to include a warning message that the query has expired, for example, too.
Then there will be no duplication of code, and no need for contorted
control flow in the code. It also makes the URL reflect better what is
actually being displayed -- to wit, the standard index without any
parameters.
re: your proposed handling of type/types/show_type/whatever -- Sounds
fine. I don't know that anyone actually ever uses those features to start
with, and I certainly do not, so I don't really care that much how they
behave or are implemented. Whatever makes most sense to you. You have a
better feel for UI and modern coding standards than I do, so I trust you.
Fortunately, the other controllers are not burdened with that type crap.
…On Mon, Jun 20, 2022 at 2:55 PM andrew nimmo ***@***.***> wrote:
re: why three indexes? -- The first (/observer/index) is just a routing
thing. Nowadays it would be done in config/routes.rb instead. The remaining
pair is repeated in all the controllers. One is the main entry point for
doing an index of whatever object: it creates the query. The second is the
re-entry point if you've already started a query and are resorting it or
changing the filter parameters or whatever. The query itself is passed back
in via the "q" parameter. Any index can be further modified on the fly with
a bunch of other parameters -- e.g., "by" to change the order, "page" and
"letter" for pagination, and I think in the unique case of rss_logs "type"
or "types"... whatever parameter is used to allow users to specify which
type or types they wish to see in the activity log. Furthermore, there are
additional entry points in some cases, especially for observations. You can
get to a page of observation results by several paths: all observations,
observations by a given user, search results, advanced search results,
observations for a species list, observations of a name, observations at a
location, etc. All of these use show_selected_observations(query) to
display the actual results. But then the sorting and pagination and
prev/index/next controls all send the user back to list_observations. It's
the general purpose index that just takes whatever query is stored in "q",
modifies it according to the sorting, pagination, type filter and whatever
other modifier parameters are available no matter which entry point the
user arrived at, and displays the result. It probably would be okay to
merge index_observations into list_observations, and just make sure that
list_observations provides appropriate defaults -- just make sure "q" and
"by" and all the rest are not passed in if you want it to create a new
query! I thought it was simpler and made more sense to keep the actions
which created queries (index_observations, etc.) separate from the general
purpose re-entry action (list_observation). At very least I probably could
have named list_observations better! As you are the one doing all the
tremendous amount of work involved in refactoring these behemoths, I say
you get to choose going forward whatever makes most sense to you. The above
was my reasoning. But my day is done. This is a bright new day! Enjoy!
@pellaea <https://github.com/pellaea> , Thank you for the explanation.
Moving this also to the refactor discussion since it applies to other
controllers.
How about something like this, routing everything to index and handling
the "curation" via params?
def index
# Fresh version of the index, no existing query
if !params[:q].present?
query = create_query(:RssLog, :all,
type: @user ? @user.default_rss_type : "all")
# POST requests with param `show_#{type}``: potentially show multiple types
# of objects. These requests come from the checkboxes in tabset
elsif request.method == "POST"
types = RssLog.all_types.select { |type| params["show_#{type}"] == "1" }
types = "all" if types.length == RssLog.all_types.length
types = "none" if types.empty?
types = types.map(&:to_s).join(" ") if types.is_a?(Array)
query = find_or_create_query(:RssLog, type: types)
# GET requests with param `type``: show a single type of object
# These come from simple links: the tabs in tabset
elsif params[:type].present?
types = params[:type].split & (["all"] + RssLog.all_types)
query = find_or_create_query(:RssLog, type: types.join(" "))
# Unfiltered
else
query = find_query(:RssLog)
query ||= create_query(:RssLog, :all,
type: @user ? @user.default_rss_type : "all")
end
show_selected_rss_logs(query, id: params[:id].to_s, always_index: true)
end
Question: Does the first condition (no query) partly duplicate the last?
Here for RssLogs, I'd like to make the "type" param incorporate the
"show_#{type}" param.
(Currently it's either &type=location or
&show_location=1&show_observation=1)
I'm picturing the type param value could be something like
&type=location,name,observation&q=234lkdfu
and then the checkbox form and index method would be modified to build or
parse that joined array.
—
Reply to this email directly, view it on GitHub
<#1031 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAYTNNMMIRIRSQCGS627JALVQC5B7ANCNFSM5ZDAVJCA>
.
You are receiving this because you were mentioned.Message ID:
<MushroomObserver/mushroom-observer/repo-discussions/1031/comments/2988275
@github.com>
|
Beta Was this translation helpful? Give feedback.
-
The only way to tell if the query has expired is to try to look it up in
the query_records table. That's what find_query() does. It looks like it
returns nil if the query_record is no longer there.
…On Mon, Jun 20, 2022 at 3:28 PM andrew nimmo ***@***.***> wrote:
Thanks - Which of those conditions (in my condensed index) catches if q
has expired?
Should the "no-q" condition come rather last? Like this:
def index
# POST requests with param `show_#{type}``: potentially show multiple types
# of objects. These requests come from the checkboxes in tabset
if request.method == "POST"
types = RssLog.all_types.select { |type| params["show_#{type}"] == "1" }
types = "all" if types.length == RssLog.all_types.length
types = "none" if types.empty?
types = types.map(&:to_s).join(" ") if types.is_a?(Array)
query = find_or_create_query(:RssLog, type: types)
# GET requests with param `type``: show a single type of object
# These come from simple links: the tabs in tabset
elsif params[:type].present?
types = params[:type].split & (["all"] + RssLog.all_types)
query = find_or_create_query(:RssLog, type: types.join(" "))
# Unfiltered
elsif params[:q].present?
query = find_query(:RssLog)
query ||= create_query(:RssLog, :all,
type: @user ? @user.default_rss_type : "all")
# Fresh version of the index, no existing query
else
query = create_query(:RssLog, :all,
type: @user ? @user.default_rss_type : "all")
end
show_selected_rss_logs(query, id: params[:id].to_s, always_index: true)
end
—
Reply to this email directly, view it on GitHub
<#1031 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAYTNNOW5MZQFIFO3BTHFU3VQDA4HANCNFSM5ZDAVJCA>
.
You are receiving this because you were mentioned.Message ID:
<MushroomObserver/mushroom-observer/repo-discussions/1031/comments/2988447
@github.com>
|
Beta Was this translation helpful? Give feedback.
-
Further notes on controller/controller_test refactoring, from
|
Beta Was this translation helpful? Give feedback.
-
Oh geez, of course! The path is the same, so obviously the path helper is
the same. Duh. :)
…On Sun, Jun 19, 2022 at 11:40 PM andrew nimmo ***@***.***> wrote:
This is kind of neat about the generated resource routes — there's far
fewer of them.
edit_user_path(id) gets you the form.
But you just put or patch to user_path(id).
The HTTP verb lets Rails know which controller action to route to, you'll
find them in the right column.
It seems a lot cleaner than current routes, where we have a lot of
show-only pages that are automatically getting additional post routing,
the way our routes.rb is currently written.
—
Reply to this email directly, view it on GitHub
<#1031 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAYTNNOXLHTYXKBVVBAONDTVP7R2FANCNFSM5ZDAVJCA>
.
You are receiving this because you were mentioned.Message ID:
<MushroomObserver/mushroom-observer/repo-discussions/1031/comments/2982666
@github.com>
|
Beta Was this translation helpful? Give feedback.
-
I know I said GraphQL would obviate refactoring the controllers, and now i'm eating my words. Buen Provecho! 🥝
In a potential API/separate-front-end app, obviously routes would want to follow a similar regular pattern to the Rails defaults, so I'm thinking refactoring the controllers and updating paths ahead of time would "clear the path(s)" for minimal eventual URL disruption in the future. As a bonus, it would also reaquaint me with some of the things the app does now, that I have never used.
I'd like to start splitting up
ObserverController
and refactoring other controllers to emulate @JoeCohen 's redo ofHerbariaController
. That improved a lot, but the primary thing i'm interested in is changing routes to default resources routes likeshow
andindex
, regularizing CRUD, and providing redirects for the old routes. I also want to leave the controller code in better shape than I found it -- there's a chance we'll decide against the GraphQL/Svelte/React front end, after all.Currently I'm working on
UsersController
, since it keeps raising its hand (via CodeClimate noticing theTODO
). Hopefully it'll get easier following Joe's example, and ideally I'd love to work on it together, Joe I don't know if this is something you'd like to do. So I wanted to open this discussion to make some space to record the practices that work for MO. Anyone - please feel free to dump any notes you've made or pointers orTODO
s! And Joe, I apologize for saying this would not be necessary, after all your work.Beta Was this translation helpful? Give feedback.
All reactions