mirror of
https://github.com/git-touch/git-touch
synced 2025-01-18 18:29:59 +01:00
feat: object tree item size
This commit is contained in:
parent
9d6985c391
commit
39c360f281
@ -7308,10 +7308,10 @@ class GhObjectGitObject with EquatableMixin {
|
||||
|
||||
factory GhObjectGitObject.fromJson(Map<String, dynamic> json) {
|
||||
switch (json['__typename'].toString()) {
|
||||
case 'Tree':
|
||||
return GhObjectTree.fromJson(json);
|
||||
case 'Blob':
|
||||
return GhObjectBlob.fromJson(json);
|
||||
case 'Tree':
|
||||
return GhObjectTree.fromJson(json);
|
||||
default:
|
||||
}
|
||||
return _$GhObjectGitObjectFromJson(json);
|
||||
@ -7324,16 +7324,53 @@ class GhObjectGitObject with EquatableMixin {
|
||||
List<Object> get props => [resolveType];
|
||||
Map<String, dynamic> toJson() {
|
||||
switch (resolveType) {
|
||||
case 'Tree':
|
||||
return (this as GhObjectTree).toJson();
|
||||
case 'Blob':
|
||||
return (this as GhObjectBlob).toJson();
|
||||
case 'Tree':
|
||||
return (this as GhObjectTree).toJson();
|
||||
default:
|
||||
}
|
||||
return _$GhObjectGitObjectToJson(this);
|
||||
}
|
||||
}
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class GhObjectBlob
|
||||
with EquatableMixin
|
||||
implements GhObjectNode, GhObjectGitObject {
|
||||
GhObjectBlob({this.text, this.byteSize});
|
||||
|
||||
factory GhObjectBlob.fromJson(Map<String, dynamic> json) =>
|
||||
_$GhObjectBlobFromJson(json);
|
||||
|
||||
String text;
|
||||
|
||||
int byteSize;
|
||||
|
||||
@override
|
||||
@JsonKey(name: '__typename')
|
||||
String resolveType;
|
||||
|
||||
@override
|
||||
List<Object> get props => [text, byteSize, resolveType];
|
||||
Map<String, dynamic> toJson() => _$GhObjectBlobToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class GhObjectNode with EquatableMixin {
|
||||
GhObjectNode();
|
||||
|
||||
factory GhObjectNode.fromJson(Map<String, dynamic> json) =>
|
||||
_$GhObjectNodeFromJson(json);
|
||||
|
||||
@JsonKey(name: '__typename')
|
||||
String resolveType;
|
||||
|
||||
@override
|
||||
List<Object> get props => [resolveType];
|
||||
Map<String, dynamic> toJson() => _$GhObjectNodeToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class GhObjectTree
|
||||
with EquatableMixin
|
||||
@ -7356,7 +7393,7 @@ class GhObjectTree
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class GhObjectTreeEntry with EquatableMixin {
|
||||
GhObjectTreeEntry({this.type, this.name});
|
||||
GhObjectTreeEntry({this.type, this.name, this.object});
|
||||
|
||||
factory GhObjectTreeEntry.fromJson(Map<String, dynamic> json) =>
|
||||
_$GhObjectTreeEntryFromJson(json);
|
||||
@ -7365,46 +7402,13 @@ class GhObjectTreeEntry with EquatableMixin {
|
||||
|
||||
String name;
|
||||
|
||||
GhObjectGitObject object;
|
||||
|
||||
@override
|
||||
List<Object> get props => [type, name];
|
||||
List<Object> get props => [type, name, object];
|
||||
Map<String, dynamic> toJson() => _$GhObjectTreeEntryToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class GhObjectNode with EquatableMixin {
|
||||
GhObjectNode();
|
||||
|
||||
factory GhObjectNode.fromJson(Map<String, dynamic> json) =>
|
||||
_$GhObjectNodeFromJson(json);
|
||||
|
||||
@JsonKey(name: '__typename')
|
||||
String resolveType;
|
||||
|
||||
@override
|
||||
List<Object> get props => [resolveType];
|
||||
Map<String, dynamic> toJson() => _$GhObjectNodeToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class GhObjectBlob
|
||||
with EquatableMixin
|
||||
implements GhObjectNode, GhObjectGitObject {
|
||||
GhObjectBlob({this.text});
|
||||
|
||||
factory GhObjectBlob.fromJson(Map<String, dynamic> json) =>
|
||||
_$GhObjectBlobFromJson(json);
|
||||
|
||||
String text;
|
||||
|
||||
@override
|
||||
@JsonKey(name: '__typename')
|
||||
String resolveType;
|
||||
|
||||
@override
|
||||
List<Object> get props => [text, resolveType];
|
||||
Map<String, dynamic> toJson() => _$GhObjectBlobToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class GhObjectPinnableItem with EquatableMixin {
|
||||
GhObjectPinnableItem();
|
||||
@ -7603,6 +7607,26 @@ class GhObjectQuery extends GraphQLQuery<GhObject, GhObjectArguments> {
|
||||
arguments: [],
|
||||
directives: [],
|
||||
selectionSet: null),
|
||||
InlineFragmentNode(
|
||||
typeCondition: TypeConditionNode(
|
||||
on: NamedTypeNode(
|
||||
name: NameNode(value: 'Blob'),
|
||||
isNonNull: false)),
|
||||
directives: [],
|
||||
selectionSet: SelectionSetNode(selections: [
|
||||
FieldNode(
|
||||
name: NameNode(value: 'text'),
|
||||
alias: null,
|
||||
arguments: [],
|
||||
directives: [],
|
||||
selectionSet: null),
|
||||
FieldNode(
|
||||
name: NameNode(value: 'byteSize'),
|
||||
alias: null,
|
||||
arguments: [],
|
||||
directives: [],
|
||||
selectionSet: null)
|
||||
])),
|
||||
InlineFragmentNode(
|
||||
typeCondition: TypeConditionNode(
|
||||
on: NamedTypeNode(
|
||||
@ -7627,22 +7651,39 @@ class GhObjectQuery extends GraphQLQuery<GhObject, GhObjectArguments> {
|
||||
alias: null,
|
||||
arguments: [],
|
||||
directives: [],
|
||||
selectionSet: null)
|
||||
selectionSet: null),
|
||||
FieldNode(
|
||||
name: NameNode(value: 'object'),
|
||||
alias: null,
|
||||
arguments: [],
|
||||
directives: [],
|
||||
selectionSet:
|
||||
SelectionSetNode(selections: [
|
||||
FieldNode(
|
||||
name: NameNode(value: '__typename'),
|
||||
alias: null,
|
||||
arguments: [],
|
||||
directives: [],
|
||||
selectionSet: null),
|
||||
InlineFragmentNode(
|
||||
typeCondition: TypeConditionNode(
|
||||
on: NamedTypeNode(
|
||||
name:
|
||||
NameNode(value: 'Blob'),
|
||||
isNonNull: false)),
|
||||
directives: [],
|
||||
selectionSet:
|
||||
SelectionSetNode(selections: [
|
||||
FieldNode(
|
||||
name: NameNode(
|
||||
value: 'byteSize'),
|
||||
alias: null,
|
||||
arguments: [],
|
||||
directives: [],
|
||||
selectionSet: null)
|
||||
]))
|
||||
]))
|
||||
]))
|
||||
])),
|
||||
InlineFragmentNode(
|
||||
typeCondition: TypeConditionNode(
|
||||
on: NamedTypeNode(
|
||||
name: NameNode(value: 'Blob'),
|
||||
isNonNull: false)),
|
||||
directives: [],
|
||||
selectionSet: SelectionSetNode(selections: [
|
||||
FieldNode(
|
||||
name: NameNode(value: 'text'),
|
||||
alias: null,
|
||||
arguments: [],
|
||||
directives: [],
|
||||
selectionSet: null)
|
||||
]))
|
||||
]))
|
||||
]))
|
||||
|
@ -2947,6 +2947,29 @@ Map<String, dynamic> _$GhObjectGitObjectToJson(GhObjectGitObject instance) =>
|
||||
'__typename': instance.resolveType,
|
||||
};
|
||||
|
||||
GhObjectBlob _$GhObjectBlobFromJson(Map<String, dynamic> json) {
|
||||
return GhObjectBlob(
|
||||
text: json['text'] as String,
|
||||
byteSize: json['byteSize'] as int,
|
||||
)..resolveType = json['__typename'] as String;
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$GhObjectBlobToJson(GhObjectBlob instance) =>
|
||||
<String, dynamic>{
|
||||
'text': instance.text,
|
||||
'byteSize': instance.byteSize,
|
||||
'__typename': instance.resolveType,
|
||||
};
|
||||
|
||||
GhObjectNode _$GhObjectNodeFromJson(Map<String, dynamic> json) {
|
||||
return GhObjectNode()..resolveType = json['__typename'] as String;
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$GhObjectNodeToJson(GhObjectNode instance) =>
|
||||
<String, dynamic>{
|
||||
'__typename': instance.resolveType,
|
||||
};
|
||||
|
||||
GhObjectTree _$GhObjectTreeFromJson(Map<String, dynamic> json) {
|
||||
return GhObjectTree(
|
||||
entries: (json['entries'] as List)
|
||||
@ -2967,6 +2990,9 @@ GhObjectTreeEntry _$GhObjectTreeEntryFromJson(Map<String, dynamic> json) {
|
||||
return GhObjectTreeEntry(
|
||||
type: json['type'] as String,
|
||||
name: json['name'] as String,
|
||||
object: json['object'] == null
|
||||
? null
|
||||
: GhObjectGitObject.fromJson(json['object'] as Map<String, dynamic>),
|
||||
);
|
||||
}
|
||||
|
||||
@ -2974,27 +3000,7 @@ Map<String, dynamic> _$GhObjectTreeEntryToJson(GhObjectTreeEntry instance) =>
|
||||
<String, dynamic>{
|
||||
'type': instance.type,
|
||||
'name': instance.name,
|
||||
};
|
||||
|
||||
GhObjectNode _$GhObjectNodeFromJson(Map<String, dynamic> json) {
|
||||
return GhObjectNode()..resolveType = json['__typename'] as String;
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$GhObjectNodeToJson(GhObjectNode instance) =>
|
||||
<String, dynamic>{
|
||||
'__typename': instance.resolveType,
|
||||
};
|
||||
|
||||
GhObjectBlob _$GhObjectBlobFromJson(Map<String, dynamic> json) {
|
||||
return GhObjectBlob(
|
||||
text: json['text'] as String,
|
||||
)..resolveType = json['__typename'] as String;
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$GhObjectBlobToJson(GhObjectBlob instance) =>
|
||||
<String, dynamic>{
|
||||
'text': instance.text,
|
||||
'__typename': instance.resolveType,
|
||||
'object': instance.object?.toJson(),
|
||||
};
|
||||
|
||||
GhObjectPinnableItem _$GhObjectPinnableItemFromJson(Map<String, dynamic> json) {
|
||||
|
@ -2,15 +2,22 @@ query GhObject($owner: String!, $name: String!, $expression: String!) {
|
||||
repository(owner: $owner, name: $name) {
|
||||
object(expression: $expression) {
|
||||
__typename
|
||||
... on Blob {
|
||||
text
|
||||
byteSize # x
|
||||
}
|
||||
... on Tree {
|
||||
entries {
|
||||
type
|
||||
name
|
||||
object {
|
||||
__typename
|
||||
... on Blob {
|
||||
byteSize
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
... on Blob {
|
||||
text
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ class GiteaTree {
|
||||
String type;
|
||||
String name;
|
||||
String path;
|
||||
int size;
|
||||
GiteaTree();
|
||||
factory GiteaTree.fromJson(Map<String, dynamic> json) =>
|
||||
_$GiteaTreeFromJson(json);
|
||||
|
@ -63,13 +63,15 @@ GiteaTree _$GiteaTreeFromJson(Map<String, dynamic> json) {
|
||||
return GiteaTree()
|
||||
..type = json['type'] as String
|
||||
..name = json['name'] as String
|
||||
..path = json['path'] as String;
|
||||
..path = json['path'] as String
|
||||
..size = json['size'] as int;
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$GiteaTreeToJson(GiteaTree instance) => <String, dynamic>{
|
||||
'type': instance.type,
|
||||
'name': instance.name,
|
||||
'path': instance.path,
|
||||
'size': instance.size,
|
||||
};
|
||||
|
||||
GiteaBlob _$GiteaBlobFromJson(Map<String, dynamic> json) {
|
||||
@ -77,6 +79,7 @@ GiteaBlob _$GiteaBlobFromJson(Map<String, dynamic> json) {
|
||||
..type = json['type'] as String
|
||||
..name = json['name'] as String
|
||||
..path = json['path'] as String
|
||||
..size = json['size'] as int
|
||||
..content = json['content'] as String;
|
||||
}
|
||||
|
||||
@ -84,5 +87,6 @@ Map<String, dynamic> _$GiteaBlobToJson(GiteaBlob instance) => <String, dynamic>{
|
||||
'type': instance.type,
|
||||
'name': instance.name,
|
||||
'path': instance.path,
|
||||
'size': instance.size,
|
||||
'content': instance.content,
|
||||
};
|
||||
|
@ -56,6 +56,7 @@ class GiteaObjectScreen extends StatelessWidget {
|
||||
return ObjectTreeItem(
|
||||
name: v.name,
|
||||
type: v.type,
|
||||
size: v.type == 'file' ? v.size : null,
|
||||
url: '/gitea/$owner/$name/blob?path=${v.path.urlencode}',
|
||||
);
|
||||
}),
|
||||
|
@ -94,8 +94,15 @@ class ObjectScreen extends StatelessWidget {
|
||||
items: (data as GhObjectTree).entries.map((v) {
|
||||
// if (item.type == 'commit') return null;
|
||||
final p = [...paths, v.name].join('/').urlencode;
|
||||
final url = '/$owner/$name/blob/$branch?path=$p';
|
||||
return ObjectTreeItem(name: v.name, type: v.type, url: url);
|
||||
|
||||
return ObjectTreeItem(
|
||||
name: v.name,
|
||||
type: v.type,
|
||||
url: '/$owner/$name/blob/$branch?path=$p',
|
||||
size: v.object.resolveType == 'Blob'
|
||||
? (v.object as GhObjectBlob).byteSize
|
||||
: null,
|
||||
);
|
||||
}),
|
||||
);
|
||||
case 'Blob':
|
||||
|
@ -1,3 +1,4 @@
|
||||
import 'package:filesize/filesize.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:git_touch/utils/utils.dart';
|
||||
import 'package:git_touch/widgets/table_view.dart';
|
||||
@ -8,10 +9,12 @@ class ObjectTreeItem {
|
||||
final String url;
|
||||
final String name;
|
||||
final String type;
|
||||
final int size;
|
||||
ObjectTreeItem({
|
||||
@required this.name,
|
||||
@required this.url,
|
||||
@required this.type,
|
||||
this.size,
|
||||
});
|
||||
}
|
||||
|
||||
@ -51,7 +54,9 @@ class ObjectTree extends StatelessWidget {
|
||||
TableViewItem(
|
||||
leftWidget: _buildIcon(item),
|
||||
text: Text(item.name),
|
||||
rightWidget: item.size == null ? null : Text(filesize(item.size)),
|
||||
url: item.url,
|
||||
hideRightChevron: item.size != null,
|
||||
)
|
||||
],
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user