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';
|
|
|
|
import 'package:git_touch/widgets/table_view.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:git_touch/models/auth.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:git_touch/utils/utils.dart';
|
|
|
|
import 'package:primer/primer.dart';
|
|
|
|
import 'package:seti/seti.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;
|
2019-12-11 16:37:29 +01:00
|
|
|
|
2019-12-11 17:07:12 +01:00
|
|
|
GitlabTreeScreen(this.id, {this.path});
|
2019-12-11 16:37:29 +01:00
|
|
|
|
|
|
|
static const _iconDefaultColor = PrimerColors.blue300;
|
|
|
|
|
|
|
|
Widget _buildIcon(GitlabTreeItem item) {
|
|
|
|
switch (item.type) {
|
|
|
|
case 'blob':
|
|
|
|
return SetiIcon(item.path, size: 36);
|
|
|
|
case 'tree':
|
|
|
|
case 'commit':
|
|
|
|
return Icon(
|
|
|
|
item.type == 'tree'
|
|
|
|
? Octicons.file_directory
|
|
|
|
: Octicons.file_submodule,
|
|
|
|
color: _iconDefaultColor,
|
|
|
|
size: 24,
|
|
|
|
);
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@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, _) {
|
|
|
|
return TableView(
|
|
|
|
hasIcon: true,
|
|
|
|
items: data.map((item) {
|
|
|
|
return TableViewItem(
|
|
|
|
leftWidget: _buildIcon(item),
|
2019-12-11 17:07:12 +01:00
|
|
|
text: Text(item.name),
|
2019-12-12 13:29:56 +01:00
|
|
|
url: (() {
|
2019-12-11 16:58:25 +01:00
|
|
|
switch (item.type) {
|
|
|
|
case 'tree':
|
2019-12-14 17:08:12 +01:00
|
|
|
return '/projects/$id/tree?path=${item.path.urlencode}';
|
2019-12-11 16:58:25 +01:00
|
|
|
case 'blob':
|
2019-12-14 17:08:12 +01:00
|
|
|
return '/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
|
|
|
);
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|