Frontend refactor: move Vue related code from index.js
to components
dir, and remove unused codes. #17301
Labels
No Label
backport/done
backport/v1.0
backport/v1.1
backport/v1.10
backport/v1.11
backport/v1.12
backport/v1.13
backport/v1.14
backport/v1.15
backport/v1.2
backport/v1.3
backport/v1.4
backport/v1.5
backport/v1.6
backport/v1.7
backport/v1.8
backport/v1.9
bounty
changelog
dependencies
frontport/done
frontport/main
good first issue
Hacktoberfest
hacktoberfest-accepted
in progress
kind/api
kind/breaking
kind/bug
kind/build
kind/deployment
kind/deprecated
kind/docs
kind/enhancement
kind/feature
kind/lint
kind/misc
kind/moderation
kind/package
kind/proposal
kind/question
kind/refactor
kind/regression
kind/security
kind/summary
kind/testing
kind/translation
kind/ui
kind/upstream-related
kind/usability
kind/ux
lgtm/done
lgtm/need 1
lgtm/need 2
performance/bigrepo
performance/cpu
performance/memory
performance/speed
priority/critical
priority/low
priority/maybe
priority/medium
proposal/rejected
reviewed/confirmed
reviewed/duplicate
reviewed/fixed
reviewed/invalid
reviewed/not-a-bug
reviewed/wontfix
skip-changelog
stale
status/blocked
status/needs-feedback
status/wip
theme/2fa
theme/authentication
theme/avatar
theme/backup-restore
theme/docker
theme/federation
theme/issues
theme/kanban
theme/markdown
theme/migration
theme/mobile
theme/pr
theme/signing
theme/sqlite
theme/timetracker
theme/webhook
theme/wiki
No Milestone
No project
No Assignees
4 Participants
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: lunny/gitea#17301
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "frontend-refactor"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This is the first big frontend refactor for Frontend Plan (https://github.com/go-gitea/gitea/issues/17149)
Major changes:
head.tmpl
, including:<head data-suburl="{{AppSubUrl}}">
<meta name="_uid" content="{{.SignedUser.ID}}" />
<meta name="_context_uid" content="{{.ContextUser.ID}}" />
<meta name="_search_limit" content="{{.SearchLimit}}" />
submitDeleteForm
fromrepo/view_file.tmpl
index.js
tocomponents
dir, including:DashboardRepoList.js
: used by the repo list on the home dashboardRepoActivityTopAuthors.vue
, used by/org/repo/activity
to show a bar chart for top activity usersRepoBranchTagDropdown.js
, used by repo pages to show a dropdown list to select branches and tags.ignorePatterns
items from.eslint
, we are clear enough now!@ -0,0 +21,4 @@
## Background
Gitea uses [Less CSS](https://lesscss.org), [Fomantic-UI](https://fomantic-ui.com/introduction/getting-started.html) (based on [jQuery](https://api.jquery.com)) and [Vue2](https://vuejs.org/v2/guide/) for its frontend.
@ -0,0 +27,4 @@
## General Guidelines
We recommend [Google HTML/CSS Style Guide](https://google.github.io/styleguide/htmlcssguide.html) and [Google JavaScript Style Guide](https://google.github.io/styleguide/jsguide.html)
@ -62,3 +62,3 @@
if ctx.Data["ActivityTopAuthors"], err = models.GetActivityStatsTopAuthors(ctx.Repo.Repository, timeFrom, 10); err != nil {
if ctx.PageData["repoActivityTopAuthors"], err = models.GetActivityStatsTopAuthors(ctx.Repo.Repository, timeFrom, 10); err != nil {
ctx.ServerError("GetActivityStatsTopAuthors", err)
Do we use UpperCamelCase for
ctx.Data
and lowerCamelCase forctx.PageData
? Why?Could we please be consistent here, or would that lead to UpperCamelCase variables in the frontend?
@ -110,1 +110,4 @@
ctx.PageData["dashboardRepoList"] = map[string]interface{}{
"searchLimit": setting.UI.User.RepoPagingNum,
}
😕
What's the benefit in this case of using a single-entry map instead of a simple int?
@ -1,6 +1,6 @@
<!DOCTYPE html>
<html lang="{{.Lang}}" class="theme-{{.SignedUser.Theme}}">
I don't think that will form a valid html file. Was that taken out by accident? Did you perhaps simply want to remove the
data-suburl
?Alternatively, the original line:
@ -36,3 +28,3 @@
csrf: '{{.CsrfToken}}',
PageData: {{ .PageData }},
pageData: {{ .PageData }},
HighlightJS: {{if .RequireHighlightJS}}true{{else}}false{{end}},
Were those extracted to
ctx.PageData
and are hence not needed anymore?What happened to this function? Why could it be deleted (as it seems without replacement as far as I can see)?
@ -1,8 +1,7 @@
<div id="app" class="six wide column">
<div id="dashboard-repo-list" class="six wide column">
<repo-search
Assuming it still works: 👍
@ -70,4 +70,3 @@ export default {
},
};
</script>
<style scoped/>
You now only require this file when you are on the correct page and hence removed the
scoped
attribute?@ -0,0 +26,4 @@
},
organizations: {
type: Array,
default: () => [],
Or why would you use an additional function call?
@ -0,0 +30,4 @@
},
isOrganization: {
type: Boolean,
default: true
Why would you assume by default that our user is an organization?
@ -0,0 +252,4 @@
break;
default:
this.archivedFilter = 'unarchived';
break;
@ -0,0 +274,4 @@
break;
default:
this.privateFilter = 'both';
break;
@ -0,0 +291,4 @@
}
if (this.page < 1) {
this.page = 1;
}
@ -0,0 +6,4 @@
let vueEnvInited = false;
function initVueEnv() {
if (vueEnvInited) return;
vueEnvInited = true;
@ -0,0 +16,4 @@
let vueSvgInited = false;
function initVueSvg() {
if (vueSvgInited) return;
vueSvgInited = true;
@ -0,0 +21,4 @@
## Background
Gitea uses [Less CSS](https://lesscss.org), [Fomantic-UI](https://fomantic-ui.com/introduction/getting-started.html) (based on [jQuery](https://api.jquery.com)) and [Vue2](https://vuejs.org/v2/guide/) for its frontend.
It's not a syntax problem. See: https://www.grammarly.com/blog/comma-before-and/
@ -0,0 +27,4 @@
## General Guidelines
We recommend [Google HTML/CSS Style Guide](https://google.github.io/styleguide/htmlcssguide.html) and [Google JavaScript Style Guide](https://google.github.io/styleguide/jsguide.html)
It's not a syntax problem: https://english.stackexchange.com/questions/273067/when-to-use-the-in-book-titles
In my mind, this list is supplementary clauses to the google guidelines, so we do not need a new section.
As above, I think we do not call
the Vue2
orthe Go Text Template
.watch-frontend
is better for development so we had better keep it here@ -62,3 +62,3 @@
if ctx.Data["ActivityTopAuthors"], err = models.GetActivityStatsTopAuthors(ctx.Repo.Repository, timeFrom, 10); err != nil {
if ctx.PageData["repoActivityTopAuthors"], err = models.GetActivityStatsTopAuthors(ctx.Repo.Repository, timeFrom, 10); err != nil {
ctx.ServerError("GetActivityStatsTopAuthors", err)
Most keys in
window.config
use PascalCase. Some people prefer to use camelCase for (new) JavaScript keys.Both are fine to me.
@ -110,1 +110,4 @@
ctx.PageData["dashboardRepoList"] = map[string]interface{}{
"searchLimit": setting.UI.User.RepoPagingNum,
}
More options can be added in future. And
PageData
passes data for JavaScript modeuls likectx.PageData["theModuleName"]
, so we can not just put an int here.@ -36,3 +28,3 @@
csrf: '{{.CsrfToken}}',
PageData: {{ .PageData }},
pageData: {{ .PageData }},
HighlightJS: {{if .RequireHighlightJS}}true{{else}}false{{end}},
Yes, I searched the whole project, only legacy
dashboard repo list
depends on<meta name="_search_limit"
I think it won't work. It's difficult to tune the CSS styles mixing with a Vue app element. So we just put the Vue app element inside a
<div>
we have full control.No caller to it, the HTML id
#delete-message
and#delete-file-form
also disappeared.Now the deletion function is provided by
/org/repo/_delete/master/FILENAME
.@ -1,8 +1,7 @@
<div id="app" class="six wide column">
<div id="dashboard-repo-list" class="six wide column">
<repo-search
Why not, it is used by
DashboardRepoList.js
@ -70,4 +70,3 @@ export default {
},
};
</script>
<style scoped/>
This is an incorrect syntax. No effect.
@ -0,0 +26,4 @@
},
organizations: {
type: Array,
default: () => [],
I just copied(moved) old code here, I won't make big change for the first commit, otherwise it will be difficult for us to view commit history and diff. Any refactor should happen in future after the move.
@ -0,0 +30,4 @@
},
isOrganization: {
type: Boolean,
default: true
As above, no big change to first copy-move refactor.
@ -0,0 +252,4 @@
break;
default:
this.archivedFilter = 'unarchived';
break;
As above, no big change to first copy-move refactor.
@ -0,0 +274,4 @@
break;
default:
this.privateFilter = 'both';
break;
As above, no big change to first copy-move refactor.
@ -0,0 +291,4 @@
}
if (this.page < 1) {
this.page = 1;
}
As above, no big change to first copy-move refactor.
@ -0,0 +6,4 @@
let vueEnvInited = false;
function initVueEnv() {
if (vueEnvInited) return;
vueEnvInited = true;
inited
is OK for abbr.https://www.definify.com/word/inited
@ -0,0 +16,4 @@
let vueSvgInited = false;
function initVueSvg() {
if (vueSvgInited) return;
vueSvgInited = true;
As above
@ -0,0 +27,4 @@
## General Guidelines
We recommend [Google HTML/CSS Style Guide](https://google.github.io/styleguide/htmlcssguide.html) and [Google JavaScript Style Guide](https://google.github.io/styleguide/jsguide.html)
That only applies inside the book title, not when referencing the book:
What that StackExchange discussion is saying is:
It is perfectly fine to call the book
Lord of the rings
.You should, however, append the
the
when referencing theLord of the rings
series.Not a new section, a subsection.
Simply for the visual difference.
Yes, but it is already mentioned a few lines (5 to 10) above.
That way, it simply is duplicated.
@ -110,1 +110,4 @@
ctx.PageData["dashboardRepoList"] = map[string]interface{}{
"searchLimit": setting.UI.User.RepoPagingNum,
}
What I mean: This setting was previously rendered on the server-side, if I see that correctly.
Now the same thing seems to be rendered on the frontend with a more complicated mechanism?
Correct me if I'm wrong.
@ -70,4 +70,3 @@ export default {
},
};
</script>
<style scoped/>
Also makes sense.
@ -0,0 +27,4 @@
## General Guidelines
We recommend [Google HTML/CSS Style Guide](https://google.github.io/styleguide/htmlcssguide.html) and [Google JavaScript Style Guide](https://google.github.io/styleguide/jsguide.html)
Do you read Harry Potter?
orDo you read the Harry Potter?
That's similar to the guideline names.
Do we like Google Guideline?
@ -110,1 +110,4 @@
ctx.PageData["dashboardRepoList"] = map[string]interface{}{
"searchLimit": setting.UI.User.RepoPagingNum,
}
I don't understand why it's more complicated.
With old mechanism, a tag also must be written into the template. And frontend must query the tag.
The new mechanism, we just construct a map and frontend just reads it, nothing else. If you mean to write
ctx.PageData["SearcLimit"] = xxx
, I am totally against it, it pollutes the namespace. More code doesn't mean more complicated.Isn't the
<div>
by default an invisible element where it makes no difference if it exists or not?I think this approach should behave just the same.
It won't work.
My code
Your code
@ -0,0 +27,4 @@
## General Guidelines
We recommend [Google HTML/CSS Style Guide](https://google.github.io/styleguide/htmlcssguide.html) and [Google JavaScript Style Guide](https://google.github.io/styleguide/jsguide.html)
I would say that's part of the problem:
guideline
/style guide
are normal English words.While they are also inside the title, for me it makes more sense to use them as the words they are, not as parts of the title.
To me,
Do we like Google Guideline?
sounds like incorrect English.@ -110,1 +110,4 @@
ctx.PageData["dashboardRepoList"] = map[string]interface{}{
"searchLimit": setting.UI.User.RepoPagingNum,
}
That is also true.
Okay, then I'm fine with it.
Interesting. Then ignore my comment.
That's how Vue works. If we want to add CSS style to the root element, I think it must be added to the template directly. Otherwise the attached element will be replaced.
@ -0,0 +27,4 @@
## General Guidelines
We recommend [Google HTML/CSS Style Guide](https://google.github.io/styleguide/htmlcssguide.html) and [Google JavaScript Style Guide](https://google.github.io/styleguide/jsguide.html)
this is bike shading ... and Germans do like the :D (I use it to much too - it's not so common if you listen to native speaker ....)
anyway lets just leave it as is!
it's for the beginners ... let it be duplicated
@ -36,3 +28,3 @@
csrf: '{{.CsrfToken}}',
PageData: {{ .PageData }},
pageData: {{ .PageData }},
HighlightJS: {{if .RequireHighlightJS}}true{{else}}false{{end}},
The dashboard repo list depended on the uid and removing this has broken the dashboard repo list.
@ -36,3 +28,3 @@
csrf: '{{.CsrfToken}}',
PageData: {{ .PageData }},
pageData: {{ .PageData }},
HighlightJS: {{if .RequireHighlightJS}}true{{else}}false{{end}},
context_uid was used to fix the dashboard repo list for organisations too.
@ -36,3 +28,3 @@
csrf: '{{.CsrfToken}}',
PageData: {{ .PageData }},
pageData: {{ .PageData }},
HighlightJS: {{if .RequireHighlightJS}}true{{else}}false{{end}},
But there has to be a better way to achieve this than adding it as a global header for every single page.
I dunno, what about the
pageData
mechanism?@ -36,3 +28,3 @@
csrf: '{{.CsrfToken}}',
PageData: {{ .PageData }},
pageData: {{ .PageData }},
HighlightJS: {{if .RequireHighlightJS}}true{{else}}false{{end}},
Also, in what way did it break the
dashboard repo list
? Seemed fine to me, and I have a PR currently where I refactor that file (#17340)…