mirror of
https://github.com/git-touch/git-touch
synced 2025-03-21 05:30:07 +01:00
feat(gitlab): repository tree screen
This commit is contained in:
parent
2636e902f2
commit
edd3a8d02e
@ -132,6 +132,11 @@ class AuthModel with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> fetchWithGitlabToken(String p) async {
|
||||
final res = await http.get(p, headers: {'Private-Token': token});
|
||||
return res.body;
|
||||
}
|
||||
|
||||
Future fetchGitlab(String p) async {
|
||||
final res = await http.get(activeAccount.domain + '/api/v4' + p,
|
||||
headers: {'Private-Token': token});
|
||||
|
@ -121,3 +121,14 @@ class GitlabProjectNamespace {
|
||||
factory GitlabProjectNamespace.fromJson(Map<String, dynamic> json) =>
|
||||
_$GitlabProjectNamespaceFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable(fieldRename: FieldRename.snake)
|
||||
class GitlabTreeItem {
|
||||
String type;
|
||||
String path;
|
||||
|
||||
GitlabTreeItem();
|
||||
|
||||
factory GitlabTreeItem.fromJson(Map<String, dynamic> json) =>
|
||||
_$GitlabTreeItemFromJson(json);
|
||||
}
|
||||
|
@ -166,3 +166,15 @@ Map<String, dynamic> _$GitlabProjectNamespaceToJson(
|
||||
'id': instance.id,
|
||||
'name': instance.name,
|
||||
};
|
||||
|
||||
GitlabTreeItem _$GitlabTreeItemFromJson(Map<String, dynamic> json) {
|
||||
return GitlabTreeItem()
|
||||
..type = json['type'] as String
|
||||
..path = json['path'] as String;
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$GitlabTreeItemToJson(GitlabTreeItem instance) =>
|
||||
<String, dynamic>{
|
||||
'type': instance.type,
|
||||
'path': instance.path,
|
||||
};
|
||||
|
@ -3,6 +3,7 @@ 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/screens/gitlab_tree.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';
|
||||
@ -115,7 +116,7 @@ class GitlabProjectScreen extends StatelessWidget {
|
||||
TableViewItem(
|
||||
leftIconData: Octicons.code,
|
||||
text: Text('Code'),
|
||||
// screenBuilder: (_) => GitlabObjectScreen(),
|
||||
screenBuilder: (_) => GitlabTreeScreen(data.id),
|
||||
),
|
||||
if (data.issuesEnabled)
|
||||
TableViewItem(
|
||||
|
73
lib/screens/gitlab_tree.dart
Normal file
73
lib/screens/gitlab_tree.dart
Normal file
@ -0,0 +1,73 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:git_touch/models/gitlab.dart';
|
||||
import 'package:git_touch/scaffolds/refresh_stateful.dart';
|
||||
import 'package:git_touch/widgets/app_bar_title.dart';
|
||||
import 'package:git_touch/widgets/table_view.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:git_touch/models/auth.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:git_touch/utils/utils.dart';
|
||||
import 'package:primer/primer.dart';
|
||||
import 'package:seti/seti.dart';
|
||||
|
||||
class GitlabTreeScreen extends StatelessWidget {
|
||||
final int id;
|
||||
final List<String> paths;
|
||||
|
||||
GitlabTreeScreen(this.id, {this.paths = const []});
|
||||
|
||||
String get _path => paths.join('/');
|
||||
|
||||
static const _iconDefaultColor = PrimerColors.blue300;
|
||||
|
||||
Widget _buildIcon(GitlabTreeItem item) {
|
||||
switch (item.type) {
|
||||
case 'blob':
|
||||
return SetiIcon(item.path, size: 36);
|
||||
case 'tree':
|
||||
case 'commit':
|
||||
return Icon(
|
||||
item.type == 'tree'
|
||||
? Octicons.file_directory
|
||||
: Octicons.file_submodule,
|
||||
color: _iconDefaultColor,
|
||||
size: 24,
|
||||
);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return RefreshStatefulScaffold<Iterable<GitlabTreeItem>>(
|
||||
title: AppBarTitle(_path.isEmpty ? 'Files' : _path),
|
||||
fetchData: () async {
|
||||
var url = '/projects/$id/repository/tree';
|
||||
if (paths.isNotEmpty) {
|
||||
url += '?path=' + paths.join('/');
|
||||
}
|
||||
final res = await Provider.of<AuthModel>(context).fetchGitlab(url);
|
||||
return (res as List).map((v) => GitlabTreeItem.fromJson(v));
|
||||
},
|
||||
bodyBuilder: (data, _) {
|
||||
return TableView(
|
||||
hasIcon: true,
|
||||
items: data.map((item) {
|
||||
return TableViewItem(
|
||||
leftWidget: _buildIcon(item),
|
||||
text: Text(item.path),
|
||||
screenBuilder: (_) {
|
||||
if (item.type == 'commit') return null;
|
||||
return GitlabTreeScreen(
|
||||
id,
|
||||
paths: [...paths, item.path],
|
||||
);
|
||||
},
|
||||
);
|
||||
}),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user