parent
2981db0d17
commit
f9d014c047
4 changed files with 38 additions and 27 deletions
|
@ -24,6 +24,13 @@ class RecordApi {
|
||||||
return Record.fromMap(body);
|
return Record.fromMap(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<Record> getGroupRecordByPath(ApiClient client, {required String path, required String groupId}) async {
|
||||||
|
final response = await client.get("/groups/$groupId/records/$path");
|
||||||
|
client.checkResponse(response);
|
||||||
|
final body = jsonDecode(response.body) as Map;
|
||||||
|
return Record.fromMap(body);
|
||||||
|
}
|
||||||
|
|
||||||
static Future<List<Record>> getUserRecordsAt(ApiClient client, {required String path, String? user}) async {
|
static Future<List<Record>> getUserRecordsAt(ApiClient client, {required String path, String? user}) async {
|
||||||
final response = await client.get(Uri.encodeFull("/users/${user ?? client.userId}/records?path=$path"));
|
final response = await client.get(Uri.encodeFull("/users/${user ?? client.userId}/records?path=$path"));
|
||||||
client.checkResponse(response);
|
client.checkResponse(response);
|
||||||
|
@ -32,7 +39,7 @@ class RecordApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<List<Record>> getGroupRecordsAt(ApiClient client, {required String path, required String groupId}) async {
|
static Future<List<Record>> getGroupRecordsAt(ApiClient client, {required String path, required String groupId}) async {
|
||||||
final response = await client.get("/users/$groupId/records?path=$path");
|
final response = await client.get("/groups/$groupId/records?path=$path");
|
||||||
client.checkResponse(response);
|
client.checkResponse(response);
|
||||||
final body = jsonDecode(response.body) as List;
|
final body = jsonDecode(response.body) as List;
|
||||||
return body.map((e) => Record.fromMap(e)).toList();
|
return body.map((e) => Record.fromMap(e)).toList();
|
||||||
|
|
|
@ -63,7 +63,8 @@ class InventoryClient extends ChangeNotifier {
|
||||||
Future<ResoniteDirectory>? get directoryFuture => _currentDirectory?.then(
|
Future<ResoniteDirectory>? get directoryFuture => _currentDirectory?.then(
|
||||||
(ResoniteDirectory value) {
|
(ResoniteDirectory value) {
|
||||||
value.children.sort(
|
value.children.sort(
|
||||||
(ResoniteDirectory a, ResoniteDirectory b) => _sortMode.sortFunction(a.record, b.record, reverse: _sortReverse),
|
(ResoniteDirectory a, ResoniteDirectory b) =>
|
||||||
|
_sortMode.sortFunction(a.record, b.record, reverse: _sortReverse),
|
||||||
);
|
);
|
||||||
return value;
|
return value;
|
||||||
},
|
},
|
||||||
|
@ -113,10 +114,29 @@ class InventoryClient extends ChangeNotifier {
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
if (record.recordType == RecordType.link) {
|
if (record.recordType == RecordType.link) {
|
||||||
final linkRecord =
|
if (record.isGroupRecord) {
|
||||||
await RecordApi.getUserRecord(apiClient, recordId: record.linkRecordId, user: record.linkOwnerId);
|
final linkRecord = await RecordApi.getGroupRecordByPath(
|
||||||
records = await RecordApi.getUserRecordsAt(apiClient,
|
apiClient,
|
||||||
path: "${linkRecord.path}\\${linkRecord.name}", user: linkRecord.ownerId);
|
path: "root/${record.path}/${record.name}",
|
||||||
|
groupId: record.linkOwnerId,
|
||||||
|
);
|
||||||
|
records = await RecordApi.getGroupRecordsAt(
|
||||||
|
apiClient,
|
||||||
|
path: "${linkRecord.path}\\${linkRecord.name}",
|
||||||
|
groupId: linkRecord.ownerId,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
final linkRecord = await RecordApi.getUserRecord(
|
||||||
|
apiClient,
|
||||||
|
recordId: record.linkRecordId,
|
||||||
|
user: record.linkOwnerId,
|
||||||
|
);
|
||||||
|
records = await RecordApi.getUserRecordsAt(
|
||||||
|
apiClient,
|
||||||
|
path: "${linkRecord.path}\\${linkRecord.name}",
|
||||||
|
user: linkRecord.ownerId,
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
records =
|
records =
|
||||||
await RecordApi.getUserRecordsAt(apiClient, path: "${record.path}\\${record.name}", user: record.ownerId);
|
await RecordApi.getUserRecordsAt(apiClient, path: "${record.path}\\${record.name}", user: record.ownerId);
|
||||||
|
|
|
@ -222,6 +222,8 @@ class Record {
|
||||||
|
|
||||||
bool get isItem => assetUri.startsWith("resdb");
|
bool get isItem => assetUri.startsWith("resdb");
|
||||||
|
|
||||||
|
bool get isGroupRecord => linkOwnerId.startsWith("G-");
|
||||||
|
|
||||||
String get linkRecordId {
|
String get linkRecordId {
|
||||||
if (!isLink) {
|
if (!isLink) {
|
||||||
throw "Record is not a link.";
|
throw "Record is not a link.";
|
||||||
|
@ -242,12 +244,12 @@ class Record {
|
||||||
|
|
||||||
String ownerId = assetUri.replaceFirst("resrec:///", "");
|
String ownerId = assetUri.replaceFirst("resrec:///", "");
|
||||||
|
|
||||||
final lastSlashIdx = ownerId.lastIndexOf("/");
|
final nextSlashIdx = ownerId.indexOf("/");
|
||||||
if (lastSlashIdx == -1) {
|
if (nextSlashIdx == -1) {
|
||||||
throw "Record has invalid assetUri";
|
throw "Record has invalid assetUri";
|
||||||
}
|
}
|
||||||
|
|
||||||
return ownerId.substring(0, lastSlashIdx);
|
return ownerId.substring(0, nextSlashIdx);
|
||||||
}
|
}
|
||||||
|
|
||||||
Record copyWith({
|
Record copyWith({
|
||||||
|
|
|
@ -187,24 +187,6 @@ class _InventoryBrowserState extends State<InventoryBrowser> with AutomaticKeepA
|
||||||
final record = objects[index];
|
final record = objects[index];
|
||||||
return ObjectInventoryTile(
|
return ObjectInventoryTile(
|
||||||
record: record,
|
record: record,
|
||||||
selected: iClient.isRecordSelected(record),
|
|
||||||
onTap: iClient.isAnyRecordSelected
|
|
||||||
? () async {
|
|
||||||
iClient.toggleRecordSelected(record);
|
|
||||||
}
|
|
||||||
: () async {
|
|
||||||
await Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (context) => PhotoView(
|
|
||||||
minScale: PhotoViewComputedScale.contained,
|
|
||||||
imageProvider:
|
|
||||||
CachedNetworkImageProvider(Aux.resdbToHttp(record.thumbnailUri)),
|
|
||||||
heroAttributes: PhotoViewHeroAttributes(tag: record.id),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
onLongPress: () async {
|
onLongPress: () async {
|
||||||
iClient.toggleRecordSelected(record);
|
iClient.toggleRecordSelected(record);
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue