Enable sharing of a folder
This commit is contained in:
parent
2949d5858d
commit
97c1d0532b
|
@ -26,9 +26,11 @@ class FolderSharingService {
|
||||||
headers: {"X-Auth-Token": Configuration.instance.getToken()}),
|
headers: {"X-Auth-Token": Configuration.instance.getToken()}),
|
||||||
)
|
)
|
||||||
.then((foldersResponse) {
|
.then((foldersResponse) {
|
||||||
|
log(foldersResponse.toString());
|
||||||
var folders = (foldersResponse.data as List)
|
var folders = (foldersResponse.data as List)
|
||||||
.map((f) => Folder.fromMap(f))
|
.map((f) => Folder.fromMap(f))
|
||||||
.toList();
|
.toList();
|
||||||
|
log(folders.toString());
|
||||||
Folder sharedFolder;
|
Folder sharedFolder;
|
||||||
for (var folder in folders) {
|
for (var folder in folders) {
|
||||||
if (folder.owner == Configuration.instance.getUsername() &&
|
if (folder.owner == Configuration.instance.getUsername() &&
|
||||||
|
@ -52,5 +54,14 @@ class FolderSharingService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void shareFolder(String path) {}
|
Future<void> shareFolder(String name, String path, Set<String> users) {
|
||||||
|
var folder = Folder(0, name, Configuration.instance.getUsername(), path,
|
||||||
|
users.toList(), -1);
|
||||||
|
return _dio
|
||||||
|
.put(Configuration.instance.getHttpEndpoint() + "/folders/",
|
||||||
|
options: Options(
|
||||||
|
headers: {"X-Auth-Token": Configuration.instance.getToken()}),
|
||||||
|
data: folder.toMap())
|
||||||
|
.then((response) => log(response.toString()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
|
||||||
class Folder {
|
class Folder {
|
||||||
final int folderID;
|
final int id;
|
||||||
final String name;
|
final String name;
|
||||||
final String owner;
|
final String owner;
|
||||||
final String deviceFolder;
|
final String deviceFolder;
|
||||||
|
@ -7,7 +11,7 @@ class Folder {
|
||||||
final int updateTimestamp;
|
final int updateTimestamp;
|
||||||
|
|
||||||
Folder(
|
Folder(
|
||||||
this.folderID,
|
this.id,
|
||||||
this.name,
|
this.name,
|
||||||
this.owner,
|
this.owner,
|
||||||
this.deviceFolder,
|
this.deviceFolder,
|
||||||
|
@ -19,7 +23,7 @@ class Folder {
|
||||||
if (map == null) return null;
|
if (map == null) return null;
|
||||||
|
|
||||||
return Folder(
|
return Folder(
|
||||||
map['folderID'],
|
map['id'],
|
||||||
map['name'],
|
map['name'],
|
||||||
map['owner'],
|
map['owner'],
|
||||||
map['deviceFolder'],
|
map['deviceFolder'],
|
||||||
|
@ -30,6 +34,44 @@ class Folder {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'Folder(folderID: $folderID, name: $name, owner: $owner, deviceFolder: $deviceFolder, sharedWith: $sharedWith, updateTimestamp: $updateTimestamp)';
|
return 'Folder(id: $id, name: $name, owner: $owner, deviceFolder: $deviceFolder, sharedWith: $sharedWith, updateTimestamp: $updateTimestamp)';
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toMap() {
|
||||||
|
return {
|
||||||
|
'id': id,
|
||||||
|
'name': name,
|
||||||
|
'owner': owner,
|
||||||
|
'deviceFolder': deviceFolder,
|
||||||
|
'sharedWith': sharedWith,
|
||||||
|
'updateTimestamp': updateTimestamp,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
String toJson() => json.encode(toMap());
|
||||||
|
|
||||||
|
static Folder fromJson(String source) => fromMap(json.decode(source));
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object o) {
|
||||||
|
if (identical(this, o)) return true;
|
||||||
|
|
||||||
|
return o is Folder &&
|
||||||
|
o.id == id &&
|
||||||
|
o.name == name &&
|
||||||
|
o.owner == owner &&
|
||||||
|
o.deviceFolder == deviceFolder &&
|
||||||
|
listEquals(o.sharedWith, sharedWith) &&
|
||||||
|
o.updateTimestamp == updateTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode {
|
||||||
|
return id.hashCode ^
|
||||||
|
name.hashCode ^
|
||||||
|
owner.hashCode ^
|
||||||
|
deviceFolder.hashCode ^
|
||||||
|
sharedWith.hashCode ^
|
||||||
|
updateTimestamp.hashCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,12 +18,15 @@ class ShareFolderWidget extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ShareFolderWidgetState extends State<ShareFolderWidget> {
|
class _ShareFolderWidgetState extends State<ShareFolderWidget> {
|
||||||
|
Map<String, bool> _sharingStatus;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return FutureBuilder<Map<String, bool>>(
|
return FutureBuilder<Map<String, bool>>(
|
||||||
future: FolderSharingService.instance.getSharingStatus(widget.path),
|
future: FolderSharingService.instance.getSharingStatus(widget.path),
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
if (snapshot.hasData) {
|
if (snapshot.hasData) {
|
||||||
|
_sharingStatus = snapshot.data;
|
||||||
return _getSharingDialog(snapshot.data);
|
return _getSharingDialog(snapshot.data);
|
||||||
} else if (snapshot.hasError) {
|
} else if (snapshot.hasError) {
|
||||||
return Text(snapshot.error.toString());
|
return Text(snapshot.error.toString());
|
||||||
|
@ -47,8 +50,18 @@ class _ShareFolderWidgetState extends State<ShareFolderWidget> {
|
||||||
actions: <Widget>[
|
actions: <Widget>[
|
||||||
FlatButton(
|
FlatButton(
|
||||||
child: Text("Share"),
|
child: Text("Share"),
|
||||||
onPressed: () {
|
onPressed: () async {
|
||||||
// TODO: FolderSharingService.instance.shareFolder();
|
var sharedWith = Set<String>();
|
||||||
|
for (var user in _sharingStatus.keys) {
|
||||||
|
if (_sharingStatus[user]) {
|
||||||
|
sharedWith.add(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await FolderSharingService.instance.shareFolder(
|
||||||
|
"namewa",
|
||||||
|
widget.path,
|
||||||
|
sharedWith,
|
||||||
|
);
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in a new issue