mirror of
https://github.com/git-touch/git-touch
synced 2024-12-18 19:22:54 +01:00
58 lines
1.9 KiB
Dart
58 lines
1.9 KiB
Dart
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/object_tree.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';
|
|
|
|
class GlTreeScreen extends StatelessWidget {
|
|
final int id;
|
|
final String ref;
|
|
final String path;
|
|
GlTreeScreen(this.id, this.ref, {this.path});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final auth = Provider.of<AuthModel>(context);
|
|
return RefreshStatefulScaffold<Iterable<GitlabTreeItem>>(
|
|
title: AppBarTitle(path ?? 'Files'),
|
|
fetchData: () async {
|
|
final uri = Uri(
|
|
path: '/projects/$id/repository/tree',
|
|
queryParameters: {
|
|
'ref': ref,
|
|
...(path == null ? {} : {'path': path})
|
|
},
|
|
);
|
|
final res = await auth.fetchGitlab(uri.toString());
|
|
return (res as List).map((v) => GitlabTreeItem.fromJson(v));
|
|
},
|
|
bodyBuilder: (data, _) {
|
|
return ObjectTree(
|
|
items: data.map((item) {
|
|
return ObjectTreeItem(
|
|
type: item.type,
|
|
name: item.name,
|
|
downloadUrl:
|
|
'${auth.activeAccount.domain}/api/v4/projects/$id/repository/files/${item.path.urlencode}/raw?ref=master', // TODO:
|
|
url: (() {
|
|
switch (item.type) {
|
|
case 'tree':
|
|
return '/gitlab/projects/$id/tree/$ref?path=${item.path.urlencode}';
|
|
case 'blob':
|
|
return '/gitlab/projects/$id/blob/$ref?path=${item.path.urlencode}';
|
|
default:
|
|
return null;
|
|
}
|
|
})(),
|
|
);
|
|
}),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|