2019-12-11 23:37:29 +08:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2022-09-17 20:35:45 +08:00
|
|
|
import 'package:flutter/widgets.dart';
|
2022-09-13 23:52:35 +08:00
|
|
|
import 'package:flutter_gen/gen_l10n/S.dart';
|
|
|
|
import 'package:git_touch/models/auth.dart';
|
2019-12-11 23:37:29 +08:00
|
|
|
import 'package:git_touch/models/gitlab.dart';
|
2021-06-14 11:28:12 +08:00
|
|
|
import 'package:git_touch/scaffolds/list_stateful.dart';
|
2019-12-11 23:37:29 +08:00
|
|
|
import 'package:git_touch/widgets/app_bar_title.dart';
|
2020-01-30 12:55:55 +08:00
|
|
|
import 'package:git_touch/widgets/object_tree.dart';
|
2022-09-13 23:52:35 +08:00
|
|
|
import 'package:git_touch/widgets/table_view.dart';
|
2019-12-11 23:37:29 +08:00
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
2020-02-07 22:26:37 +08:00
|
|
|
class GlTreeScreen extends StatelessWidget {
|
2019-12-11 23:37:29 +08:00
|
|
|
final int id;
|
2020-02-02 10:58:42 +08:00
|
|
|
final String ref;
|
2021-05-16 15:16:35 +08:00
|
|
|
final String? path;
|
2022-09-07 00:28:12 +08:00
|
|
|
const GlTreeScreen(this.id, this.ref, {this.path});
|
2019-12-11 23:37:29 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-01-31 16:40:20 +08:00
|
|
|
final auth = Provider.of<AuthModel>(context);
|
2021-06-14 11:28:12 +08:00
|
|
|
|
|
|
|
return ListStatefulScaffold<GitlabTreeItem, int>(
|
2021-05-16 15:16:35 +08:00
|
|
|
title: AppBarTitle(path ?? AppLocalizations.of(context)!.files),
|
2021-06-14 11:28:12 +08:00
|
|
|
fetch: (page) async {
|
2020-02-02 10:58:42 +08:00
|
|
|
final uri = Uri(
|
|
|
|
path: '/projects/$id/repository/tree',
|
|
|
|
queryParameters: {
|
|
|
|
'ref': ref,
|
2021-06-14 11:28:12 +08:00
|
|
|
'page': page?.toString(),
|
2020-02-02 10:58:42 +08:00
|
|
|
...(path == null ? {} : {'path': path})
|
|
|
|
},
|
|
|
|
);
|
2021-06-14 11:28:12 +08:00
|
|
|
final res = await auth.fetchGitlabWithPage(uri.toString());
|
|
|
|
return ListPayload(
|
|
|
|
cursor: res.cursor,
|
|
|
|
hasMore: res.hasMore,
|
|
|
|
items: [for (var v in res.data) GitlabTreeItem.fromJson(v)],
|
|
|
|
);
|
2019-12-11 23:37:29 +08:00
|
|
|
},
|
2021-06-14 11:28:12 +08:00
|
|
|
itemBuilder: (item) {
|
2022-09-13 23:52:35 +08:00
|
|
|
return TableViewItemWidget(
|
|
|
|
createObjectTreeItem(
|
|
|
|
type: item.type,
|
|
|
|
name: item.name,
|
|
|
|
downloadUrl:
|
|
|
|
'${auth.activeAccount!.domain}/api/v4/projects/$id/repository/files/${item.path.urlencode}/raw?ref=master', // TODO:
|
|
|
|
url: item.type == 'tree'
|
|
|
|
? '/gitlab/projects/$id/tree/$ref?path=${item.path.urlencode}'
|
|
|
|
: item.type == 'blob'
|
|
|
|
? '/gitlab/projects/$id/blob/$ref?path=${item.path.urlencode}'
|
|
|
|
: '',
|
|
|
|
),
|
2019-12-11 23:37:29 +08:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|