2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-28 13:36:50 +00:00

Edit existing profile

This commit is contained in:
Oliver Walters 2021-02-09 08:57:56 +11:00
parent d5649af2f9
commit 74e6315a57
2 changed files with 47 additions and 18 deletions

@ -1 +1 @@
Subproject commit 86fbf66aea18c43cc8920eddce22df5966a7a875 Subproject commit ef139565bba4fcd5889aa242a0062827eab5eceb

View File

@ -27,9 +27,7 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
List<UserProfile> profiles; List<UserProfile> profiles;
_InvenTreeLoginSettingsState(this.profiles) { _InvenTreeLoginSettingsState(this.profiles);
}
void _reload() async { void _reload() async {
@ -39,13 +37,19 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
}); });
} }
void _createProfile(BuildContext context) { void _editProfile(BuildContext context, {UserProfile userProfile, bool createNew = false}) {
var _name; var _name;
var _server; var _server;
var _username; var _username;
var _password; var _password;
UserProfile profile;
if (userProfile != null) {
profile = userProfile;
}
showFormDialog( showFormDialog(
context, context,
I18N.of(context).profileAdd, I18N.of(context).profileAdd,
@ -63,15 +67,26 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
if (_addProfileKey.currentState.validate()) { if (_addProfileKey.currentState.validate()) {
_addProfileKey.currentState.save(); _addProfileKey.currentState.save();
// TODO - create the new profile... if (createNew) {
UserProfile profile = UserProfile( // TODO - create the new profile...
name: _name, UserProfile profile = UserProfile(
server: _server, name: _name,
username: _username, server: _server,
password: _password username: _username,
); password: _password
);
_addProfile(profile); _addProfile(profile);
} else {
profile.name = _name;
profile.server = _server;
profile.username = _username;
profile.password = _password;
_updateProfile(profile);
}
} }
} }
) )
@ -80,24 +95,28 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
StringField( StringField(
label: I18N.of(context).name, label: I18N.of(context).name,
hint: "Enter profile name", hint: "Enter profile name",
initial: createNew ? '' : profile.name,
onSaved: (value) => _name = value, onSaved: (value) => _name = value,
validator: _validateProfileName, validator: _validateProfileName,
), ),
StringField( StringField(
label: I18N.of(context).server, label: I18N.of(context).server,
hint: "http[s]://<server>:<port>", hint: "http[s]://<server>:<port>",
initial: createNew ? '' : profile.server,
validator: _validateServer, validator: _validateServer,
onSaved: (value) => _server = value, onSaved: (value) => _server = value,
), ),
StringField( StringField(
label: I18N.of(context).username, label: I18N.of(context).username,
hint: "Enter username", hint: "Enter username",
initial: createNew ? '' : profile.username,
onSaved: (value) => _username = value, onSaved: (value) => _username = value,
validator: _validateUsername, validator: _validateUsername,
), ),
StringField( StringField(
label: I18N.of(context).password, label: I18N.of(context).password,
hint: "Enter password", hint: "Enter password",
initial: createNew ? '' : profile.password,
onSaved: (value) => _password = value, onSaved: (value) => _password = value,
validator: _validatePassword, validator: _validatePassword,
) )
@ -173,6 +192,16 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
_reload(); _reload();
} }
void _updateProfile(UserProfile profile) async {
await UserProfileDBManager().updateProfile(profile);
// Dismiss the dialog
Navigator.of(context).pop();
_reload();
}
void _addProfile(UserProfile profile) async { void _addProfile(UserProfile profile) async {
await UserProfileDBManager().addProfile(profile); await UserProfileDBManager().addProfile(profile);
@ -216,8 +245,8 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
), ),
SimpleDialogOption( SimpleDialogOption(
onPressed: () { onPressed: () {
//Navigator.of(context).pop(); Navigator.of(context).pop();
// TODO - Edit profile! _editProfile(context, userProfile: profile);
}, },
child: Text(I18N.of(context).profileEdit), child: Text(I18N.of(context).profileEdit),
), ),
@ -226,7 +255,7 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
// Navigator.of(context, rootNavigator: true).pop(); // Navigator.of(context, rootNavigator: true).pop();
confirmationDialog( confirmationDialog(
context, context,
"Delete", I18N.of(context).delete,
"Delete this profile?", "Delete this profile?",
onAccept: () { onAccept: () {
_deleteProfile(profile); _deleteProfile(profile);
@ -248,7 +277,7 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text(I18N.of(context).profile), title: Text(I18N.of(context).profileSelect),
), ),
body: Container( body: Container(
child: ListView( child: ListView(
@ -258,7 +287,7 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
floatingActionButton: FloatingActionButton( floatingActionButton: FloatingActionButton(
child: Icon(FontAwesomeIcons.plus), child: Icon(FontAwesomeIcons.plus),
onPressed: () { onPressed: () {
_createProfile(context); _editProfile(context, createNew: true);
}, },
) )
); );