Skip to content
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

Team page #790

Merged
merged 16 commits into from
Jun 21, 2017
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions app/controllers/team.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Ember from 'ember';
import PaginationMixin from '../mixins/pagination';

const { computed } = Ember;

export default Ember.Controller.extend(PaginationMixin, {
queryParams: ['page', 'per_page', 'sort'],
page: '1',
per_page: 10,
sort: 'alpha',

totalItems: computed.readOnly('model.crates.meta.total'),

currentSortBy: computed('sort', function() {
return (this.get('sort') === 'downloads') ? 'Downloads' : 'Alphabetical';
}),
});
2 changes: 2 additions & 0 deletions app/models/crate.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export default DS.Model.extend({
badge_sort: ['badge_type'],
annotated_badges: Ember.computed.sort('enhanced_badges', 'badge_sort'),
owners: DS.hasMany('users', { async: true }),
owner_team: DS.hasMany('teams', { async: true }),
owner_user: DS.hasMany('users', { async: true }),
version_downloads: DS.hasMany('version-download', { async: true }),
keywords: DS.hasMany('keywords', { async: true }),
categories: DS.hasMany('categories', { async: true }),
Expand Down
17 changes: 17 additions & 0 deletions app/models/team.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import DS from 'ember-data';
import Ember from 'ember';

export default DS.Model.extend({
email: DS.attr('string'),
name: DS.attr('string'),
login: DS.attr('string'),
api_token: DS.attr('string'),
avatar: DS.attr('string'),
url: DS.attr('string'),
kind: DS.attr('string'),
org_name: Ember.computed('login', function() {
let login = this.get('login');
let login_split = login.split(':');
return login_split[1];
})
});
1 change: 1 addition & 0 deletions app/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export default DS.Model.extend({
api_token: DS.attr('string'),
avatar: DS.attr('string'),
url: DS.attr('string'),
kind: DS.attr('string'),
});
1 change: 1 addition & 0 deletions app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Router.map(function() {
});
this.route('category_slugs');
this.route('catchAll', { path: '*path' });
this.route('team', { path: '/teams/:team_id' });
});

export default Router;
38 changes: 38 additions & 0 deletions app/routes/team.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import Ember from 'ember';

