2019-11-01 18:12:17 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:git_touch/models/auth.dart';
|
2019-12-04 15:00:39 +01:00
|
|
|
import 'package:git_touch/models/gitlab.dart';
|
2019-11-08 11:29:08 +01:00
|
|
|
import 'package:git_touch/models/theme.dart';
|
2019-11-01 18:12:17 +01:00
|
|
|
import 'package:git_touch/scaffolds/refresh_stateful.dart';
|
|
|
|
import 'package:git_touch/utils/utils.dart';
|
|
|
|
import 'package:git_touch/widgets/avatar.dart';
|
|
|
|
import 'package:git_touch/widgets/link.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
class GitlabTodosScreen extends StatelessWidget {
|
2019-12-30 14:25:02 +01:00
|
|
|
InlineSpan _buildActor(BuildContext context, GitlabTodo p) {
|
|
|
|
final theme = Provider.of<ThemeModel>(context);
|
|
|
|
return TextSpan(
|
|
|
|
text: p.author.name,
|
2020-01-14 11:13:07 +01:00
|
|
|
style: TextStyle(color: theme.paletteOf(context).primary),
|
2019-12-30 14:25:02 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
InlineSpan _buildIssue(BuildContext context, GitlabTodo p) {
|
|
|
|
final theme = Provider.of<ThemeModel>(context);
|
|
|
|
return TextSpan(
|
|
|
|
text: '${p.project.pathWithNamespace}!${p.target.iid}',
|
2020-01-14 11:13:07 +01:00
|
|
|
style: TextStyle(color: theme.paletteOf(context).primary),
|
2019-12-30 14:25:02 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Iterable<InlineSpan> _buildItem(BuildContext context, GitlabTodo p) {
|
|
|
|
switch (p.actionName) {
|
|
|
|
case 'mentioned':
|
|
|
|
return [
|
|
|
|
_buildActor(context, p),
|
|
|
|
TextSpan(text: ' mentioned you on ${p.targetType} '),
|
|
|
|
_buildIssue(context, p),
|
|
|
|
];
|
|
|
|
case 'build_failed':
|
|
|
|
return [
|
|
|
|
TextSpan(text: ' the build failed for ${p.targetType} '),
|
|
|
|
_buildIssue(context, p),
|
|
|
|
];
|
|
|
|
case 'directly_addressed':
|
|
|
|
return [
|
|
|
|
_buildActor(context, p),
|
|
|
|
TextSpan(text: ' directly addressed you ${p.targetType} '),
|
|
|
|
_buildIssue(context, p),
|
|
|
|
];
|
|
|
|
case 'assigned':
|
|
|
|
return [
|
|
|
|
_buildActor(context, p),
|
|
|
|
TextSpan(text: ' directly addressed you ${p.targetType} '),
|
|
|
|
_buildIssue(context, p),
|
|
|
|
];
|
|
|
|
default:
|
|
|
|
return [
|
|
|
|
TextSpan(text: ' action type ${p.actionName} not implemented yet')
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-01 18:12:17 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2019-11-08 11:29:08 +01:00
|
|
|
final theme = Provider.of<ThemeModel>(context);
|
|
|
|
|
2019-12-04 15:00:39 +01:00
|
|
|
return RefreshStatefulScaffold<Iterable<GitlabTodo>>(
|
2019-11-01 18:12:17 +01:00
|
|
|
title: Text('Todos'),
|
2019-12-04 15:00:39 +01:00
|
|
|
fetchData: () async {
|
|
|
|
final vs = await Provider.of<AuthModel>(context).fetchGitlab('/todos');
|
|
|
|
return (vs as List).map((v) => GitlabTodo.fromJson(v));
|
2019-11-01 18:12:17 +01:00
|
|
|
},
|
2019-11-02 13:54:23 +01:00
|
|
|
bodyBuilder: (data, _) {
|
2019-11-01 18:12:17 +01:00
|
|
|
return Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
2019-12-04 15:00:39 +01:00
|
|
|
children: data.map((item) {
|
2019-11-01 18:12:17 +01:00
|
|
|
return Link(
|
2019-12-13 04:02:05 +01:00
|
|
|
url:
|
2019-12-14 17:08:12 +01:00
|
|
|
'/projects/${item.target.projectId}/${item.targetType == 'MergeRequest' ? 'merge_requests' : 'issue'}/${item.target.iid}',
|
2019-11-01 18:12:17 +01:00
|
|
|
child: Container(
|
|
|
|
padding: CommonStyle.padding,
|
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
2019-12-30 14:25:02 +01:00
|
|
|
GitlabAvatar(
|
|
|
|
url: item.author.avatarUrl, id: item.author.id),
|
2019-11-01 18:12:17 +01:00
|
|
|
SizedBox(width: 12),
|
|
|
|
Expanded(
|
|
|
|
child: Text.rich(
|
|
|
|
TextSpan(
|
2019-12-30 14:25:02 +01:00
|
|
|
style: TextStyle(
|
2020-01-14 11:13:07 +01:00
|
|
|
color: theme.paletteOf(context).text,
|
|
|
|
fontSize: 17),
|
2019-11-01 18:12:17 +01:00
|
|
|
children: [
|
2019-12-30 14:25:02 +01:00
|
|
|
..._buildItem(context, item),
|
2019-11-01 18:12:17 +01:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}).toList(),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|