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';
|
2021-01-05 10:25:19 +01:00
|
|
|
import '../generated/l10n.dart';
|
2019-12-11 16:37:29 +01:00
|
|
|
|
2020-02-07 15:26:37 +01:00
|
|
|
class GlTreeScreen extends StatelessWidget {
|
2019-12-11 16:37:29 +01:00
|
|
|
final int id;
|
2020-02-02 03:58:42 +01:00
|
|
|
final String ref;
|
2019-12-11 17:07:12 +01:00
|
|
|
final String path;
|
2020-02-07 15:26:37 +01:00
|
|
|
GlTreeScreen(this.id, this.ref, {this.path});
|
2019-12-11 16:37:29 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-01-31 09:40:20 +01:00
|
|
|
final auth = Provider.of<AuthModel>(context);
|
2019-12-11 16:37:29 +01:00
|
|
|
return RefreshStatefulScaffold<Iterable<GitlabTreeItem>>(
|
2021-01-05 10:25:19 +01:00
|
|
|
title: AppBarTitle(path ?? S.of(context).files),
|
2020-10-06 14:52:40 +02:00
|
|
|
fetch: () async {
|
2020-02-02 03:58:42 +01:00
|
|
|
final uri = Uri(
|
|
|
|
path: '/projects/$id/repository/tree',
|
|
|
|
queryParameters: {
|
|
|
|
'ref': ref,
|
|
|
|
...(path == null ? {} : {'path': path})
|
|
|
|
},
|
|
|
|
);
|
|
|
|
final res = await auth.fetchGitlab(uri.toString());
|
2019-12-11 16:37:29 +01:00
|
|
|
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,
|
2020-01-31 09:40:20 +01:00
|
|
|
downloadUrl:
|
|
|
|
'${auth.activeAccount.domain}/api/v4/projects/$id/repository/files/${item.path.urlencode}/raw?ref=master', // TODO:
|
2019-12-12 13:29:56 +01:00
|
|
|
url: (() {
|
2019-12-11 16:58:25 +01:00
|
|
|
switch (item.type) {
|
|
|
|
case 'tree':
|
2020-02-02 03:58:42 +01:00
|
|
|
return '/gitlab/projects/$id/tree/$ref?path=${item.path.urlencode}';
|
2019-12-11 16:58:25 +01:00
|
|
|
case 'blob':
|
2020-02-02 03:58:42 +01:00
|
|
|
return '/gitlab/projects/$id/blob/$ref?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
|
|
|
);
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|