git-touch-android-ios-app/lib/screens/gitlab_project.dart

172 lines
6.1 KiB
Dart
Raw Normal View History

2020-01-28 14:01:06 +01:00
import 'package:filesize/filesize.dart';
2019-12-11 16:09:39 +01:00
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
2020-01-28 13:50:38 +01:00
import 'package:flutter_svg/svg.dart';
2019-12-11 16:09:39 +01:00
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/utils/utils.dart';
import 'package:git_touch/widgets/app_bar_title.dart';
2020-01-28 13:50:38 +01:00
import 'package:git_touch/widgets/avatar.dart';
2019-12-11 16:09:39 +01:00
import 'package:git_touch/widgets/entry_item.dart';
import 'package:git_touch/widgets/markdown_view.dart';
import 'package:git_touch/widgets/table_view.dart';
import 'package:provider/provider.dart';
import 'package:git_touch/models/theme.dart';
import 'package:git_touch/widgets/action_button.dart';
2020-01-28 13:50:38 +01:00
import 'package:tuple/tuple.dart';
2019-12-11 16:09:39 +01:00
2020-01-01 09:51:10 +01:00
final gitlabProjectRouter = RouterScreen('/gitlab/projects/:id',
2020-01-29 06:14:21 +01:00
(context, params) => GitlabProjectScreen(int.parse(params['id'].first)));
2019-12-14 17:08:12 +01:00
2019-12-11 16:09:39 +01:00
class GitlabProjectScreen extends StatelessWidget {
final int id;
2019-12-14 17:08:12 +01:00
GitlabProjectScreen(this.id);
2019-12-11 16:09:39 +01:00
@override
Widget build(BuildContext context) {
2020-01-28 13:50:38 +01:00
return RefreshStatefulScaffold<
2020-01-28 14:01:06 +01:00
Tuple4<GitlabProject, Map<String, double>, List<GitlabProjectBadge>,
String>>(
2019-12-11 16:09:39 +01:00
title: AppBarTitle('Project'),
fetchData: () async {
final auth = Provider.of<AuthModel>(context);
2020-01-28 13:50:38 +01:00
final res = await Future.wait([
2020-01-28 14:01:06 +01:00
auth.fetchGitlab('/projects/$id?statistics=1'),
2020-01-28 13:50:38 +01:00
auth.fetchGitlab('/projects/$id/languages'),
auth.fetchGitlab('/projects/$id/badges'),
]);
final p = GitlabProject.fromJson(res[0]);
String readme;
if (p.readmeUrl != null) {
readme = await auth.fetchWithGitlabToken(
p.readmeUrl.replaceFirst(r'/blob/', '/raw/'));
2019-12-11 16:09:39 +01:00
}
2020-01-28 13:50:38 +01:00
return Tuple4(
p,
Map<String, double>.from(res[1]),
2020-01-28 14:01:06 +01:00
(res[2] as List).map((v) => GitlabProjectBadge.fromJson(v)).toList(),
2020-01-28 13:50:38 +01:00
readme,
);
2019-12-11 16:09:39 +01:00
},
2020-01-28 13:50:38 +01:00
actionBuilder: (t, setState) {
2019-12-11 16:09:39 +01:00
return ActionButton(
title: 'Project Actions',
items: [
2020-01-28 13:50:38 +01:00
...ActionItem.getUrlActions(t.item1.webUrl),
2019-12-11 16:09:39 +01:00
],
);
},
2020-01-28 13:50:38 +01:00
bodyBuilder: (t, _) {
// final langWidth = MediaQuery.of(context).size.width -
// CommonStyle.padding.left -
// CommonStyle.padding.right -
// data.languages.length +
// 1;
final p = t.item1;
final langs = t.item2;
final badges = t.item3;
2019-12-11 16:09:39 +01:00
final theme = Provider.of<ThemeModel>(context);
2020-01-29 05:42:36 +01:00
// final auth = Provider.of<AuthModel>(context);
2019-12-11 16:09:39 +01:00
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
2020-01-28 13:50:38 +01:00
Container(
padding: CommonStyle.padding,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: join(SizedBox(height: 12), [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Avatar(
url: p.avatarUrl,
size: AvatarSize.small,
linkUrl: '/${p.namespace.name}',
),
SizedBox(width: 8),
Text(
'${p.namespace.name} / ${p.name}',
style: TextStyle(
fontSize: 20,
color: theme.palette.primary,
),
),
],
),
if (p.description != null && p.description.isNotEmpty)
Text(
p.description,
style: TextStyle(
color: theme.palette.secondaryText,
fontSize: 17,
),
),
if (badges.isNotEmpty)
Wrap(spacing: 4, runSpacing: 4, children: [
for (var label in badges)
2020-01-29 05:42:36 +01:00
SvgPicture.network(label.renderedImageUrl, height: 20),
2020-01-28 13:50:38 +01:00
])
]),
),
2020-01-11 10:25:01 +01:00
),
2019-12-11 16:09:39 +01:00
CommonStyle.border,
Row(
children: <Widget>[
EntryItem(
2020-01-28 13:50:38 +01:00
count: p.starCount,
2019-12-11 16:09:39 +01:00
text: 'Stars',
),
EntryItem(
2020-01-28 13:50:38 +01:00
count: p.forksCount,
2019-12-11 16:09:39 +01:00
text: 'Forks', // TODO:
),
],
),
2020-01-28 13:50:38 +01:00
CommonStyle.border,
2019-12-11 16:09:39 +01:00
TableView(
hasIcon: true,
items: [
TableViewItem(
leftIconData: Octicons.code,
2020-01-28 13:50:38 +01:00
text: Text(langs.keys.isEmpty ? 'Code' : langs.keys.first),
2020-01-28 14:01:06 +01:00
rightWidget: Text(filesize(p.statistics.repositorySize)),
2020-01-28 13:50:38 +01:00
url: '/gitlab/projects/$id/tree',
2019-12-11 16:09:39 +01:00
),
2020-01-28 13:50:38 +01:00
if (p.issuesEnabled)
2019-12-11 16:09:39 +01:00
TableViewItem(
leftIconData: Octicons.issue_opened,
text: Text('Issues'),
2020-01-28 13:50:38 +01:00
rightWidget: Text(numberFormat.format(p.openIssuesCount)),
url: '/gitlab/projects/$id/issues',
2019-12-11 16:09:39 +01:00
),
2020-01-28 13:50:38 +01:00
if (p.mergeRequestsEnabled)
2019-12-11 16:09:39 +01:00
TableViewItem(
leftIconData: Octicons.git_pull_request,
text: Text('Merge requests'),
2020-01-28 13:50:38 +01:00
url: '/gitlab/projects/$id/merge_requests',
2019-12-11 16:09:39 +01:00
),
2020-01-28 14:01:06 +01:00
TableViewItem(
leftIconData: Octicons.history,
text: Text('Commits'),
rightWidget: Text(p.statistics.commitCount.toString()),
url: '/gitlab/projects/$id/commits',
),
2019-12-11 16:09:39 +01:00
],
),
CommonStyle.verticalGap,
2020-01-28 13:50:38 +01:00
if (t.item4 != null)
2019-12-11 16:09:39 +01:00
Container(
padding: CommonStyle.padding,
2020-01-27 08:11:51 +01:00
color: theme.palette.background,
2020-01-28 13:50:38 +01:00
child: MarkdownView(t.item4),
2019-12-11 16:09:39 +01:00
),
CommonStyle.verticalGap,
],
);
},
);
}
}