2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-07-01 11:20:41 +00:00

Format Code and Add Format Checks to CI (#643)

* Remove unused lib/generated/i18n.dart

* Use `fvm dart format .`

* Add contributing guidelines

* Enforce dart format

* Add `dart format off` directive to generated files
This commit is contained in:
Ben Hagen
2025-06-24 01:55:01 +02:00
committed by GitHub
parent e9db6532e4
commit 4444884afa
100 changed files with 5332 additions and 5592 deletions

View File

@ -1,11 +1,9 @@
import "package:sembast/sembast.dart";
import "package:inventree/helpers.dart";
import "package:inventree/preferences.dart";
class UserProfile {
UserProfile({
this.key,
this.name = "",
@ -14,7 +12,11 @@ class UserProfile {
this.selected = false,
});
factory UserProfile.fromJson(int key, Map<String, dynamic> json, bool isSelected) => UserProfile(
factory UserProfile.fromJson(
int key,
Map<String, dynamic> json,
bool isSelected,
) => UserProfile(
key: key,
name: (json["name"] ?? "") as String,
server: (json["server"] ?? "") as String,
@ -58,7 +60,6 @@ class UserProfile {
* Class for storing and managing user (server) profiles
*/
class UserProfileDBManager {
final store = StoreRef("profiles");
Future<Database> get _db async => InvenTreePreferencesDB.instance.database;
@ -67,7 +68,6 @@ class UserProfileDBManager {
* Check if a profile with the specified name exists in the database
*/
Future<bool> profileNameExists(String name) async {
final profiles = await getAllProfiles();
for (var prf in profiles) {
@ -84,9 +84,10 @@ class UserProfileDBManager {
* Add a new UserProfile to the profiles database.
*/
Future<bool> addProfile(UserProfile profile) async {
if (profile.name.isEmpty) {
debug("addProfile() : Profile missing required values - not adding to database");
debug(
"addProfile() : Profile missing required values - not adding to database",
);
return false;
}
@ -113,7 +114,6 @@ class UserProfileDBManager {
* The unique integer <key> is used to determine if the profile already exists.
*/
Future<bool> updateProfile(UserProfile profile) async {
// Prevent invalid profile data from being updated
if (profile.name.isEmpty) {
debug("updateProfile() : Profile missing required values - not updating");
@ -144,15 +144,15 @@ class UserProfileDBManager {
* The key of the UserProfile should match the "selected" property
*/
Future<UserProfile?> getSelectedProfile() async {
final selected = await store.record("selected").get(await _db);
final profiles = await store.find(await _db);
debug("getSelectedProfile() : ${profiles.length} profiles available - selected = ${selected}");
debug(
"getSelectedProfile() : ${profiles.length} profiles available - selected = ${selected}",
);
for (int idx = 0; idx < profiles.length; idx++) {
if (profiles[idx].key is int && profiles[idx].key == selected) {
return UserProfile.fromJson(
profiles[idx].key! as int,
@ -169,7 +169,6 @@ class UserProfileDBManager {
* Return all user profile objects
*/
Future<List<UserProfile>> getAllProfiles() async {
final selected = await store.record("selected").get(await _db);
final profiles = await store.find(await _db);
@ -177,25 +176,26 @@ class UserProfileDBManager {
List<UserProfile> profileList = [];
for (int idx = 0; idx < profiles.length; idx++) {
if (profiles[idx].key is int) {
profileList.add(
UserProfile.fromJson(
profiles[idx].key! as int,
profiles[idx].value! as Map<String, dynamic>,
profiles[idx].key == selected,
)
),
);
}
}
// If there are no available profiles, create a demo profile
if (profileList.isEmpty) {
bool added = await InvenTreeSettingsManager().getBool("demo_profile_added", false);
bool added = await InvenTreeSettingsManager().getBool(
"demo_profile_added",
false,
);
// Don't add a new profile if we have added it previously
if (!added) {
await InvenTreeSettingsManager().setValue("demo_profile_added", true);
UserProfile demoProfile = UserProfile(
@ -212,7 +212,6 @@ class UserProfileDBManager {
return profileList;
}
/*
* Retrieve a profile by key (or null if no match exists)
*/
@ -231,7 +230,6 @@ class UserProfileDBManager {
return prf;
}
/*
* Retrieve a profile by name (or null if no match exists)
*/