mirror of
https://github.com/git-touch/git-touch
synced 2025-02-21 22:07:51 +01:00
feat(bb): repo screen
This commit is contained in:
parent
3542c36dcc
commit
7f2649c691
@ -53,6 +53,10 @@ void main() async {
|
|||||||
themeModel.router.define(GiteaRouter.prefix + screen.path,
|
themeModel.router.define(GiteaRouter.prefix + screen.path,
|
||||||
handler: Handler(handlerFunc: screen.handler));
|
handler: Handler(handlerFunc: screen.handler));
|
||||||
});
|
});
|
||||||
|
BitbucketRouter.routes.forEach((screen) {
|
||||||
|
themeModel.router.define(BitbucketRouter.prefix + screen.path,
|
||||||
|
handler: Handler(handlerFunc: screen.handler));
|
||||||
|
});
|
||||||
GithubRouter.routes.forEach((screen) {
|
GithubRouter.routes.forEach((screen) {
|
||||||
themeModel.router.define(GithubRouter.prefix + screen.path,
|
themeModel.router.define(GithubRouter.prefix + screen.path,
|
||||||
handler: Handler(handlerFunc: screen.handler));
|
handler: Handler(handlerFunc: screen.handler));
|
||||||
|
@ -284,6 +284,19 @@ class AuthModel with ChangeNotifier {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<String> fetchBbReadme(String p) async {
|
||||||
|
if (p.startsWith('/') && !p.startsWith('/api')) p = '/api/2.0$p';
|
||||||
|
final input = Uri.parse(p);
|
||||||
|
final uri = Uri.parse(activeAccount.domain).replace(
|
||||||
|
userInfo: '${activeAccount.login}:${activeAccount.appPassword}',
|
||||||
|
path: input.path,
|
||||||
|
query: input.query,
|
||||||
|
);
|
||||||
|
final res = await http.get(uri);
|
||||||
|
if (res.statusCode >= 400) return null;
|
||||||
|
return res.body;
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> init() async {
|
Future<void> init() async {
|
||||||
// Listen scheme
|
// Listen scheme
|
||||||
_sub = getUriLinksStream().listen(_onSchemeDetected, onError: (err) {
|
_sub = getUriLinksStream().listen(_onSchemeDetected, onError: (err) {
|
||||||
|
@ -14,15 +14,22 @@ class BbPagination {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@JsonSerializable(fieldRename: FieldRename.snake)
|
@JsonSerializable(fieldRename: FieldRename.snake)
|
||||||
class BbUser {
|
class BbRepoOwner {
|
||||||
String username;
|
|
||||||
String nickname;
|
String nickname;
|
||||||
String displayName;
|
String displayName;
|
||||||
String type; // user, team
|
String type; // user, team
|
||||||
bool isStaff;
|
|
||||||
DateTime createdOn;
|
|
||||||
Map<String, dynamic> links;
|
Map<String, dynamic> links;
|
||||||
String get avatarUrl => links['avatar']['href'];
|
String get avatarUrl => links['avatar']['href'];
|
||||||
|
BbRepoOwner();
|
||||||
|
factory BbRepoOwner.fromJson(Map<String, dynamic> json) =>
|
||||||
|
_$BbRepoOwnerFromJson(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonSerializable(fieldRename: FieldRename.snake)
|
||||||
|
class BbUser extends BbRepoOwner {
|
||||||
|
String username;
|
||||||
|
bool isStaff;
|
||||||
|
DateTime createdOn;
|
||||||
BbUser();
|
BbUser();
|
||||||
factory BbUser.fromJson(Map<String, dynamic> json) => _$BbUserFromJson(json);
|
factory BbUser.fromJson(Map<String, dynamic> json) => _$BbUserFromJson(json);
|
||||||
}
|
}
|
||||||
@ -30,7 +37,7 @@ class BbUser {
|
|||||||
@JsonSerializable(fieldRename: FieldRename.snake)
|
@JsonSerializable(fieldRename: FieldRename.snake)
|
||||||
class BbRepo {
|
class BbRepo {
|
||||||
String name;
|
String name;
|
||||||
BbUser owner;
|
BbRepoOwner owner;
|
||||||
String website;
|
String website;
|
||||||
String language;
|
String language;
|
||||||
int size;
|
int size;
|
||||||
@ -40,8 +47,19 @@ class BbRepo {
|
|||||||
DateTime updatedOn;
|
DateTime updatedOn;
|
||||||
String description;
|
String description;
|
||||||
String fullName;
|
String fullName;
|
||||||
|
String slug;
|
||||||
|
BbRepoMainbranch mainbranch;
|
||||||
Map<String, dynamic> links;
|
Map<String, dynamic> links;
|
||||||
String get avatarUrl => links['avatar']['href'];
|
String get avatarUrl => links['avatar']['href'];
|
||||||
BbRepo();
|
BbRepo();
|
||||||
factory BbRepo.fromJson(Map<String, dynamic> json) => _$BbRepoFromJson(json);
|
factory BbRepo.fromJson(Map<String, dynamic> json) => _$BbRepoFromJson(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonSerializable(fieldRename: FieldRename.snake)
|
||||||
|
class BbRepoMainbranch {
|
||||||
|
String type;
|
||||||
|
String name;
|
||||||
|
BbRepoMainbranch();
|
||||||
|
factory BbRepoMainbranch.fromJson(Map<String, dynamic> json) =>
|
||||||
|
_$BbRepoMainbranchFromJson(json);
|
||||||
|
}
|
||||||
|
@ -24,27 +24,43 @@ Map<String, dynamic> _$BbPaginationToJson(BbPagination instance) =>
|
|||||||
'values': instance.values,
|
'values': instance.values,
|
||||||
};
|
};
|
||||||
|
|
||||||
BbUser _$BbUserFromJson(Map<String, dynamic> json) {
|
BbRepoOwner _$BbRepoOwnerFromJson(Map<String, dynamic> json) {
|
||||||
return BbUser()
|
return BbRepoOwner()
|
||||||
..username = json['username'] as String
|
|
||||||
..nickname = json['nickname'] as String
|
..nickname = json['nickname'] as String
|
||||||
..displayName = json['display_name'] as String
|
..displayName = json['display_name'] as String
|
||||||
..type = json['type'] as String
|
..type = json['type'] as String
|
||||||
..isStaff = json['is_staff'] as bool
|
|
||||||
..createdOn = json['created_on'] == null
|
|
||||||
? null
|
|
||||||
: DateTime.parse(json['created_on'] as String)
|
|
||||||
..links = json['links'] as Map<String, dynamic>;
|
..links = json['links'] as Map<String, dynamic>;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> _$BbUserToJson(BbUser instance) => <String, dynamic>{
|
Map<String, dynamic> _$BbRepoOwnerToJson(BbRepoOwner instance) =>
|
||||||
'username': instance.username,
|
<String, dynamic>{
|
||||||
'nickname': instance.nickname,
|
'nickname': instance.nickname,
|
||||||
'display_name': instance.displayName,
|
'display_name': instance.displayName,
|
||||||
'type': instance.type,
|
'type': instance.type,
|
||||||
|
'links': instance.links,
|
||||||
|
};
|
||||||
|
|
||||||
|
BbUser _$BbUserFromJson(Map<String, dynamic> json) {
|
||||||
|
return BbUser()
|
||||||
|
..nickname = json['nickname'] as String
|
||||||
|
..displayName = json['display_name'] as String
|
||||||
|
..type = json['type'] as String
|
||||||
|
..links = json['links'] as Map<String, dynamic>
|
||||||
|
..username = json['username'] as String
|
||||||
|
..isStaff = json['is_staff'] as bool
|
||||||
|
..createdOn = json['created_on'] == null
|
||||||
|
? null
|
||||||
|
: DateTime.parse(json['created_on'] as String);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> _$BbUserToJson(BbUser instance) => <String, dynamic>{
|
||||||
|
'nickname': instance.nickname,
|
||||||
|
'display_name': instance.displayName,
|
||||||
|
'type': instance.type,
|
||||||
|
'links': instance.links,
|
||||||
|
'username': instance.username,
|
||||||
'is_staff': instance.isStaff,
|
'is_staff': instance.isStaff,
|
||||||
'created_on': instance.createdOn?.toIso8601String(),
|
'created_on': instance.createdOn?.toIso8601String(),
|
||||||
'links': instance.links,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
BbRepo _$BbRepoFromJson(Map<String, dynamic> json) {
|
BbRepo _$BbRepoFromJson(Map<String, dynamic> json) {
|
||||||
@ -52,7 +68,7 @@ BbRepo _$BbRepoFromJson(Map<String, dynamic> json) {
|
|||||||
..name = json['name'] as String
|
..name = json['name'] as String
|
||||||
..owner = json['owner'] == null
|
..owner = json['owner'] == null
|
||||||
? null
|
? null
|
||||||
: BbUser.fromJson(json['owner'] as Map<String, dynamic>)
|
: BbRepoOwner.fromJson(json['owner'] as Map<String, dynamic>)
|
||||||
..website = json['website'] as String
|
..website = json['website'] as String
|
||||||
..language = json['language'] as String
|
..language = json['language'] as String
|
||||||
..size = json['size'] as int
|
..size = json['size'] as int
|
||||||
@ -66,6 +82,10 @@ BbRepo _$BbRepoFromJson(Map<String, dynamic> json) {
|
|||||||
: DateTime.parse(json['updated_on'] as String)
|
: DateTime.parse(json['updated_on'] as String)
|
||||||
..description = json['description'] as String
|
..description = json['description'] as String
|
||||||
..fullName = json['full_name'] as String
|
..fullName = json['full_name'] as String
|
||||||
|
..slug = json['slug'] as String
|
||||||
|
..mainbranch = json['mainbranch'] == null
|
||||||
|
? null
|
||||||
|
: BbRepoMainbranch.fromJson(json['mainbranch'] as Map<String, dynamic>)
|
||||||
..links = json['links'] as Map<String, dynamic>;
|
..links = json['links'] as Map<String, dynamic>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,5 +101,19 @@ Map<String, dynamic> _$BbRepoToJson(BbRepo instance) => <String, dynamic>{
|
|||||||
'updated_on': instance.updatedOn?.toIso8601String(),
|
'updated_on': instance.updatedOn?.toIso8601String(),
|
||||||
'description': instance.description,
|
'description': instance.description,
|
||||||
'full_name': instance.fullName,
|
'full_name': instance.fullName,
|
||||||
|
'slug': instance.slug,
|
||||||
|
'mainbranch': instance.mainbranch,
|
||||||
'links': instance.links,
|
'links': instance.links,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
BbRepoMainbranch _$BbRepoMainbranchFromJson(Map<String, dynamic> json) {
|
||||||
|
return BbRepoMainbranch()
|
||||||
|
..type = json['type'] as String
|
||||||
|
..name = json['name'] as String;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> _$BbRepoMainbranchToJson(BbRepoMainbranch instance) =>
|
||||||
|
<String, dynamic>{
|
||||||
|
'type': instance.type,
|
||||||
|
'name': instance.name,
|
||||||
|
};
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
import 'package:fluro/fluro.dart';
|
import 'package:fluro/fluro.dart';
|
||||||
|
import 'package:git_touch/screens/bb_repo.dart';
|
||||||
|
import 'package:git_touch/screens/bb_user.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_commits.dart';
|
import 'package:git_touch/screens/gitea_commits.dart';
|
||||||
@ -232,3 +234,22 @@ class GiteaRouter {
|
|||||||
(_, p) =>
|
(_, p) =>
|
||||||
GiteaIssuesScreen(p['owner'].first, p['name'].first, isPr: true));
|
GiteaIssuesScreen(p['owner'].first, p['name'].first, isPr: true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class BitbucketRouter {
|
||||||
|
static const prefix = '/bitbucket';
|
||||||
|
static final routes = [
|
||||||
|
BitbucketRouter.user,
|
||||||
|
BitbucketRouter.repo,
|
||||||
|
];
|
||||||
|
static final user = RouterScreen(
|
||||||
|
'/:login',
|
||||||
|
(context, params) => params['team'].first == '1'
|
||||||
|
? BbUserScreen(params['login'].first)
|
||||||
|
: BbUserScreen(params['login'].first),
|
||||||
|
);
|
||||||
|
static final repo = RouterScreen(
|
||||||
|
'/:owner/:name',
|
||||||
|
(context, params) =>
|
||||||
|
BbRepoScreen(params['owner'].first, params['name'].first),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
76
lib/screens/bb_repo.dart
Normal file
76
lib/screens/bb_repo.dart
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
import 'package:filesize/filesize.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:git_touch/models/auth.dart';
|
||||||
|
import 'package:git_touch/models/bitbucket.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/app_bar_title.dart';
|
||||||
|
import 'package:git_touch/widgets/markdown_view.dart';
|
||||||
|
import 'package:git_touch/widgets/repo_header.dart';
|
||||||
|
import 'package:git_touch/widgets/table_view.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:tuple/tuple.dart';
|
||||||
|
|
||||||
|
class BbRepoScreen extends StatelessWidget {
|
||||||
|
final String owner;
|
||||||
|
final String name;
|
||||||
|
BbRepoScreen(this.owner, this.name);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return RefreshStatefulScaffold<Tuple2<BbRepo, String>>(
|
||||||
|
title: AppBarTitle('Repository'),
|
||||||
|
fetchData: () async {
|
||||||
|
final auth = Provider.of<AuthModel>(context);
|
||||||
|
final res = await auth.fetchBb('/repositories/$owner/$name');
|
||||||
|
final repo = BbRepo.fromJson(res);
|
||||||
|
final readme = await auth.fetchBbReadme(
|
||||||
|
'/repositories/$owner/$name/src/${repo.mainbranch.name}/README.md');
|
||||||
|
return Tuple2(repo, readme);
|
||||||
|
},
|
||||||
|
bodyBuilder: (t, setState) {
|
||||||
|
final theme = Provider.of<ThemeModel>(context);
|
||||||
|
final p = t.item1;
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: <Widget>[
|
||||||
|
RepoHeader(
|
||||||
|
avatarUrl: p.avatarUrl,
|
||||||
|
avatarLink: null,
|
||||||
|
owner: p.owner.displayName, // TODO:
|
||||||
|
name: p.slug,
|
||||||
|
description: p.description,
|
||||||
|
homepageUrl: p.website,
|
||||||
|
),
|
||||||
|
CommonStyle.border,
|
||||||
|
TableView(
|
||||||
|
hasIcon: true,
|
||||||
|
items: [
|
||||||
|
TableViewItem(
|
||||||
|
leftIconData: Octicons.code,
|
||||||
|
text: Text('Code'),
|
||||||
|
rightWidget: Text(filesize(p.size)),
|
||||||
|
url: '/bitbucket/$owner/$name/src/${p.mainbranch.name}',
|
||||||
|
),
|
||||||
|
TableViewItem(
|
||||||
|
leftIconData: Octicons.history,
|
||||||
|
text: Text('Commits'),
|
||||||
|
url: '/bitbucket/$owner/$name/commits',
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
CommonStyle.verticalGap,
|
||||||
|
if (t.item2 != null)
|
||||||
|
Container(
|
||||||
|
padding: CommonStyle.padding,
|
||||||
|
color: theme.palette.background,
|
||||||
|
child: MarkdownView(t.item2),
|
||||||
|
),
|
||||||
|
CommonStyle.verticalGap,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user