Skip to content

Commit 7455604

Browse files
Morlinestlunny
authored andcommitted
Remove (almost) server side data rendering from repo-search component (#2317)
* Rename some shorthands * Remove (almost) server side data rendering from repo-search component template
1 parent 2c6a0fd commit 7455604

File tree

2 files changed

+72
-44
lines changed

2 files changed

+72
-44
lines changed

public/js/index.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,13 +1687,33 @@ function initVueComponents(){
16871687
type: Number,
16881688
required: true
16891689
},
1690+
organizations: {
1691+
type: Array,
1692+
default: []
1693+
},
1694+
isOrganization: {
1695+
type: Boolean,
1696+
default: true
1697+
},
1698+
canCreateOrganization: {
1699+
type: Boolean,
1700+
default: false
1701+
},
1702+
organizationsTotalCount: {
1703+
type: Number,
1704+
default: 0
1705+
},
1706+
moreReposLink: {
1707+
type: String,
1708+
default: ''
1709+
}
16901710
},
16911711

16921712
data: function() {
16931713
return {
16941714
tab: 'repos',
16951715
repos: [],
1696-
reposTotal: 0,
1716+
reposTotalCount: 0,
16971717
reposFilter: 'all',
16981718
searchQuery: '',
16991719
isLoading: false
@@ -1741,7 +1761,7 @@ function initVueComponents(){
17411761
if (searchedQuery == self.searchQuery) {
17421762
self.repos = result.data;
17431763
if (searchedQuery == "") {
1744-
self.reposTotal = request.getResponseHeader('X-Total-Count');
1764+
self.reposTotalCount = request.getResponseHeader('X-Total-Count');
17451765
}
17461766
}
17471767
}).always(function() {

templates/user/dashboard/dashboard.tmpl

Lines changed: 50 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,34 @@
88
{{template "user/dashboard/feeds" .}}
99
</div>
1010
<div id="app" class="six wide column">
11-
<repo-search :search-limit="searchLimit" :suburl="suburl" :uid="uid" inline-template v-cloak>
11+
<repo-search
12+
:search-limit="searchLimit"
13+
:suburl="suburl"
14+
:uid="uid"
15+
:more-repos-link="'{{.ContextUser.HomeLink}}'"
16+
{{if not .ContextUser.IsOrganization}}
17+
:organizations="[
18+
{{range .ContextUser.Orgs}}
19+
{name: '{{.Name}}', num_repos: '{{.NumRepos}}'},
20+
{{end}}
21+
]"
22+
:is-organization="false"
23+
:organizations-total-count="{{.ContextUser.GetOrganizationCount}}"
24+
:can-create-organization="{{.SignedUser.CanCreateOrganization}}"
25+
{{end}}
26+
inline-template
27+
v-cloak
28+
>
1229
<div>
13-
{{if not .ContextUser.IsOrganization}}
14-
<div class="ui two item stackable tabable menu">
30+
<div v-if="!isOrganization" class="ui two item stackable tabable menu">
1531
<a :class="{item: true, active: tab === 'repos'}" @click="changeTab('repos')">{{.i18n.Tr "repository"}}</a>
16-
<a :class="{item: true, active: tab === 'orgs'}" @click="changeTab('orgs')">{{.i18n.Tr "organization"}}</a>
32+
<a :class="{item: true, active: tab === 'organizations'}" @click="changeTab('organizations')">{{.i18n.Tr "organization"}}</a>
1733
</div>
18-
{{end}}
19-
<div v-if="tab === 'repos'" class="ui tab active list">
34+
<div v-show="tab === 'repos'" class="ui tab active list">
2035
<h4 class="ui top attached header">
21-
{{.i18n.Tr "home.my_repos"}} <span class="ui grey label">${ reposTotal }</span>
36+
{{.i18n.Tr "home.my_repos"}} <span class="ui grey label">${reposTotalCount}</span>
2237
<div class="ui right">
23-
<a class="poping up" href="{{AppSubUrl}}/repo/create" data-content="{{.i18n.Tr "new_repo"}}" data-variation="tiny inverted" data-position="left center">
38+
<a class="poping up" :href="suburl + '/repo/create>'" data-content="{{.i18n.Tr "new_repo"}}" data-variation="tiny inverted" data-position="left center">
2439
<i class="plus icon"></i>
2540
<span class="sr-only">{{.i18n.Tr "new_repo"}}</span>
2641
</a>
@@ -42,51 +57,44 @@
4257
<div class="ui attached table segment">
4358
<ul class="repo-owner-name-list">
4459
<li v-for="repo in repos" :class="{'private': repo.private}" v-show="showRepo(repo, reposFilter)">
45-
<a :href="'{{AppSubUrl}}/' + repo.full_name">
60+
<a :href="suburl + '/' + repo.full_name">
4661
<i :class="repoClass(repo)"></i>
47-
<strong class="text truncate item-name">${ repo.full_name }</strong>
62+
<strong class="text truncate item-name">${repo.full_name}</strong>
4863
<span class="ui right text light grey">
49-
${ repo.stars_count } <i class="octicon octicon-star rear"></i>
64+
${repo.stars_count} <i class="octicon octicon-star rear"></i>
5065
</span>
5166
</a>
5267
</li>
53-
<li v-if="repos.length < reposTotal">
54-
<a href="{{.ContextUser.HomeLink}}">{{.i18n.Tr "home.show_more_repos"}}</a>
68+
<li v-if="repos.length < reposTotalCount">
69+
<a :href="moreReposLink">{{.i18n.Tr "home.show_more_repos"}}</a>
5570
</li>
5671
</ul>
5772
</div>
5873
</div>
59-
60-
{{if not .ContextUser.IsOrganization}}
61-
<div v-if="tab === 'orgs'" class="ui tab active list">
62-
<h4 class="ui top attached header">
63-
{{.i18n.Tr "home.my_orgs"}} <span class="ui grey label">{{.ContextUser.GetOrganizationCount}}</span>
64-
<div class="ui right">
65-
{{if .SignedUser.CanCreateOrganization}}
66-
<a class="poping up" href="{{AppSubUrl}}/org/create" data-content="{{.i18n.Tr "new_org"}}" data-variation="tiny inverted" data-position="left center">
67-
<i class="plus icon"></i>
68-
<span class="sr-only">{{.i18n.Tr "new_org"}}</span>
69-
</a>
70-
{{end}}
71-
</div>
72-
</h4>
73-
<div class="ui attached table segment">
74-
<ul class="repo-owner-name-list">
75-
{{range .ContextUser.Orgs}}
76-
<li>
77-
<a href="{{AppSubUrl}}/{{.Name}}">
78-
<i class="octicon octicon-organization"></i>
79-
<strong class="text truncate item-name">{{.Name}}</strong>
80-
<span class="ui right text light grey">
81-
{{.NumRepos}} <i class="octicon octicon-repo rear"></i>
82-
</span>
83-
</a>
84-
</li>
85-
{{end}}
86-
</ul>
74+
<div v-if="!isOrganization" v-show="tab === 'organizations'" class="ui tab active list">
75+
<h4 class="ui top attached header">
76+
{{.i18n.Tr "home.my_orgs"}} <span class="ui grey label">${organizationsTotalCount}</span>
77+
<div v-if="canCreateOrganization" class="ui right">
78+
<a class="poping up" :href="suburl + '/org/create'" data-content="{{.i18n.Tr "new_org"}}" data-variation="tiny inverted" data-position="left center">
79+
<i class="plus icon"></i>
80+
<span class="sr-only">{{.i18n.Tr "new_org"}}</span>
81+
</a>
8782
</div>
83+
</h4>
84+
<div class="ui attached table segment">
85+
<ul class="repo-owner-name-list">
86+
<li v-for="org in organizations">
87+
<a :href="suburl + '/' + org.name">
88+
<i class="octicon octicon-organization"></i>
89+
<strong class="text truncate item-name">${org.name}</strong>
90+
<span class="ui right text light grey">
91+
${org.num_repos} <i class="octicon octicon-repo rear"></i>
92+
</span>
93+
</a>
94+
</li>
95+
</ul>
8896
</div>
89-
{{end}}
97+
</div>
9098
</div>
9199
</repo-search>
92100
</div>

0 commit comments

Comments
 (0)