export default Ember.Route.extend({
queryParams: {
page: { refreshedModel: true },
sort: { refreshedModel: true },
},
data: {},

setupController(controller, model) {
this._super(controller, model);

controller.set('fetchingFeed', true);
controller.set('crates', this.get('data.crates'));
},

model(params) {
const { team_id } = params;
return this.store.find('team', team_id).then(
(team) => {
params.team_id = team.get('id');
return Ember.RSVP.hash({
crates: this.store.query('crate', params),
team
});
},
(e) => {
if (e.errors.any(e => e.detail === 'Not Found')) {
console.log(params);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a debugging console.log left in here :)

this
.controllerFor('application')
.set('nextFlashError', `User '${params.team_id}' does not exist`);
return this.replaceWith('index');
}
}
);
},
});
3 changes: 3 additions & 0 deletions app/styles/crate.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
img {
@include align-self(center);
}
.team-info {
@include flex-direction(column);
}
}
h1 {
padding-left: 10px;
Expand Down
16 changes: 12 additions & 4 deletions app/templates/crate/version.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,19 @@
<div>
<h3>Owners</h3>
<ul class='owners'>
{{#each crate.owners as |owner|}}
{{#each crate.owner_team as |team|}}
<li>
{{#link-to 'user' owner.login}}
{{user-avatar user=owner size='medium-small'}}
{{/link-to}}
{{#link-to team.kind team.login}}
{{user-avatar user=team size='medium-small'}}
{{/link-to}}
</li>
{{/each}}

{{#each crate.owner_user as |user|}}
<li>
{{#link-to user.kind user.login}}
{{user-avatar user=user size='medium-small'}}
{{/link-to}}
</li>
{{/each}}
</ul>
Expand Down
76 changes: 76 additions & 0 deletions app/templates/team.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<div id='crates-heading'>
<div class="wide">
<div class='info'>
{{user-avatar user=model.team size='medium'}}
<div class='team-info'>
<h1>
{{ model.team.org_name }}
</h1>
<h2>
{{ model.team.name }}
</h2>
</div>
{{#user-link user=model.team}}
<img alt="GitHub profile" title="GitHub profile" src="/assets/GitHub-Mark-32px.png"/>
{{/user-link}}
</div>
</div>
</div>

<div id='user-profile'>
<div class='info'>
{{! TODO: reduce duplication with templates/crates.hbs }}

<div id='results'>
<div class='nav'>
<span class='amt small'>
Displaying
<span class='cur'>{{ currentPageStart }}-{{ currentPageEnd }}</span>
of <span class='total'>{{ totalItems }}</span> total results
</span>
</div>

<div class='sort'>
<span class='small'>Sort by</span>
{{#rl-dropdown-container class="dropdown-container"}}
{{#rl-dropdown-toggle tagName="a" class="dropdown"}}
<img class="sort" src="/assets/sort.png"/>
{{ currentSortBy }}
<span class='arrow'></span>
{{/rl-dropdown-toggle}}

{{#rl-dropdown tagName="ul" class="dropdown" closeOnChildClick="a:link"}}
<li>
{{#link-to (query-params sort="alpha")}}
Alphabetical
{{/link-to}}
</li>
<li>
{{#link-to (query-params sort="downloads")}}
Downloads
{{/link-to}}
</li>
{{/rl-dropdown}}
{{/rl-dropdown-container}}
</div>
</div>

<div id='crates' class='white-rows'>
{{#each model.crates as |crate|}}
{{crate-row crate=crate}}
{{/each}}
</div>

<div class='pagination'>
{{#link-to (query-params page=prevPage) class="prev" rel="prev" title="previous page"}}
<img class="left-pag" src="/assets/left-pag.png"/>
{{/link-to}}
{{#each pages as |page|}}
{{#link-to (query-params page=page)}}{{ page }}{{/link-to}}
{{/each}}
{{#link-to (query-params page=nextPage) class="next" rel="next" title="next page"}}
<img class="right-pag" src="/assets/right-pag.png"/>
{{/link-to}}
</div>
</div>
</div>
22 changes: 21 additions & 1 deletion mirage/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import crateFixture from '../mirage/fixtures/crate';
import crateVersionsFixture from '../mirage/fixtures/crate_versions';
import crateAuthorsFixture from '../mirage/fixtures/crate_authors';
import crateOwnersFixture from '../mirage/fixtures/crate_owners';
import crateTeamsFixture from '../mirage/fixtures/crate_teams';
import crateReverseDependenciesFixture from '../mirage/fixtures/crate_reverse_dependencies';
import crateDependenciesFixture from '../mirage/fixtures/crate_dependencies';
import crateDownloadsFixture from '../mirage/fixtures/crate_downloads';
import keywordFixture from '../mirage/fixtures/keyword';
import teamFixture from '../mirage/fixtures/team';
import userFixture from '../mirage/fixtures/user';

export default function() {
this.get('/summary', () => summaryFixture);
Expand All @@ -20,6 +23,20 @@ export default function() {
crates: searchFixture.crates.slice(start, end),
meta: searchFixture.meta,
};
} else if (request.queryParams.team_id) {
const { start, end } = pageParams(request);
return {
team: teamFixture.team,
crates: searchFixture.crates.slice(start, end),
meta: searchFixture.meta,
};
} else if (request.queryParams.user_id) {
const { start, end } = pageParams(request);
return {
user: userFixture.user,
crates: searchFixture.crates.slice(start, end),
meta: searchFixture.meta,
};
}
});

Expand All @@ -28,11 +45,14 @@ export default function() {
this.get('/api/v1/crates/nanomsg', () => crateFixture);
this.get('/api/v1/crates/nanomsg/versions', () => crateVersionsFixture);
this.get('/api/v1/crates/nanomsg/:version_num/authors', () => crateAuthorsFixture);
this.get('/api/v1/crates/nanomsg/owners', () => crateOwnersFixture);
this.get('/api/v1/crates/nanomsg/owner_user', () => crateOwnersFixture);
this.get('/api/v1/crates/nanomsg/owner_team', () => crateTeamsFixture);
this.get('/api/v1/crates/nanomsg/reverse_dependencies', () => crateReverseDependenciesFixture);
this.get('/api/v1/crates/nanomsg/:version_num/dependencies', () => crateDependenciesFixture);
this.get('/api/v1/crates/nanomsg/downloads', () => crateDownloadsFixture);
this.get('/api/v1/keywords/network', () => keywordFixture);
this.get('/api/v1/teams/:team_id', () => teamFixture);
this.get('/api/v1/users/:user_id', () => userFixture);
}

function pageParams(request) {
Expand Down
3 changes: 2 additions & 1 deletion mirage/fixtures/crate.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export default {
],
"license": "MIT",
"links": {
"owners": "/api/v1/crates/nanomsg/owners",
"owner_user": "/api/v1/crates/nanomsg/owner_user",
"owner_team": "/api/v1/crates/nanomsg/owner_team",
"reverse_dependencies": "/api/v1/crates/nanomsg/reverse_dependencies",
"version_downloads": "/api/v1/crates/nanomsg/downloads",
"versions": null
Expand Down
23 changes: 23 additions & 0 deletions mirage/fixtures/crate_teams.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// jscs:disable validateQuoteMarks
export default {
"teams": [
{
"avatar": "https://avatars.githubusercontent.com/u/565790?v=3",
"email": "someone@example.com",
"id": 2,
"kind": "team",
"login": "github:org:thehydroimpulse",
"name": "Team Daniel Fagnan",
"url": "https://github.com/thehydroimpulse"
},
{
"avatar": "https://avatars.githubusercontent.com/u/9447137?v=3",
"email": null,
"id": 303,
"kind": "team",
"login": "github:org:blabaere",
"name": "Team Benoît Labaere",
"url": "https://github.com/blabaere"
}
]
};
10 changes: 10 additions & 0 deletions mirage/fixtures/team.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// jscs:disable validateQuoteMarks
export default {
"team": {
"avatar": "https://avatars.githubusercontent.com/u/565790?v=3",
"id": 1,
"login": "github:org_test:thehydroimpulseteam",
"name": "thehydroimpulseteam",
"url": "https://github.com/thehydroimpulse",
}
};
10 changes: 10 additions & 0 deletions mirage/fixtures/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// jscs:disable validateQuoteMarks
export default {
"user": {
"avatar": "https://avatars.githubusercontent.com/u/565790?v=3",
"email": "someone@example.com",
"id": 1,
"login": "thehydroimpulse",
"name": "Daniel Fagnan"
}
};
Loading