Skip to content

Commit e82f1b1

Browse files
Refactor dashboard repo list to Vue SFC (#23405)
Similar to #23394 The dashboard repo list mixes jQuery/Fomantic UI/Vue together, it's very diffcult to maintain and causes unfixable a11y problems. This PR uses two steps to refactor the repo list: 1. move `data-` attributes to JS object and use Vue data as much as possible d3adc0d 2. move the code into a Vue SFC 7ebe55d Total: +516 −585 Screenshots: <details> ![image](https://user-images.githubusercontent.com/2114189/224271457-a23e05be-d7d3-4247-a803-f0ee30c36f44.png) ![image](https://user-images.githubusercontent.com/2114189/224271504-76fbd3da-4d7a-4725-b0d1-fbff83caac63.png) ![image](https://user-images.githubusercontent.com/2114189/224271845-f007cadf-6c49-46bd-a65c-a3fc75bdba3b.png) </details> --------- Co-authored-by: John Olheiser <[email protected]>
1 parent b942838 commit e82f1b1

File tree

8 files changed

+516
-585
lines changed

8 files changed

+516
-585
lines changed
+53-180
Original file line numberDiff line numberDiff line change
@@ -1,181 +1,54 @@
1-
<div id="dashboard-repo-list" class="six wide column">
2-
<repo-search
3-
:search-limit="searchLimit"
4-
:sub-url="subUrl"
5-
:uid="uid"
6-
{{if .Team}}
7-
:team-id="{{.Team.ID}}"
8-
{{end}}
9-
:more-repos-link="'{{.ContextUser.HomeLink}}'"
10-
{{if not .ContextUser.IsOrganization}}
11-
:organizations="[
12-
{{range .Orgs}}
13-
{name: '{{.Name}}', num_repos: '{{.NumRepos}}'},
14-
{{end}}
15-
]"
16-
:is-organization="false"
17-
:organizations-total-count="{{.UserOrgsCount}}"
18-
:can-create-organization="{{.SignedUser.CanCreateOrganization}}"
19-
{{end}}
20-
inline-template
21-
v-cloak
22-
></repo-search>
23-
</div>
1+
<script type="module">
2+
const data = {
3+
...window.config.pageData.dashboardRepoList, // it only contains searchLimit and uid
244

25-
<template id="dashboard-repo-list-template">
26-
<div>
27-
<div v-if="!isOrganization" class="ui two item tabable menu">
28-
<a :class="{item: true, active: tab === 'repos'}" @click="changeTab('repos')">{{.locale.Tr "repository"}}</a>
29-
<a :class="{item: true, active: tab === 'organizations'}" @click="changeTab('organizations')">{{.locale.Tr "organization"}}</a>
30-
</div>
31-
<div v-show="tab === 'repos'" class="ui tab active list dashboard-repos">
32-
<h4 class="ui top attached header gt-df gt-ac">
33-
<div class="gt-f1 gt-df gt-ac">
34-
{{.locale.Tr "home.my_repos"}}
35-
<span class="ui grey label gt-ml-3">${reposTotalCount}</span>
36-
</div>
37-
<a class="tooltip" :href="subUrl + '/repo/create'" data-content="{{.locale.Tr "new_repo"}}" data-position="left center">
38-
{{svg "octicon-plus"}}
39-
<span class="sr-only">{{.locale.Tr "new_repo"}}</span>
40-
</a>
41-
</h4>
42-
<div class="ui attached segment repos-search">
43-
<div class="ui fluid right action left icon input" :class="{loading: isLoading}">
44-
<input @input="changeReposFilter(reposFilter)" v-model="searchQuery" ref="search" placeholder="{{.locale.Tr "home.search_repos"}}">
45-
<i class="icon gt-df gt-ac gt-jc">{{svg "octicon-search" 16}}</i>
46-
<div class="ui dropdown icon button" title="{{.locale.Tr "home.filter"}}">
47-
<i class="icon gt-df gt-ac gt-jc gt-m-0">{{svg "octicon-filter" 16}}</i>
48-
<div class="menu">
49-
<a class="item" @click="toggleArchivedFilter()">
50-
<div class="ui checkbox"
51-
ref="checkboxArchivedFilter"
52-
data-title-both="{{.locale.Tr "home.show_both_archived_unarchived"}}"
53-
data-title-unarchived="{{.locale.Tr "home.show_only_unarchived"}}"
54-
data-title-archived="{{.locale.Tr "home.show_only_archived"}}"
55-
:title="checkboxArchivedFilterTitle"
56-
>
57-
<!--the "hidden" is necessary to make the checkbox work without Fomantic UI js,
58-
otherwise if the "input" handles click event for intermediate status, it breaks the internal state-->
59-
<input type="checkbox" class="hidden" v-bind.prop="checkboxArchivedFilterProps">
60-
<label>
61-
{{svg "octicon-archive" 16 "gt-mr-2"}}
62-
{{.locale.Tr "home.show_archived"}}
63-
</label>
64-
</div>
65-
</a>
66-
<a class="item" @click="togglePrivateFilter()">
67-
<div class="ui checkbox"
68-
ref="checkboxPrivateFilter"
69-
data-title-both="{{.locale.Tr "home.show_both_private_public"}}"
70-
data-title-public="{{.locale.Tr "home.show_only_public"}}"
71-
data-title-private="{{.locale.Tr "home.show_only_private"}}"
72-
:title="checkboxPrivateFilterTitle"
73-
>
74-
<input type="checkbox" class="hidden" v-bind.prop="checkboxPrivateFilterProps">
75-
<label>
76-
{{svg "octicon-lock" 16 "gt-mr-2"}}
77-
{{.locale.Tr "home.show_private"}}
78-
</label>
79-
</div>
80-
</a>
81-
</div>
82-
</div>
83-
</div>
84-
<div class="ui secondary tiny pointing borderless menu center grid repos-filter">
85-
<a class="item" :class="{active: reposFilter === 'all'}" @click="changeReposFilter('all')">
86-
{{.locale.Tr "all"}}
87-
<div v-show="reposFilter === 'all'" class="ui circular mini grey label">${repoTypeCount}</div>
88-
</a>
89-
<a class="item" :class="{active: reposFilter === 'sources'}" @click="changeReposFilter('sources')">
90-
{{.locale.Tr "sources"}}
91-
<div v-show="reposFilter === 'sources'" class="ui circular mini grey label">${repoTypeCount}</div>
92-
</a>
93-
<a class="item" :class="{active: reposFilter === 'forks'}" @click="changeReposFilter('forks')">
94-
{{.locale.Tr "forks"}}
95-
<div v-show="reposFilter === 'forks'" class="ui circular mini grey label">${repoTypeCount}</div>
96-
</a>
97-
{{if .MirrorsEnabled}}
98-
<a class="item" :class="{active: reposFilter === 'mirrors'}" @click="changeReposFilter('mirrors')">
99-
{{.locale.Tr "mirrors"}}
100-
<div v-show="reposFilter === 'mirrors'" class="ui circular mini grey label">${repoTypeCount}</div>
101-
</a>
102-
{{end}}
103-
<a class="item" :class="{active: reposFilter === 'collaborative'}" @click="changeReposFilter('collaborative')">
104-
{{.locale.Tr "collaborative"}}
105-
<div v-show="reposFilter === 'collaborative'" class="ui circular mini grey label">${repoTypeCount}</div>
106-
</a>
107-
</div>
108-
</div>
109-
<div v-if="repos.length" class="ui attached table segment gt-rounded-bottom">
110-
<ul class="repo-owner-name-list">
111-
<li v-for="repo in repos" :class="{'private': repo.private || repo.internal}">
112-
<a class="repo-list-link gt-df gt-ac gt-sb" :href="repo.link">
113-
<div class="item-name gt-df gt-ac gt-f1 gt-mr-2">
114-
<component v-bind:is="repoIcon(repo)" size="16" class="gt-mr-2"></component>
115-
<div class="text gt-bold truncate gt-ml-1">${repo.full_name}</div>
116-
<span v-if="repo.archived">
117-
{{svg "octicon-archive" 16 "gt-ml-2"}}
118-
</span>
119-
</div>
120-
{{if not .DisableStars}}
121-
<div class="text light grey gt-df gt-ac">
122-
${repo.stars_count}
123-
{{svg "octicon-star" 16 "gt-ml-2"}}
124-
</div>
125-
{{end}}
126-
</a>
127-
</li>
128-
</ul>
129-
<div v-if="showMoreReposLink" class="center gt-py-3 gt-border-secondary-top">
130-
<div class="ui borderless pagination menu narrow">
131-
<a class="item navigation gt-py-2" :class="{'disabled': page === 1}"
132-
@click="changePage(1)" title="{{$.locale.Tr "admin.first_page"}}">
133-
{{svg "gitea-double-chevron-left" 16 "gt-mr-2"}}
134-
</a>
135-
<a class="item navigation gt-py-2" :class="{'disabled': page === 1}"
136-
@click="changePage(page - 1)" title="{{$.locale.Tr "repo.issues.previous"}}">
137-
{{svg "octicon-chevron-left" 16 "gt-mr-2"}}
138-
</a>
139-
<a class="active item gt-py-2">${page}</a>
140-
<a class="item navigation" :class="{'disabled': page === finalPage}"
141-
@click="changePage(page + 1)" title="{{$.locale.Tr "repo.issues.next"}}">
142-
{{svg "octicon-chevron-right" 16 "gt-ml-2"}}
143-
</a>
144-
<a class="item navigation gt-py-2" :class="{'disabled': page === finalPage}"
145-
@click="changePage(finalPage)" title="{{$.locale.Tr "admin.last_page"}}">
146-
{{svg "gitea-double-chevron-right" 16 "gt-ml-2"}}
147-
</a>
148-
</div>
149-
</div>
150-
</div>
151-
</div>
152-
<div v-if="!isOrganization" v-show="tab === 'organizations'" class="ui tab active list dashboard-orgs">
153-
<h4 class="ui top attached header gt-df gt-ac">
154-
<div class="gt-f1 gt-df gt-ac">
155-
{{.locale.Tr "home.my_orgs"}}
156-
<span class="ui grey label gt-ml-3">${organizationsTotalCount}</span>
157-
</div>
158-
<a v-if="canCreateOrganization" class="tooltip" :href="subUrl + '/org/create'" data-content="{{.locale.Tr "new_org"}}" data-position="left center">
159-
{{svg "octicon-plus"}}
160-
<span class="sr-only">{{.locale.Tr "new_org"}}</span>
161-
</a>
162-
</h4>
163-
<div v-if="organizations.length" class="ui attached table segment gt-rounded-bottom">
164-
<ul class="repo-owner-name-list">
165-
<li v-for="org in organizations">
166-
<a class="repo-list-link gt-df gt-ac gt-sb" :href="subUrl + '/' + encodeURIComponent(org.name)">
167-
<div class="text truncate item-name gt-f1">
168-
{{svg "octicon-organization" 16 "gt-mr-2"}}
169-
<strong>${org.name}</strong>
170-
</div>
171-
<div class="text light grey gt-df gt-ac">
172-
${org.num_repos}
173-
{{svg "octicon-repo" 16 "gt-ml-2 gt-mt-1"}}
174-
</div>
175-
</a>
176-
</li>
177-
</ul>
178-
</div>
179-
</div>
180-
</div>
181-
</template>
5+
isMirrorsEnabled: {{.IsMirrorsEnabled}},
6+
isStarsEnabled: {{not .IsDisableStars}},
7+
8+
textRepository: {{.locale.Tr "repository"}},
9+
textOrganization: {{.locale.Tr "organization"}},
10+
textMyRepos: {{.locale.Tr "home.my_repos"}},
11+
textNewRepo: {{.locale.Tr "new_repo"}},
12+
textSearchRepos: {{.locale.Tr "home.search_repos"}},
13+
textFilter: {{.locale.Tr "home.filter"}},
14+
textShowArchived: {{.locale.Tr "home.show_archived"}},
15+
textShowPrivate: {{.locale.Tr "home.show_private"}},
16+
17+
textShowBothArchivedUnarchived: {{.locale.Tr "home.show_both_archived_unarchived"}},
18+
textShowOnlyUnarchived: {{.locale.Tr "home.show_only_unarchived"}},
19+
textShowOnlyArchived: {{.locale.Tr "home.show_only_archived"}},
20+
21+
textShowBothPrivatePublic: {{.locale.Tr "home.show_both_private_public"}},
22+
textShowOnlyPublic: {{.locale.Tr "home.show_only_public"}},
23+
textShowOnlyPrivate: {{.locale.Tr "home.show_only_private"}},
24+
25+
textAll: {{.locale.Tr "all"}},
26+
textSources: {{.locale.Tr "sources"}},
27+
textForks: {{.locale.Tr "forks"}},
28+
textMirrors: {{.locale.Tr "mirrors"}},
29+
textCollaborative: {{.locale.Tr "collaborative"}},
30+
31+
textFirstPage: {{.locale.Tr "admin.first_page"}},
32+
textPreviousPage: {{.locale.Tr "repo.issues.previous"}},
33+
textNextPage: {{.locale.Tr "repo.issues.next"}},
34+
textLastPage: {{.locale.Tr "admin.last_page"}},
35+
36+
textMyOrgs: {{.locale.Tr "home.my_orgs"}},
37+
textNewOrg: {{.locale.Tr "new_org"}},
38+
};
39+
40+
{{if .Team}}
41+
data.teamId = {{.Team.ID}};
42+
{{end}}
43+
44+
{{if not .ContextUser.IsOrganization}}
45+
data.organizations = [{{range .Orgs}}{'name': {{.Name}}, 'num_repos': {{.NumRepos}}},{{end}}];
46+
data.isOrganization = false;
47+
data.organizationsTotalCount = {{.UserOrgsCount}}
48+
data.canCreateOrganization = {{.SignedUser.CanCreateOrganization}}
49+
{{end}}
50+
51+
window.config.pageData.dashboardRepoList = data;
52+
</script>
53+
54+
<div id="dashboard-repo-list" class="six wide column"></div>

0 commit comments

Comments
 (0)