feat(bb): object screen
This commit is contained in:
parent
376b8724a4
commit
a9f9b95793
|
@ -260,7 +260,7 @@ class AuthModel with ChangeNotifier {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future fetchBb(String p) async {
|
Future<http.Response> fetchBb(String p) async {
|
||||||
if (p.startsWith('/') && !p.startsWith('/api')) p = '/api/2.0$p';
|
if (p.startsWith('/') && !p.startsWith('/api')) p = '/api/2.0$p';
|
||||||
final input = Uri.parse(p);
|
final input = Uri.parse(p);
|
||||||
final uri = Uri.parse(activeAccount.domain).replace(
|
final uri = Uri.parse(activeAccount.domain).replace(
|
||||||
|
@ -268,14 +268,17 @@ class AuthModel with ChangeNotifier {
|
||||||
path: input.path,
|
path: input.path,
|
||||||
query: input.query,
|
query: input.query,
|
||||||
);
|
);
|
||||||
final res = await http.get(uri);
|
return http.get(uri);
|
||||||
final info = json.decode(utf8.decode(res.bodyBytes));
|
}
|
||||||
return info;
|
|
||||||
|
Future fetchBbJson(String p) async {
|
||||||
|
final res = await fetchBb(p);
|
||||||
|
return json.decode(utf8.decode(res.bodyBytes));
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<BbPagePayload<List>> fetchBbWithPage(String p) async {
|
Future<BbPagePayload<List>> fetchBbWithPage(String p) async {
|
||||||
final res = await fetchBb(p);
|
final data = await fetchBbJson(p);
|
||||||
final v = BbPagination.fromJson(res);
|
final v = BbPagination.fromJson(data);
|
||||||
return BbPagePayload(
|
return BbPagePayload(
|
||||||
cursor: v.next,
|
cursor: v.next,
|
||||||
total: v.size,
|
total: v.size,
|
||||||
|
@ -285,14 +288,7 @@ class AuthModel with ChangeNotifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String> fetchBbReadme(String p) async {
|
Future<String> fetchBbReadme(String p) async {
|
||||||
if (p.startsWith('/') && !p.startsWith('/api')) p = '/api/2.0$p';
|
final res = await fetchBb(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;
|
if (res.statusCode >= 400) return null;
|
||||||
return res.body;
|
return res.body;
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,3 +64,12 @@ class BbRepoMainbranch {
|
||||||
factory BbRepoMainbranch.fromJson(Map<String, dynamic> json) =>
|
factory BbRepoMainbranch.fromJson(Map<String, dynamic> json) =>
|
||||||
_$BbRepoMainbranchFromJson(json);
|
_$BbRepoMainbranchFromJson(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonSerializable(fieldRename: FieldRename.snake)
|
||||||
|
class BbTree {
|
||||||
|
String type;
|
||||||
|
String path;
|
||||||
|
int size;
|
||||||
|
BbTree();
|
||||||
|
factory BbTree.fromJson(Map<String, dynamic> json) => _$BbTreeFromJson(json);
|
||||||
|
}
|
||||||
|
|
|
@ -117,3 +117,16 @@ Map<String, dynamic> _$BbRepoMainbranchToJson(BbRepoMainbranch instance) =>
|
||||||
'type': instance.type,
|
'type': instance.type,
|
||||||
'name': instance.name,
|
'name': instance.name,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
BbTree _$BbTreeFromJson(Map<String, dynamic> json) {
|
||||||
|
return BbTree()
|
||||||
|
..type = json['type'] as String
|
||||||
|
..path = json['path'] as String
|
||||||
|
..size = json['size'] as int;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> _$BbTreeToJson(BbTree instance) => <String, dynamic>{
|
||||||
|
'type': instance.type,
|
||||||
|
'path': instance.path,
|
||||||
|
'size': instance.size,
|
||||||
|
};
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import 'package:fluro/fluro.dart';
|
import 'package:fluro/fluro.dart';
|
||||||
|
import 'package:git_touch/screens/bb_object.dart';
|
||||||
import 'package:git_touch/screens/bb_repo.dart';
|
import 'package:git_touch/screens/bb_repo.dart';
|
||||||
import 'package:git_touch/screens/bb_user.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';
|
||||||
|
@ -240,6 +241,7 @@ class BitbucketRouter {
|
||||||
static final routes = [
|
static final routes = [
|
||||||
BitbucketRouter.user,
|
BitbucketRouter.user,
|
||||||
BitbucketRouter.repo,
|
BitbucketRouter.repo,
|
||||||
|
BitbucketRouter.object,
|
||||||
];
|
];
|
||||||
static final user = RouterScreen(
|
static final user = RouterScreen(
|
||||||
'/:login',
|
'/:login',
|
||||||
|
@ -252,4 +254,13 @@ class BitbucketRouter {
|
||||||
(context, params) =>
|
(context, params) =>
|
||||||
BbRepoScreen(params['owner'].first, params['name'].first),
|
BbRepoScreen(params['owner'].first, params['name'].first),
|
||||||
);
|
);
|
||||||
|
static final object = RouterScreen(
|
||||||
|
'/:owner/:name/src/:ref',
|
||||||
|
(context, params) => BbObjectScreen(
|
||||||
|
params['owner'].first,
|
||||||
|
params['name'].first,
|
||||||
|
params['ref'].first,
|
||||||
|
path: params['path']?.first,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:io';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:git_touch/models/auth.dart';
|
||||||
|
import 'package:git_touch/models/bitbucket.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';
|
||||||
|
import 'package:path/path.dart' as p;
|
||||||
|
|
||||||
|
class BbObjectScreen extends StatelessWidget {
|
||||||
|
final String owner;
|
||||||
|
final String name;
|
||||||
|
final String ref;
|
||||||
|
final String path;
|
||||||
|
BbObjectScreen(this.owner, this.name, this.ref, {this.path});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return RefreshStatefulScaffold(
|
||||||
|
title: AppBarTitle(path ?? 'Files'),
|
||||||
|
fetchData: () async {
|
||||||
|
final res = await Provider.of<AuthModel>(context)
|
||||||
|
.fetchBb('/repositories/$owner/$name/src/$ref/${path ?? ''}');
|
||||||
|
if (res.headers[HttpHeaders.contentTypeHeader] == 'text/plain') {
|
||||||
|
return res.body;
|
||||||
|
} else {
|
||||||
|
return BbPagination.fromJson(json.decode(res.body)).values;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
actionBuilder: (p, _) {
|
||||||
|
if (p is String) {
|
||||||
|
return ActionEntry(
|
||||||
|
iconData: Icons.settings,
|
||||||
|
url: '/choose-code-theme',
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
bodyBuilder: (pl, _) {
|
||||||
|
if (pl is String) {
|
||||||
|
return BlobView(path, text: pl);
|
||||||
|
} else if (pl is List) {
|
||||||
|
final items = pl.map((t) => BbTree.fromJson(t)).toList();
|
||||||
|
items.sort((a, b) {
|
||||||
|
return sortByKey('dir', a.type, b.type);
|
||||||
|
});
|
||||||
|
return ObjectTree(items: [
|
||||||
|
for (var v in items)
|
||||||
|
ObjectTreeItem(
|
||||||
|
name: p.basename(v.path),
|
||||||
|
type: v.type,
|
||||||
|
size: v.type == 'commit_file' ? v.size : null,
|
||||||
|
url:
|
||||||
|
'/bitbucket/$owner/$name/src/$ref?path=${v.path.urlencode}',
|
||||||
|
downloadUrl: null,
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,10 +23,11 @@ class BbRepoScreen extends StatelessWidget {
|
||||||
title: AppBarTitle('Repository'),
|
title: AppBarTitle('Repository'),
|
||||||
fetchData: () async {
|
fetchData: () async {
|
||||||
final auth = Provider.of<AuthModel>(context);
|
final auth = Provider.of<AuthModel>(context);
|
||||||
final res = await auth.fetchBb('/repositories/$owner/$name');
|
final r = await auth.fetchBbJson('/repositories/$owner/$name');
|
||||||
final repo = BbRepo.fromJson(res);
|
final repo = BbRepo.fromJson(r);
|
||||||
final readme = await auth.fetchBbReadme(
|
final res = await auth.fetchBb(
|
||||||
'/repositories/$owner/$name/src/${repo.mainbranch.name}/README.md');
|
'/repositories/$owner/$name/src/${repo.mainbranch.name}/README.md');
|
||||||
|
final readme = res.statusCode >= 400 ? null : res.body;
|
||||||
return Tuple2(repo, readme);
|
return Tuple2(repo, readme);
|
||||||
},
|
},
|
||||||
bodyBuilder: (t, setState) {
|
bodyBuilder: (t, setState) {
|
||||||
|
|
|
@ -23,7 +23,7 @@ class BbUserScreen extends StatelessWidget {
|
||||||
title: Text(isViewer ? 'Me' : 'User'),
|
title: Text(isViewer ? 'Me' : 'User'),
|
||||||
fetchData: () async {
|
fetchData: () async {
|
||||||
final res = await Future.wait([
|
final res = await Future.wait([
|
||||||
auth.fetchBb('/users/$_login'),
|
auth.fetchBbJson('/users/$_login'),
|
||||||
auth.fetchBbWithPage('/repositories/$_login'),
|
auth.fetchBbWithPage('/repositories/$_login'),
|
||||||
]);
|
]);
|
||||||
return Tuple2(
|
return Tuple2(
|
||||||
|
|
|
@ -13,16 +13,18 @@ import 'package:git_touch/utils/utils.dart';
|
||||||
|
|
||||||
class BlobView extends StatelessWidget {
|
class BlobView extends StatelessWidget {
|
||||||
final String name;
|
final String name;
|
||||||
// final String text;
|
final String text;
|
||||||
final String base64Text;
|
final String base64Text;
|
||||||
final String networkUrl;
|
final String networkUrl;
|
||||||
BlobView(
|
BlobView(
|
||||||
this.name, {
|
this.name, {
|
||||||
// this.text,
|
this.text,
|
||||||
@required this.base64Text,
|
this.base64Text,
|
||||||
this.networkUrl,
|
this.networkUrl,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
String get _text => text ?? base64Text.base64ToUtf8;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final codeProvider = Provider.of<CodeModel>(context);
|
final codeProvider = Provider.of<CodeModel>(context);
|
||||||
|
@ -52,13 +54,13 @@ class BlobView extends StatelessWidget {
|
||||||
case 'markdown':
|
case 'markdown':
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: CommonStyle.padding,
|
padding: CommonStyle.padding,
|
||||||
child: MarkdownView(base64Text.base64ToUtf8), // TODO: basePath
|
child: MarkdownView(_text), // TODO: basePath
|
||||||
);
|
);
|
||||||
default:
|
default:
|
||||||
return SingleChildScrollView(
|
return SingleChildScrollView(
|
||||||
scrollDirection: Axis.horizontal,
|
scrollDirection: Axis.horizontal,
|
||||||
child: HighlightView(
|
child: HighlightView(
|
||||||
base64Text.base64ToUtf8,
|
_text,
|
||||||
language: name.ext ?? 'plaintext',
|
language: name.ext ?? 'plaintext',
|
||||||
theme: themeMap[theme.brightness == Brightness.dark
|
theme: themeMap[theme.brightness == Brightness.dark
|
||||||
? codeProvider.themeDark
|
? codeProvider.themeDark
|
||||||
|
|
|
@ -28,9 +28,11 @@ class ObjectTree extends StatelessWidget {
|
||||||
switch (item.type) {
|
switch (item.type) {
|
||||||
case 'blob': // github gql, gitlab
|
case 'blob': // github gql, gitlab
|
||||||
case 'file': // github rest, gitea
|
case 'file': // github rest, gitea
|
||||||
|
case 'commit_file': // bitbucket
|
||||||
return SetiIcon(item.name, size: 36);
|
return SetiIcon(item.name, size: 36);
|
||||||
case 'tree': // github gql, gitlab
|
case 'tree': // github gql, gitlab
|
||||||
case 'dir': // github rest, gitea
|
case 'dir': // github rest, gitea
|
||||||
|
case 'commit_directory': // bitbucket
|
||||||
return Icon(
|
return Icon(
|
||||||
Octicons.file_directory,
|
Octicons.file_directory,
|
||||||
color: PrimerColors.blue300,
|
color: PrimerColors.blue300,
|
||||||
|
|
|
@ -46,7 +46,7 @@ class RepositoryItem extends StatelessWidget {
|
||||||
name = payload.name,
|
name = payload.name,
|
||||||
url = '/bitbucket/${payload.fullName}',
|
url = '/bitbucket/${payload.fullName}',
|
||||||
avatarUrl = payload.avatarUrl,
|
avatarUrl = payload.avatarUrl,
|
||||||
avatarLink = '/bitbucket/${payload.owner.displayName}',
|
avatarLink = null,
|
||||||
note = 'Updated ${timeago.format(payload.updatedOn)}',
|
note = 'Updated ${timeago.format(payload.updatedOn)}',
|
||||||
description = payload.description,
|
description = payload.description,
|
||||||
forkCount = 0,
|
forkCount = 0,
|
||||||
|
|
Loading…
Reference in New Issue