mirror of
https://github.com/pd4d10/git-touch.git
synced 2026-03-26 04:42:35 -05:00
feat(gitlab): project activity screen
This commit is contained in:
@@ -143,3 +143,28 @@ class GitlabBlob {
|
||||
factory GitlabBlob.fromJson(Map<String, dynamic> json) =>
|
||||
_$GitlabBlobFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable(fieldRename: FieldRename.snake)
|
||||
class GitlabEvent {
|
||||
GitlabUser author;
|
||||
String actionName;
|
||||
String targetType;
|
||||
GitlabEventNote note;
|
||||
|
||||
GitlabEvent();
|
||||
|
||||
factory GitlabEvent.fromJson(Map<String, dynamic> json) =>
|
||||
_$GitlabEventFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable(fieldRename: FieldRename.snake)
|
||||
class GitlabEventNote {
|
||||
String body;
|
||||
String noteableType;
|
||||
int noteableIid;
|
||||
|
||||
GitlabEventNote();
|
||||
|
||||
factory GitlabEventNote.fromJson(Map<String, dynamic> json) =>
|
||||
_$GitlabEventNoteFromJson(json);
|
||||
}
|
||||
|
||||
@@ -189,3 +189,37 @@ Map<String, dynamic> _$GitlabBlobToJson(GitlabBlob instance) =>
|
||||
<String, dynamic>{
|
||||
'content': instance.content,
|
||||
};
|
||||
|
||||
GitlabEvent _$GitlabEventFromJson(Map<String, dynamic> json) {
|
||||
return GitlabEvent()
|
||||
..author = json['author'] == null
|
||||
? null
|
||||
: GitlabUser.fromJson(json['author'] as Map<String, dynamic>)
|
||||
..actionName = json['action_name'] as String
|
||||
..targetType = json['target_type'] as String
|
||||
..note = json['note'] == null
|
||||
? null
|
||||
: GitlabEventNote.fromJson(json['note'] as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$GitlabEventToJson(GitlabEvent instance) =>
|
||||
<String, dynamic>{
|
||||
'author': instance.author,
|
||||
'action_name': instance.actionName,
|
||||
'target_type': instance.targetType,
|
||||
'note': instance.note,
|
||||
};
|
||||
|
||||
GitlabEventNote _$GitlabEventNoteFromJson(Map<String, dynamic> json) {
|
||||
return GitlabEventNote()
|
||||
..body = json['body'] as String
|
||||
..noteableType = json['noteable_type'] as String
|
||||
..noteableIid = json['noteable_iid'] as int;
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$GitlabEventNoteToJson(GitlabEventNote instance) =>
|
||||
<String, dynamic>{
|
||||
'body': instance.body,
|
||||
'noteable_type': instance.noteableType,
|
||||
'noteable_iid': instance.noteableIid,
|
||||
};
|
||||
|
||||
70
lib/screens/gitlab_project_activity.dart
Normal file
70
lib/screens/gitlab_project_activity.dart
Normal file
@@ -0,0 +1,70 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:git_touch/models/auth.dart';
|
||||
import 'package:git_touch/models/gitlab.dart';
|
||||
import 'package:git_touch/models/theme.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/avatar.dart';
|
||||
import 'package:git_touch/widgets/link.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class GitlabProjectActivity extends StatelessWidget {
|
||||
final int id;
|
||||
|
||||
GitlabProjectActivity(this.id);
|
||||
|
||||
Future<ListPayload<GitlabEvent, int>> _query(BuildContext context,
|
||||
[int page]) async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final vs = await auth.fetchGitlab('/projects/$id/events');
|
||||
final events = (vs as List).map((v) => GitlabEvent.fromJson(v)).toList();
|
||||
return ListPayload(cursor: page, items: events, hasMore: false);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Provider.of<ThemeModel>(context);
|
||||
return ListStatefulScaffold<GitlabEvent, int>(
|
||||
title: AppBarTitle('Activity'),
|
||||
onRefresh: () => _query(context),
|
||||
onLoadMore: (int page) => _query(context, page),
|
||||
itemBuilder: (data) {
|
||||
return Link(
|
||||
url: '',
|
||||
child: Container(
|
||||
padding: CommonStyle.padding,
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Avatar.medium(url: data.author.avatarUrl),
|
||||
SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Text.rich(
|
||||
TextSpan(
|
||||
children: [
|
||||
TextSpan(
|
||||
text: data.author.name,
|
||||
style: TextStyle(
|
||||
color: theme.palette.primary,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
TextSpan(
|
||||
text: ' ' + data.actionName + data.targetType),
|
||||
],
|
||||
),
|
||||
),
|
||||
Text(data.note.body)
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user