1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-26 07:46:59 +01:00
git-touch-android-ios-app/lib/screens/gitlab_tree.dart

56 lines
1.8 KiB
Dart
Raw Normal View History

2019-12-11 16:37:29 +01:00
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';
2020-01-30 05:55:55 +01:00
import 'package:git_touch/widgets/object_tree.dart';
2019-12-11 16:37:29 +01:00
import 'package:flutter/material.dart';
import 'package:git_touch/models/auth.dart';
import 'package:provider/provider.dart';
import 'package:git_touch/utils/utils.dart';
2019-12-14 17:08:12 +01:00
final gitlabTreeRouter = RouterScreen(
2020-01-01 09:51:10 +01:00
'/gitlab/projects/:id/tree',
2019-12-14 17:08:12 +01:00
(context, params) => GitlabTreeScreen(params['id'].first.toInt,
path: params['path']?.first));
2019-12-14 17:08:12 +01:00
2019-12-11 16:37:29 +01:00
class GitlabTreeScreen extends StatelessWidget {
final int id;
2019-12-11 17:07:12 +01:00
final String path;
GitlabTreeScreen(this.id, {this.path});
2019-12-11 16:37:29 +01:00
@override
Widget build(BuildContext context) {
return RefreshStatefulScaffold<Iterable<GitlabTreeItem>>(
2019-12-14 17:08:12 +01:00
title: AppBarTitle(path ?? 'Files'),
2019-12-11 16:37:29 +01:00
fetchData: () async {
var url = '/projects/$id/repository/tree';
2019-12-11 17:07:12 +01:00
if (path != null) {
url += '?path=' + path;
2019-12-11 16:37:29 +01:00
}
final res = await Provider.of<AuthModel>(context).fetchGitlab(url);
return (res as List).map((v) => GitlabTreeItem.fromJson(v));
},
bodyBuilder: (data, _) {
2020-01-30 05:55:55 +01:00
return ObjectTree(
2019-12-11 16:37:29 +01:00
items: data.map((item) {
2020-01-30 05:55:55 +01:00
return ObjectTreeItem(
type: item.type,
name: item.name,
2019-12-12 13:29:56 +01:00
url: (() {
2019-12-11 16:58:25 +01:00
switch (item.type) {
case 'tree':
2020-01-29 05:42:36 +01:00
return '/gitlab/projects/$id/tree?path=${item.path.urlencode}';
2019-12-11 16:58:25 +01:00
case 'blob':
2020-01-29 05:42:36 +01:00
return '/gitlab/projects/$id/blob?path=${item.path.urlencode}';
2019-12-11 17:07:12 +01:00
default:
return null;
2019-12-11 16:58:25 +01:00
}
2019-12-12 13:29:56 +01:00
})(),
2019-12-11 16:37:29 +01:00
);
}),
);
},
);
}
}