From d7d05bc72ba374ecb0737341738969ac0f7a1bcd Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Fri, 31 Jan 2020 22:45:40 +0800 Subject: [PATCH] feat(gitlab): group screen --- lib/main.dart | 2 ++ lib/models/gitlab.dart | 13 ++++++++ lib/models/gitlab.g.dart | 24 +++++++++++++++ lib/screens/gitlab_group.dart | 57 +++++++++++++++++++++++++++++++++++ lib/widgets/user_header.dart | 31 ++++++++++--------- 5 files changed, 112 insertions(+), 15 deletions(-) create mode 100644 lib/screens/gitlab_group.dart diff --git a/lib/main.dart b/lib/main.dart index ff2f50e..f08b5fb 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -12,6 +12,7 @@ import 'package:git_touch/screens/gitea_repo.dart'; import 'package:git_touch/screens/gitea_user.dart'; import 'package:git_touch/screens/gitlab_blob.dart'; import 'package:git_touch/screens/gitlab_commits.dart'; +import 'package:git_touch/screens/gitlab_group.dart'; import 'package:git_touch/screens/gitlab_issue.dart'; import 'package:git_touch/screens/gitlab_issues.dart'; import 'package:git_touch/screens/gitlab_merge_requests.dart'; @@ -70,6 +71,7 @@ void main() async { codeThemeRouter, aboutRouter, gitlabUserRouter, + gitlabGroupRouter, gitlabBlobRouter, gitlabTreeRouter, gitlabProjectRouter, diff --git a/lib/models/gitlab.dart b/lib/models/gitlab.dart index f0f1c72..5309aa2 100644 --- a/lib/models/gitlab.dart +++ b/lib/models/gitlab.dart @@ -15,6 +15,19 @@ class GitlabUser { _$GitlabUserFromJson(json); } +@JsonSerializable(fieldRename: FieldRename.snake) +class GitlabGroup { + int id; + String path; + String name; + String avatarUrl; + String description; + List projects; + GitlabGroup(); + factory GitlabGroup.fromJson(Map json) => + _$GitlabGroupFromJson(json); +} + @JsonSerializable(fieldRename: FieldRename.snake) class GitlabTodoProject { String pathWithNamespace; diff --git a/lib/models/gitlab.g.dart b/lib/models/gitlab.g.dart index 85ad5cf..cd9f83f 100644 --- a/lib/models/gitlab.g.dart +++ b/lib/models/gitlab.g.dart @@ -28,6 +28,30 @@ Map _$GitlabUserToJson(GitlabUser instance) => 'created_at': instance.createdAt?.toIso8601String(), }; +GitlabGroup _$GitlabGroupFromJson(Map json) { + return GitlabGroup() + ..id = json['id'] as int + ..path = json['path'] as String + ..name = json['name'] as String + ..avatarUrl = json['avatar_url'] as String + ..description = json['description'] as String + ..projects = (json['projects'] as List) + ?.map((e) => e == null + ? null + : GitlabProject.fromJson(e as Map)) + ?.toList(); +} + +Map _$GitlabGroupToJson(GitlabGroup instance) => + { + 'id': instance.id, + 'path': instance.path, + 'name': instance.name, + 'avatar_url': instance.avatarUrl, + 'description': instance.description, + 'projects': instance.projects, + }; + GitlabTodoProject _$GitlabTodoProjectFromJson(Map json) { return GitlabTodoProject() ..pathWithNamespace = json['path_with_namespace'] as String; diff --git a/lib/screens/gitlab_group.dart b/lib/screens/gitlab_group.dart new file mode 100644 index 0000000..7c801ed --- /dev/null +++ b/lib/screens/gitlab_group.dart @@ -0,0 +1,57 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; +import 'package:git_touch/models/auth.dart'; +import 'package:git_touch/models/gitlab.dart'; +import 'package:git_touch/scaffolds/refresh_stateful.dart'; +import 'package:git_touch/widgets/repository_item.dart'; +import 'package:git_touch/widgets/user_header.dart'; +import 'package:provider/provider.dart'; +import 'package:tuple/tuple.dart'; +import 'package:git_touch/utils/utils.dart'; +import 'package:timeago/timeago.dart' as timeago; + +final gitlabGroupRouter = RouterScreen( + '/gitlab/group/:id', + (context, parameters) => + GitlabGroupScreen(int.parse(parameters['id'].first))); + +class GitlabGroupScreen extends StatelessWidget { + final int id; + GitlabGroupScreen(this.id); + + @override + Widget build(BuildContext context) { + return RefreshStatefulScaffold>( + title: Text('Group'), + fetchData: () async { + final auth = Provider.of(context); + final res = await Future.wait([auth.fetchGitlab('/groups/$id')]); + return Tuple2(GitlabGroup.fromJson(res[0]), null); + }, + bodyBuilder: (data, _) { + final p = data.item1; + return Column( + children: [ + UserHeader( + login: p.path, + avatarUrl: p.avatarUrl, + name: p.name, + createdAt: null, + bio: p.description, + ), + CommonStyle.border, + Column( + children: [ + for (var v in p.projects) + RepositoryItem.gl( + payload: v, + note: 'Created ${timeago.format(v.createdAt)}', + ) + ], + ) + ], + ); + }, + ); + } +} diff --git a/lib/widgets/user_header.dart b/lib/widgets/user_header.dart index b4e1269..066f564 100644 --- a/lib/widgets/user_header.dart +++ b/lib/widgets/user_header.dart @@ -58,23 +58,24 @@ class UserHeader extends StatelessWidget { ), ), SizedBox(height: 8), - Row( - children: [ - Icon( - Octicons.clock, - size: 16, - color: theme.palette.tertiaryText, - ), - SizedBox(width: 4), - Text( - 'Joined on ${dateFormat.format(createdAt)}', - style: TextStyle( + if (createdAt != null) + Row( + children: [ + Icon( + Octicons.clock, + size: 16, color: theme.palette.tertiaryText, - fontSize: 16, ), - ), - ], - ), + SizedBox(width: 4), + Text( + 'Joined on ${dateFormat.format(createdAt)}', + style: TextStyle( + color: theme.palette.tertiaryText, + fontSize: 16, + ), + ), + ], + ), if (bio != null && bio.isNotEmpty) ...[ SizedBox(height: 10), Text(