mirror of
https://github.com/git-touch/git-touch
synced 2025-02-20 13:30:38 +01:00
feat(gitlab): issues screen
This commit is contained in:
parent
8012ea6544
commit
2c9951be7b
@ -10,6 +10,7 @@ import 'package:git_touch/screens/commits.dart';
|
||||
import 'package:git_touch/screens/gitlab_blob.dart';
|
||||
import 'package:git_touch/screens/gitlab_commits.dart';
|
||||
import 'package:git_touch/screens/gitlab_issue.dart';
|
||||
import 'package:git_touch/screens/gitlab_issues.dart';
|
||||
import 'package:git_touch/screens/gitlab_project.dart';
|
||||
import 'package:git_touch/screens/gitlab_tree.dart';
|
||||
import 'package:git_touch/screens/gitlab_user.dart';
|
||||
@ -69,6 +70,7 @@ void main() async {
|
||||
gitlabTreeRouter,
|
||||
gitlabProjectRouter,
|
||||
gitlabIssueRouter,
|
||||
gitlabIssuesRouter,
|
||||
gitlabCommitsRouter,
|
||||
loginRouter,
|
||||
settingsRouter,
|
||||
|
@ -47,7 +47,7 @@ class GitlabTodo {
|
||||
GitlabTodoProject project;
|
||||
String actionName;
|
||||
String targetType;
|
||||
GitlabIssue target;
|
||||
GitlabTodoTarget target;
|
||||
|
||||
GitlabTodo();
|
||||
|
||||
@ -56,7 +56,7 @@ class GitlabTodo {
|
||||
}
|
||||
|
||||
@JsonSerializable(fieldRename: FieldRename.snake)
|
||||
class GitlabIssue {
|
||||
class GitlabTodoTarget {
|
||||
int iid;
|
||||
int projectId;
|
||||
String title;
|
||||
@ -64,10 +64,10 @@ class GitlabIssue {
|
||||
String description;
|
||||
String createdAt;
|
||||
|
||||
GitlabIssue();
|
||||
GitlabTodoTarget();
|
||||
|
||||
factory GitlabIssue.fromJson(Map<String, dynamic> json) =>
|
||||
_$GitlabIssueFromJson(json);
|
||||
factory GitlabTodoTarget.fromJson(Map<String, dynamic> json) =>
|
||||
_$GitlabTodoTargetFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable(fieldRename: FieldRename.snake)
|
||||
@ -188,3 +188,17 @@ class GitlabCommit {
|
||||
factory GitlabCommit.fromJson(Map<String, dynamic> json) =>
|
||||
_$GitlabCommitFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable(fieldRename: FieldRename.snake)
|
||||
class GitlabIssue {
|
||||
String title;
|
||||
int iid;
|
||||
int projectId;
|
||||
GitlabUser author;
|
||||
int userNotesCount;
|
||||
DateTime updatedAt;
|
||||
List<String> labels;
|
||||
GitlabIssue();
|
||||
factory GitlabIssue.fromJson(Map<String, dynamic> json) =>
|
||||
_$GitlabIssueFromJson(json);
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ GitlabTodo _$GitlabTodoFromJson(Map<String, dynamic> json) {
|
||||
..targetType = json['target_type'] as String
|
||||
..target = json['target'] == null
|
||||
? null
|
||||
: GitlabIssue.fromJson(json['target'] as Map<String, dynamic>);
|
||||
: GitlabTodoTarget.fromJson(json['target'] as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$GitlabTodoToJson(GitlabTodo instance) =>
|
||||
@ -80,8 +80,8 @@ Map<String, dynamic> _$GitlabTodoToJson(GitlabTodo instance) =>
|
||||
'target': instance.target,
|
||||
};
|
||||
|
||||
GitlabIssue _$GitlabIssueFromJson(Map<String, dynamic> json) {
|
||||
return GitlabIssue()
|
||||
GitlabTodoTarget _$GitlabTodoTargetFromJson(Map<String, dynamic> json) {
|
||||
return GitlabTodoTarget()
|
||||
..iid = json['iid'] as int
|
||||
..projectId = json['project_id'] as int
|
||||
..title = json['title'] as String
|
||||
@ -92,7 +92,7 @@ GitlabIssue _$GitlabIssueFromJson(Map<String, dynamic> json) {
|
||||
..createdAt = json['created_at'] as String;
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$GitlabIssueToJson(GitlabIssue instance) =>
|
||||
Map<String, dynamic> _$GitlabTodoTargetToJson(GitlabTodoTarget instance) =>
|
||||
<String, dynamic>{
|
||||
'iid': instance.iid,
|
||||
'project_id': instance.projectId,
|
||||
@ -274,3 +274,29 @@ Map<String, dynamic> _$GitlabCommitToJson(GitlabCommit instance) =>
|
||||
'author_name': instance.authorName,
|
||||
'message': instance.message,
|
||||
};
|
||||
|
||||
GitlabIssue _$GitlabIssueFromJson(Map<String, dynamic> json) {
|
||||
return GitlabIssue()
|
||||
..title = json['title'] as String
|
||||
..iid = json['iid'] as int
|
||||
..projectId = json['project_id'] as int
|
||||
..author = json['author'] == null
|
||||
? null
|
||||
: GitlabUser.fromJson(json['author'] as Map<String, dynamic>)
|
||||
..userNotesCount = json['user_notes_count'] as int
|
||||
..updatedAt = json['updated_at'] == null
|
||||
? null
|
||||
: DateTime.parse(json['updated_at'] as String)
|
||||
..labels = (json['labels'] as List)?.map((e) => e as String)?.toList();
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$GitlabIssueToJson(GitlabIssue instance) =>
|
||||
<String, dynamic>{
|
||||
'title': instance.title,
|
||||
'iid': instance.iid,
|
||||
'project_id': instance.projectId,
|
||||
'author': instance.author,
|
||||
'user_notes_count': instance.userNotesCount,
|
||||
'updated_at': instance.updatedAt?.toIso8601String(),
|
||||
'labels': instance.labels,
|
||||
};
|
||||
|
@ -24,7 +24,7 @@ class GitlabIssueScreen extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return RefreshStatefulScaffold<
|
||||
Tuple3<GitlabIssue, Iterable<GitlabIssueNote>, List>>(
|
||||
Tuple3<GitlabTodoTarget, Iterable<GitlabIssueNote>, List>>(
|
||||
title: Text('Issue #$iid'),
|
||||
fetchData: () async {
|
||||
final type = isMr ? 'merge_requests' : 'issues';
|
||||
@ -37,7 +37,7 @@ class GitlabIssueScreen extends StatelessWidget {
|
||||
.fetchGitlab('/projects/$projectId/$type/$iid/award_emoji'),
|
||||
]);
|
||||
return Tuple3(
|
||||
GitlabIssue.fromJson(items[0]),
|
||||
GitlabTodoTarget.fromJson(items[0]),
|
||||
(items[1] as List).map((v) => GitlabIssueNote.fromJson(v)),
|
||||
items[2] as List,
|
||||
);
|
||||
|
54
lib/screens/gitlab_issues.dart
Normal file
54
lib/screens/gitlab_issues.dart
Normal file
@ -0,0 +1,54 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:git_touch/models/auth.dart';
|
||||
import 'package:git_touch/models/gitlab.dart';
|
||||
import 'package:git_touch/scaffolds/list_stateful.dart';
|
||||
import 'package:git_touch/utils/utils.dart';
|
||||
import 'package:git_touch/widgets/app_bar_title.dart';
|
||||
import 'package:git_touch/widgets/issue_item.dart';
|
||||
import 'package:git_touch/widgets/label.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
final gitlabIssuesRouter = RouterScreen('/gitlab/projects/:id/issues',
|
||||
(context, params) => GitlabIssuesScreen(params['id'].first));
|
||||
|
||||
class GitlabIssuesScreen extends StatelessWidget {
|
||||
final String id;
|
||||
|
||||
GitlabIssuesScreen(this.id);
|
||||
|
||||
Future<ListPayload<GitlabIssue, int>> _query(BuildContext context,
|
||||
[int page = 1]) async {
|
||||
final res = await Provider.of<AuthModel>(context)
|
||||
.fetchGitlab('/projects/$id/issues?page=$page');
|
||||
return ListPayload(
|
||||
cursor: page + 1,
|
||||
hasMore: true, // TODO:
|
||||
items: (res as List).map((v) => GitlabIssue.fromJson(v)).toList(),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListStatefulScaffold<GitlabIssue, int>(
|
||||
title: AppBarTitle('Issues'),
|
||||
// TODO: create issue
|
||||
onRefresh: () => _query(context),
|
||||
onLoadMore: (cursor) => _query(context, cursor),
|
||||
itemBuilder: (p) => IssueItem(
|
||||
author: p.author.username,
|
||||
avatarUrl: p.author.avatarUrl,
|
||||
commentCount: p.userNotesCount,
|
||||
number: p.iid,
|
||||
title: p.title,
|
||||
updatedAt: p.updatedAt,
|
||||
labels: p.labels.isEmpty
|
||||
? null
|
||||
: Wrap(spacing: 4, runSpacing: 4, children: [
|
||||
for (var label in p.labels)
|
||||
MyLabel(name: label, cssColor: '#428BCA')
|
||||
]),
|
||||
url: '/gitlab/projects/${p.projectId}/issues/${p.iid}',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user