mirror of
https://github.com/git-touch/git-touch
synced 2025-01-31 08:04:51 +01:00
feat(gitlab): project badges
This commit is contained in:
parent
20bbc505f9
commit
a021f755f3
@ -81,6 +81,14 @@ class GitlabIssueNote {
|
||||
_$GitlabIssueNoteFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable(fieldRename: FieldRename.snake)
|
||||
class GitlabLabel {
|
||||
String renderedImageUrl;
|
||||
GitlabLabel();
|
||||
factory GitlabLabel.fromJson(Map<String, dynamic> json) =>
|
||||
_$GitlabLabelFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable(fieldRename: FieldRename.snake)
|
||||
class GitlabProject {
|
||||
int id;
|
||||
@ -96,18 +104,7 @@ class GitlabProject {
|
||||
bool issuesEnabled;
|
||||
int openIssuesCount;
|
||||
bool mergeRequestsEnabled;
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
String readme;
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
Map<String, double> languages;
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
String primaryLanguage;
|
||||
|
||||
GitlabProject();
|
||||
|
||||
factory GitlabProject.fromJson(Map<String, dynamic> json) =>
|
||||
_$GitlabProjectFromJson(json);
|
||||
}
|
||||
|
@ -116,6 +116,15 @@ Map<String, dynamic> _$GitlabIssueNoteToJson(GitlabIssueNote instance) =>
|
||||
'body': instance.body,
|
||||
};
|
||||
|
||||
GitlabLabel _$GitlabLabelFromJson(Map<String, dynamic> json) {
|
||||
return GitlabLabel()..renderedImageUrl = json['rendered_image_url'] as String;
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$GitlabLabelToJson(GitlabLabel instance) =>
|
||||
<String, dynamic>{
|
||||
'rendered_image_url': instance.renderedImageUrl,
|
||||
};
|
||||
|
||||
GitlabProject _$GitlabProjectFromJson(Map<String, dynamic> json) {
|
||||
return GitlabProject()
|
||||
..id = json['id'] as int
|
||||
|
@ -1,17 +1,19 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_svg/svg.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/avatar.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';
|
||||
import 'package:tuple/tuple.dart';
|
||||
|
||||
final gitlabProjectRouter = RouterScreen('/gitlab/projects/:id',
|
||||
(context, params) => GitlabProjectScreen(int.parse(['id'].first)));
|
||||
@ -23,116 +25,132 @@ class GitlabProjectScreen extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return RefreshStatefulScaffold<GitlabProject>(
|
||||
return RefreshStatefulScaffold<
|
||||
Tuple4<GitlabProject, Map<String, double>, List<GitlabLabel>, String>>(
|
||||
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 res = await Future.wait([
|
||||
auth.fetchGitlab('/projects/$id'),
|
||||
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/'));
|
||||
}
|
||||
final l = await auth.fetchGitlab('/projects/$id/languages');
|
||||
project.languages = Map<String, double>.from(l);
|
||||
return project;
|
||||
return Tuple4(
|
||||
p,
|
||||
Map<String, double>.from(res[1]),
|
||||
(res[2] as List).map((v) => GitlabLabel.fromJson(v)).toList(),
|
||||
readme,
|
||||
);
|
||||
},
|
||||
actionBuilder: (data, setState) {
|
||||
actionBuilder: (t, setState) {
|
||||
return ActionButton(
|
||||
title: 'Project Actions',
|
||||
items: [
|
||||
...ActionItem.getUrlActions(data.webUrl),
|
||||
...ActionItem.getUrlActions(t.item1.webUrl),
|
||||
],
|
||||
);
|
||||
},
|
||||
bodyBuilder: (data, _) {
|
||||
final langWidth = MediaQuery.of(context).size.width -
|
||||
CommonStyle.padding.left -
|
||||
CommonStyle.padding.right -
|
||||
data.languages.length +
|
||||
1;
|
||||
|
||||
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;
|
||||
final theme = Provider.of<ThemeModel>(context);
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
RepositoryItem(
|
||||
data.namespace.name,
|
||||
data.avatarUrl,
|
||||
data.name,
|
||||
data.description,
|
||||
data.starCount,
|
||||
data.forksCount,
|
||||
data.languages.keys.first,
|
||||
null,
|
||||
null,
|
||||
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)
|
||||
SvgPicture.network(label.renderedImageUrl, height: 20)
|
||||
])
|
||||
]),
|
||||
),
|
||||
),
|
||||
CommonStyle.border,
|
||||
Row(
|
||||
children: <Widget>[
|
||||
EntryItem(
|
||||
count: data.starCount,
|
||||
count: p.starCount,
|
||||
text: 'Stars',
|
||||
),
|
||||
EntryItem(
|
||||
count: data.forksCount,
|
||||
count: p.forksCount,
|
||||
text: 'Forks', // TODO:
|
||||
),
|
||||
],
|
||||
),
|
||||
CommonStyle.verticalGap,
|
||||
if (data.languages.isNotEmpty)
|
||||
Container(
|
||||
color: theme.palette.background,
|
||||
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(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
CommonStyle.border,
|
||||
TableView(
|
||||
hasIcon: true,
|
||||
items: [
|
||||
TableViewItem(
|
||||
leftIconData: Octicons.code,
|
||||
text: Text('Code'),
|
||||
url: '/projects/$id/tree',
|
||||
text: Text(langs.keys.isEmpty ? 'Code' : langs.keys.first),
|
||||
url: '/gitlab/projects/$id/tree',
|
||||
),
|
||||
if (data.issuesEnabled)
|
||||
if (p.issuesEnabled)
|
||||
TableViewItem(
|
||||
leftIconData: Octicons.issue_opened,
|
||||
text: Text('Issues'),
|
||||
rightWidget:
|
||||
Text(numberFormat.format(data.openIssuesCount)),
|
||||
rightWidget: Text(numberFormat.format(p.openIssuesCount)),
|
||||
url: '/gitlab/projects/$id/issues',
|
||||
),
|
||||
if (data.mergeRequestsEnabled)
|
||||
if (p.mergeRequestsEnabled)
|
||||
TableViewItem(
|
||||
leftIconData: Octicons.git_pull_request,
|
||||
text: Text('Merge requests'),
|
||||
url: '/gitlab/projects/$id/merge_requests',
|
||||
),
|
||||
],
|
||||
),
|
||||
CommonStyle.verticalGap,
|
||||
if (data.readme != null)
|
||||
if (t.item4 != null)
|
||||
Container(
|
||||
padding: CommonStyle.padding,
|
||||
color: theme.palette.background,
|
||||
child: MarkdownView(data.readme),
|
||||
child: MarkdownView(t.item4),
|
||||
),
|
||||
CommonStyle.verticalGap,
|
||||
],
|
||||
|
Loading…
x
Reference in New Issue
Block a user