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?.urldecode));
|
|
|
|
|
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
|
|
|
);
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|