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

163 lines
5.9 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';
import 'package:git_touch/widgets/entry_item.dart';
2020-02-08 07:22:20 +01:00
import 'package:git_touch/widgets/language_bar.dart';
2019-12-11 16:09:39 +01:00
import 'package:git_touch/widgets/markdown_view.dart';
2020-01-29 11:23:51 +01:00
import 'package:git_touch/widgets/repo_header.dart';
2019-12-11 16:09:39 +01:00
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-02-07 15:26:37 +01:00
class GlProjectScreen extends StatelessWidget {
2019-12-11 16:09:39 +01:00
final int id;
2020-02-07 15:26:37 +01:00
GlProjectScreen(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<
Tuple5<GitlabProject, Map<String, double>, List<GitlabProjectBadge>,
int, String>>(
2019-12-11 16:09:39 +01:00
title: AppBarTitle('Project'),
fetch: () async {
2020-10-04 14:37:23 +02:00
final auth = context.read<AuthModel>();
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'),
auth.fetchGitlabWithPage('/projects/$id/members?per_page=1')
2020-01-28 13:50:38 +01:00
]);
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
}
return Tuple5(
2020-01-28 13:50:38 +01:00
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(),
(res[3] as DataWithPage).total,
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 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);
final auth = Provider.of<AuthModel>(context);
final prefix =
'${auth.activeAccount.domain}/${p.namespace.path}/${p.name}'
.urlencode;
2019-12-11 16:09:39 +01:00
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
2020-01-29 11:23:51 +01:00
RepoHeader(
avatarUrl: p.avatarUrl,
2020-02-01 03:46:11 +01:00
avatarLink: p.namespace.kind == 'group'
? '/gitlab/group/${p.namespace.id}'
: '/gitlab/user/${p.namespace.id}',
2020-01-29 11:23:51 +01:00
owner: p.namespace.name,
name: p.name,
description: p.description,
trailings: <Widget>[
if (badges.isNotEmpty)
Wrap(spacing: 4, runSpacing: 4, children: [
for (var label in badges)
SvgPicture.network(label.renderedImageUrl, height: 20),
])
],
2020-01-11 10:25:01 +01:00
),
2019-12-11 16:09:39 +01:00
CommonStyle.border,
Row(
children: <Widget>[
EntryItem(
count: t.item4,
text: 'Members',
2020-02-01 05:14:03 +01:00
url: '/gitlab/projects/$id/members',
),
2019-12-11 16:09:39 +01:00
EntryItem(
2020-01-28 13:50:38 +01:00
count: p.starCount,
2019-12-11 16:09:39 +01:00
text: 'Stars',
url: '/gitlab/projects/$id/starrers',
2019-12-11 16:09:39 +01:00
),
EntryItem(
2020-01-28 13:50:38 +01:00
count: p.forksCount,
2019-12-11 16:09:39 +01:00
text: 'Forks', // TODO:
),
],
),
2020-02-08 07:22:20 +01:00
if (langs.isNotEmpty) ...[
CommonStyle.border,
LanguageBar([
for (var e in langs.entries)
LanguageBarItem(name: e.key, ratio: e.value / 100)
]),
],
2020-01-28 13:50:38 +01:00
CommonStyle.border,
2019-12-11 16:09:39 +01:00
TableView(
hasIcon: true,
items: [
2020-04-06 07:30:44 +02:00
TableViewItem(
leftIconData: Octicons.code,
text: Text(langs.keys.isEmpty ? 'Code' : langs.keys.first),
rightWidget: p.statistics == null
? null
: Text(filesize(p.statistics.repositorySize)),
url: '/gitlab/projects/$id/tree/${p.defaultBranch}',
),
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?prefix=$prefix',
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'),
url: '/gitlab/projects/$id/merge_requests?prefix=$prefix',
2019-12-11 16:09:39 +01:00
),
2020-04-06 07:30:44 +02:00
TableViewItem(
leftIconData: Octicons.history,
text: Text('Commits'),
rightWidget: p.statistics == null
? null
: Text(p.statistics.commitCount.toString()),
url: '/gitlab/projects/$id/commits?prefix=$prefix',
),
2019-12-11 16:09:39 +01:00
],
),
CommonStyle.verticalGap,
if (t.item5 != 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,
child: MarkdownView(t.item5),
2019-12-11 16:09:39 +01:00
),
CommonStyle.verticalGap,
],
);
},
);
}
}