fixes and setup
This commit is contained in:
parent
6ed4db0737
commit
c95242e016
@ -2,7 +2,7 @@ if(PROJECT_ENABLE_SQLITE)
|
|||||||
if(PROJECT_BUILD)
|
if(PROJECT_BUILD)
|
||||||
add_definitions(-DPROJECT_ENABLE_SQLITE)
|
add_definitions(-DPROJECT_ENABLE_SQLITE)
|
||||||
if (PROJECT_IS_MINGW AND NOT PROJECT_IS_MINGW_UNIX)
|
if (PROJECT_IS_MINGW AND NOT PROJECT_IS_MINGW_UNIX)
|
||||||
pkg_check_modules(SQLITE3 REQUIRED sqlite3>=${SQLITE2_VERSION})
|
pkg_check_modules(SQLITE3 REQUIRED sqlite3)
|
||||||
include_directories(SYSTEM BEFORE ${SQLITE3_INCLUDE_DIRS})
|
include_directories(SYSTEM BEFORE ${SQLITE3_INCLUDE_DIRS})
|
||||||
link_libraries(${SQLITE3_LIBRARIES})
|
link_libraries(${SQLITE3_LIBRARIES})
|
||||||
else()
|
else()
|
||||||
|
@ -71,7 +71,7 @@ static const std::unordered_map<utils::cli::option, action, option_hasher>
|
|||||||
cli::actions::pinned_status},
|
cli::actions::pinned_status},
|
||||||
{utils::cli::options::set_option, cli::actions::set},
|
{utils::cli::options::set_option, cli::actions::set},
|
||||||
{utils::cli::options::status_option, cli::actions::status},
|
{utils::cli::options::status_option, cli::actions::status},
|
||||||
{utils::cli::options::ui, cli::actions::ui},
|
{utils::cli::options::ui_option, cli::actions::ui},
|
||||||
{utils::cli::options::unmount_option, cli::actions::unmount},
|
{utils::cli::options::unmount_option, cli::actions::unmount},
|
||||||
{utils::cli::options::unpin_file_option, cli::actions::unpin_file},
|
{utils::cli::options::unpin_file_option, cli::actions::unpin_file},
|
||||||
};
|
};
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include "types/repertory.hpp"
|
#include "types/repertory.hpp"
|
||||||
#include "ui/handlers.hpp"
|
#include "ui/handlers.hpp"
|
||||||
#include "utils/cli_utils.hpp"
|
#include "utils/cli_utils.hpp"
|
||||||
|
#include "utils/file.hpp"
|
||||||
#include "utils/string.hpp"
|
#include "utils/string.hpp"
|
||||||
|
|
||||||
namespace repertory::cli::actions {
|
namespace repertory::cli::actions {
|
||||||
@ -41,18 +42,22 @@ ui(std::vector<const char *> args, const std::string & /*data_directory*/,
|
|||||||
ui_port = utils::string::to_uint16(data);
|
ui_port = utils::string::to_uint16(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
utils::file::change_to_process_directory();
|
if (not utils::file::change_to_process_directory()) {
|
||||||
|
|
||||||
httplib::Server srv;
|
|
||||||
if (not srv.set_mount_point("/", "./web")) {
|
|
||||||
return exit_code::ui_mount_failed;
|
return exit_code::ui_mount_failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
httplib::Server server;
|
||||||
ui::handlers(&srv);
|
if (not server.set_mount_point("/ui", "./web")) {
|
||||||
srv.listen("127.0.0.1", ui_port);
|
return exit_code::ui_mount_failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ui::mgmt_app_config config{
|
||||||
|
.api_auth_ = "test",
|
||||||
|
.api_port_ = ui_port,
|
||||||
|
.api_user_ = "test",
|
||||||
|
};
|
||||||
|
ui::handlers handlers(&config, &server);
|
||||||
|
|
||||||
return exit_code::success;
|
return exit_code::success;
|
||||||
}
|
}
|
||||||
} // namespace repertory::cli::actions
|
} // namespace repertory::cli::actions
|
||||||
|
@ -22,32 +22,44 @@
|
|||||||
#ifndef REPERTORY_INCLUDE_UI_HANDLERS_HPP_
|
#ifndef REPERTORY_INCLUDE_UI_HANDLERS_HPP_
|
||||||
#define REPERTORY_INCLUDE_UI_HANDLERS_HPP_
|
#define REPERTORY_INCLUDE_UI_HANDLERS_HPP_
|
||||||
|
|
||||||
#include "types/repertory.hpp"
|
#include "events/consumers/console_consumer.hpp"
|
||||||
|
|
||||||
|
namespace repertory::ui {
|
||||||
|
struct mgmt_app_config final {
|
||||||
|
std::string api_auth_{"test"};
|
||||||
|
std::uint16_t api_port_{default_ui_mgmt_port};
|
||||||
|
std::string api_user_{"test"};
|
||||||
|
|
||||||
|
[[nodiscard]] auto get_api_auth() const -> std::string { return api_auth_; }
|
||||||
|
|
||||||
|
[[nodiscard]] auto get_api_port() const -> std::uint16_t { return api_port_; }
|
||||||
|
|
||||||
|
[[nodiscard]] auto get_api_user() const -> std::string { return api_user_; }
|
||||||
|
};
|
||||||
|
|
||||||
namespace repertory {
|
|
||||||
class app_config;
|
|
||||||
namespace ui {
|
|
||||||
class handlers final {
|
class handlers final {
|
||||||
public:
|
public:
|
||||||
handlers(app_config *config, httplib::Server *server);
|
handlers(mgmt_app_config *config, httplib::Server *server);
|
||||||
|
|
||||||
handlers() = delete;
|
handlers() = delete;
|
||||||
handlers(const handlers &) = delete;
|
handlers(const handlers &) = delete;
|
||||||
handlers(handlers &&) = delete;
|
handlers(handlers &&) = delete;
|
||||||
|
|
||||||
~handlers() = default;
|
~handlers();
|
||||||
|
|
||||||
auto operator=(const handlers &) -> handlers & = delete;
|
auto operator=(const handlers &) -> handlers & = delete;
|
||||||
auto operator=(handlers &&) -> handlers & = delete;
|
auto operator=(handlers &&) -> handlers & = delete;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
app_config *config_{nullptr};
|
mgmt_app_config *config_;
|
||||||
httplib::Server *server_{nullptr};
|
httplib::Server *server_;
|
||||||
|
|
||||||
|
private:
|
||||||
|
console_consumer console{};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
[[nodiscard]] auto check_authorization(const httplib::Request &req) -> bool;
|
[[nodiscard]] auto check_authorization(const httplib::Request &req) -> bool;
|
||||||
};
|
};
|
||||||
} // namespace ui
|
} // namespace repertory::ui
|
||||||
} // namespace repertory
|
|
||||||
|
|
||||||
#endif // REPERTORY_INCLUDE_UI_HANDLERS_HPP_
|
#endif // REPERTORY_INCLUDE_UI_HANDLERS_HPP_
|
||||||
|
@ -21,12 +21,17 @@
|
|||||||
*/
|
*/
|
||||||
#include "ui/handlers.hpp"
|
#include "ui/handlers.hpp"
|
||||||
|
|
||||||
#include "app_config.hpp"
|
#include "events/event_system.hpp"
|
||||||
|
#include "types/repertory.hpp"
|
||||||
|
#include "utils/base64.hpp"
|
||||||
#include "utils/error_utils.hpp"
|
#include "utils/error_utils.hpp"
|
||||||
|
#include "utils/string.hpp"
|
||||||
|
|
||||||
namespace repertory::ui {
|
namespace repertory::ui {
|
||||||
handlers::handlers(app_config *config, httplib::Server *server)
|
handlers::handlers(mgmt_app_config *config, httplib::Server *server)
|
||||||
: config_(config), server_(server) {
|
: config_(config), server_(server) {
|
||||||
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
server_->set_pre_routing_handler(
|
server_->set_pre_routing_handler(
|
||||||
[this](auto &&req, auto &&res) -> httplib::Server::HandlerResponse {
|
[this](auto &&req, auto &&res) -> httplib::Server::HandlerResponse {
|
||||||
if (check_authorization(req)) {
|
if (check_authorization(req)) {
|
||||||
@ -36,8 +41,36 @@ handlers::handlers(app_config *config, httplib::Server *server)
|
|||||||
res.status = http_error_codes::unauthorized;
|
res.status = http_error_codes::unauthorized;
|
||||||
return httplib::Server::HandlerResponse::Handled;
|
return httplib::Server::HandlerResponse::Handled;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
server_->set_exception_handler([](const httplib::Request &req,
|
||||||
|
httplib::Response &res,
|
||||||
|
std::exception_ptr ptr) {
|
||||||
|
json data{
|
||||||
|
{"path", req.path},
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
std::rethrow_exception(ptr);
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
data["error"] = (e.what() == nullptr) ? "unknown error" : e.what();
|
||||||
|
utils::error::raise_error(function_name, e,
|
||||||
|
"failed request: " + req.path);
|
||||||
|
} catch (...) {
|
||||||
|
data["error"] = "unknown error";
|
||||||
|
utils::error::raise_error(function_name, "unknown error",
|
||||||
|
"failed request: " + req.path);
|
||||||
|
}
|
||||||
|
|
||||||
|
res.set_content(data.dump(), "application/json");
|
||||||
|
res.status = http_error_codes::internal_error;
|
||||||
|
});
|
||||||
|
|
||||||
|
event_system::instance().start();
|
||||||
|
server_->listen("127.0.0.1", config_->get_api_port());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handlers::~handlers() { event_system::instance().stop(); }
|
||||||
|
|
||||||
auto handlers::check_authorization(const httplib::Request &req) -> bool {
|
auto handlers::check_authorization(const httplib::Request &req) -> bool {
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
@ -85,5 +118,4 @@ auto handlers::check_authorization(const httplib::Request &req) -> bool {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace repertory::ui
|
} // namespace repertory::ui
|
||||||
|
@ -89,7 +89,7 @@ if [ -f "${PROJECT_SOURCE_DIR}/web/${PROJECT_NAME}/pubspec.yaml" ]; then
|
|||||||
|
|
||||||
docker build \
|
docker build \
|
||||||
-t ${FLUTTER_TAG_NAME} \
|
-t ${FLUTTER_TAG_NAME} \
|
||||||
${PROJECT_SOURCE_DIR}/docker/x86_64/flutter || exit 1
|
"${PROJECT_SOURCE_DIR}/docker/x86_64/flutter" || exit 1
|
||||||
|
|
||||||
docker run -td \
|
docker run -td \
|
||||||
--name ${FLUTTER_CONTAINER_NAME} \
|
--name ${FLUTTER_CONTAINER_NAME} \
|
||||||
@ -106,8 +106,8 @@ if [ -f "${PROJECT_SOURCE_DIR}/web/${PROJECT_NAME}/pubspec.yaml" ]; then
|
|||||||
flutter build web || exit 1
|
flutter build web || exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rsync -av --progress ${PROJECT_SOURCE_DIR}/web/${PROJECT_NAME}/build/web/ \
|
rsync -av --progress "${PROJECT_SOURCE_DIR}/web/${PROJECT_NAME}/build/web/" \
|
||||||
${PROJECT_DIST_DIR}/web/
|
"${PROJECT_DIST_DIR}/web/"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${PROJECT_IS_MINGW}" == "1" ]; then
|
if [ "${PROJECT_IS_MINGW}" == "1" ]; then
|
||||||
|
1
web/repertory/lib/constants.dart
Normal file
1
web/repertory/lib/constants.dart
Normal file
@ -0,0 +1 @@
|
|||||||
|
const String APP_TITLE = "Repertory Management Portal";
|
@ -1,5 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'constants.dart' as constants;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(const MyApp());
|
runApp(const MyApp());
|
||||||
}
|
}
|
||||||
@ -7,28 +9,12 @@ void main() {
|
|||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
const MyApp({super.key});
|
const MyApp({super.key});
|
||||||
|
|
||||||
// This widget is the root of your application.
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
title: 'Flutter Demo',
|
title: constants.APP_TITLE,
|
||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
// This is the theme of your application.
|
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepOrange),
|
||||||
//
|
|
||||||
// TRY THIS: Try running your application with "flutter run". You'll see
|
|
||||||
// the application has a purple toolbar. Then, without quitting the app,
|
|
||||||
// try changing the seedColor in the colorScheme below to Colors.green
|
|
||||||
// and then invoke "hot reload" (save your changes or press the "hot
|
|
||||||
// reload" button in a Flutter-supported IDE, or press "r" if you used
|
|
||||||
// the command line to start the app).
|
|
||||||
//
|
|
||||||
// Notice that the counter didn't reset back to zero; the application
|
|
||||||
// state is not lost during the reload. To reset the state, use hot
|
|
||||||
// restart instead.
|
|
||||||
//
|
|
||||||
// This works for code too, not just values: Most code changes can be
|
|
||||||
// tested with just a hot reload.
|
|
||||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
|
||||||
),
|
),
|
||||||
home: const MyHomePage(title: 'Flutter Demo Home Page'),
|
home: const MyHomePage(title: 'Flutter Demo Home Page'),
|
||||||
);
|
);
|
||||||
@ -38,15 +24,6 @@ class MyApp extends StatelessWidget {
|
|||||||
class MyHomePage extends StatefulWidget {
|
class MyHomePage extends StatefulWidget {
|
||||||
const MyHomePage({super.key, required this.title});
|
const MyHomePage({super.key, required this.title});
|
||||||
|
|
||||||
// This widget is the home page of your application. It is stateful, meaning
|
|
||||||
// that it has a State object (defined below) that contains fields that affect
|
|
||||||
// how it looks.
|
|
||||||
|
|
||||||
// This class is the configuration for the state. It holds the values (in this
|
|
||||||
// case the title) provided by the parent (in this case the App widget) and
|
|
||||||
// used by the build method of the State. Fields in a Widget subclass are
|
|
||||||
// always marked "final".
|
|
||||||
|
|
||||||
final String title;
|
final String title;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -54,69 +31,19 @@ class MyHomePage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _MyHomePageState extends State<MyHomePage> {
|
class _MyHomePageState extends State<MyHomePage> {
|
||||||
int _counter = 0;
|
|
||||||
|
|
||||||
void _incrementCounter() {
|
|
||||||
setState(() {
|
|
||||||
// This call to setState tells the Flutter framework that something has
|
|
||||||
// changed in this State, which causes it to rerun the build method below
|
|
||||||
// so that the display can reflect the updated values. If we changed
|
|
||||||
// _counter without calling setState(), then the build method would not be
|
|
||||||
// called again, and so nothing would appear to happen.
|
|
||||||
_counter++;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// This method is rerun every time setState is called, for instance as done
|
|
||||||
// by the _incrementCounter method above.
|
|
||||||
//
|
|
||||||
// The Flutter framework has been optimized to make rerunning build methods
|
|
||||||
// fast, so that you can just rebuild anything that needs updating rather
|
|
||||||
// than having to individually change instances of widgets.
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
// TRY THIS: Try changing the color here to a specific color (to
|
|
||||||
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
|
|
||||||
// change color while the other colors stay the same.
|
|
||||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||||
// Here we take the value from the MyHomePage object that was created by
|
|
||||||
// the App.build method, and use it to set our appbar title.
|
|
||||||
title: Text(widget.title),
|
title: Text(widget.title),
|
||||||
),
|
),
|
||||||
body: Center(
|
body: Center(
|
||||||
// Center is a layout widget. It takes a single child and positions it
|
|
||||||
// in the middle of the parent.
|
|
||||||
child: Column(
|
child: Column(
|
||||||
// Column is also a layout widget. It takes a list of children and
|
|
||||||
// arranges them vertically. By default, it sizes itself to fit its
|
|
||||||
// children horizontally, and tries to be as tall as its parent.
|
|
||||||
//
|
|
||||||
// Column has various properties to control how it sizes itself and
|
|
||||||
// how it positions its children. Here we use mainAxisAlignment to
|
|
||||||
// center the children vertically; the main axis here is the vertical
|
|
||||||
// axis because Columns are vertical (the cross axis would be
|
|
||||||
// horizontal).
|
|
||||||
//
|
|
||||||
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
|
|
||||||
// action in the IDE, or press "p" in the console), to see the
|
|
||||||
// wireframe for each widget.
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: <Widget>[
|
children: <Widget>[const Text('TODO-Everything')],
|
||||||
const Text('You have pushed the button this many times:'),
|
|
||||||
Text(
|
|
||||||
'$_counter',
|
|
||||||
style: Theme.of(context).textTheme.headlineMedium,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
floatingActionButton: FloatingActionButton(
|
|
||||||
onPressed: _incrementCounter,
|
|
||||||
tooltip: 'Increment',
|
|
||||||
child: const Icon(Icons.add),
|
|
||||||
), // This trailing comma makes auto-formatting nicer for build methods.
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user