-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce the "Prefer absolute timestamps" setting for users that want to disable relative time #24342
Conversation
How about |
I can't think of other possible values except the ones you mentioned |
Hmm, I would invert the setting at least and name it like "Force Absolute Timestamps". Settings which default to false seem better in general. Also, I think ideally this would be a per-user setting, not per-server because as you said, it's a user preference, not an admin preference. |
I think it may be worth it to introduce a block in the user appearance settings for options like this, stored server-side. I have a few other settings in mind for this as well, like tab size preference. |
I think we can postpone this setting to per-user setting. And we might have found a perfect context-function solution at that time. |
What's the process for adding a setting to the user's appearance page? |
"progress": There are already some setting, eg: hide some comments |
Do I need to add a migration? Any PR I can look at to model mine? |
I will try |
Thanks, I'm looking forward to it. It'll be helpful to have as a reference for future PRs that add user settings. |
I would love to see this soon in Gitea. A per user setting is appreciated, but being able to set this server wide is much more important to me. |
ALLOW_RELATIVE_TIME
setting for users that want to disable relative time…e setting Signed-off-by: Yarden Shoham <git@yardenshoham.com>
44db04c
to
569b131
Compare
I managed to add the setting to the appearance page but I now need the context user in |
Need "a perfect context-function solution" #24228 |
Not sure we want it. Personal preference is important and I wouldn't want to see a admin forcing one particular style onto users. What can be global is a default style, but users need to be able to change it. |
I don't think the problem is context now. I have an import cycle, how can I avoid it? |
In company environments forcing user settings is often the better choice. For a company it is important that everyone is using the tools the same way. Documentation how tools have to be configured is often not read carefully. If an admin can force certain settings you can avoid misconfiguration. Nevertheless, I appreciate that setting, even if every user needs to configure it by its own. |
I would still recommend to wait for a perfect context support. The last time for such "context passing trick" is the avatar, it causes a lot of 500, not only one PRs were trying to fix these bugs. |
Even if I wait for that, I would still have the issue with the import cycle, right? |
Co-authored-by: silverwind <me@silverwind.io>
@yardenshoham what do you think about switchting to string option |
The thing is, if you choose |
Right, it's not used everywhere. Let's rename the vars and such to "absoluteTimestamps" and if you agree, also add the setting |
Sounds good, I'm on it |
There are some possible choices:
For "global setting", I think it's better to have a new inheritable config system (but not ini): global setting -> org/user setting -> repo setting, instead of adding many global ini options (maintainability?), there will be a lot of similar requirements: global-2FA/org-2FA, global merge style / org merge style, etc. If we agree for choice-2, then choice-1 seems not necessary, and we had better do choice-3. My personal opinion is: at the moment only do 2+3 (per-user + wait for template context function) What do you think? |
Yes I agree global setting is not needed in case we are planning for a better config system later which also covers per-org settings. I'm still of the opinion that per-user setting is enough as a start here, and admins don't really need "power" over this imho, as it seems like power abuse to force stylistic choices onto users. So let's just rename and then I'm happy to approve. |
@@ -76,7 +76,7 @@ | |||
{{$.locale.Tr "repo.released_this"}} | |||
</span> | |||
{{if .CreatedUnix}} | |||
<span class="time">{{TimeSinceUnix .CreatedUnix $.locale}}</span> | |||
<span class="time">{{TimeSinceUnix $.Context .CreatedUnix $.locale}}</span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this not work when a user is unauthenticated but nil
is fine?
<span class="time">{{TimeSinceUnix $.Context .CreatedUnix $.locale}}</span> | |
<span class="time">{{TimeSinceUnix nil .CreatedUnix $.locale}}</span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't, in the worse case, $.Context
be nil?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error:
Render failed, failed to render template: repo/release/list, error: template error: builtin(static):repo/release/list:80:30 : executing "repo/release/list" at <TimeSinceUnix $.Context .CreatedUnix $.locale>: error calling TimeSinceUnix: runtime error: invalid memory address or nil pointer dereference
----------------------------------------------------------------------
<span class="time">{{TimeSinceUnix $.Context .CreatedUnix $.locale}}</span>
^
----------------------------------------------------------------------
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't looked into details, just share some my experiences:
- Golang template is not friendly to panic text/template: provide full stacktrace when the function call panics golang/go#59400 , you need to write some temp code to do "recover" to see what happens.
- According to Golang standard,
ctx
should never be nil. The Golang standard library functions will panic if you feed nil to them.
If we are not in a hurry, I would suggest to leave enough time for this PR. I wouldn't put Request Changes, but there are indeed some problems which need enough attention:
|
I understand and agree |
Right, it should be one database query per request, maybe even with an additional caching mechanism on top. |
I am doing my best to improve the template system now, hopefully we can start the "per-user setting for all templates" work soon. Thank you! 🙏 |
If you want we could go back to the server-wide option |
If I failed to get the context function working before 1.20 frozen, let's go back to the global ini option solution, I also agree that it brings true values for end users. 👍 |
Still I don't quite understand why this was closed as the issues would surely have been fixable, or does it really depend on this upcoming context rewrite? |
Apparently, some users prefer all timestamps to display the full date instead of relative time. They can do that now by setting it in their appearance preferences.
This setting is set to
false
by default, allowing dates to render as "5 hours ago". Here are some screenshots of the UI with this setting set totrue
:Changes
TimeSince
, pass context in templates that callTimeSince
DateTime
so we can pass thetime-since
class