mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 05:26:47 +00:00
Add function to update user profile
This commit is contained in:
parent
b34a91b865
commit
c2abfbe00f
@ -8,12 +8,16 @@ import 'preferences.dart';
|
|||||||
class UserProfile {
|
class UserProfile {
|
||||||
|
|
||||||
UserProfile({
|
UserProfile({
|
||||||
|
this.key,
|
||||||
this.name,
|
this.name,
|
||||||
this.server,
|
this.server,
|
||||||
this.username,
|
this.username,
|
||||||
this.password
|
this.password
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ID of the profile
|
||||||
|
int key;
|
||||||
|
|
||||||
// Name of the user profile
|
// Name of the user profile
|
||||||
String name;
|
String name;
|
||||||
|
|
||||||
@ -29,7 +33,8 @@ class UserProfile {
|
|||||||
// User ID (will be provided by the server on log-in)
|
// User ID (will be provided by the server on log-in)
|
||||||
int user_id;
|
int user_id;
|
||||||
|
|
||||||
factory UserProfile.fromJson(Map<String, dynamic> json) => UserProfile(
|
factory UserProfile.fromJson(int key, Map<String, dynamic> json) => UserProfile(
|
||||||
|
key: key,
|
||||||
name: json['name'],
|
name: json['name'],
|
||||||
server: json['server'],
|
server: json['server'],
|
||||||
username: json['username'],
|
username: json['username'],
|
||||||
@ -66,16 +71,32 @@ class UserProfileDBManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await _folder.add(await _db, profile.toJson());
|
int key = await _folder.add(await _db, profile.toJson());
|
||||||
|
|
||||||
print("Added user profile '${profile.name}'");
|
print("Added user profile <${key}> - '${profile.name}'");
|
||||||
|
|
||||||
|
// Record the key
|
||||||
|
profile.key = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future updateProfile(UserProfile profile) async {
|
||||||
|
|
||||||
|
if (profile.key == null) {
|
||||||
|
addProfile(profile);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final finder = Finder(filter: Filter.byKey(profile.key));
|
||||||
|
await _folder.update(await _db, profile.toJson(), finder: finder);
|
||||||
|
|
||||||
|
print("Updated user profile <%{profile.key}> - '${profile.name}");
|
||||||
}
|
}
|
||||||
|
|
||||||
Future deleteProfile(UserProfile profile) async {
|
Future deleteProfile(UserProfile profile) async {
|
||||||
final finder = Finder(filter: Filter.equals("name", profile.name));
|
final finder = Finder(filter: Filter.equals("name", profile.name));
|
||||||
await _folder.delete(await _db, finder: finder);
|
await _folder.delete(await _db, finder: finder);
|
||||||
|
|
||||||
print("Deleted user profile ${profile.name}");
|
print("Deleted user profile <${profile.key}> - '${profile.name}'");
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<UserProfile> getProfile(String name) async {
|
Future<UserProfile> getProfile(String name) async {
|
||||||
@ -89,7 +110,7 @@ class UserProfileDBManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return the first matching profile object
|
// Return the first matching profile object
|
||||||
return UserProfile.fromJson(profiles[0].value);
|
return UserProfile.fromJson(profiles[0].key, profiles[0].value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -101,7 +122,7 @@ class UserProfileDBManager {
|
|||||||
List<UserProfile> profileList = new List<UserProfile>();
|
List<UserProfile> profileList = new List<UserProfile>();
|
||||||
|
|
||||||
for (int idx = 0; idx < profiles.length; idx++) {
|
for (int idx = 0; idx < profiles.length; idx++) {
|
||||||
profileList.add(UserProfile.fromJson(profiles[idx].value));
|
profileList.add(UserProfile.fromJson(profiles[idx].key, profiles[idx].value));
|
||||||
}
|
}
|
||||||
|
|
||||||
return profileList;
|
return profileList;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user