Compare commits
3 Commits
56beeacbb3
...
2a1abd0bb0
Author | SHA1 | Date | |
---|---|---|---|
2a1abd0bb0 | |||
c75ce9ad21 | |||
9afc8e3cb6 |
@ -71,6 +71,8 @@ private:
|
||||
|
||||
void handle_put_set_value_by_name(auto &&req, auto &&res) const;
|
||||
|
||||
void handle_put_settings(auto &&req, auto &&res) const;
|
||||
|
||||
auto launch_process(provider_type prov, std::string_view name,
|
||||
std::string_view args, bool background = false) const
|
||||
-> std::vector<std::string>;
|
||||
|
@ -56,8 +56,12 @@ public:
|
||||
std::string_view name) const
|
||||
-> std::string;
|
||||
|
||||
void set_api_password(std::string_view api_password);
|
||||
|
||||
void set_api_port(std::uint16_t api_port);
|
||||
|
||||
void set_api_user(std::string_view api_user);
|
||||
|
||||
void set_mount_location(provider_type prov, std::string_view name,
|
||||
std::string_view location);
|
||||
};
|
||||
|
@ -118,6 +118,10 @@ handlers::handlers(mgmt_app_config *config, httplib::Server *server)
|
||||
handle_put_set_value_by_name(req, res);
|
||||
});
|
||||
|
||||
server->Put("/api/v1/settings", [this](auto &&req, auto &&res) {
|
||||
handle_put_settings(req, res);
|
||||
});
|
||||
|
||||
static std::atomic<httplib::Server *> this_server{server_};
|
||||
static const auto quit_handler = [](int /* sig */) {
|
||||
auto *ptr = this_server.load();
|
||||
@ -385,6 +389,25 @@ void handlers::handle_put_set_value_by_name(auto &&req, auto &&res) const {
|
||||
res.status = http_error_codes::ok;
|
||||
}
|
||||
|
||||
void handlers::handle_put_settings(auto &&req, auto &&res) const {
|
||||
nlohmann::json data = nlohmann::json::parse(req.get_param_value("data"));
|
||||
|
||||
if (data.contains(JSON_API_PASSWORD)) {
|
||||
config_->set_api_password(data.at(JSON_API_PASSWORD).get<std::string>());
|
||||
}
|
||||
|
||||
if (data.contains(JSON_API_PORT)) {
|
||||
config_->set_api_port(
|
||||
utils::string::to_uint16(data.at(JSON_API_PORT).get<std::string>()));
|
||||
}
|
||||
|
||||
if (data.contains(JSON_API_USER)) {
|
||||
config_->set_api_user(data.at(JSON_API_USER).get<std::string>());
|
||||
}
|
||||
|
||||
res.status = http_error_codes::ok;
|
||||
}
|
||||
|
||||
auto handlers::launch_process(provider_type prov, std::string_view name,
|
||||
std::string_view args, bool background) const
|
||||
-> std::vector<std::string> {
|
||||
|
@ -147,6 +147,15 @@ void mgmt_app_config::save() const {
|
||||
}
|
||||
}
|
||||
|
||||
void mgmt_app_config::set_api_password(std::string_view api_password) {
|
||||
if (api_password_ == std::string{api_password}) {
|
||||
return;
|
||||
}
|
||||
|
||||
api_password_ = std::string{api_password};
|
||||
save();
|
||||
}
|
||||
|
||||
void mgmt_app_config::set_api_port(std::uint16_t api_port) {
|
||||
if (api_port_ == api_port) {
|
||||
return;
|
||||
@ -156,6 +165,15 @@ void mgmt_app_config::set_api_port(std::uint16_t api_port) {
|
||||
save();
|
||||
}
|
||||
|
||||
void mgmt_app_config::set_api_user(std::string_view api_user) {
|
||||
if (api_user_ == std::string{api_user}) {
|
||||
return;
|
||||
}
|
||||
|
||||
api_user_ = std::string{api_user};
|
||||
save();
|
||||
}
|
||||
|
||||
void mgmt_app_config::set_mount_location(provider_type prov,
|
||||
std::string_view name,
|
||||
std::string_view location) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart' show GlobalKey, NavigatorState;
|
||||
|
||||
const addMountTitle = 'Add New Mount';
|
||||
const appSettingsTitle = 'Portal Settings';
|
||||
const appTitle = 'Repertory Management Portal';
|
||||
const databaseTypeList = ['rocksdb', 'sqlite'];
|
||||
const downloadTypeList = ['default', 'direct', 'ring_buffer'];
|
||||
|
@ -52,7 +52,8 @@ class _MyAppState extends State<MyApp> {
|
||||
'/add':
|
||||
(context) => const AddMountScreen(title: constants.addMountTitle),
|
||||
'/settings':
|
||||
(context) => const EditSettingsScreen(title: constants.appTitle),
|
||||
(context) =>
|
||||
const EditSettingsScreen(title: constants.appSettingsTitle),
|
||||
},
|
||||
onGenerateRoute: (settings) {
|
||||
if (settings.name != '/edit') {
|
||||
|
@ -26,12 +26,10 @@ void createBooleanSetting(
|
||||
onPressed:
|
||||
(_) => setState(() {
|
||||
settings[key] = !value;
|
||||
widget.onChanged?.call(widget.settings);
|
||||
}),
|
||||
onToggle: (bool nextValue) {
|
||||
setState(() {
|
||||
settings[key] = nextValue;
|
||||
widget.onChanged?.call(widget.settings);
|
||||
});
|
||||
},
|
||||
),
|
||||
@ -64,7 +62,6 @@ void createIntListSetting(
|
||||
onChanged: (newValue) {
|
||||
setState(() {
|
||||
settings[key] = int.parse(newValue ?? defaultValue.toString());
|
||||
widget.onChanged?.call(widget.settings);
|
||||
});
|
||||
},
|
||||
items:
|
||||
@ -121,7 +118,6 @@ void createIntSetting(
|
||||
}
|
||||
setState(() {
|
||||
settings[key] = int.parse(updatedValue);
|
||||
widget.onChanged?.call(widget.settings);
|
||||
});
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
@ -197,7 +193,6 @@ void createPasswordSetting(
|
||||
|
||||
setState(() {
|
||||
settings[key] = updatedValue1;
|
||||
widget.onChanged?.call(widget.settings);
|
||||
});
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
@ -279,7 +274,6 @@ void createStringListSetting(
|
||||
onChanged:
|
||||
(newValue) => setState(() {
|
||||
settings[key] = newValue;
|
||||
widget.onChanged?.call(widget.settings);
|
||||
}),
|
||||
items:
|
||||
valueList.map<DropdownMenuItem<String>>((item) {
|
||||
@ -336,7 +330,6 @@ void createStringSetting(
|
||||
}
|
||||
setState(() {
|
||||
settings[key] = updatedValue;
|
||||
widget.onChanged?.call(widget.settings);
|
||||
});
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
|
@ -13,13 +13,11 @@ class MountSettingsWidget extends StatefulWidget {
|
||||
final bool isAdd;
|
||||
final bool showAdvanced;
|
||||
final Mount mount;
|
||||
final Function? onChanged;
|
||||
final Map<String, dynamic> settings;
|
||||
const MountSettingsWidget({
|
||||
super.key,
|
||||
this.isAdd = false,
|
||||
required this.mount,
|
||||
this.onChanged,
|
||||
required this.settings,
|
||||
required this.showAdvanced,
|
||||
});
|
||||
|
@ -1,21 +1,23 @@
|
||||
import 'dart:convert' show jsonDecode, jsonEncode;
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:repertory/constants.dart' as constants;
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:repertory/helpers.dart'
|
||||
show getSettingDescription, getSettingValidators, trimNotEmptyValidator;
|
||||
import 'package:repertory/models/mount.dart';
|
||||
import 'package:repertory/models/mount_list.dart';
|
||||
show
|
||||
convertAllToString,
|
||||
getBaseUri,
|
||||
getSettingDescription,
|
||||
getSettingValidators,
|
||||
trimNotEmptyValidator;
|
||||
import 'package:repertory/settings.dart';
|
||||
import 'package:settings_ui/settings_ui.dart';
|
||||
|
||||
class UISettingsWidget extends StatefulWidget {
|
||||
final bool showAdvanced;
|
||||
final Function? onChanged;
|
||||
final Map<String, dynamic> settings;
|
||||
const UISettingsWidget({
|
||||
super.key,
|
||||
this.onChanged,
|
||||
required this.settings,
|
||||
required this.showAdvanced,
|
||||
});
|
||||
@ -25,6 +27,8 @@ class UISettingsWidget extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _UISettingsWidgetState extends State<UISettingsWidget> {
|
||||
late Map<String, dynamic> _origSettings;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
List<SettingsTile> commonSettings = [];
|
||||
@ -94,6 +98,32 @@ class _UISettingsWidgetState extends State<UISettingsWidget> {
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
if (!DeepCollectionEquality().equals(widget.settings, _origSettings)) {
|
||||
http
|
||||
.put(
|
||||
Uri.parse(
|
||||
Uri.encodeFull(
|
||||
'${getBaseUri()}/api/v1/settings?data=${jsonEncode(convertAllToString(widget.settings))}',
|
||||
),
|
||||
),
|
||||
)
|
||||
.then((_) {})
|
||||
.catchError((e) {
|
||||
debugPrint('$e');
|
||||
});
|
||||
}
|
||||
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_origSettings = jsonDecode(jsonEncode(widget.settings));
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void setState(VoidCallback fn) {
|
||||
if (!mounted) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user