Start implementing BugVault

This commit is contained in:
zontreck 2025-03-14 23:28:27 -07:00
parent 847fd65fae
commit db7130aca5
7 changed files with 261 additions and 121 deletions

4
lib/Constants.dart Normal file
View file

@ -0,0 +1,4 @@
class Constants {
static const VERSION = "1.0.031425+2328";
static const APP_NAME = "BugVault";
}

13
lib/FlutterConstants.dart Normal file
View file

@ -0,0 +1,13 @@
import 'package:flutter/widgets.dart';
class FlutterConstants {
static const PROGRESS_BAR_COLOR = Color.fromARGB(255, 0, 165, 102);
static const PROGRESS_BAR_WAIT = Color.fromARGB(255, 97, 0, 0);
static const INPUT_TEXTFIELD_NOT_SELECTED = Color.fromARGB(
255,
228,
228,
228,
);
static const INPUT_TEXTFIELD_SELECTED = Color.fromARGB(255, 0, 170, 170);
}

6
lib/SessionData.dart Normal file
View file

@ -0,0 +1,6 @@
import 'package:libac_dart/nbt/impl/CompoundTag.dart';
class SessionData {
static var g_bDarkMode = true;
static CompoundTag g_nbtConfiguration = CompoundTag();
}

View file

@ -0,0 +1,223 @@
import 'dart:async';
import 'dart:io';
import 'package:bugvault/Constants.dart';
import 'package:bugvault/FlutterConstants.dart';
import 'package:bugvault/SessionData.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:libac_dart/nbt/NbtIo.dart';
import 'package:libac_dart/nbt/impl/CompoundTag.dart';
import 'package:libacflutter/Constants.dart';
class BugVault extends StatefulWidget {
BugVault({super.key});
@override
State<StatefulWidget> createState() {
return BugVaultLoader();
}
}
class BugVaultLoader extends State<BugVault> {
@override
Widget build(BuildContext context) {
return MaterialApp(
routes: {"/": (ctx) => BugVaultLoadPage()},
theme: SessionData.g_bDarkMode ? ThemeData.dark() : ThemeData.light(),
);
}
}
class BugVaultLoadPage extends StatefulWidget {
BugVaultLoadPage({super.key});
@override
State<StatefulWidget> createState() {
return BugVaultLoadPageState();
}
}
class LoadStates {
static const READ_CONFIG = 1;
static const NO_CONFIG = 2;
static const CONFIG_LOADED = 4;
static const WAIT_READ = 8;
static const CONNECTING = 16;
static const LOGIN = 32;
}
class BugVaultLoadPageState extends State<BugVaultLoadPage> {
var g_dLoadProgress = 0.0;
var g_bFirstLoad = true;
var g_ixState = 0;
var g_sLoadMessage = "Please Wait...";
var g_sPageTitle = "BugVault - Loading...";
var g_cProgressBarColor = FlutterConstants.PROGRESS_BAR_COLOR;
TextEditingController USERNAME_CONTROLLER = TextEditingController();
TextEditingController URL_CONTROLLER = TextEditingController(
text: "bugs.zontreck.com",
);
TextEditingController PORT_CONTROLLER = TextEditingController(text: "8372");
@override
void didChangeDependencies() {
if (g_bFirstLoad) {
g_bFirstLoad = false;
// Schedule a timer that will get removed when we hit Progress 1.0
// TODO: When loading, we read a file from the application settings. That file should contain the last BugVault URL accessed. Alternatively, if the environment it is running on is WebJS, it should immediately call the backend to request data.
// NOTE: Data from backend is dependent on page and state. If accessing a bug report/feature request, it may be that the data requested is progress, assigned user, etc.
Timer.periodic(Duration(milliseconds: 150), (timer) async {
g_dLoadProgress += 0.01;
if (g_dLoadProgress >= 1.00) {
g_dLoadProgress = 1.0;
timer.cancel();
}
// STATE SPECIFIC
if (g_dLoadProgress > 0.05 &&
!(g_ixState & LoadStates.READ_CONFIG == LoadStates.READ_CONFIG)) {
g_ixState |= LoadStates.READ_CONFIG;
g_ixState |= LoadStates.WAIT_READ;
g_sLoadMessage = "Reading Configuration File...";
}
if (g_dLoadProgress > 0.10 &&
(g_ixState & LoadStates.WAIT_READ == LoadStates.WAIT_READ)) {
g_ixState = g_ixState & ~LoadStates.WAIT_READ;
File settings = File("settings.dat");
if (settings.existsSync()) {
g_ixState |= LoadStates.CONFIG_LOADED;
SessionData.g_nbtConfiguration =
await NbtIo.read("settings.dat") as CompoundTag;
} else
g_ixState |= LoadStates.NO_CONFIG;
}
if (g_dLoadProgress > 0.15 &&
(g_ixState & LoadStates.CONFIG_LOADED ==
LoadStates.CONFIG_LOADED)) {
g_sLoadMessage =
"Configuration Loaded... Connecting to last server...";
g_ixState = g_ixState & ~LoadStates.CONFIG_LOADED;
g_ixState |= LoadStates.CONNECTING;
}
if (g_dLoadProgress > 0.15 &&
(g_ixState & LoadStates.NO_CONFIG == LoadStates.NO_CONFIG)) {
g_sLoadMessage = "No configuration found... Please Login";
g_ixState = g_ixState & ~LoadStates.NO_CONFIG;
timer.cancel();
g_ixState |= LoadStates.LOGIN;
g_sPageTitle = "BugVault - Login";
g_cProgressBarColor = FlutterConstants.PROGRESS_BAR_WAIT;
}
// Refresh the state in app
setState(() {});
});
}
}
Widget GetLoginElements() {
return Column(
children: [
ListTile(
title: Text("Username"),
subtitle: Text(
"Your username on the server. Leave blank for anonymous access (if the server allows it)",
),
),
highlightTextField(USERNAME_CONTROLLER),
ListTile(
title: Text("URL"),
subtitle: Text(
"The URL to where the instance of BugVault is running",
),
),
Row(
children: [
Text("HOST / FQDN :"),
Expanded(child: highlightTextField(URL_CONTROLLER)),
Text("PORT :"),
Expanded(
child: highlightTextField(
PORT_CONTROLLER,
keyboardType: TextInputType.number,
),
),
],
),
ListTile(
title: Text("NOTICE"),
subtitle: Text(
"By logging in, or registering, you agree to any terms set forth by the service host. If an account does not exist, one will be created for you using the specified user name. \n\nThis application uses Passwordless Logins. \nIf this is your first time using BugVault, you may need to register a TOTP device for MFA. You'll also need to verify an email address. \nFor returning users, you will only be asked for the TOTP code. The email on file will only be used if you do not have access to the device with your TOTP code.",
),
),
],
);
}
Widget highlightTextField(
TextEditingController controller, {
TextInputType keyboardType = TextInputType.text,
}) {
return TextField(
controller: controller,
keyboardType: keyboardType,
inputFormatters: [
keyboardType == TextInputType.text
? FilteringTextInputFormatter.deny("")
: FilteringTextInputFormatter.digitsOnly,
],
decoration: InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: FlutterConstants.INPUT_TEXTFIELD_SELECTED,
),
),
border: OutlineInputBorder(
borderSide: BorderSide(
color: FlutterConstants.INPUT_TEXTFIELD_NOT_SELECTED,
),
),
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(g_sPageTitle),
backgroundColor: LibACFlutterConstants.TITLEBAR_COLOR,
),
body: SingleChildScrollView(
child: Padding(
padding: EdgeInsets.all(8),
child: Column(
children: [
ListTile(title: Text(g_sLoadMessage)),
LinearProgressIndicator(
value: g_dLoadProgress,
minHeight: 20,
color: g_cProgressBarColor,
),
if (g_ixState & LoadStates.LOGIN == LoadStates.LOGIN)
GetLoginElements(),
],
),
),
),
);
}
}

View file

@ -1,122 +1,6 @@
import 'package:bugvault/flutter/BugVaultMain.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// 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'),
);
}
}
class MyHomePage extends StatefulWidget {
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;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
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
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(
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,
// 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),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
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,
children: <Widget>[
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.
);
}
runApp(BugVault());
}

11
lib/users/User.dart Normal file
View file

@ -0,0 +1,11 @@
import 'package:libac_dart/utils/uuid/UUID.dart';
/// The user class is a user object.
///
/// This, most basic object, will only contain data needed for user identification. Issues, groups, etc shall be handled in another area.
class User {
String sName;
UUID ID;
User({required this.sName, required this.ID});
}

View file

@ -2,7 +2,7 @@ name: bugvault
description: "A new Flutter project."
# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
publish_to: "none" # Remove this line if you wish to publish to pub.dev
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.0.0+1
version: 1.0.031425+2328
environment:
sdk: ^3.7.0
@ -57,7 +57,6 @@ dev_dependencies:
# The following section is specific to Flutter packages.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.