mirror of
https://github.com/git-touch/git-touch
synced 2025-02-21 22:07:51 +01:00
feat(gitlab): project icons
This commit is contained in:
parent
a5fc703a24
commit
956b57e869
@ -16,18 +16,19 @@ class GitlabUser {
|
||||
}
|
||||
|
||||
@JsonSerializable(fieldRename: FieldRename.snake)
|
||||
class GitlabRepository {
|
||||
class GitlabProject {
|
||||
int id;
|
||||
GitlabUser owner;
|
||||
String name;
|
||||
String description;
|
||||
int starCount;
|
||||
int forksCount;
|
||||
String visibility;
|
||||
|
||||
GitlabRepository();
|
||||
GitlabProject();
|
||||
|
||||
factory GitlabRepository.fromJson(Map<String, dynamic> json) =>
|
||||
_$GitlabRepositoryFromJson(json);
|
||||
factory GitlabProject.fromJson(Map<String, dynamic> json) =>
|
||||
_$GitlabProjectFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable(fieldRename: FieldRename.snake)
|
||||
|
@ -22,8 +22,8 @@ Map<String, dynamic> _$GitlabUserToJson(GitlabUser instance) =>
|
||||
'avatar_url': instance.avatarUrl,
|
||||
};
|
||||
|
||||
GitlabRepository _$GitlabRepositoryFromJson(Map<String, dynamic> json) {
|
||||
return GitlabRepository()
|
||||
GitlabProject _$GitlabProjectFromJson(Map<String, dynamic> json) {
|
||||
return GitlabProject()
|
||||
..id = json['id'] as int
|
||||
..owner = json['owner'] == null
|
||||
? null
|
||||
@ -31,10 +31,11 @@ GitlabRepository _$GitlabRepositoryFromJson(Map<String, dynamic> json) {
|
||||
..name = json['name'] as String
|
||||
..description = json['description'] as String
|
||||
..starCount = json['star_count'] as int
|
||||
..forksCount = json['forks_count'] as int;
|
||||
..forksCount = json['forks_count'] as int
|
||||
..visibility = json['visibility'] as String;
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$GitlabRepositoryToJson(GitlabRepository instance) =>
|
||||
Map<String, dynamic> _$GitlabProjectToJson(GitlabProject instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'owner': instance.owner,
|
||||
@ -42,6 +43,7 @@ Map<String, dynamic> _$GitlabRepositoryToJson(GitlabRepository instance) =>
|
||||
'description': instance.description,
|
||||
'star_count': instance.starCount,
|
||||
'forks_count': instance.forksCount,
|
||||
'visibility': instance.visibility,
|
||||
};
|
||||
|
||||
GitlabTodoProject _$GitlabTodoProjectFromJson(Map<String, dynamic> json) {
|
||||
|
@ -15,9 +15,7 @@ class GitlabUserScreen extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return RefreshStatefulScaffold<
|
||||
Tuple3<GitlabUser, Iterable<GitlabRepository>,
|
||||
List<Map<String, double>>>>(
|
||||
return RefreshStatefulScaffold<Tuple2<GitlabUser, Iterable<GitlabProject>>>(
|
||||
title: Text('User'),
|
||||
fetchData: () async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
@ -26,17 +24,14 @@ class GitlabUserScreen extends StatelessWidget {
|
||||
final user = GitlabUser.fromJson(v0[0]);
|
||||
|
||||
final v1 = await auth.fetchGitlab('/users/${user.id}/projects');
|
||||
final projects = (v1 as List).map((v) => GitlabRepository.fromJson(v));
|
||||
final projects =
|
||||
(v1 as List).map((v) => GitlabProject.fromJson(v)).toList();
|
||||
|
||||
final languages = await Future.wait(projects
|
||||
.map((p) => auth.fetchGitlab('/projects/${p.id}/languages')));
|
||||
|
||||
return Tuple3(user, projects, languages.cast<Map<String, double>>());
|
||||
return Tuple2(user, projects);
|
||||
},
|
||||
bodyBuilder: (data, _) {
|
||||
final user = data.item1;
|
||||
final projects = data.item2;
|
||||
final languages = data.item3;
|
||||
|
||||
return Column(
|
||||
children: <Widget>[
|
||||
@ -47,9 +42,7 @@ class GitlabUserScreen extends StatelessWidget {
|
||||
),
|
||||
BorderView(height: 10),
|
||||
Column(
|
||||
children: projects.map((project) {
|
||||
return RepositoryItem.gitlab(project);
|
||||
}).toList(),
|
||||
children: projects.map((v) => RepositoryItem.gitlab(v)).toList(),
|
||||
)
|
||||
],
|
||||
);
|
||||
|
@ -99,12 +99,25 @@ class RepositoryItem extends StatelessWidget {
|
||||
// ? []
|
||||
// : payload['repositoryTopics']['nodes'];
|
||||
|
||||
RepositoryItem.gitlab(GitlabRepository payload, {this.inRepoScreen = false})
|
||||
static _getGitlabIcon(String visibility) {
|
||||
switch (visibility) {
|
||||
case 'internal':
|
||||
return FontAwesome.shield;
|
||||
case 'public':
|
||||
return FontAwesome.globe;
|
||||
case 'private':
|
||||
return FontAwesome.lock;
|
||||
default:
|
||||
return Octicons.repo;
|
||||
}
|
||||
}
|
||||
|
||||
RepositoryItem.gitlab(GitlabProject payload, {this.inRepoScreen = false})
|
||||
: this.owner = payload.owner.name,
|
||||
this.avatarUrl = payload.owner.avatarUrl,
|
||||
this.name = payload.name,
|
||||
this.description = payload.description,
|
||||
this.iconData = Octicons.repo,
|
||||
this.iconData = _getGitlabIcon(payload.visibility),
|
||||
this.starCount = payload.starCount,
|
||||
this.forkCount = payload.forksCount,
|
||||
this.primaryLanguageName = null,
|
||||
|
Loading…
x
Reference in New Issue
Block a user