feat(gitlab): project and group members
This commit is contained in:
parent
3cde09bf23
commit
b56111db6f
|
@ -29,7 +29,8 @@ class DataWithPage<T> {
|
|||
T data;
|
||||
int cursor;
|
||||
bool hasMore;
|
||||
DataWithPage(this.data, this.cursor, this.hasMore);
|
||||
int total;
|
||||
DataWithPage({this.data, this.cursor, this.hasMore, this.total});
|
||||
}
|
||||
|
||||
class AuthModel with ChangeNotifier {
|
||||
|
@ -162,7 +163,13 @@ class AuthModel with ChangeNotifier {
|
|||
res.headers['X-Next-Pages'] ?? res.headers['x-next-page'] ?? '');
|
||||
final info = json.decode(utf8.decode(res.bodyBytes));
|
||||
if (info is Map && info['message'] != null) throw info['message'];
|
||||
return DataWithPage(info, next, next != null);
|
||||
return DataWithPage(
|
||||
data: info,
|
||||
cursor: next,
|
||||
hasMore: next != null,
|
||||
total:
|
||||
int.tryParse(res.headers['X-Total'] ?? res.headers['x-total'] ?? ''),
|
||||
);
|
||||
}
|
||||
|
||||
Future loginToGitea(String domain, String token) async {
|
||||
|
|
|
@ -3,6 +3,7 @@ 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/entry_item.dart';
|
||||
import 'package:git_touch/widgets/repository_item.dart';
|
||||
import 'package:git_touch/widgets/user_header.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
@ -21,12 +22,18 @@ class GitlabGroupScreen extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return RefreshStatefulScaffold<Tuple2<GitlabGroup, Null>>(
|
||||
return RefreshStatefulScaffold<Tuple2<GitlabGroup, int>>(
|
||||
title: Text('Group'),
|
||||
fetchData: () async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final res = await Future.wait([auth.fetchGitlab('/groups/$id')]);
|
||||
return Tuple2(GitlabGroup.fromJson(res[0]), null);
|
||||
final res = await Future.wait([
|
||||
auth.fetchGitlab('/groups/$id'),
|
||||
auth.fetchGitlabWithPage('/groups/$id/members?per_page=1')
|
||||
]);
|
||||
return Tuple2(
|
||||
GitlabGroup.fromJson(res[0]),
|
||||
(res[1] as DataWithPage).total,
|
||||
);
|
||||
},
|
||||
bodyBuilder: (data, _) {
|
||||
final p = data.item1;
|
||||
|
@ -40,6 +47,13 @@ class GitlabGroupScreen extends StatelessWidget {
|
|||
bio: p.description,
|
||||
),
|
||||
CommonStyle.border,
|
||||
Row(children: [
|
||||
EntryItem(
|
||||
count: data.item2,
|
||||
text: 'Members',
|
||||
),
|
||||
]),
|
||||
CommonStyle.border,
|
||||
Column(
|
||||
children: <Widget>[
|
||||
for (var v in p.projects)
|
||||
|
|
|
@ -27,8 +27,8 @@ class GitlabProjectScreen extends StatelessWidget {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return RefreshStatefulScaffold<
|
||||
Tuple4<GitlabProject, Map<String, double>, List<GitlabProjectBadge>,
|
||||
String>>(
|
||||
Tuple5<GitlabProject, Map<String, double>, List<GitlabProjectBadge>,
|
||||
int, String>>(
|
||||
title: AppBarTitle('Project'),
|
||||
fetchData: () async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
|
@ -36,6 +36,7 @@ class GitlabProjectScreen extends StatelessWidget {
|
|||
auth.fetchGitlab('/projects/$id?statistics=1'),
|
||||
auth.fetchGitlab('/projects/$id/languages'),
|
||||
auth.fetchGitlab('/projects/$id/badges'),
|
||||
auth.fetchGitlabWithPage('/projects/$id/members?per_page=1')
|
||||
]);
|
||||
final p = GitlabProject.fromJson(res[0]);
|
||||
String readme;
|
||||
|
@ -43,10 +44,11 @@ class GitlabProjectScreen extends StatelessWidget {
|
|||
readme = await auth.fetchWithGitlabToken(
|
||||
p.readmeUrl.replaceFirst(r'/blob/', '/raw/'));
|
||||
}
|
||||
return Tuple4(
|
||||
return Tuple5(
|
||||
p,
|
||||
Map<String, double>.from(res[1]),
|
||||
(res[2] as List).map((v) => GitlabProjectBadge.fromJson(v)).toList(),
|
||||
(res[3] as DataWithPage).total,
|
||||
readme,
|
||||
);
|
||||
},
|
||||
|
@ -91,6 +93,10 @@ class GitlabProjectScreen extends StatelessWidget {
|
|||
CommonStyle.border,
|
||||
Row(
|
||||
children: <Widget>[
|
||||
EntryItem(
|
||||
count: t.item4,
|
||||
text: 'Members',
|
||||
),
|
||||
EntryItem(
|
||||
count: p.starCount,
|
||||
text: 'Stars',
|
||||
|
@ -133,11 +139,11 @@ class GitlabProjectScreen extends StatelessWidget {
|
|||
],
|
||||
),
|
||||
CommonStyle.verticalGap,
|
||||
if (t.item4 != null)
|
||||
if (t.item5 != null)
|
||||
Container(
|
||||
padding: CommonStyle.padding,
|
||||
color: theme.palette.background,
|
||||
child: MarkdownView(t.item4),
|
||||
child: MarkdownView(t.item5),
|
||||
),
|
||||
CommonStyle.verticalGap,
|
||||
],
|
||||
|
|
Loading…
Reference in New Issue