mirror of
https://github.com/git-touch/git-touch
synced 2025-03-05 19:57:42 +01:00
feat(gitea): blob screen
This commit is contained in:
parent
f604d467dc
commit
9d6985c391
@ -7,6 +7,7 @@ import 'package:git_touch/models/theme.dart';
|
|||||||
import 'package:git_touch/screens/about.dart';
|
import 'package:git_touch/screens/about.dart';
|
||||||
import 'package:git_touch/screens/code_theme.dart';
|
import 'package:git_touch/screens/code_theme.dart';
|
||||||
import 'package:git_touch/screens/commits.dart';
|
import 'package:git_touch/screens/commits.dart';
|
||||||
|
import 'package:git_touch/screens/gitea_object.dart';
|
||||||
import 'package:git_touch/screens/gitea_repo.dart';
|
import 'package:git_touch/screens/gitea_repo.dart';
|
||||||
import 'package:git_touch/screens/gitea_user.dart';
|
import 'package:git_touch/screens/gitea_user.dart';
|
||||||
import 'package:git_touch/screens/gitlab_blob.dart';
|
import 'package:git_touch/screens/gitlab_blob.dart';
|
||||||
@ -78,6 +79,7 @@ void main() async {
|
|||||||
gitlabCommitsRouter,
|
gitlabCommitsRouter,
|
||||||
giteaUserRouter,
|
giteaUserRouter,
|
||||||
giteaRepoRouter,
|
giteaRepoRouter,
|
||||||
|
giteaObjectRouter,
|
||||||
loginRouter,
|
loginRouter,
|
||||||
settingsRouter,
|
settingsRouter,
|
||||||
userRouter,
|
userRouter,
|
||||||
|
@ -31,3 +31,21 @@ class GiteaRepository {
|
|||||||
factory GiteaRepository.fromJson(Map<String, dynamic> json) =>
|
factory GiteaRepository.fromJson(Map<String, dynamic> json) =>
|
||||||
_$GiteaRepositoryFromJson(json);
|
_$GiteaRepositoryFromJson(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonSerializable(fieldRename: FieldRename.snake)
|
||||||
|
class GiteaTree {
|
||||||
|
String type;
|
||||||
|
String name;
|
||||||
|
String path;
|
||||||
|
GiteaTree();
|
||||||
|
factory GiteaTree.fromJson(Map<String, dynamic> json) =>
|
||||||
|
_$GiteaTreeFromJson(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonSerializable(fieldRename: FieldRename.snake)
|
||||||
|
class GiteaBlob extends GiteaTree {
|
||||||
|
String content;
|
||||||
|
GiteaBlob();
|
||||||
|
factory GiteaBlob.fromJson(Map<String, dynamic> json) =>
|
||||||
|
_$GiteaBlobFromJson(json);
|
||||||
|
}
|
||||||
|
@ -58,3 +58,31 @@ Map<String, dynamic> _$GiteaRepositoryToJson(GiteaRepository instance) =>
|
|||||||
'open_issues_count': instance.openIssuesCount,
|
'open_issues_count': instance.openIssuesCount,
|
||||||
'open_pr_counter': instance.openPrCounter,
|
'open_pr_counter': instance.openPrCounter,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GiteaTree _$GiteaTreeFromJson(Map<String, dynamic> json) {
|
||||||
|
return GiteaTree()
|
||||||
|
..type = json['type'] as String
|
||||||
|
..name = json['name'] as String
|
||||||
|
..path = json['path'] as String;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> _$GiteaTreeToJson(GiteaTree instance) => <String, dynamic>{
|
||||||
|
'type': instance.type,
|
||||||
|
'name': instance.name,
|
||||||
|
'path': instance.path,
|
||||||
|
};
|
||||||
|
|
||||||
|
GiteaBlob _$GiteaBlobFromJson(Map<String, dynamic> json) {
|
||||||
|
return GiteaBlob()
|
||||||
|
..type = json['type'] as String
|
||||||
|
..name = json['name'] as String
|
||||||
|
..path = json['path'] as String
|
||||||
|
..content = json['content'] as String;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> _$GiteaBlobToJson(GiteaBlob instance) => <String, dynamic>{
|
||||||
|
'type': instance.type,
|
||||||
|
'name': instance.name,
|
||||||
|
'path': instance.path,
|
||||||
|
'content': instance.content,
|
||||||
|
};
|
||||||
|
70
lib/screens/gitea_object.dart
Normal file
70
lib/screens/gitea_object.dart
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:git_touch/models/auth.dart';
|
||||||
|
import 'package:git_touch/models/gitea.dart';
|
||||||
|
import 'package:git_touch/models/theme.dart';
|
||||||
|
import 'package:git_touch/scaffolds/refresh_stateful.dart';
|
||||||
|
import 'package:git_touch/utils/utils.dart';
|
||||||
|
import 'package:git_touch/widgets/action_entry.dart';
|
||||||
|
import 'package:git_touch/widgets/app_bar_title.dart';
|
||||||
|
import 'package:git_touch/widgets/blob_view.dart';
|
||||||
|
import 'package:git_touch/widgets/object_tree.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
|
final giteaObjectRouter = RouterScreen(
|
||||||
|
'/gitea/:owner/:name/blob',
|
||||||
|
(context, params) => GiteaObjectScreen(
|
||||||
|
params['owner'].first,
|
||||||
|
params['name'].first,
|
||||||
|
path: params['path']?.first?.urldecode,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
class GiteaObjectScreen extends StatelessWidget {
|
||||||
|
final String owner;
|
||||||
|
final String name;
|
||||||
|
final String path;
|
||||||
|
GiteaObjectScreen(this.owner, this.name, {this.path});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return RefreshStatefulScaffold(
|
||||||
|
title: AppBarTitle(path ?? 'Files'),
|
||||||
|
fetchData: () async {
|
||||||
|
final suffix = path == null ? '' : '/$path';
|
||||||
|
final res = await Provider.of<AuthModel>(context)
|
||||||
|
.fetchGitea('/repos/$owner/$name/contents$suffix');
|
||||||
|
return res;
|
||||||
|
},
|
||||||
|
actionBuilder: (p, _) {
|
||||||
|
if (p is List) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
final theme = Provider.of<ThemeModel>(context);
|
||||||
|
return ActionEntry(
|
||||||
|
iconData: Icons.settings,
|
||||||
|
onTap: () {
|
||||||
|
theme.push(context, '/choose-code-theme');
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
bodyBuilder: (p, _) {
|
||||||
|
if (p is List) {
|
||||||
|
return ObjectTree(
|
||||||
|
items: p.map((t) {
|
||||||
|
final v = GiteaTree.fromJson(t);
|
||||||
|
return ObjectTreeItem(
|
||||||
|
name: v.name,
|
||||||
|
type: v.type,
|
||||||
|
url: '/gitea/$owner/$name/blob?path=${v.path.urlencode}',
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
final v = GiteaBlob.fromJson(p);
|
||||||
|
return BlobView(v.name, base64Text: v.content);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -74,7 +74,7 @@ class GiteaRepoScreen extends StatelessWidget {
|
|||||||
leftIconData: Octicons.code,
|
leftIconData: Octicons.code,
|
||||||
text: Text('Code'),
|
text: Text('Code'),
|
||||||
rightWidget: Text(filesize(p.size * 1000)),
|
rightWidget: Text(filesize(p.size * 1000)),
|
||||||
url: '/gitea/blob',
|
url: '/gitea/$owner/$name/blob',
|
||||||
),
|
),
|
||||||
TableViewItem(
|
TableViewItem(
|
||||||
leftIconData: Octicons.issue_opened,
|
leftIconData: Octicons.issue_opened,
|
||||||
|
@ -22,8 +22,10 @@ class ObjectTree extends StatelessWidget {
|
|||||||
Widget _buildIcon(ObjectTreeItem item) {
|
Widget _buildIcon(ObjectTreeItem item) {
|
||||||
switch (item.type) {
|
switch (item.type) {
|
||||||
case 'blob':
|
case 'blob':
|
||||||
|
case 'file': // Gitea
|
||||||
return SetiIcon(item.name, size: 36);
|
return SetiIcon(item.name, size: 36);
|
||||||
case 'tree':
|
case 'tree':
|
||||||
|
case 'dir': // Gitea
|
||||||
return Icon(
|
return Icon(
|
||||||
Octicons.file_directory,
|
Octicons.file_directory,
|
||||||
color: PrimerColors.blue300,
|
color: PrimerColors.blue300,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user