1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-23 13:50:19 +01:00
git-touch-android-ios-app/lib/screens/gitlab_project.dart

144 lines
4.9 KiB
Dart
Raw Normal View History

2019-12-11 16:09:39 +01:00
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.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/utils/utils.dart';
import 'package:git_touch/widgets/app_bar_title.dart';
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/repository_item.dart';
import 'package:git_touch/widgets/action_button.dart';
2020-01-01 09:51:10 +01:00
final gitlabProjectRouter = RouterScreen('/gitlab/projects/:id',
2019-12-14 17:08:12 +01:00
(context, params) => GitlabProjectScreen(int.parse(['id'].first)));
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) {
return RefreshStatefulScaffold<GitlabProject>(
title: AppBarTitle('Project'),
fetchData: () async {
final auth = Provider.of<AuthModel>(context);
final json = await auth.fetchGitlab('/projects/$id');
final project = GitlabProject.fromJson(json);
if (project.readmeUrl != null) {
project.readme = await auth.fetchWithGitlabToken(
project.readmeUrl.replaceFirst(r'/blob/', '/raw/'));
}
final l = await auth.fetchGitlab('/projects/$id/languages');
project.languages = Map<String, double>.from(l);
return project;
},
actionBuilder: (data, setState) {
return ActionButton(
title: 'Project Actions',
items: [
2020-01-27 06:41:17 +01:00
...ActionItem.getUrlActions(data.webUrl),
2019-12-11 16:09:39 +01:00
],
);
},
bodyBuilder: (data, _) {
final langWidth = MediaQuery.of(context).size.width -
CommonStyle.padding.left -
CommonStyle.padding.right -
data.languages.length +
1;
final theme = Provider.of<ThemeModel>(context);
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
2020-01-11 10:25:01 +01:00
RepositoryItem(
data.namespace.name,
data.avatarUrl,
data.name,
data.description,
data.starCount,
data.forksCount,
data.languages.keys.first,
2020-01-11 12:52:17 +01:00
null,
null,
2020-01-11 10:25:01 +01:00
),
2019-12-11 16:09:39 +01:00
CommonStyle.border,
Row(
children: <Widget>[
EntryItem(
count: data.starCount,
text: 'Stars',
),
EntryItem(
count: data.forksCount,
text: 'Forks', // TODO:
),
],
),
CommonStyle.verticalGap,
if (data.languages.isNotEmpty)
Container(
2020-01-14 11:13:07 +01:00
color: theme.paletteOf(context).background,
2019-12-11 16:09:39 +01:00
padding: CommonStyle.padding.copyWith(top: 8, bottom: 8),
child: ClipRRect(
borderRadius: BorderRadius.circular(2),
child: SizedBox(
height: 10,
child: Row(
children: join(
SizedBox(width: 1),
data.languages.entries
.map((e) => Container(
color: convertColor('#ff0'),
width: langWidth *
e.value /
data.languages.length))
.toList(),
),
),
),
),
),
TableView(
hasIcon: true,
items: [
TableViewItem(
leftIconData: Octicons.code,
text: Text('Code'),
2019-12-14 17:08:12 +01:00
url: '/projects/$id/tree',
2019-12-11 16:09:39 +01:00
),
if (data.issuesEnabled)
TableViewItem(
leftIconData: Octicons.issue_opened,
text: Text('Issues'),
rightWidget:
Text(numberFormat.format(data.openIssuesCount)),
),
if (data.mergeRequestsEnabled)
TableViewItem(
leftIconData: Octicons.git_pull_request,
text: Text('Merge requests'),
),
],
),
CommonStyle.verticalGap,
if (data.readme != null)
Container(
padding: CommonStyle.padding,
2020-01-14 11:13:07 +01:00
color: theme.paletteOf(context).background,
2019-12-11 16:09:39 +01:00
child: MarkdownView(data.readme),
),
CommonStyle.verticalGap,
],
);
},
);
}
}