forked from firka/firka
feat: add mock kréta server + login-screen mock mode toggle
Adds a standalone Go mock server (mock_kreta_server/) with an admin GUI for editing student/grade/timetable/etc data, plus a login-screen long-press toggle to point the app at it instead of the real e-Kréta service for local testing. Also pulls in updated translations from the firka-localization submodule.
This commit is contained in:
@@ -7,10 +7,10 @@ icons:
|
||||
"assets/images/logos/colored_logo_only_mustache.png": "bad6220c11bdfb1dfe04e5173bd2ebedd3999689d4b3a68fc63dc520c96dd33b"
|
||||
l10n:
|
||||
"l10n.yml": "a57bc304cac4a2b0235593586f17f400a5165d67fc9aadeaa11893cfa36ee082"
|
||||
"lib/l10n/app_hu.arb": "e11b8fe4d4fd239584792971c341f1e329fb91f5f49fa6baa664c98b06fc5176"
|
||||
"lib/l10n/app_de.arb": "5114c70b506f290217161881336d6118c975d59f32347bbdc94a51c1a25293e7"
|
||||
"lib/l10n/app_en.arb": "a5417b2de058a67db40fa7bfb3526d800fd2f82349dfbc895cff8b298069e707"
|
||||
"lib/l10n/app_pl.arb": "36cad0796cf8bd20fe969d5fd8443430d25fa932028c0177917ecef6964a08dd"
|
||||
"lib/l10n/app_de.arb": "125070dd8de963b7e3b91196c4e94c4d18404a4013fd3bd41a43b92ec9109fc9"
|
||||
"lib/l10n/app_hu.arb": "90bffe2a339abbc9ece90a19d2fac0c56f07f2f54c713e45fb710c9a09dc01a6"
|
||||
"lib/l10n/app_en.arb": "f1898853cf2503aaf28f79640a4ed81dd8ce9b156d8a618d2492550ecc7c3f24"
|
||||
"lib/l10n/app_pl.arb": "a8426455757e587c7635c3a62c650a4aae2a0cac1de1175e8ab7fb0d3b387537"
|
||||
isar:
|
||||
"lib/data/models/app_settings_model.dart": "5eb5af345f1347f104257f0999763650fe2673f9da1754bd12d3f756fe5c9723"
|
||||
"lib/data/models/token_model.dart": "8c957cd07e473827d78fd8fd4fb6c1336b636a69c25c93618e1e7f94b7cf0683"
|
||||
|
||||
@@ -21,6 +21,7 @@ import 'package:kreta_api/kreta_api.dart';
|
||||
|
||||
import 'package:firka/app/app_state.dart';
|
||||
import 'package:firka/core/bloc/toast_cubit.dart';
|
||||
import 'package:firka/core/dev/mock_backend.dart';
|
||||
import 'package:firka_common/data/models/token_model.dart';
|
||||
import 'package:firka/core/debug_helper.dart';
|
||||
import 'package:firka_common/data/util.dart';
|
||||
@@ -480,7 +481,7 @@ class KretaClient {
|
||||
};
|
||||
|
||||
return await dio.get(
|
||||
url,
|
||||
MockBackend.rewrite(url),
|
||||
options: Options(
|
||||
method: method,
|
||||
headers: headers,
|
||||
|
||||
34
firka/lib/api/login_finish.dart
Normal file
34
firka/lib/api/login_finish.dart
Normal file
@@ -0,0 +1,34 @@
|
||||
import "dart:io";
|
||||
|
||||
import "package:firka/app/app_state.dart";
|
||||
import "package:firka/app/initialization.dart";
|
||||
import "package:firka/services/watch_sync_helper.dart";
|
||||
import "package:firka_common/data/models/token_model.dart";
|
||||
import "package:kreta_api/kreta_api.dart";
|
||||
|
||||
Future<void> completeLogin(
|
||||
AppInitialization data,
|
||||
TokenGrantResponse resp,
|
||||
) async {
|
||||
var tokenModel = TokenModel.fromResp(resp);
|
||||
|
||||
await data.isar.writeTxn(() async {
|
||||
await data.isar.tokenModels.put(tokenModel);
|
||||
});
|
||||
|
||||
await data.settings.setSelectedAccountKey(tokenModel.key);
|
||||
await initializeApp();
|
||||
|
||||
if (Platform.isIOS) {
|
||||
final watchInstalled = await WatchSyncHelper.isWatchAppInstalled();
|
||||
if (watchInstalled) {
|
||||
try {
|
||||
await WatchSyncHelper.saveTokenToiCloud(tokenModel);
|
||||
} catch (_) {}
|
||||
|
||||
try {
|
||||
await WatchSyncHelper.sendTokenToWatch();
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
38
firka/lib/api/mock_login.dart
Normal file
38
firka/lib/api/mock_login.dart
Normal file
@@ -0,0 +1,38 @@
|
||||
import "package:dio/dio.dart";
|
||||
import "package:firka_common/core/consts.dart";
|
||||
|
||||
import "package:firka/app/app_state.dart";
|
||||
import "package:firka/core/dev/mock_backend.dart";
|
||||
import "package:kreta_api/kreta_api.dart";
|
||||
|
||||
Future<TokenGrantResponse> mockLogin(String username, String password) async {
|
||||
final headers = <String, String>{
|
||||
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
|
||||
"accept": "*/*",
|
||||
"user-agent": initData.userAgent,
|
||||
};
|
||||
|
||||
final formData = <String, String>{
|
||||
"grant_type": "password",
|
||||
"username": username,
|
||||
"password": password,
|
||||
"client_id": Constants.clientId,
|
||||
};
|
||||
|
||||
final response = await dio.post(
|
||||
MockBackend.rewrite(KretaLoginEndpoints.tokenGrantUrl),
|
||||
options: Options(headers: headers),
|
||||
data: formData,
|
||||
);
|
||||
|
||||
switch (response.statusCode) {
|
||||
case 200:
|
||||
return TokenGrantResponse.fromJson(response.data);
|
||||
case 401:
|
||||
throw Exception("Invalid credentials");
|
||||
default:
|
||||
throw Exception(
|
||||
"Failed to get access token, response code: ${response.statusCode}",
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import 'package:firka_common/core/consts.dart';
|
||||
import 'package:firka_common/data/models/token_model.dart';
|
||||
|
||||
import 'package:firka/app/app_state.dart';
|
||||
import 'package:firka/core/dev/mock_backend.dart';
|
||||
import 'package:kreta_api/kreta_api.dart';
|
||||
|
||||
Future<TokenGrantResponse> getAccessToken(String code) async {
|
||||
@@ -23,7 +24,7 @@ Future<TokenGrantResponse> getAccessToken(String code) async {
|
||||
|
||||
try {
|
||||
final response = await dio.post(
|
||||
KretaLoginEndpoints.tokenGrantUrl,
|
||||
MockBackend.rewrite(KretaLoginEndpoints.tokenGrantUrl),
|
||||
options: Options(headers: headers),
|
||||
data: formData,
|
||||
);
|
||||
@@ -76,7 +77,7 @@ Future<TokenGrantResponse> extendToken(TokenModel model) async {
|
||||
}
|
||||
|
||||
final response = await dio.post(
|
||||
KretaLoginEndpoints.tokenGrantUrl,
|
||||
MockBackend.rewrite(KretaLoginEndpoints.tokenGrantUrl),
|
||||
options: Options(headers: headers),
|
||||
data: formData,
|
||||
);
|
||||
|
||||
22
firka/lib/core/dev/mock_backend.dart
Normal file
22
firka/lib/core/dev/mock_backend.dart
Normal file
@@ -0,0 +1,22 @@
|
||||
import "package:firka/core/settings/settings_repository.dart";
|
||||
import "package:firka/core/settings/settings_schema.dart";
|
||||
|
||||
class MockBackend {
|
||||
static String rewrite(String url) {
|
||||
if (!Settings.mockBackendEnabled.value) return url;
|
||||
|
||||
final mockBase = Settings.mockBackendUrl.value;
|
||||
if (mockBase.isEmpty) return url;
|
||||
|
||||
final mockUri = Uri.parse(mockBase);
|
||||
final uri = Uri.parse(url);
|
||||
|
||||
return uri
|
||||
.replace(
|
||||
scheme: mockUri.scheme,
|
||||
host: mockUri.host,
|
||||
port: mockUri.hasPort ? mockUri.port : null,
|
||||
)
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
@@ -142,4 +142,10 @@ abstract class SettingsSchema {
|
||||
|
||||
@StringSetting(id: 1031, defaultValue: "firka")
|
||||
String get selectedGradeThemeId;
|
||||
|
||||
@BoolSetting(id: 1032, defaultValue: false)
|
||||
bool get mockBackendEnabled;
|
||||
|
||||
@StringSetting(id: 1033, defaultValue: "http://10.0.0.144:8090")
|
||||
String get mockBackendUrl;
|
||||
}
|
||||
|
||||
@@ -33,9 +33,11 @@ class SettingsRegistry {
|
||||
static const selectedThemeId = StringSetting(id: 1029, defaultValue: "builtin-firka-firka");
|
||||
static const selectedCoreThemeId = StringSetting(id: 1030, defaultValue: "firka");
|
||||
static const selectedGradeThemeId = StringSetting(id: 1031, defaultValue: "firka");
|
||||
static const mockBackendEnabled = BoolSetting(id: 1032, defaultValue: false);
|
||||
static const mockBackendUrl = StringSetting(id: 1033, defaultValue: "http://10.0.0.144:8090");
|
||||
|
||||
static const all = <Setting>[
|
||||
bellDelay, rounding1, rounding2, rounding3, rounding4, classAvgOnGraph, leftHandedMode, language, appIcon, childProtection, betaWarning, ttToastLessonNo, ttToastTestsAndHw, ttToastBreaks, statsForNerds, developerOptsEnabled, themeBrightness, ttToastSubstitution, liveActivityEnabled, liveActivityPrivacyEverDeclined, morningNotificationEnabled, morningNotificationTime, ttToastABTimetable, wearOsSupport, titleFont, titleWeight, titleCapitalization, selectedThemeId, selectedCoreThemeId, selectedGradeThemeId,
|
||||
bellDelay, rounding1, rounding2, rounding3, rounding4, classAvgOnGraph, leftHandedMode, language, appIcon, childProtection, betaWarning, ttToastLessonNo, ttToastTestsAndHw, ttToastBreaks, statsForNerds, developerOptsEnabled, themeBrightness, ttToastSubstitution, liveActivityEnabled, liveActivityPrivacyEverDeclined, morningNotificationEnabled, morningNotificationTime, ttToastABTimetable, wearOsSupport, titleFont, titleWeight, titleCapitalization, selectedThemeId, selectedCoreThemeId, selectedGradeThemeId, mockBackendEnabled, mockBackendUrl,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -70,4 +72,6 @@ extension SettingsAccessors on SettingsRepository {
|
||||
SilentlySettable<String> get selectedThemeId => SilentlySettable(this, SettingsRegistry.selectedThemeId);
|
||||
SilentlySettable<String> get selectedCoreThemeId => SilentlySettable(this, SettingsRegistry.selectedCoreThemeId);
|
||||
SilentlySettable<String> get selectedGradeThemeId => SilentlySettable(this, SettingsRegistry.selectedGradeThemeId);
|
||||
SilentlySettable<bool> get mockBackendEnabled => SilentlySettable(this, SettingsRegistry.mockBackendEnabled);
|
||||
SilentlySettable<String> get mockBackendUrl => SilentlySettable(this, SettingsRegistry.mockBackendUrl);
|
||||
}
|
||||
|
||||
Submodule firka/lib/l10n updated: f4812ec3b3...e4b58064ee
@@ -20,6 +20,8 @@ import 'package:go_router/go_router.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
|
||||
import 'package:firka/core/debug_helper.dart';
|
||||
import 'package:firka/core/settings/settings_repository.dart';
|
||||
import 'package:firka/core/settings/settings_schema.dart';
|
||||
import 'package:firka/core/state/firka_state.dart';
|
||||
import 'package:firka/ui/shared/firka_icon.dart';
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
@@ -44,6 +46,7 @@ class _DebugScreen extends FirkaState<DebugScreen> {
|
||||
Uint8List? profilePictureData;
|
||||
|
||||
bool useCache = true;
|
||||
late TextEditingController _mockBackendUrlController;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -51,6 +54,15 @@ class _DebugScreen extends FirkaState<DebugScreen> {
|
||||
|
||||
_picker = ImagePicker();
|
||||
profilePictureData = widget.data.profilePicture;
|
||||
_mockBackendUrlController = TextEditingController(
|
||||
text: Settings.mockBackendUrl.value,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_mockBackendUrlController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -99,6 +111,30 @@ class _DebugScreen extends FirkaState<DebugScreen> {
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Row(
|
||||
children: [
|
||||
Text('use mock backend'),
|
||||
Switch(
|
||||
value: Settings.mockBackendEnabled.value,
|
||||
onChanged: (bool value) {
|
||||
setState(() {
|
||||
Settings.mockBackendEnabled.set(value);
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: TextField(
|
||||
controller: _mockBackendUrlController,
|
||||
decoration: const InputDecoration(labelText: 'mock backend url'),
|
||||
onSubmitted: (value) {
|
||||
Settings.mockBackendUrl.set(value);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
profilePicture,
|
||||
ElevatedButton(
|
||||
|
||||
@@ -15,7 +15,11 @@ import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:sensors_plus/sensors_plus.dart';
|
||||
import 'package:vibration/vibration.dart';
|
||||
|
||||
import 'package:firka/api/login_finish.dart';
|
||||
import 'package:firka/api/mock_login.dart';
|
||||
import 'package:firka/core/bloc/theme_cubit.dart';
|
||||
import 'package:firka/core/settings/settings_repository.dart';
|
||||
import 'package:firka/core/settings/settings_schema.dart';
|
||||
import 'package:firka/core/state/firka_state.dart';
|
||||
import 'package:firka/core/image_preloader.dart';
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
@@ -32,6 +36,11 @@ class _LoginScreenState extends FirkaState<LoginScreen> {
|
||||
late LoginWebviewWidget _loginWebView;
|
||||
bool _preloadDone = false;
|
||||
|
||||
final _mockUsernameController = TextEditingController(text: "student");
|
||||
final _mockPasswordController = TextEditingController(text: "student");
|
||||
bool _mockLoginInProgress = false;
|
||||
String? _mockLoginError;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -40,6 +49,125 @@ class _LoginScreenState extends FirkaState<LoginScreen> {
|
||||
_preloadImages();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_mockUsernameController.dispose();
|
||||
_mockPasswordController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _showMockModeDialog() async {
|
||||
final wasEnabled = Settings.mockBackendEnabled.value;
|
||||
final urlController = TextEditingController(
|
||||
text: Settings.mockBackendUrl.value,
|
||||
);
|
||||
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (BuildContext dialogContext) {
|
||||
return AlertDialog(
|
||||
backgroundColor: appStyle.colors.card,
|
||||
title: Text(
|
||||
wasEnabled ? 'Disable mock mode?' : 'Enable mock mode?',
|
||||
style: appStyle.fonts.H_16px.copyWith(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
content: wasEnabled
|
||||
? Text(
|
||||
'Logging in will go back to the real e-Kréta service.',
|
||||
style: appStyle.fonts.B_14R.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
)
|
||||
: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Logging in will talk to this mock kréta server instead of the real e-Kréta service. Use the mock API\'s IP, not localhost.',
|
||||
style: appStyle.fonts.B_14R.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
controller: urlController,
|
||||
autofocus: true,
|
||||
style: appStyle.fonts.B_14R.apply(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
hintText: 'http://10.0.0.144:8090',
|
||||
hintStyle: appStyle.fonts.B_14R.apply(
|
||||
color: appStyle.colors.textTertiary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text(
|
||||
'Cancel',
|
||||
style: appStyle.fonts.B_14R.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
),
|
||||
onPressed: () => Navigator.of(dialogContext).pop(false),
|
||||
),
|
||||
TextButton(
|
||||
child: Text(
|
||||
wasEnabled ? 'Disable' : 'Enable',
|
||||
style: appStyle.fonts.B_14R.apply(color: appStyle.colors.accent),
|
||||
),
|
||||
onPressed: () => Navigator.of(dialogContext).pop(true),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (confirmed != true) return;
|
||||
|
||||
if (!wasEnabled) {
|
||||
await Settings.mockBackendUrl.set(urlController.text.trim());
|
||||
}
|
||||
await Settings.mockBackendEnabled.set(!wasEnabled);
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_mockLoginError = null;
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _submitMockLogin() async {
|
||||
setState(() {
|
||||
_mockLoginInProgress = true;
|
||||
_mockLoginError = null;
|
||||
});
|
||||
|
||||
try {
|
||||
final resp = await mockLogin(
|
||||
_mockUsernameController.text,
|
||||
_mockPasswordController.text,
|
||||
);
|
||||
await completeLogin(widget.data, resp);
|
||||
if (!mounted) return;
|
||||
appRouter?.go('/home');
|
||||
} catch (ex) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_mockLoginError = ex.toString();
|
||||
});
|
||||
} finally {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_mockLoginInProgress = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String _getPrivacyPolicyUrl() {
|
||||
return "https://firka.app/privacy";
|
||||
}
|
||||
@@ -87,6 +215,143 @@ class _LoginScreenState extends FirkaState<LoginScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildRealLoginButton() {
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
showModalBottomSheet<void>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
showDragHandle: false,
|
||||
builder: (BuildContext context) {
|
||||
return SizedBox(
|
||||
height: MediaQuery.sizeOf(context).height,
|
||||
child: _loginWebView,
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
height: 48,
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
decoration: ShapeDecoration(
|
||||
color: appStyle.colors.accent,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
shadows: [
|
||||
BoxShadow(
|
||||
color: appStyle.colors.textPrimary.withAlpha(13),
|
||||
blurRadius: 2,
|
||||
offset: const Offset(0, 1),
|
||||
spreadRadius: 0,
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
widget.data.l10n.loginBtn,
|
||||
textAlign: TextAlign.center,
|
||||
style: appStyle.fonts.H_16px.copyWith(
|
||||
color: appStyle.colors.textPrimaryLight,
|
||||
fontVariations: const [FontVariation("wght", 800)],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMockLoginField(
|
||||
TextEditingController controller,
|
||||
String hint, {
|
||||
bool obscure = false,
|
||||
}) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: appStyle.colors.card,
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
),
|
||||
child: TextField(
|
||||
controller: controller,
|
||||
obscureText: obscure,
|
||||
textInputAction: TextInputAction.next,
|
||||
cursorColor: appStyle.colors.accent,
|
||||
style: appStyle.fonts.B_16R.apply(color: appStyle.colors.textPrimary),
|
||||
decoration: InputDecoration(
|
||||
hintText: hint,
|
||||
hintStyle: appStyle.fonts.B_16R.apply(
|
||||
color: appStyle.colors.textTertiary,
|
||||
),
|
||||
border: InputBorder.none,
|
||||
enabledBorder: InputBorder.none,
|
||||
focusedBorder: InputBorder.none,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMockLoginForm() {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
'Mock mode, will connect to: ${Settings.mockBackendUrl.value.isEmpty ? "(not set, long-press the logo to disable then enable again and fill in the URL)" : Settings.mockBackendUrl.value}',
|
||||
textAlign: TextAlign.center,
|
||||
style: appStyle.fonts.B_12R.copyWith(
|
||||
color: appStyle.colors.textTertiary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_buildMockLoginField(_mockUsernameController, 'Username'),
|
||||
const SizedBox(height: 8),
|
||||
_buildMockLoginField(
|
||||
_mockPasswordController,
|
||||
'Password',
|
||||
obscure: true,
|
||||
),
|
||||
if (_mockLoginError != null) ...[
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
_mockLoginError!,
|
||||
textAlign: TextAlign.center,
|
||||
style: appStyle.fonts.B_12R.copyWith(color: Colors.red),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 8),
|
||||
InkWell(
|
||||
onTap: _mockLoginInProgress ? null : _submitMockLogin,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
height: 48,
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
decoration: ShapeDecoration(
|
||||
color: appStyle.colors.accent,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
child: Center(
|
||||
child: _mockLoginInProgress
|
||||
? const DelayedSpinnerWidget()
|
||||
: Text(
|
||||
widget.data.l10n.loginBtn,
|
||||
textAlign: TextAlign.center,
|
||||
style: appStyle.fonts.H_16px.copyWith(
|
||||
color: appStyle.colors.textPrimaryLight,
|
||||
fontVariations: const [FontVariation("wght", 800)],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!_preloadDone) {
|
||||
@@ -176,33 +441,44 @@ class _LoginScreenState extends FirkaState<LoginScreen> {
|
||||
const SizedBox(height: 16),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: paddingWidthHorizontal),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 30,
|
||||
height: 30,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
decoration: ShapeDecoration(
|
||||
image: DecorationImage(
|
||||
image: PreloadedImageProvider(
|
||||
DefaultAssetBundle.of(context),
|
||||
'assets/images/logos/colored_logo.webp',
|
||||
child: GestureDetector(
|
||||
onLongPress: _showMockModeDialog,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 12,
|
||||
horizontal: 8,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
width: 30,
|
||||
height: 30,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
decoration: ShapeDecoration(
|
||||
image: DecorationImage(
|
||||
image: PreloadedImageProvider(
|
||||
DefaultAssetBundle.of(context),
|
||||
'assets/images/logos/colored_logo.webp',
|
||||
),
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
),
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'Firka Napló',
|
||||
style: appStyle.fonts.H_18px.copyWith(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'Firka Napló',
|
||||
style: appStyle.fonts.H_18px.copyWith(
|
||||
color: appStyle.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
@@ -459,61 +735,13 @@ class _LoginScreenState extends FirkaState<LoginScreen> {
|
||||
right: 0,
|
||||
child: Column(
|
||||
children: [
|
||||
Center(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: paddingWidthHorizontal,
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
showModalBottomSheet<void>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
showDragHandle: false,
|
||||
builder: (BuildContext context) {
|
||||
return SizedBox(
|
||||
height: MediaQuery.sizeOf(context).height,
|
||||
child: _loginWebView,
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
height: 48,
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
decoration: ShapeDecoration(
|
||||
color: appStyle.colors.accent,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
shadows: [
|
||||
BoxShadow(
|
||||
color: appStyle.colors.textPrimary.withAlpha(
|
||||
13,
|
||||
),
|
||||
blurRadius: 2,
|
||||
offset: const Offset(0, 1),
|
||||
spreadRadius: 0,
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
widget.data.l10n.loginBtn,
|
||||
textAlign: TextAlign.center,
|
||||
style: appStyle.fonts.H_16px.copyWith(
|
||||
color: appStyle.colors.textPrimaryLight,
|
||||
fontVariations: const [
|
||||
FontVariation("wght", 800),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: paddingWidthHorizontal,
|
||||
),
|
||||
child: Settings.mockBackendEnabled.value
|
||||
? _buildMockLoginForm()
|
||||
: _buildRealLoginButton(),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
GestureDetector(
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:firka_common/core/consts.dart';
|
||||
import 'package:firka/app/app_state.dart';
|
||||
import 'package:firka/app/initialization.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -11,9 +9,9 @@ import 'package:flutter_svg/svg.dart';
|
||||
import 'package:majesticons_flutter/majesticons_flutter.dart';
|
||||
import 'package:webview_flutter/webview_flutter.dart';
|
||||
|
||||
import 'package:firka/services/watch_sync_helper.dart';
|
||||
import 'package:firka/api/login_finish.dart';
|
||||
import 'package:firka/api/token_grant.dart';
|
||||
import 'package:firka_common/data/models/token_model.dart';
|
||||
import 'package:firka/core/dev/mock_backend.dart';
|
||||
import 'package:firka/core/state/firka_state.dart';
|
||||
import 'package:firka/ui/theme/style.dart';
|
||||
|
||||
@@ -65,6 +63,8 @@ class _LoginWebviewWidgetState extends FirkaState<LoginWebviewWidget>
|
||||
);
|
||||
}
|
||||
|
||||
loginUrl = MockBackend.rewrite(loginUrl);
|
||||
|
||||
final trimmed = loginUrl.replaceFirst(RegExp(r'^https?://'), '');
|
||||
final parts = trimmed.split('/');
|
||||
_displayHost = parts.isNotEmpty ? parts.first : trimmed;
|
||||
@@ -102,37 +102,11 @@ class _LoginWebviewWidgetState extends FirkaState<LoginWebviewWidget>
|
||||
var code = uri.queryParameters["code"]!;
|
||||
|
||||
try {
|
||||
var isar = widget.data.isar;
|
||||
var resp = await getAccessToken(code);
|
||||
|
||||
logger.info("getAccessToken(): $resp");
|
||||
|
||||
var tokenModel = TokenModel.fromResp(resp);
|
||||
|
||||
await isar.writeTxn(() async {
|
||||
await isar.tokenModels.put(tokenModel);
|
||||
});
|
||||
|
||||
await widget.data.settings.setSelectedAccountKey(
|
||||
tokenModel.key,
|
||||
);
|
||||
await initializeApp();
|
||||
|
||||
if (Platform.isIOS) {
|
||||
final watchInstalled =
|
||||
await WatchSyncHelper.isWatchAppInstalled();
|
||||
if (watchInstalled) {
|
||||
try {
|
||||
await WatchSyncHelper.saveTokenToiCloud(tokenModel);
|
||||
} catch (_) {}
|
||||
|
||||
try {
|
||||
await WatchSyncHelper.sendTokenToWatch();
|
||||
} catch (_) {
|
||||
// Watch may be unavailable, ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
await completeLogin(widget.data, resp);
|
||||
|
||||
if (!mounted) return NavigationDecision.prevent;
|
||||
|
||||
|
||||
2
mock_kreta_server/.gitignore
vendored
Normal file
2
mock_kreta_server/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
mock_kreta_server
|
||||
186
mock_kreta_server/admin.go
Normal file
186
mock_kreta_server/admin.go
Normal file
@@ -0,0 +1,186 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func decodeBody(r *http.Request, v any) error {
|
||||
defer r.Body.Close()
|
||||
return json.NewDecoder(r.Body).Decode(v)
|
||||
}
|
||||
|
||||
func (s *Server) adminCollection(
|
||||
get func() any,
|
||||
set func(*http.Request) error,
|
||||
) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
writeJSON(w, get())
|
||||
case http.MethodPut:
|
||||
if err := set(r); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
default:
|
||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) registerAdminRoutes(mux *http.ServeMux) {
|
||||
mux.HandleFunc("/admin/api/config", s.adminCollection(
|
||||
func() any { return s.store.GetConfig() },
|
||||
func(r *http.Request) error {
|
||||
var v ServerConfig
|
||||
if err := decodeBody(r, &v); err != nil {
|
||||
return err
|
||||
}
|
||||
s.store.SetConfig(v)
|
||||
return nil
|
||||
},
|
||||
))
|
||||
|
||||
mux.HandleFunc("/admin/api/student", s.adminCollection(
|
||||
func() any { return s.store.GetStudent() },
|
||||
func(r *http.Request) error {
|
||||
var v Student
|
||||
if err := decodeBody(r, &v); err != nil {
|
||||
return err
|
||||
}
|
||||
s.store.SetStudent(v)
|
||||
return nil
|
||||
},
|
||||
))
|
||||
|
||||
mux.HandleFunc("/admin/api/classGroups", s.adminCollection(
|
||||
func() any { return s.store.GetClassGroups() },
|
||||
func(r *http.Request) error {
|
||||
var v []ClassGroup
|
||||
if err := decodeBody(r, &v); err != nil {
|
||||
return err
|
||||
}
|
||||
s.store.SetClassGroups(v)
|
||||
return nil
|
||||
},
|
||||
))
|
||||
|
||||
mux.HandleFunc("/admin/api/grades", s.adminCollection(
|
||||
func() any { return s.store.GetGrades() },
|
||||
func(r *http.Request) error {
|
||||
var v []Grade
|
||||
if err := decodeBody(r, &v); err != nil {
|
||||
return err
|
||||
}
|
||||
s.store.SetGrades(v)
|
||||
return nil
|
||||
},
|
||||
))
|
||||
|
||||
mux.HandleFunc("/admin/api/homework", s.adminCollection(
|
||||
func() any { return s.store.GetHomework() },
|
||||
func(r *http.Request) error {
|
||||
var v []Homework
|
||||
if err := decodeBody(r, &v); err != nil {
|
||||
return err
|
||||
}
|
||||
s.store.SetHomework(v)
|
||||
return nil
|
||||
},
|
||||
))
|
||||
|
||||
mux.HandleFunc("/admin/api/tests", s.adminCollection(
|
||||
func() any { return s.store.GetTests() },
|
||||
func(r *http.Request) error {
|
||||
var v []Test
|
||||
if err := decodeBody(r, &v); err != nil {
|
||||
return err
|
||||
}
|
||||
s.store.SetTests(v)
|
||||
return nil
|
||||
},
|
||||
))
|
||||
|
||||
mux.HandleFunc("/admin/api/omissions", s.adminCollection(
|
||||
func() any { return s.store.GetOmissions() },
|
||||
func(r *http.Request) error {
|
||||
var v []Omission
|
||||
if err := decodeBody(r, &v); err != nil {
|
||||
return err
|
||||
}
|
||||
s.store.SetOmissions(v)
|
||||
return nil
|
||||
},
|
||||
))
|
||||
|
||||
mux.HandleFunc("/admin/api/lessons", s.adminCollection(
|
||||
func() any { return s.store.GetLessons() },
|
||||
func(r *http.Request) error {
|
||||
var v []Lesson
|
||||
if err := decodeBody(r, &v); err != nil {
|
||||
return err
|
||||
}
|
||||
s.store.SetLessons(v)
|
||||
return nil
|
||||
},
|
||||
))
|
||||
|
||||
mux.HandleFunc("/admin/api/notices", s.adminCollection(
|
||||
func() any { return s.store.GetNotices() },
|
||||
func(r *http.Request) error {
|
||||
var v []NoticeBoardItem
|
||||
if err := decodeBody(r, &v); err != nil {
|
||||
return err
|
||||
}
|
||||
s.store.SetNotices(v)
|
||||
return nil
|
||||
},
|
||||
))
|
||||
|
||||
mux.HandleFunc("/admin/api/infoBoard", s.adminCollection(
|
||||
func() any { return s.store.GetInfoBoard() },
|
||||
func(r *http.Request) error {
|
||||
var v []InfoBoardItem
|
||||
if err := decodeBody(r, &v); err != nil {
|
||||
return err
|
||||
}
|
||||
s.store.SetInfoBoard(v)
|
||||
return nil
|
||||
},
|
||||
))
|
||||
|
||||
mux.HandleFunc("/admin/api/dktSubjects", s.adminCollection(
|
||||
func() any { return s.store.GetDktSubjects() },
|
||||
func(r *http.Request) error {
|
||||
var v []DktSubject
|
||||
if err := decodeBody(r, &v); err != nil {
|
||||
return err
|
||||
}
|
||||
s.store.SetDktSubjects(v)
|
||||
return nil
|
||||
},
|
||||
))
|
||||
|
||||
mux.HandleFunc("/admin/api/averages", s.adminCollection(
|
||||
func() any { return s.store.GetAverages() },
|
||||
func(r *http.Request) error {
|
||||
var v []ClassGroupSubjectAverage
|
||||
if err := decodeBody(r, &v); err != nil {
|
||||
return err
|
||||
}
|
||||
s.store.SetAverages(v)
|
||||
return nil
|
||||
},
|
||||
))
|
||||
|
||||
mux.HandleFunc("/admin/api/reset", func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
s.store.Reset()
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
})
|
||||
}
|
||||
55
mock_kreta_server/api.go
Normal file
55
mock_kreta_server/api.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func writeJSON(w http.ResponseWriter, v any) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(v)
|
||||
}
|
||||
|
||||
func (s *Server) handleGetStudent(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, s.store.GetStudent())
|
||||
}
|
||||
|
||||
func (s *Server) handleGetClassGroups(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, s.store.GetClassGroups())
|
||||
}
|
||||
|
||||
func (s *Server) handleGetNoticeBoard(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, s.store.GetNotices())
|
||||
}
|
||||
|
||||
func (s *Server) handleGetInfoBoard(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, s.store.GetInfoBoard())
|
||||
}
|
||||
|
||||
func (s *Server) handleGetGrades(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, s.store.GetGrades())
|
||||
}
|
||||
|
||||
func (s *Server) handleGetClassGroupAverages(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, s.store.GetAverages())
|
||||
}
|
||||
|
||||
func (s *Server) handleGetTimeTable(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, s.store.GetLessons())
|
||||
}
|
||||
|
||||
func (s *Server) handleGetOmissions(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, s.store.GetOmissions())
|
||||
}
|
||||
|
||||
func (s *Server) handleGetHomework(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, s.store.GetHomework())
|
||||
}
|
||||
|
||||
func (s *Server) handleGetTests(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, s.store.GetTests())
|
||||
}
|
||||
|
||||
func (s *Server) handleGetDktSubjects(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, s.store.GetDktSubjects())
|
||||
}
|
||||
219
mock_kreta_server/auth.go
Normal file
219
mock_kreta_server/auth.go
Normal file
@@ -0,0 +1,219 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
func randomToken() string {
|
||||
b := make([]byte, 24)
|
||||
rand.Read(b)
|
||||
return base64.RawURLEncoding.EncodeToString(b)
|
||||
}
|
||||
|
||||
func base64URL(v any) string {
|
||||
b, _ := json.Marshal(v)
|
||||
return base64.RawURLEncoding.EncodeToString(b)
|
||||
}
|
||||
|
||||
func buildIdToken(instituteCode, userId, username string) string {
|
||||
header := map[string]string{"alg": "none", "typ": "JWT"}
|
||||
payload := map[string]any{
|
||||
"kreta:institute_code": instituteCode,
|
||||
"kreta:institute_user_id": userId,
|
||||
"kreta:user_name": username,
|
||||
"iat": time.Now().Unix(),
|
||||
}
|
||||
sig := make([]byte, 16)
|
||||
rand.Read(sig)
|
||||
return base64URL(header) + "." + base64URL(payload) + "." + base64.RawURLEncoding.EncodeToString(sig)
|
||||
}
|
||||
|
||||
type sessionInfo struct {
|
||||
instituteCode string
|
||||
userId string
|
||||
username string
|
||||
}
|
||||
|
||||
type AuthStore struct {
|
||||
mu sync.Mutex
|
||||
pendingCodes map[string]bool
|
||||
accessTokens map[string]sessionInfo
|
||||
refreshTokens map[string]sessionInfo
|
||||
}
|
||||
|
||||
func NewAuthStore() *AuthStore {
|
||||
return &AuthStore{
|
||||
pendingCodes: map[string]bool{},
|
||||
accessTokens: map[string]sessionInfo{},
|
||||
refreshTokens: map[string]sessionInfo{},
|
||||
}
|
||||
}
|
||||
|
||||
func (a *AuthStore) issueCode() string {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
code := randomToken()
|
||||
a.pendingCodes[code] = true
|
||||
return code
|
||||
}
|
||||
|
||||
func (a *AuthStore) consumeCode(code string) bool {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
if !a.pendingCodes[code] {
|
||||
return false
|
||||
}
|
||||
delete(a.pendingCodes, code)
|
||||
return true
|
||||
}
|
||||
|
||||
func (a *AuthStore) issueTokens(info sessionInfo) (string, string) {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
access := randomToken()
|
||||
refresh := randomToken()
|
||||
a.accessTokens[access] = info
|
||||
a.refreshTokens[refresh] = info
|
||||
return access, refresh
|
||||
}
|
||||
|
||||
func (a *AuthStore) consumeRefresh(token string) (sessionInfo, bool) {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
info, ok := a.refreshTokens[token]
|
||||
if !ok {
|
||||
return sessionInfo{}, false
|
||||
}
|
||||
delete(a.refreshTokens, token)
|
||||
return info, true
|
||||
}
|
||||
|
||||
func (a *AuthStore) isValidAccess(token string) bool {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
_, ok := a.accessTokens[token]
|
||||
return ok
|
||||
}
|
||||
|
||||
func loginPageHTML(code string) string {
|
||||
return fmt.Sprintf(`<!doctype html>
|
||||
<html><head><meta charset="utf-8"><title>Mock e-Kréta login</title>
|
||||
<style>body{font-family:sans-serif;max-width:420px;margin:80px auto;padding:0 16px}
|
||||
button{width:100%%;padding:12px;font-size:16px;background:#4c6b3a;color:#fff;border:none;border-radius:8px;cursor:pointer}</style>
|
||||
</head><body>
|
||||
<h2>Mock e-Kréta bejelentkezés</h2>
|
||||
<p>Ez a firka mock szerver bejelentkezési képernyője. Nincs szükség valódi felhasználónévre vagy jelszóra.</p>
|
||||
<form method="get" action="/ellenorzo-student/prod/oauthredirect">
|
||||
<input type="hidden" name="code" value="%s">
|
||||
<button type="submit">Belépés mock diákként</button>
|
||||
</form>
|
||||
</body></html>`, code)
|
||||
}
|
||||
|
||||
func (s *Server) handleAccountLogin(w http.ResponseWriter, r *http.Request) {
|
||||
code := s.auth.issueCode()
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
w.Write([]byte(loginPageHTML(code)))
|
||||
}
|
||||
|
||||
func (s *Server) handleOauthRedirect(w http.ResponseWriter, r *http.Request) {
|
||||
code := r.URL.Query().Get("code")
|
||||
if code == "" {
|
||||
http.Error(w, "missing code", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
w.Write([]byte("<!doctype html><html><body>OK, code issued: " + code + "</body></html>"))
|
||||
}
|
||||
|
||||
func (s *Server) handleToken(w http.ResponseWriter, r *http.Request) {
|
||||
if err := r.ParseForm(); err != nil {
|
||||
http.Error(w, "bad request", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
cfg := s.store.GetConfig()
|
||||
student := s.store.GetStudent()
|
||||
grantType := r.FormValue("grant_type")
|
||||
log.Printf(
|
||||
"connect/token: content-type=%q grant_type=%q username=%q form=%v",
|
||||
r.Header.Get("Content-Type"), grantType, r.FormValue("username"), r.Form,
|
||||
)
|
||||
|
||||
var info sessionInfo
|
||||
switch grantType {
|
||||
case "authorization_code":
|
||||
code := r.FormValue("code")
|
||||
if !s.auth.consumeCode(code) {
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
info = sessionInfo{
|
||||
instituteCode: cfg.InstituteCode,
|
||||
userId: student.Uid,
|
||||
username: cfg.Username,
|
||||
}
|
||||
case "refresh_token":
|
||||
token := r.FormValue("refresh_token")
|
||||
found, ok := s.auth.consumeRefresh(token)
|
||||
if !ok {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
info = found
|
||||
case "password":
|
||||
username := r.FormValue("username")
|
||||
password := r.FormValue("password")
|
||||
if username != cfg.Username || password != cfg.Password {
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
info = sessionInfo{
|
||||
instituteCode: cfg.InstituteCode,
|
||||
userId: student.Uid,
|
||||
username: cfg.Username,
|
||||
}
|
||||
default:
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
access, refresh := s.auth.issueTokens(info)
|
||||
idToken := buildIdToken(info.instituteCode, info.userId, info.username)
|
||||
|
||||
resp := map[string]any{
|
||||
"id_token": idToken,
|
||||
"access_token": access,
|
||||
"expires_in": cfg.AccessTokenTTLSeconds,
|
||||
"token_type": "Bearer",
|
||||
"refresh_token": refresh,
|
||||
"scope": "openid email offline_access kreta-ellenorzo-webapi.public",
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(resp)
|
||||
}
|
||||
|
||||
func (s *Server) requireAuth(next http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
authz := r.Header.Get("Authorization")
|
||||
const prefix = "Bearer "
|
||||
if len(authz) <= len(prefix) || authz[:len(prefix)] != prefix {
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
token := authz[len(prefix):]
|
||||
if !s.auth.isValidAccess(token) {
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
next(w, r)
|
||||
}
|
||||
}
|
||||
341
mock_kreta_server/data.json
Normal file
341
mock_kreta_server/data.json
Normal file
@@ -0,0 +1,341 @@
|
||||
{
|
||||
"config": {
|
||||
"instituteCode": "mockschool",
|
||||
"username": "student",
|
||||
"password": "student",
|
||||
"accessTokenTtlSeconds": 43200
|
||||
},
|
||||
"student": {
|
||||
"Uid": "100",
|
||||
"Nev": "Teszt Elek",
|
||||
"Cimek": [
|
||||
"1234 Budapest, Példa utca 1."
|
||||
],
|
||||
"Bankszamla": {
|
||||
"IsReadOnly": false,
|
||||
"BankszamlaTulajdonosTipusId": 0
|
||||
},
|
||||
"SzuletesiEv": 2008,
|
||||
"SzuletesiHonap": 9,
|
||||
"SzuletesiNap": 1,
|
||||
"EmailCim": "teszt.elek@example.com",
|
||||
"TanevUid": "2025/2026",
|
||||
"Gondviselok": [
|
||||
{
|
||||
"Uid": "200",
|
||||
"Nev": "Teszt Anna",
|
||||
"EmailCim": "teszt.anna@example.com",
|
||||
"IsTorvenyesKepviselo": true,
|
||||
"Telefonszam": "+36301234567"
|
||||
}
|
||||
],
|
||||
"IntezmenyAzonosito": "mockschool",
|
||||
"IntezmenyNev": "Mock Gimnázium",
|
||||
"Intezmeny": {
|
||||
"Uid": "1",
|
||||
"RovidNev": "Mock Gimnázium",
|
||||
"TestreszabasBeallitasok": {
|
||||
"ErtekelesekMegjelenitesenekKesleltetesenekMerteke": 0,
|
||||
"IsOsztalyAtlagMegjeleniteseEllenorzoben": true,
|
||||
"IsTanorakTemajaMegtekinthetoEllenorzoben": true,
|
||||
"KovetkezoTelepitesDatuma": ""
|
||||
},
|
||||
"Rendszermodulok": []
|
||||
}
|
||||
},
|
||||
"classGroups": [
|
||||
{
|
||||
"Uid": "10,11.A",
|
||||
"Nev": "11.A",
|
||||
"OsztalyFonok": {
|
||||
"Uid": ""
|
||||
},
|
||||
"OsztalyFonokHelyettes": {
|
||||
"Uid": ""
|
||||
},
|
||||
"OktatasNevelesiKategoria": {
|
||||
"Uid": "1",
|
||||
"Nev": "Gimnázium",
|
||||
"Leiras": "Nappali gimnáziumi oktatás"
|
||||
},
|
||||
"OktatasNevelesiKategoriaSortIndex": 0,
|
||||
"OktatasNevelesiFeladat": {
|
||||
"Uid": "",
|
||||
"Nev": "",
|
||||
"Leiras": ""
|
||||
},
|
||||
"IsAktiv": true,
|
||||
"Tipus": "Osztaly"
|
||||
}
|
||||
],
|
||||
"grades": [
|
||||
{
|
||||
"Uid": "1000",
|
||||
"RogzitesDatuma": "2026-08-25T00:00:00",
|
||||
"KeszitesDatuma": "2026-08-25T00:00:00",
|
||||
"Tantargy": {
|
||||
"Uid": "1,MATEK",
|
||||
"Nev": "Matematika",
|
||||
"Kategoria": {
|
||||
"Uid": "1",
|
||||
"Nev": "Kötelező",
|
||||
"Leiras": "Kötelező tantárgy"
|
||||
},
|
||||
"SortIndex": 1
|
||||
},
|
||||
"Tema": "Másodfokú egyenletek",
|
||||
"Tipus": {
|
||||
"Uid": "1",
|
||||
"Nev": "Írásbeli",
|
||||
"Leiras": "Írásbeli felelet"
|
||||
},
|
||||
"Mod": {
|
||||
"Uid": "",
|
||||
"Nev": "",
|
||||
"Leiras": ""
|
||||
},
|
||||
"ErtekFajta": {
|
||||
"Uid": "1",
|
||||
"Nev": "Osztályzat",
|
||||
"Leiras": "Osztályzat"
|
||||
},
|
||||
"ErtekeloTanarNeve": "Kovács Béla",
|
||||
"SzamErtek": 5,
|
||||
"SzovegesErtek": "Jeles",
|
||||
"OsztalyCsoport": {
|
||||
"Uid": "10,11.A"
|
||||
},
|
||||
"SortIndex": 1
|
||||
}
|
||||
],
|
||||
"homework": [
|
||||
{
|
||||
"Uid": "2000",
|
||||
"Tantargy": {
|
||||
"Uid": "2,MAGYAR",
|
||||
"Nev": "Magyar nyelv és irodalom",
|
||||
"Kategoria": {
|
||||
"Uid": "1",
|
||||
"Nev": "Kötelező",
|
||||
"Leiras": "Kötelező tantárgy"
|
||||
},
|
||||
"SortIndex": 2
|
||||
},
|
||||
"TantargyNeve": "Magyar nyelv és irodalom",
|
||||
"RogzitoTanarNeve": "Nagy Ilona",
|
||||
"Szoveg": "Olvassátok el az 5. fejezetet.",
|
||||
"FeladasDatuma": "2026-08-26T00:00:00",
|
||||
"HataridoDatuma": "2026-09-02T00:00:00",
|
||||
"RogzitesIdopontja": "2026-08-26T00:00:00",
|
||||
"IsTanarRogzitette": true,
|
||||
"IsMegoldva": false,
|
||||
"IsBeadhato": false,
|
||||
"OsztalyCsoport": {
|
||||
"Uid": "10,11.A"
|
||||
},
|
||||
"IsCsatolasEngedelyezes": false
|
||||
}
|
||||
],
|
||||
"tests": [
|
||||
{
|
||||
"Uid": "3000",
|
||||
"Datum": "2026-08-31T00:00:00",
|
||||
"BejelentesDatuma": "2026-08-26T00:00:00",
|
||||
"RogzitoTanarNeve": "Kovács Béla",
|
||||
"OrarendiOraOraszama": 2,
|
||||
"Tantargy": {
|
||||
"Uid": "1,MATEK",
|
||||
"Nev": "Matematika",
|
||||
"Kategoria": {
|
||||
"Uid": "1",
|
||||
"Nev": "Kötelező",
|
||||
"Leiras": "Kötelező tantárgy"
|
||||
},
|
||||
"SortIndex": 1
|
||||
},
|
||||
"TantargyNeve": "Matematika",
|
||||
"Temaja": "Trigonometria",
|
||||
"Modja": {
|
||||
"Uid": "1",
|
||||
"Nev": "Írásbeli",
|
||||
"Leiras": "Írásbeli dolgozat"
|
||||
},
|
||||
"OsztalyCsoport": {
|
||||
"Uid": "10,11.A"
|
||||
}
|
||||
}
|
||||
],
|
||||
"omissions": [
|
||||
{
|
||||
"Uid": "4000",
|
||||
"Tantargy": {
|
||||
"Uid": "1,MATEK",
|
||||
"Nev": "Matematika",
|
||||
"Kategoria": {
|
||||
"Uid": "1",
|
||||
"Nev": "Kötelező",
|
||||
"Leiras": "Kötelező tantárgy"
|
||||
},
|
||||
"SortIndex": 1
|
||||
},
|
||||
"Datum": "2026-08-24T00:00:00",
|
||||
"RogzitoTanarNeve": "Kovács Béla",
|
||||
"Tipus": {
|
||||
"Uid": "1",
|
||||
"Nev": "Hiányzás",
|
||||
"Leiras": "Hiányzás"
|
||||
},
|
||||
"Mod": {
|
||||
"Uid": "",
|
||||
"Nev": "",
|
||||
"Leiras": ""
|
||||
},
|
||||
"KeszitesDatuma": "2026-08-24T00:00:00",
|
||||
"IgazolasAllapota": "Igazolt",
|
||||
"IgazolasTipusa": {
|
||||
"Uid": "",
|
||||
"Nev": "",
|
||||
"Leiras": ""
|
||||
},
|
||||
"OsztalyCsoport": {
|
||||
"Uid": "10,11.A"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Uid": "",
|
||||
"Tantargy": {
|
||||
"Uid": "",
|
||||
"Nev": "fasz",
|
||||
"Kategoria": {
|
||||
"Uid": "1",
|
||||
"Nev": "Kötelező",
|
||||
"Leiras": ""
|
||||
},
|
||||
"SortIndex": 0
|
||||
},
|
||||
"Datum": "2026-08-26T20:00:26.713Z",
|
||||
"RogzitoTanarNeve": "fasz",
|
||||
"Tipus": {
|
||||
"Uid": "1",
|
||||
"Nev": "Hiányzás",
|
||||
"Leiras": ""
|
||||
},
|
||||
"Mod": {
|
||||
"Uid": "",
|
||||
"Nev": "",
|
||||
"Leiras": ""
|
||||
},
|
||||
"KeszitesDatuma": "2026-08-26T20:00:26.713Z",
|
||||
"IgazolasAllapota": "Igazolt",
|
||||
"IgazolasTipusa": {
|
||||
"Uid": "",
|
||||
"Nev": "",
|
||||
"Leiras": ""
|
||||
},
|
||||
"OsztalyCsoport": {
|
||||
"Uid": ""
|
||||
}
|
||||
}
|
||||
],
|
||||
"lessons": [
|
||||
{
|
||||
"Uid": "5000",
|
||||
"Datum": "2026-08-26T00:00:00",
|
||||
"KezdetIdopont": "2026-08-26T08:00:00",
|
||||
"VegIdopont": "2026-08-26T08:45:00",
|
||||
"Nev": "Matematika",
|
||||
"Oraszam": 1,
|
||||
"OsztalyCsoport": {
|
||||
"Uid": "10,11.A",
|
||||
"Nev": "11.A"
|
||||
},
|
||||
"TanarNeve": "Kovács Béla",
|
||||
"Tantargy": {
|
||||
"Uid": "1,MATEK",
|
||||
"Nev": "Matematika",
|
||||
"Kategoria": {
|
||||
"Uid": "1",
|
||||
"Nev": "Kötelező",
|
||||
"Leiras": "Kötelező tantárgy"
|
||||
},
|
||||
"SortIndex": 1
|
||||
},
|
||||
"TeremNeve": "101",
|
||||
"Tipus": {
|
||||
"Uid": "1",
|
||||
"Nev": "Tanóra",
|
||||
"Leiras": "Normál tanóra"
|
||||
},
|
||||
"TanuloJelenlet": {
|
||||
"Uid": "",
|
||||
"Nev": "",
|
||||
"Leiras": ""
|
||||
},
|
||||
"Allapot": {
|
||||
"Uid": "1",
|
||||
"Nev": "Megtartott",
|
||||
"Leiras": "Megtartott óra"
|
||||
},
|
||||
"IsTanuloHaziFeladatEnabled": true,
|
||||
"IsHaziFeladatMegoldva": false,
|
||||
"Csatolmanyok": [],
|
||||
"IsDigitalisOra": false,
|
||||
"DigitalisTamogatoEszkozTipusList": [],
|
||||
"Letrehozas": "2026-07-27T00:00:00",
|
||||
"UtolsoModositas": "2026-07-27T00:00:00"
|
||||
}
|
||||
],
|
||||
"notices": [
|
||||
{
|
||||
"Uid": "6000",
|
||||
"RogzitoNeve": "Igazgatóság",
|
||||
"ErvenyessegKezdete": "2026-08-26T00:00:00",
|
||||
"ErvenyessegVege": "2026-09-09T00:00:00",
|
||||
"Cim": "Őszi szünet",
|
||||
"Tartalom": "Az őszi szünet előtti utolsó tanítási nap...",
|
||||
"TartalomText": "Az őszi szünet előtti utolsó tanítási nap..."
|
||||
}
|
||||
],
|
||||
"infoBoard": [
|
||||
{
|
||||
"Uid": "7000",
|
||||
"Cim": "Osztályfőnöki bejegyzés",
|
||||
"Datum": "2026-08-26T00:00:00",
|
||||
"KeszitoTanarNeve": "Kovács Béla",
|
||||
"KeszitesDatuma": "2026-08-26T00:00:00",
|
||||
"Tartalom": "Dicséret szorgalmi feladatért.",
|
||||
"TartalomFormazott": "",
|
||||
"Tipus": {
|
||||
"Uid": "1",
|
||||
"Nev": "Dicséret",
|
||||
"Leiras": "Szaktanári dicséret"
|
||||
}
|
||||
}
|
||||
],
|
||||
"dktSubjects": [
|
||||
{
|
||||
"tantargyId": 1,
|
||||
"tantargyNev": "Matematika",
|
||||
"alkalmazottNev": "Kovács Béla",
|
||||
"osztalyCsoportNev": "11.A",
|
||||
"tipusId": 0
|
||||
}
|
||||
],
|
||||
"averages": [
|
||||
{
|
||||
"Uid": "8000",
|
||||
"Tantargy": {
|
||||
"Uid": "1,MATEK",
|
||||
"Nev": "Matematika",
|
||||
"Kategoria": {
|
||||
"Uid": "1",
|
||||
"Nev": "Kötelező",
|
||||
"Leiras": "Kötelező tantárgy"
|
||||
},
|
||||
"SortIndex": 1
|
||||
},
|
||||
"TanuloAtlag": 4.5,
|
||||
"OsztalyCsoportAtlag": 3.8
|
||||
}
|
||||
]
|
||||
}
|
||||
3
mock_kreta_server/go.mod
Normal file
3
mock_kreta_server/go.mod
Normal file
@@ -0,0 +1,3 @@
|
||||
module mock_kreta_server
|
||||
|
||||
go 1.26.5
|
||||
64
mock_kreta_server/main.go
Normal file
64
mock_kreta_server/main.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"flag"
|
||||
"io/fs"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
//go:embed static
|
||||
var staticFiles embed.FS
|
||||
|
||||
type Server struct {
|
||||
store *Store
|
||||
auth *AuthStore
|
||||
}
|
||||
|
||||
func main() {
|
||||
addr := flag.String("addr", ":8090", "listen address")
|
||||
dataPath := flag.String("data", "data.json", "path to the JSON data file")
|
||||
flag.Parse()
|
||||
|
||||
s := &Server{
|
||||
store: NewStore(*dataPath),
|
||||
auth: NewAuthStore(),
|
||||
}
|
||||
|
||||
mux := http.NewServeMux()
|
||||
|
||||
staticContent, err := fs.Sub(staticFiles, "static")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
mux.Handle("/", http.FileServer(http.FS(staticContent)))
|
||||
|
||||
mux.HandleFunc("/Account/Login", s.handleAccountLogin)
|
||||
mux.HandleFunc("/ellenorzo-student/prod/oauthredirect", s.handleOauthRedirect)
|
||||
mux.HandleFunc("/connect/token", s.handleToken)
|
||||
|
||||
mux.HandleFunc("/ellenorzo/v3/sajat/TanuloAdatlap", s.requireAuth(s.handleGetStudent))
|
||||
mux.HandleFunc("/ellenorzo/v3/sajat/OsztalyCsoportok", s.requireAuth(s.handleGetClassGroups))
|
||||
mux.HandleFunc("/ellenorzo/v3/sajat/FaliujsagElemek", s.requireAuth(s.handleGetNoticeBoard))
|
||||
mux.HandleFunc("/ellenorzo/v3/sajat/Feljegyzesek", s.requireAuth(s.handleGetInfoBoard))
|
||||
mux.HandleFunc("/ellenorzo/v3/sajat/Ertekelesek", s.requireAuth(s.handleGetGrades))
|
||||
mux.HandleFunc("/ellenorzo/v3/sajat/Ertekelesek/Atlagok/OsztalyAtlagok", s.requireAuth(s.handleGetClassGroupAverages))
|
||||
mux.HandleFunc("/ellenorzo/v3/sajat/OrarendElemek", s.requireAuth(s.handleGetTimeTable))
|
||||
mux.HandleFunc("/ellenorzo/v3/sajat/Mulasztasok", s.requireAuth(s.handleGetOmissions))
|
||||
mux.HandleFunc("/ellenorzo/v3/sajat/HaziFeladatok", s.requireAuth(s.handleGetHomework))
|
||||
mux.HandleFunc("/ellenorzo/v3/sajat/BejelentettSzamonkeresek", s.requireAuth(s.handleGetTests))
|
||||
mux.HandleFunc("/dktapi/intezmenyek/munkaterek/tanulok", s.requireAuth(s.handleGetDktSubjects))
|
||||
|
||||
s.registerAdminRoutes(mux)
|
||||
|
||||
log.Printf("mock kreta server listening on %s (data: %s)", *addr, *dataPath)
|
||||
log.Fatal(http.ListenAndServe(*addr, logRequests(mux)))
|
||||
}
|
||||
|
||||
func logRequests(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("%s %s from %s", r.Method, r.URL.String(), r.RemoteAddr)
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
204
mock_kreta_server/seed.go
Normal file
204
mock_kreta_server/seed.go
Normal file
@@ -0,0 +1,204 @@
|
||||
package main
|
||||
|
||||
import "time"
|
||||
|
||||
func iso(t time.Time) string {
|
||||
return t.Format("2006-01-02T15:04:05")
|
||||
}
|
||||
|
||||
func seedData() storeData {
|
||||
now := time.Now()
|
||||
today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
|
||||
|
||||
mathSubject := Subject{
|
||||
Uid: "1,MATEK",
|
||||
Nev: "Matematika",
|
||||
Kategoria: NameUidDesc{Uid: "1", Nev: "Kötelező", Leiras: "Kötelező tantárgy"},
|
||||
SortIndex: 1,
|
||||
}
|
||||
litSubject := Subject{
|
||||
Uid: "2,MAGYAR",
|
||||
Nev: "Magyar nyelv és irodalom",
|
||||
Kategoria: NameUidDesc{Uid: "1", Nev: "Kötelező", Leiras: "Kötelező tantárgy"},
|
||||
SortIndex: 2,
|
||||
}
|
||||
|
||||
classGroup := UidRef{Uid: "10,11.A"}
|
||||
|
||||
return storeData{
|
||||
Config: ServerConfig{
|
||||
InstituteCode: "mockschool",
|
||||
Username: "student",
|
||||
Password: "student",
|
||||
AccessTokenTTLSeconds: 43200,
|
||||
},
|
||||
Student: Student{
|
||||
Uid: "100",
|
||||
Nev: "Teszt Elek",
|
||||
Cimek: []string{
|
||||
"1234 Budapest, Példa utca 1.",
|
||||
},
|
||||
Bankszamla: BankAccount{
|
||||
BankszamlaSzam: "",
|
||||
IsReadOnly: false,
|
||||
BankszamlaTulajdonosNeve: "",
|
||||
BankszamlaTulajdonosTipusId: 0,
|
||||
},
|
||||
SzuletesiEv: 2008,
|
||||
SzuletesiHonap: 9,
|
||||
SzuletesiNap: 1,
|
||||
EmailCim: "teszt.elek@example.com",
|
||||
Telefonszam: "",
|
||||
TanevUid: "2025/2026",
|
||||
IntezmenyAzonosito: "mockschool",
|
||||
IntezmenyNev: "Mock Gimnázium",
|
||||
Gondviselok: []Guardian{
|
||||
{
|
||||
Uid: "200",
|
||||
Nev: "Teszt Anna",
|
||||
EmailCim: "teszt.anna@example.com",
|
||||
IsTorvenyesKepviselo: true,
|
||||
Telefonszam: "+36301234567",
|
||||
},
|
||||
},
|
||||
Intezmeny: Institution{
|
||||
Uid: "1",
|
||||
RovidNev: "Mock Gimnázium",
|
||||
TestreszabasBeallitasok: CustomizationSettings{
|
||||
ErtekelesekMegjelenitesenekKesleltetesenekMerteke: 0,
|
||||
IsOsztalyAtlagMegjeleniteseEllenorzoben: true,
|
||||
IsTanorakTemajaMegtekinthetoEllenorzoben: true,
|
||||
KovetkezoTelepitesDatuma: "",
|
||||
},
|
||||
Rendszermodulok: []SystemModule{},
|
||||
},
|
||||
},
|
||||
ClassGroups: []ClassGroup{
|
||||
{
|
||||
Uid: classGroup.Uid,
|
||||
Nev: "11.A",
|
||||
OktatasNevelesiKategoria: NameUidDesc{Uid: "1", Nev: "Gimnázium", Leiras: "Nappali gimnáziumi oktatás"},
|
||||
IsAktiv: true,
|
||||
Tipus: "Osztaly",
|
||||
},
|
||||
},
|
||||
Grades: []Grade{
|
||||
{
|
||||
Uid: "1000",
|
||||
RogzitesDatuma: iso(today.Add(-24 * time.Hour)),
|
||||
KeszitesDatuma: iso(today.Add(-24 * time.Hour)),
|
||||
Tantargy: mathSubject,
|
||||
Tema: "Másodfokú egyenletek",
|
||||
Tipus: NameUidDesc{Uid: "1", Nev: "Írásbeli", Leiras: "Írásbeli felelet"},
|
||||
ErtekFajta: NameUidDesc{Uid: "1", Nev: "Osztályzat", Leiras: "Osztályzat"},
|
||||
ErtekeloTanarNeve: "Kovács Béla",
|
||||
SzamErtek: 5,
|
||||
SzovegesErtek: "Jeles",
|
||||
OsztalyCsoport: classGroup,
|
||||
SortIndex: 1,
|
||||
},
|
||||
},
|
||||
Homework: []Homework{
|
||||
{
|
||||
Uid: "2000",
|
||||
Tantargy: litSubject,
|
||||
TantargyNeve: litSubject.Nev,
|
||||
RogzitoTanarNeve: "Nagy Ilona",
|
||||
Szoveg: "Olvassátok el az 5. fejezetet.",
|
||||
FeladasDatuma: iso(today),
|
||||
HataridoDatuma: iso(today.Add(7 * 24 * time.Hour)),
|
||||
RogzitesIdopontja: iso(today),
|
||||
IsTanarRogzitette: true,
|
||||
OsztalyCsoport: classGroup,
|
||||
},
|
||||
},
|
||||
Tests: []Test{
|
||||
{
|
||||
Uid: "3000",
|
||||
Datum: iso(today.Add(5 * 24 * time.Hour)),
|
||||
BejelentesDatuma: iso(today),
|
||||
RogzitoTanarNeve: "Kovács Béla",
|
||||
OrarendiOraOraszama: 2,
|
||||
Tantargy: mathSubject,
|
||||
TantargyNeve: mathSubject.Nev,
|
||||
Temaja: "Trigonometria",
|
||||
Modja: NameUidDesc{Uid: "1", Nev: "Írásbeli", Leiras: "Írásbeli dolgozat"},
|
||||
OsztalyCsoport: classGroup,
|
||||
},
|
||||
},
|
||||
Omissions: []Omission{
|
||||
{
|
||||
Uid: "4000",
|
||||
Tantargy: mathSubject,
|
||||
Datum: iso(today.Add(-48 * time.Hour)),
|
||||
RogzitoTanarNeve: "Kovács Béla",
|
||||
Tipus: NameUidDesc{Uid: "1", Nev: "Hiányzás", Leiras: "Hiányzás"},
|
||||
KeszitesDatuma: iso(today.Add(-48 * time.Hour)),
|
||||
IgazolasAllapota: "Igazolt",
|
||||
OsztalyCsoport: classGroup,
|
||||
},
|
||||
},
|
||||
Lessons: []Lesson{
|
||||
{
|
||||
Uid: "5000",
|
||||
Datum: iso(today),
|
||||
KezdetIdopont: iso(today.Add(8 * time.Hour)),
|
||||
VegIdopont: iso(today.Add(8*time.Hour + 45*time.Minute)),
|
||||
Nev: mathSubject.Nev,
|
||||
Oraszam: 1,
|
||||
OsztalyCsoport: NameUid{Uid: classGroup.Uid, Nev: "11.A"},
|
||||
TanarNeve: "Kovács Béla",
|
||||
Tantargy: mathSubject,
|
||||
TeremNeve: "101",
|
||||
Tipus: NameUidDesc{Uid: "1", Nev: "Tanóra", Leiras: "Normál tanóra"},
|
||||
Allapot: NameUidDesc{Uid: "1", Nev: "Megtartott", Leiras: "Megtartott óra"},
|
||||
IsTanuloHaziFeladatEnabled: true,
|
||||
Csatolmanyok: []NameUid{},
|
||||
DigitalisTamogatoEszkozTipusList: []string{},
|
||||
Letrehozas: iso(today.Add(-30 * 24 * time.Hour)),
|
||||
UtolsoModositas: iso(today.Add(-30 * 24 * time.Hour)),
|
||||
},
|
||||
},
|
||||
Notices: []NoticeBoardItem{
|
||||
{
|
||||
Uid: "6000",
|
||||
RogzitoNeve: "Igazgatóság",
|
||||
ErvenyessegKezdete: iso(today),
|
||||
ErvenyessegVege: iso(today.Add(14 * 24 * time.Hour)),
|
||||
Cim: "Őszi szünet",
|
||||
Tartalom: "Az őszi szünet előtti utolsó tanítási nap...",
|
||||
TartalomText: "Az őszi szünet előtti utolsó tanítási nap...",
|
||||
},
|
||||
},
|
||||
InfoBoard: []InfoBoardItem{
|
||||
{
|
||||
Uid: "7000",
|
||||
Cim: "Osztályfőnöki bejegyzés",
|
||||
Datum: iso(today),
|
||||
KeszitoTanarNeve: "Kovács Béla",
|
||||
KeszitesDatuma: iso(today),
|
||||
Tartalom: "Dicséret szorgalmi feladatért.",
|
||||
Tipus: NameUidDesc{Uid: "1", Nev: "Dicséret", Leiras: "Szaktanári dicséret"},
|
||||
},
|
||||
},
|
||||
DktSubjects: []DktSubject{
|
||||
{
|
||||
TantargyId: 1,
|
||||
TantargyNev: mathSubject.Nev,
|
||||
AlkalmazottNev: "Kovács Béla",
|
||||
OsztalyCsoportNev: "11.A",
|
||||
TipusId: 0,
|
||||
},
|
||||
},
|
||||
Averages: []ClassGroupSubjectAverage{
|
||||
{
|
||||
Uid: "8000",
|
||||
Tantargy: mathSubject,
|
||||
TanuloAtlag: 4.5,
|
||||
OsztalyCsoportAtlag: 3.8,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
//xdd mi a faszom ez kreta
|
||||
696
mock_kreta_server/static/app.js
Normal file
696
mock_kreta_server/static/app.js
Normal file
@@ -0,0 +1,696 @@
|
||||
function getPath(obj, path) {
|
||||
return path.split(".").reduce((o, k) => (o == null ? undefined : o[k]), obj);
|
||||
}
|
||||
|
||||
function setPath(obj, path, value) {
|
||||
const keys = path.split(".");
|
||||
let o = obj;
|
||||
for (let i = 0; i < keys.length - 1; i++) {
|
||||
if (o[keys[i]] == null || typeof o[keys[i]] !== "object") o[keys[i]] = {};
|
||||
o = o[keys[i]];
|
||||
}
|
||||
o[keys[keys.length - 1]] = value;
|
||||
}
|
||||
|
||||
function nowIso() {
|
||||
return new Date().toISOString();
|
||||
}
|
||||
|
||||
async function getJSON(url) {
|
||||
const res = await fetch(url);
|
||||
if (!res.ok) throw new Error(url + ": " + res.status);
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async function putJSON(url, body) {
|
||||
const res = await fetch(url, {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
if (!res.ok) throw new Error(url + ": " + res.status);
|
||||
}
|
||||
|
||||
function flash(el, message) {
|
||||
el.textContent = message;
|
||||
setTimeout(() => {
|
||||
if (el.textContent === message) el.textContent = "";
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
function cellInput(row, field, onChange) {
|
||||
const paths = field.paths || [field.path];
|
||||
const value = getPath(row, paths[0]);
|
||||
|
||||
if (field.type === "bool") {
|
||||
const input = document.createElement("input");
|
||||
input.type = "checkbox";
|
||||
input.checked = !!value;
|
||||
input.onchange = () => {
|
||||
paths.forEach((p) => setPath(row, p, input.checked));
|
||||
onChange();
|
||||
};
|
||||
return input;
|
||||
}
|
||||
|
||||
if (field.type === "lines") {
|
||||
const textarea = document.createElement("textarea");
|
||||
textarea.rows = 2;
|
||||
textarea.value = Array.isArray(value) ? value.join("\n") : "";
|
||||
textarea.onchange = () => {
|
||||
const list = textarea.value.split("\n").map((s) => s.trim()).filter(Boolean);
|
||||
paths.forEach((p) => setPath(row, p, list));
|
||||
onChange();
|
||||
};
|
||||
return textarea;
|
||||
}
|
||||
|
||||
const input = document.createElement("input");
|
||||
input.type = field.type === "number" ? "number" : "text";
|
||||
input.value = value == null ? "" : value;
|
||||
input.onchange = () => {
|
||||
const v = field.type === "number" ? (input.value === "" ? 0 : Number(input.value)) : input.value;
|
||||
paths.forEach((p) => setPath(row, p, v));
|
||||
onChange();
|
||||
}; //i hate js
|
||||
return input;
|
||||
}
|
||||
|
||||
function renderTable(container, opts) {
|
||||
container.innerHTML = "";
|
||||
|
||||
const toolbar = document.createElement("div");
|
||||
toolbar.className = "toolbar";
|
||||
const addBtn = document.createElement("button");
|
||||
addBtn.textContent = "Add row";
|
||||
const saveBtn = document.createElement("button");
|
||||
saveBtn.className = "secondary";
|
||||
saveBtn.textContent = "Save";
|
||||
const resetBtn = document.createElement("button");
|
||||
resetBtn.className = "secondary";
|
||||
resetBtn.textContent = "Reload";
|
||||
const status = document.createElement("span");
|
||||
status.className = "status";
|
||||
toolbar.append(addBtn, saveBtn, resetBtn, status);
|
||||
container.appendChild(toolbar);
|
||||
|
||||
const table = document.createElement("table");
|
||||
container.appendChild(table);
|
||||
|
||||
let rows = [];
|
||||
|
||||
function draw() {
|
||||
table.innerHTML = "";
|
||||
const thead = document.createElement("tr");
|
||||
opts.columns.forEach((c) => {
|
||||
const th = document.createElement("th");
|
||||
th.textContent = c.label;
|
||||
thead.appendChild(th);
|
||||
});
|
||||
thead.appendChild(document.createElement("th"));
|
||||
table.appendChild(thead);
|
||||
|
||||
rows.forEach((row, idx) => {
|
||||
const tr = document.createElement("tr");
|
||||
opts.columns.forEach((field) => {
|
||||
const td = document.createElement("td");
|
||||
td.appendChild(cellInput(row, field, () => {}));
|
||||
tr.appendChild(td);
|
||||
});
|
||||
const actionTd = document.createElement("td");
|
||||
actionTd.className = "row-actions";
|
||||
const delBtn = document.createElement("button");
|
||||
delBtn.className = "danger";
|
||||
delBtn.textContent = "Delete";
|
||||
delBtn.onclick = () => {
|
||||
rows.splice(idx, 1);
|
||||
draw();
|
||||
};
|
||||
actionTd.appendChild(delBtn);
|
||||
tr.appendChild(actionTd);
|
||||
table.appendChild(tr);
|
||||
});
|
||||
}
|
||||
|
||||
addBtn.onclick = () => {
|
||||
rows.push(JSON.parse(JSON.stringify(opts.template())));
|
||||
draw();
|
||||
};
|
||||
|
||||
saveBtn.onclick = async () => {
|
||||
try {
|
||||
await putJSON(opts.url, rows);
|
||||
flash(status, "saved");
|
||||
} catch (e) {
|
||||
flash(status, "error: " + e.message);
|
||||
}
|
||||
};
|
||||
|
||||
resetBtn.onclick = load;
|
||||
|
||||
async function load() {
|
||||
rows = await getJSON(opts.url);
|
||||
draw();
|
||||
}
|
||||
|
||||
load();
|
||||
}
|
||||
|
||||
function renderForm(container, opts) {
|
||||
container.innerHTML = "";
|
||||
|
||||
const status = document.createElement("span");
|
||||
status.className = "status";
|
||||
|
||||
const grid = document.createElement("div");
|
||||
grid.className = "form-grid";
|
||||
container.appendChild(grid);
|
||||
|
||||
let data = {};
|
||||
|
||||
function draw() {
|
||||
grid.innerHTML = "";
|
||||
opts.fields.forEach((field) => {
|
||||
const label = document.createElement("label");
|
||||
label.textContent = field.label;
|
||||
grid.appendChild(label);
|
||||
grid.appendChild(cellInput(data, field, () => {}));
|
||||
});
|
||||
}
|
||||
|
||||
const toolbar = document.createElement("div");
|
||||
toolbar.className = "toolbar";
|
||||
const saveBtn = document.createElement("button");
|
||||
saveBtn.textContent = "Save";
|
||||
saveBtn.onclick = async () => {
|
||||
try {
|
||||
if (opts.beforeSave) opts.beforeSave(data);
|
||||
await putJSON(opts.url, data);
|
||||
flash(status, "saved");
|
||||
} catch (e) {
|
||||
flash(status, "error: " + e.message);
|
||||
}
|
||||
};
|
||||
toolbar.append(saveBtn, status);
|
||||
container.appendChild(toolbar);
|
||||
container.appendChild(grid);
|
||||
|
||||
(async () => {
|
||||
data = await getJSON(opts.url);
|
||||
draw();
|
||||
})();
|
||||
|
||||
return {
|
||||
getSubArray(path) {
|
||||
if (!getPath(data, path)) setPath(data, path, []);
|
||||
return getPath(data, path);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const subjectTemplate = () => ({
|
||||
Uid: "",
|
||||
Nev: "",
|
||||
Kategoria: { Uid: "1", Nev: "Kötelező", Leiras: "" },
|
||||
SortIndex: 0,
|
||||
});
|
||||
|
||||
const nameUidDescTemplate = () => ({ Uid: "", Nev: "", Leiras: "" });
|
||||
|
||||
const entities = {
|
||||
classGroups: {
|
||||
url: "/admin/api/classGroups",
|
||||
template: () => ({
|
||||
Uid: "",
|
||||
Nev: "",
|
||||
OsztalyFonok: { Uid: "" },
|
||||
OsztalyFonokHelyettes: { Uid: "" },
|
||||
OktatasNevelesiKategoria: { Uid: "1", Nev: "Gimnázium", Leiras: "" },
|
||||
OktatasNevelesiKategoriaSortIndex: 0,
|
||||
OktatasNevelesiFeladat: nameUidDescTemplate(),
|
||||
IsAktiv: true,
|
||||
Tipus: "Osztaly",
|
||||
}),
|
||||
columns: [
|
||||
{ path: "Nev", label: "Name", type: "text" },
|
||||
{ path: "Uid", label: "UID", type: "text" },
|
||||
{ path: "Tipus", label: "Type", type: "text" },
|
||||
{ path: "IsAktiv", label: "Active", type: "bool" },
|
||||
{ path: "OktatasNevelesiKategoria.Nev", label: "Category", type: "text" },
|
||||
],
|
||||
},
|
||||
|
||||
grades: {
|
||||
url: "/admin/api/grades",
|
||||
template: () => ({
|
||||
Uid: "",
|
||||
RogzitesDatuma: nowIso(),
|
||||
KeszitesDatuma: nowIso(),
|
||||
LattamozasDatuma: "",
|
||||
Tantargy: subjectTemplate(),
|
||||
Tema: "",
|
||||
Tipus: { Uid: "1", Nev: "Írásbeli", Leiras: "" },
|
||||
Mod: nameUidDescTemplate(),
|
||||
ErtekFajta: { Uid: "1", Nev: "Osztályzat", Leiras: "" },
|
||||
ErtekeloTanarNeve: "",
|
||||
Kind: "",
|
||||
SzamErtek: 5,
|
||||
SzovegesErtek: "Jeles",
|
||||
SulySzazalekErteke: 100,
|
||||
SzovegesErtekelesRovidNev: "",
|
||||
OsztalyCsoport: { Uid: "" },
|
||||
SortIndex: 0,
|
||||
}),
|
||||
columns: [
|
||||
{ path: "Tantargy.Nev", label: "Subject", type: "text" },
|
||||
{ path: "ErtekeloTanarNeve", label: "Teacher", type: "text" },
|
||||
{ path: "Tipus.Nev", label: "Type", type: "text" },
|
||||
{ path: "ErtekFajta.Nev", label: "Value type", type: "text" },
|
||||
{ path: "SzamErtek", label: "Value (number)", type: "number" },
|
||||
{ path: "SzovegesErtek", label: "Value (text)", type: "text" },
|
||||
{ path: "Tema", label: "Topic", type: "text" },
|
||||
{ path: "RogzitesDatuma", label: "Date", type: "text" },
|
||||
],
|
||||
},
|
||||
|
||||
homework: {
|
||||
url: "/admin/api/homework",
|
||||
template: () => ({
|
||||
Uid: "",
|
||||
Tantargy: subjectTemplate(),
|
||||
TantargyNeve: "",
|
||||
RogzitoTanarNeve: "",
|
||||
Szoveg: "",
|
||||
FeladasDatuma: nowIso(),
|
||||
HataridoDatuma: nowIso(),
|
||||
RogzitesIdopontja: nowIso(),
|
||||
IsTanarRogzitette: true,
|
||||
IsMegoldva: false,
|
||||
IsBeadhato: false,
|
||||
OsztalyCsoport: { Uid: "" },
|
||||
IsCsatolasEngedelyezes: false,
|
||||
}),
|
||||
columns: [
|
||||
{ paths: ["Tantargy.Nev", "TantargyNeve"], label: "Subject", type: "text" },
|
||||
{ path: "RogzitoTanarNeve", label: "Teacher", type: "text" },
|
||||
{ path: "Szoveg", label: "Text", type: "text" },
|
||||
{ path: "FeladasDatuma", label: "Assigned", type: "text" },
|
||||
{ path: "HataridoDatuma", label: "Due", type: "text" },
|
||||
{ path: "IsMegoldva", label: "Done", type: "bool" },
|
||||
{ path: "IsBeadhato", label: "Submittable", type: "bool" },
|
||||
],
|
||||
},
|
||||
|
||||
tests: {
|
||||
url: "/admin/api/tests",
|
||||
template: () => ({
|
||||
Uid: "",
|
||||
Datum: nowIso(),
|
||||
BejelentesDatuma: nowIso(),
|
||||
RogzitoTanarNeve: "",
|
||||
OrarendiOraOraszama: 1,
|
||||
Tantargy: subjectTemplate(),
|
||||
TantargyNeve: "",
|
||||
Temaja: "",
|
||||
Modja: { Uid: "1", Nev: "Írásbeli", Leiras: "" },
|
||||
OsztalyCsoport: { Uid: "" },
|
||||
}),
|
||||
columns: [
|
||||
{ paths: ["Tantargy.Nev", "TantargyNeve"], label: "Subject", type: "text" },
|
||||
{ path: "RogzitoTanarNeve", label: "Teacher", type: "text" },
|
||||
{ path: "Temaja", label: "Topic", type: "text" },
|
||||
{ path: "Modja.Nev", label: "Method", type: "text" },
|
||||
{ path: "Datum", label: "Date", type: "text" },
|
||||
{ path: "BejelentesDatuma", label: "Announced", type: "text" },
|
||||
],
|
||||
},
|
||||
|
||||
omissions: {
|
||||
url: "/admin/api/omissions",
|
||||
template: () => ({
|
||||
Uid: "",
|
||||
Tantargy: subjectTemplate(),
|
||||
Datum: nowIso(),
|
||||
RogzitoTanarNeve: "",
|
||||
Tipus: { Uid: "1", Nev: "Hiányzás", Leiras: "" },
|
||||
Mod: nameUidDescTemplate(),
|
||||
KeszitesDatuma: nowIso(),
|
||||
IgazolasAllapota: "Igazolt",
|
||||
IgazolasTipusa: nameUidDescTemplate(),
|
||||
OsztalyCsoport: { Uid: "" },
|
||||
}),
|
||||
columns: [
|
||||
{ path: "Tantargy.Nev", label: "Subject", type: "text" },
|
||||
{ path: "RogzitoTanarNeve", label: "Teacher", type: "text" },
|
||||
{ path: "Tipus.Nev", label: "Type", type: "text" },
|
||||
{ path: "IgazolasAllapota", label: "State (Igazolt/Igazolatlan/Igazolando)", type: "text" },
|
||||
{ path: "Datum", label: "Date", type: "text" },
|
||||
],
|
||||
},
|
||||
|
||||
lessons: {
|
||||
url: "/admin/api/lessons",
|
||||
template: () => ({
|
||||
Uid: "",
|
||||
Datum: nowIso(),
|
||||
KezdetIdopont: nowIso(),
|
||||
VegIdopont: nowIso(),
|
||||
Nev: "",
|
||||
Oraszam: 1,
|
||||
OraEvesSorszama: 0,
|
||||
OsztalyCsoport: { Uid: "", Nev: "" },
|
||||
TanarNeve: "",
|
||||
Tantargy: subjectTemplate(),
|
||||
Tema: "",
|
||||
TeremNeve: "",
|
||||
Tipus: { Uid: "1", Nev: "Tanóra", Leiras: "" },
|
||||
TanuloJelenlet: nameUidDescTemplate(),
|
||||
Allapot: { Uid: "1", Nev: "Megtartott", Leiras: "" },
|
||||
HaziFeladatUid: "",
|
||||
IsTanuloHaziFeladatEnabled: true,
|
||||
IsHaziFeladatMegoldva: false,
|
||||
Csatolmanyok: [],
|
||||
IsDigitalisOra: false,
|
||||
DigitalisTamogatoEszkozTipusList: [],
|
||||
Letrehozas: nowIso(),
|
||||
UtolsoModositas: nowIso(),
|
||||
}),
|
||||
columns: [
|
||||
{ paths: ["Nev", "Tantargy.Nev"], label: "Subject / name", type: "text" },
|
||||
{ path: "Datum", label: "Date", type: "text" },
|
||||
{ path: "KezdetIdopont", label: "Start", type: "text" },
|
||||
{ path: "VegIdopont", label: "End", type: "text" },
|
||||
{ path: "Oraszam", label: "Lesson #", type: "number" },
|
||||
{ path: "TanarNeve", label: "Teacher", type: "text" },
|
||||
{ path: "TeremNeve", label: "Room", type: "text" },
|
||||
{ path: "Tipus.Nev", label: "Type", type: "text" },
|
||||
{ path: "Allapot.Nev", label: "State", type: "text" },
|
||||
],
|
||||
},
|
||||
|
||||
notices: {
|
||||
url: "/admin/api/notices",
|
||||
template: () => ({
|
||||
Uid: "",
|
||||
RogzitoNeve: "",
|
||||
ErvenyessegKezdete: nowIso(),
|
||||
ErvenyessegVege: nowIso(),
|
||||
Cim: "",
|
||||
Tartalom: "",
|
||||
TartalomText: "",
|
||||
}),
|
||||
columns: [
|
||||
{ path: "Cim", label: "Title", type: "text" },
|
||||
{ path: "RogzitoNeve", label: "Author", type: "text" },
|
||||
{ paths: ["Tartalom", "TartalomText"], label: "Content", type: "text" },
|
||||
{ path: "ErvenyessegKezdete", label: "Valid from", type: "text" },
|
||||
{ path: "ErvenyessegVege", label: "Valid to", type: "text" },
|
||||
],
|
||||
},
|
||||
|
||||
infoBoard: {
|
||||
url: "/admin/api/infoBoard",
|
||||
template: () => ({
|
||||
Uid: "",
|
||||
Cim: "",
|
||||
Datum: nowIso(),
|
||||
KeszitoTanarNeve: "",
|
||||
KeszitesDatuma: nowIso(),
|
||||
Tartalom: "",
|
||||
TartalomFormazott: "",
|
||||
Tipus: { Uid: "1", Nev: "Dicséret", Leiras: "" },
|
||||
}),
|
||||
columns: [
|
||||
{ path: "Cim", label: "Title", type: "text" },
|
||||
{ path: "KeszitoTanarNeve", label: "Teacher", type: "text" },
|
||||
{ paths: ["Tartalom", "TartalomFormazott"], label: "Content", type: "text" },
|
||||
{ path: "Tipus.Nev", label: "Type", type: "text" },
|
||||
{ path: "Datum", label: "Date", type: "text" },
|
||||
],
|
||||
},
|
||||
|
||||
dktSubjects: {
|
||||
url: "/admin/api/dktSubjects",
|
||||
template: () => ({
|
||||
tantargyId: 0,
|
||||
tantargyNev: "",
|
||||
alkalmazottNev: "",
|
||||
csoportId: 0,
|
||||
osztalyCsoportNev: "",
|
||||
tipusId: 0,
|
||||
nyelvId: "",
|
||||
}),
|
||||
columns: [
|
||||
{ path: "tantargyNev", label: "Subject", type: "text" },
|
||||
{ path: "alkalmazottNev", label: "Teacher", type: "text" },
|
||||
{ path: "osztalyCsoportNev", label: "Group", type: "text" },
|
||||
{ path: "tipusId", label: "Type ID", type: "number" },
|
||||
],
|
||||
},
|
||||
|
||||
averages: {
|
||||
url: "/admin/api/averages",
|
||||
template: () => ({
|
||||
Uid: "",
|
||||
Tantargy: subjectTemplate(),
|
||||
TanuloAtlag: 0,
|
||||
OsztalyCsoportAtlag: 0,
|
||||
}),
|
||||
columns: [
|
||||
{ path: "Tantargy.Nev", label: "Subject", type: "text" },
|
||||
{ path: "TanuloAtlag", label: "Student average", type: "number" },
|
||||
{ path: "OsztalyCsoportAtlag", label: "Class average", type: "number" },
|
||||
],
|
||||
},
|
||||
|
||||
guardians: {
|
||||
template: () => ({
|
||||
Uid: "",
|
||||
Nev: "",
|
||||
EmailCim: "",
|
||||
IsTorvenyesKepviselo: true,
|
||||
Telefonszam: "",
|
||||
}),
|
||||
columns: [
|
||||
{ path: "Nev", label: "Name", type: "text" },
|
||||
{ path: "EmailCim", label: "Email", type: "text" },
|
||||
{ path: "Telefonszam", label: "Phone", type: "text" },
|
||||
{ path: "IsTorvenyesKepviselo", label: "Legal guardian", type: "bool" },
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
function renderStudentPanel(container) {
|
||||
container.innerHTML = "<h2>Student profile</h2>";
|
||||
const formHost = document.createElement("div");
|
||||
container.appendChild(formHost);
|
||||
|
||||
const status = document.createElement("span");
|
||||
status.className = "status";
|
||||
|
||||
let data = {};
|
||||
|
||||
const fields = [
|
||||
{ path: "Nev", label: "Name", type: "text" },
|
||||
{ path: "EmailCim", label: "Email", type: "text" },
|
||||
{ path: "Telefonszam", label: "Phone", type: "text" },
|
||||
{ path: "SzuletesiEv", label: "Birth year", type: "number" },
|
||||
{ path: "SzuletesiHonap", label: "Birth month", type: "number" },
|
||||
{ path: "SzuletesiNap", label: "Birth day", type: "number" },
|
||||
{ path: "Cimek", label: "Addresses (one per line)", type: "lines" },
|
||||
{ path: "TanevUid", label: "School year UID", type: "text" },
|
||||
{ path: "IntezmenyAzonosito", label: "Institute code", type: "text" },
|
||||
{ path: "IntezmenyNev", label: "Institute name", type: "text" },
|
||||
{ path: "Intezmeny.RovidNev", label: "Institute short name", type: "text" },
|
||||
];
|
||||
|
||||
const grid = document.createElement("div");
|
||||
grid.className = "form-grid";
|
||||
|
||||
function drawForm() {
|
||||
grid.innerHTML = "";
|
||||
fields.forEach((field) => {
|
||||
const label = document.createElement("label");
|
||||
label.textContent = field.label;
|
||||
grid.appendChild(label);
|
||||
grid.appendChild(cellInput(data, field, () => {}));
|
||||
});
|
||||
}
|
||||
|
||||
const toolbar = document.createElement("div");
|
||||
toolbar.className = "toolbar";
|
||||
const saveBtn = document.createElement("button");
|
||||
saveBtn.textContent = "Save student profile";
|
||||
toolbar.append(saveBtn, status);
|
||||
|
||||
const guardianHost = document.createElement("div");
|
||||
guardianHost.innerHTML = "<h3>Guardians</h3>";
|
||||
const guardianTableHost = document.createElement("div");
|
||||
guardianHost.appendChild(guardianTableHost);
|
||||
|
||||
container.appendChild(toolbar);
|
||||
container.appendChild(grid);
|
||||
container.appendChild(guardianHost);
|
||||
|
||||
let guardianRows = [];
|
||||
|
||||
function drawGuardians() {
|
||||
guardianTableHost.innerHTML = "";
|
||||
const table = document.createElement("table");
|
||||
const thead = document.createElement("tr");
|
||||
entities.guardians.columns.forEach((c) => {
|
||||
const th = document.createElement("th");
|
||||
th.textContent = c.label;
|
||||
thead.appendChild(th);
|
||||
});
|
||||
thead.appendChild(document.createElement("th"));
|
||||
table.appendChild(thead);
|
||||
|
||||
guardianRows.forEach((row, idx) => {
|
||||
const tr = document.createElement("tr");
|
||||
entities.guardians.columns.forEach((field) => {
|
||||
const td = document.createElement("td");
|
||||
td.appendChild(cellInput(row, field, () => {}));
|
||||
tr.appendChild(td);
|
||||
});
|
||||
const actionTd = document.createElement("td");
|
||||
const delBtn = document.createElement("button");
|
||||
delBtn.className = "danger";
|
||||
delBtn.textContent = "Delete";
|
||||
delBtn.onclick = () => {
|
||||
guardianRows.splice(idx, 1);
|
||||
drawGuardians();
|
||||
};
|
||||
actionTd.appendChild(delBtn);
|
||||
tr.appendChild(actionTd);
|
||||
table.appendChild(tr);
|
||||
});
|
||||
|
||||
guardianTableHost.appendChild(table);
|
||||
|
||||
const addBtn = document.createElement("button");
|
||||
addBtn.className = "secondary";
|
||||
addBtn.textContent = "Add guardian";
|
||||
addBtn.onclick = () => {
|
||||
guardianRows.push(entities.guardians.template());
|
||||
drawGuardians();
|
||||
};
|
||||
guardianTableHost.appendChild(addBtn);
|
||||
}
|
||||
|
||||
saveBtn.onclick = async () => {
|
||||
data.Gondviselok = guardianRows;
|
||||
try {
|
||||
await putJSON("/admin/api/student", data);
|
||||
flash(status, "saved");
|
||||
} catch (e) {
|
||||
flash(status, "error: " + e.message);
|
||||
}
|
||||
};
|
||||
|
||||
(async () => {
|
||||
data = await getJSON("/admin/api/student");
|
||||
guardianRows = data.Gondviselok || [];
|
||||
drawForm();
|
||||
drawGuardians();
|
||||
})();
|
||||
}
|
||||
|
||||
function renderServerPanel(container) {
|
||||
container.innerHTML = "<h2>Server settings</h2><p>Long-press the firka logo on the app's login screen to enable mock mode and point it at this server's address, then log in with the username/password configured below.</p>";
|
||||
const grid = document.createElement("div");
|
||||
grid.className = "form-grid";
|
||||
container.appendChild(grid);
|
||||
|
||||
const status = document.createElement("span");
|
||||
status.className = "status";
|
||||
|
||||
let data = {};
|
||||
const fields = [
|
||||
{ path: "instituteCode", label: "Institute code", type: "text" },
|
||||
{ path: "username", label: "Username", type: "text" },
|
||||
{ path: "password", label: "Password", type: "text" },
|
||||
{ path: "accessTokenTtlSeconds", label: "Access token TTL (seconds)", type: "number" },
|
||||
];
|
||||
|
||||
function draw() {
|
||||
grid.innerHTML = "";
|
||||
fields.forEach((field) => {
|
||||
const label = document.createElement("label");
|
||||
label.textContent = field.label;
|
||||
grid.appendChild(label);
|
||||
grid.appendChild(cellInput(data, field, () => {}));
|
||||
});
|
||||
}
|
||||
|
||||
const toolbar = document.createElement("div");
|
||||
toolbar.className = "toolbar";
|
||||
const saveBtn = document.createElement("button");
|
||||
saveBtn.textContent = "Save";
|
||||
saveBtn.onclick = async () => {
|
||||
try {
|
||||
await putJSON("/admin/api/config", data);
|
||||
flash(status, "saved");
|
||||
} catch (e) {
|
||||
flash(status, "error: " + e.message);
|
||||
}
|
||||
};
|
||||
const resetBtn = document.createElement("button");
|
||||
resetBtn.className = "danger";
|
||||
resetBtn.textContent = "Reset all data to seed defaults";
|
||||
resetBtn.onclick = async () => {
|
||||
if (!confirm("This replaces every entity with the built-in seed data. Continue?")) return;
|
||||
await fetch("/admin/api/reset", { method: "POST" });
|
||||
location.reload();
|
||||
};
|
||||
toolbar.append(saveBtn, resetBtn, status);
|
||||
container.appendChild(toolbar);
|
||||
container.appendChild(grid);
|
||||
|
||||
(async () => {
|
||||
data = await getJSON("/admin/api/config");
|
||||
draw();
|
||||
})();
|
||||
}
|
||||
|
||||
const tabs = [
|
||||
{ key: "server", label: "Server", render: renderServerPanel },
|
||||
{ key: "student", label: "Student", render: renderStudentPanel },
|
||||
{ key: "classGroups", label: "Class groups", render: (c) => renderTable(c, entities.classGroups) },
|
||||
{ key: "grades", label: "Grades", render: (c) => renderTable(c, entities.grades) },
|
||||
{ key: "homework", label: "Homework", render: (c) => renderTable(c, entities.homework) },
|
||||
{ key: "tests", label: "Tests", render: (c) => renderTable(c, entities.tests) },
|
||||
{ key: "omissions", label: "Omissions", render: (c) => renderTable(c, entities.omissions) },
|
||||
{ key: "lessons", label: "Timetable", render: (c) => renderTable(c, entities.lessons) },
|
||||
{ key: "notices", label: "Notice board", render: (c) => renderTable(c, entities.notices) },
|
||||
{ key: "infoBoard", label: "Info board", render: (c) => renderTable(c, entities.infoBoard) },
|
||||
{ key: "dktSubjects", label: "DKT subjects", render: (c) => renderTable(c, entities.dktSubjects) },
|
||||
{ key: "averages", label: "Class averages", render: (c) => renderTable(c, entities.averages) },
|
||||
];
|
||||
|
||||
function init() {
|
||||
const nav = document.getElementById("nav");
|
||||
const main = document.getElementById("main");
|
||||
|
||||
tabs.forEach((tab) => {
|
||||
const btn = document.createElement("button");
|
||||
btn.textContent = tab.label;
|
||||
btn.onclick = () => selectTab(tab.key);
|
||||
btn.dataset.key = tab.key;
|
||||
nav.appendChild(btn);
|
||||
});
|
||||
|
||||
function selectTab(key) {
|
||||
nav.querySelectorAll("button").forEach((b) => b.classList.toggle("active", b.dataset.key === key));
|
||||
const tab = tabs.find((t) => t.key === key);
|
||||
main.innerHTML = "";
|
||||
const panel = document.createElement("div");
|
||||
panel.className = "panel active";
|
||||
main.appendChild(panel);
|
||||
tab.render(panel);
|
||||
}
|
||||
|
||||
selectTab(tabs[0].key);
|
||||
}
|
||||
|
||||
init();
|
||||
17
mock_kreta_server/static/index.html
Normal file
17
mock_kreta_server/static/index.html
Normal file
@@ -0,0 +1,17 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>firka mock server</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>firka mock kréta server</h1>
|
||||
</header>
|
||||
<nav id="nav"></nav>
|
||||
<main id="main"></main>
|
||||
<script src="app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
168
mock_kreta_server/static/style.css
Normal file
168
mock_kreta_server/static/style.css
Normal file
@@ -0,0 +1,168 @@
|
||||
:root {
|
||||
color-scheme: light dark;
|
||||
--bg: #16181c;
|
||||
--panel: #1f2228;
|
||||
--border: #33373f;
|
||||
--text: #e7e9ec;
|
||||
--muted: #9aa0aa;
|
||||
--accent: #6fae4a;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
header {
|
||||
padding: 16px 20px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
header h1 {
|
||||
font-size: 18px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
header span {
|
||||
color: var(--muted);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
nav {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
padding: 10px 16px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
nav button {
|
||||
background: none;
|
||||
border: 1px solid var(--border);
|
||||
color: var(--text);
|
||||
padding: 6px 12px;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
nav button.active {
|
||||
background: var(--accent);
|
||||
border-color: var(--accent);
|
||||
color: #10140c;
|
||||
}
|
||||
|
||||
main {
|
||||
padding: 20px;
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.panel {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.panel.active {
|
||||
display: block;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin-bottom: 12px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
th, td {
|
||||
border: 1px solid var(--border);
|
||||
padding: 4px 6px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
th {
|
||||
background: var(--panel);
|
||||
color: var(--muted);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
input[type=text], input[type=number], textarea, select {
|
||||
width: 100%;
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--border);
|
||||
color: var(--text);
|
||||
border-radius: 4px;
|
||||
padding: 4px 6px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.row-actions {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.toolbar {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-bottom: 12px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
button {
|
||||
background: var(--accent);
|
||||
color: #10140c;
|
||||
border: none;
|
||||
padding: 7px 14px;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
button.secondary {
|
||||
background: var(--panel);
|
||||
color: var(--text);
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
|
||||
button.danger {
|
||||
background: #b3543f;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.form-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 220px 1fr;
|
||||
gap: 8px 12px;
|
||||
max-width: 640px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.form-grid label {
|
||||
align-self: center;
|
||||
color: var(--muted);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.status {
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
margin-left: 8px;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 16px;
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 14px;
|
||||
color: var(--muted);
|
||||
margin-top: 28px;
|
||||
}
|
||||
444
mock_kreta_server/store.go
Normal file
444
mock_kreta_server/store.go
Normal file
@@ -0,0 +1,444 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type UidRef struct {
|
||||
Uid string `json:"Uid"`
|
||||
}
|
||||
|
||||
type NameUid struct {
|
||||
Uid string `json:"Uid"`
|
||||
Nev string `json:"Nev"`
|
||||
}
|
||||
|
||||
type NameUidDesc struct {
|
||||
Uid string `json:"Uid"`
|
||||
Nev string `json:"Nev"`
|
||||
Leiras string `json:"Leiras"`
|
||||
}
|
||||
|
||||
type Subject struct {
|
||||
Uid string `json:"Uid"`
|
||||
Nev string `json:"Nev"`
|
||||
Kategoria NameUidDesc `json:"Kategoria"`
|
||||
SortIndex int `json:"SortIndex"`
|
||||
}
|
||||
|
||||
type Guardian struct {
|
||||
Uid string `json:"Uid"`
|
||||
Nev string `json:"Nev"`
|
||||
EmailCim string `json:"EmailCim,omitempty"`
|
||||
IsTorvenyesKepviselo bool `json:"IsTorvenyesKepviselo"`
|
||||
Telefonszam string `json:"Telefonszam,omitempty"`
|
||||
}
|
||||
|
||||
type BankAccount struct {
|
||||
BankszamlaSzam string `json:"BankszamlaSzam,omitempty"`
|
||||
IsReadOnly bool `json:"IsReadOnly"`
|
||||
BankszamlaTulajdonosNeve string `json:"BankszamlaTulajdonosNeve,omitempty"`
|
||||
BankszamlaTulajdonosTipusId int `json:"BankszamlaTulajdonosTipusId"`
|
||||
}
|
||||
|
||||
type SystemModule struct {
|
||||
IsAktiv bool `json:"IsAktiv"`
|
||||
Tipus string `json:"Tipus"`
|
||||
Url string `json:"Url,omitempty"`
|
||||
}
|
||||
|
||||
type CustomizationSettings struct {
|
||||
ErtekelesekMegjelenitesenekKesleltetesenekMerteke int `json:"ErtekelesekMegjelenitesenekKesleltetesenekMerteke"`
|
||||
IsOsztalyAtlagMegjeleniteseEllenorzoben bool `json:"IsOsztalyAtlagMegjeleniteseEllenorzoben"`
|
||||
IsTanorakTemajaMegtekinthetoEllenorzoben bool `json:"IsTanorakTemajaMegtekinthetoEllenorzoben"`
|
||||
KovetkezoTelepitesDatuma string `json:"KovetkezoTelepitesDatuma"`
|
||||
}
|
||||
|
||||
type Institution struct {
|
||||
Uid string `json:"Uid"`
|
||||
RovidNev string `json:"RovidNev"`
|
||||
TestreszabasBeallitasok CustomizationSettings `json:"TestreszabasBeallitasok"`
|
||||
Rendszermodulok []SystemModule `json:"Rendszermodulok"`
|
||||
}
|
||||
|
||||
type Student struct {
|
||||
Uid string `json:"Uid"`
|
||||
Nev string `json:"Nev"`
|
||||
Cimek []string `json:"Cimek"`
|
||||
Bankszamla BankAccount `json:"Bankszamla"`
|
||||
SzuletesiEv int `json:"SzuletesiEv"`
|
||||
SzuletesiHonap int `json:"SzuletesiHonap"`
|
||||
SzuletesiNap int `json:"SzuletesiNap"`
|
||||
EmailCim string `json:"EmailCim,omitempty"`
|
||||
Telefonszam string `json:"Telefonszam,omitempty"`
|
||||
TanevUid string `json:"TanevUid"`
|
||||
Gondviselok []Guardian `json:"Gondviselok"`
|
||||
IntezmenyAzonosito string `json:"IntezmenyAzonosito"`
|
||||
IntezmenyNev string `json:"IntezmenyNev"`
|
||||
Intezmeny Institution `json:"Intezmeny"`
|
||||
}
|
||||
|
||||
type ClassGroup struct {
|
||||
Uid string `json:"Uid"`
|
||||
Nev string `json:"Nev"`
|
||||
OsztalyFonok UidRef `json:"OsztalyFonok"`
|
||||
OsztalyFonokHelyettes UidRef `json:"OsztalyFonokHelyettes"`
|
||||
OktatasNevelesiKategoria NameUidDesc `json:"OktatasNevelesiKategoria"`
|
||||
OktatasNevelesiKategoriaSortIndex int `json:"OktatasNevelesiKategoriaSortIndex"`
|
||||
OktatasNevelesiFeladat NameUidDesc `json:"OktatasNevelesiFeladat"`
|
||||
IsAktiv bool `json:"IsAktiv"`
|
||||
Tipus string `json:"Tipus"`
|
||||
}
|
||||
|
||||
type Grade struct {
|
||||
Uid string `json:"Uid"`
|
||||
RogzitesDatuma string `json:"RogzitesDatuma"`
|
||||
KeszitesDatuma string `json:"KeszitesDatuma"`
|
||||
LattamozasDatuma string `json:"LattamozasDatuma,omitempty"`
|
||||
Tantargy Subject `json:"Tantargy"`
|
||||
Tema string `json:"Tema,omitempty"`
|
||||
Tipus NameUidDesc `json:"Tipus"`
|
||||
Mod NameUidDesc `json:"Mod"`
|
||||
ErtekFajta NameUidDesc `json:"ErtekFajta"`
|
||||
ErtekeloTanarNeve string `json:"ErtekeloTanarNeve"`
|
||||
Kind string `json:"Kind,omitempty"`
|
||||
SzamErtek int `json:"SzamErtek,omitempty"`
|
||||
SzovegesErtek string `json:"SzovegesErtek"`
|
||||
SulySzazalekErteke int `json:"SulySzazalekErteke,omitempty"`
|
||||
SzovegesErtekelesRovidNev string `json:"SzovegesErtekelesRovidNev,omitempty"`
|
||||
OsztalyCsoport UidRef `json:"OsztalyCsoport"`
|
||||
SortIndex int `json:"SortIndex"`
|
||||
}
|
||||
|
||||
type Homework struct {
|
||||
Uid string `json:"Uid"`
|
||||
Tantargy Subject `json:"Tantargy"`
|
||||
TantargyNeve string `json:"TantargyNeve"`
|
||||
RogzitoTanarNeve string `json:"RogzitoTanarNeve"`
|
||||
Szoveg string `json:"Szoveg"`
|
||||
FeladasDatuma string `json:"FeladasDatuma"`
|
||||
HataridoDatuma string `json:"HataridoDatuma"`
|
||||
RogzitesIdopontja string `json:"RogzitesIdopontja"`
|
||||
IsTanarRogzitette bool `json:"IsTanarRogzitette"`
|
||||
IsMegoldva bool `json:"IsMegoldva"`
|
||||
IsBeadhato bool `json:"IsBeadhato"`
|
||||
OsztalyCsoport UidRef `json:"OsztalyCsoport"`
|
||||
IsCsatolasEngedelyezes bool `json:"IsCsatolasEngedelyezes"`
|
||||
}
|
||||
|
||||
type Test struct {
|
||||
Uid string `json:"Uid"`
|
||||
Datum string `json:"Datum"`
|
||||
BejelentesDatuma string `json:"BejelentesDatuma"`
|
||||
RogzitoTanarNeve string `json:"RogzitoTanarNeve"`
|
||||
OrarendiOraOraszama int `json:"OrarendiOraOraszama"`
|
||||
Tantargy Subject `json:"Tantargy"`
|
||||
TantargyNeve string `json:"TantargyNeve"`
|
||||
Temaja string `json:"Temaja,omitempty"`
|
||||
Modja NameUidDesc `json:"Modja"`
|
||||
OsztalyCsoport UidRef `json:"OsztalyCsoport"`
|
||||
}
|
||||
|
||||
type OmittedLesson struct {
|
||||
KezdoDatum string `json:"KezdoDatum"`
|
||||
VegDatum string `json:"VegDatum"`
|
||||
Oraszam int `json:"Oraszam,omitempty"`
|
||||
}
|
||||
|
||||
type Omission struct {
|
||||
Uid string `json:"Uid"`
|
||||
Tantargy Subject `json:"Tantargy"`
|
||||
Ora *OmittedLesson `json:"Ora,omitempty"`
|
||||
Datum string `json:"Datum"`
|
||||
RogzitoTanarNeve string `json:"RogzitoTanarNeve"`
|
||||
Tipus NameUidDesc `json:"Tipus"`
|
||||
Mod NameUidDesc `json:"Mod"`
|
||||
KesesPercben int `json:"KesesPercben,omitempty"`
|
||||
KeszitesDatuma string `json:"KeszitesDatuma"`
|
||||
IgazolasAllapota string `json:"IgazolasAllapota"`
|
||||
IgazolasTipusa NameUidDesc `json:"IgazolasTipusa"`
|
||||
OsztalyCsoport UidRef `json:"OsztalyCsoport"`
|
||||
}
|
||||
|
||||
type Lesson struct {
|
||||
Uid string `json:"Uid"`
|
||||
Datum string `json:"Datum"`
|
||||
KezdetIdopont string `json:"KezdetIdopont"`
|
||||
VegIdopont string `json:"VegIdopont"`
|
||||
Nev string `json:"Nev"`
|
||||
Oraszam int `json:"Oraszam,omitempty"`
|
||||
OraEvesSorszama int `json:"OraEvesSorszama,omitempty"`
|
||||
OsztalyCsoport NameUid `json:"OsztalyCsoport"`
|
||||
TanarNeve string `json:"TanarNeve,omitempty"`
|
||||
Tantargy Subject `json:"Tantargy"`
|
||||
Tema string `json:"Tema,omitempty"`
|
||||
TeremNeve string `json:"TeremNeve,omitempty"`
|
||||
Tipus NameUidDesc `json:"Tipus"`
|
||||
TanuloJelenlet NameUidDesc `json:"TanuloJelenlet"`
|
||||
Allapot NameUidDesc `json:"Allapot"`
|
||||
HelyettesTanarNeve string `json:"HelyettesTanarNeve,omitempty"`
|
||||
HaziFeladatUid string `json:"HaziFeladatUid,omitempty"`
|
||||
FeladatGroupUid string `json:"FeladatGroupUid,omitempty"`
|
||||
NyelviFeladatGroupUid string `json:"NyelviFeladatGroupUid,omitempty"`
|
||||
BejelentettSzamonkeresUid string `json:"BejelentettSzamonkeresUid,omitempty"`
|
||||
IsTanuloHaziFeladatEnabled bool `json:"IsTanuloHaziFeladatEnabled"`
|
||||
IsHaziFeladatMegoldva bool `json:"IsHaziFeladatMegoldva"`
|
||||
Csatolmanyok []NameUid `json:"Csatolmanyok"`
|
||||
IsDigitalisOra bool `json:"IsDigitalisOra"`
|
||||
DigitalisEszkozTipus string `json:"DigitalisEszkozTipus,omitempty"`
|
||||
DigitalisPlatformTipus string `json:"DigitalisPlatformTipus,omitempty"`
|
||||
DigitalisTamogatoEszkozTipusList []string `json:"DigitalisTamogatoEszkozTipusList"`
|
||||
Letrehozas string `json:"Letrehozas"`
|
||||
UtolsoModositas string `json:"UtolsoModositas"`
|
||||
}
|
||||
|
||||
type NoticeBoardItem struct {
|
||||
Uid string `json:"Uid"`
|
||||
RogzitoNeve string `json:"RogzitoNeve"`
|
||||
ErvenyessegKezdete string `json:"ErvenyessegKezdete"`
|
||||
ErvenyessegVege string `json:"ErvenyessegVege"`
|
||||
Cim string `json:"Cim"`
|
||||
Tartalom string `json:"Tartalom"`
|
||||
TartalomText string `json:"TartalomText"`
|
||||
}
|
||||
|
||||
type InfoBoardItem struct {
|
||||
Uid string `json:"Uid"`
|
||||
Cim string `json:"Cim"`
|
||||
Datum string `json:"Datum"`
|
||||
KeszitoTanarNeve string `json:"KeszitoTanarNeve"`
|
||||
KeszitesDatuma string `json:"KeszitesDatuma"`
|
||||
Tartalom string `json:"Tartalom"`
|
||||
TartalomFormazott string `json:"TartalomFormazott"`
|
||||
Tipus NameUidDesc `json:"Tipus"`
|
||||
}
|
||||
|
||||
type DktSubject struct {
|
||||
TantargyId int `json:"tantargyId"`
|
||||
TantargyNev string `json:"tantargyNev"`
|
||||
AlkalmazottNev string `json:"alkalmazottNev"`
|
||||
CsoportId int `json:"csoportId,omitempty"`
|
||||
OsztalyCsoportNev string `json:"osztalyCsoportNev"`
|
||||
TipusId int `json:"tipusId"`
|
||||
NyelvId string `json:"nyelvId,omitempty"`
|
||||
}
|
||||
|
||||
type ClassGroupSubjectAverage struct {
|
||||
Uid string `json:"Uid"`
|
||||
Tantargy Subject `json:"Tantargy"`
|
||||
TanuloAtlag float64 `json:"TanuloAtlag,omitempty"`
|
||||
OsztalyCsoportAtlag float64 `json:"OsztalyCsoportAtlag,omitempty"`
|
||||
}
|
||||
|
||||
type ServerConfig struct {
|
||||
InstituteCode string `json:"instituteCode"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
AccessTokenTTLSeconds int `json:"accessTokenTtlSeconds"`
|
||||
}
|
||||
|
||||
type storeData struct {
|
||||
Config ServerConfig `json:"config"`
|
||||
Student Student `json:"student"`
|
||||
ClassGroups []ClassGroup `json:"classGroups"`
|
||||
Grades []Grade `json:"grades"`
|
||||
Homework []Homework `json:"homework"`
|
||||
Tests []Test `json:"tests"`
|
||||
Omissions []Omission `json:"omissions"`
|
||||
Lessons []Lesson `json:"lessons"`
|
||||
Notices []NoticeBoardItem `json:"notices"`
|
||||
InfoBoard []InfoBoardItem `json:"infoBoard"`
|
||||
DktSubjects []DktSubject `json:"dktSubjects"`
|
||||
Averages []ClassGroupSubjectAverage `json:"averages"`
|
||||
}
|
||||
|
||||
type Store struct {
|
||||
mu sync.RWMutex
|
||||
path string
|
||||
data storeData
|
||||
}
|
||||
|
||||
func NewStore(path string) *Store {
|
||||
s := &Store{path: path}
|
||||
if raw, err := os.ReadFile(path); err == nil {
|
||||
if json.Unmarshal(raw, &s.data) == nil {
|
||||
return s
|
||||
}
|
||||
}
|
||||
s.data = seedData()
|
||||
s.save()
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *Store) save() {
|
||||
raw, err := json.MarshalIndent(s.data, "", " ")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
os.WriteFile(s.path, raw, 0o644)
|
||||
}
|
||||
|
||||
func (s *Store) Reset() {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.data = seedData()
|
||||
s.save()
|
||||
}
|
||||
|
||||
func (s *Store) GetConfig() ServerConfig {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
return s.data.Config
|
||||
}
|
||||
|
||||
func (s *Store) SetConfig(v ServerConfig) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.data.Config = v
|
||||
s.save()
|
||||
}
|
||||
|
||||
func (s *Store) GetStudent() Student {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
return s.data.Student
|
||||
}
|
||||
|
||||
func (s *Store) SetStudent(v Student) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.data.Student = v
|
||||
s.save()
|
||||
}
|
||||
|
||||
func (s *Store) GetClassGroups() []ClassGroup {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
return s.data.ClassGroups
|
||||
}
|
||||
|
||||
func (s *Store) SetClassGroups(v []ClassGroup) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.data.ClassGroups = v
|
||||
s.save()
|
||||
}
|
||||
|
||||
func (s *Store) GetGrades() []Grade {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
return s.data.Grades
|
||||
}
|
||||
|
||||
func (s *Store) SetGrades(v []Grade) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.data.Grades = v
|
||||
s.save()
|
||||
}
|
||||
|
||||
func (s *Store) GetHomework() []Homework {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
return s.data.Homework
|
||||
}
|
||||
|
||||
func (s *Store) SetHomework(v []Homework) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.data.Homework = v
|
||||
s.save()
|
||||
}
|
||||
|
||||
func (s *Store) GetTests() []Test {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
return s.data.Tests
|
||||
}
|
||||
|
||||
func (s *Store) SetTests(v []Test) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.data.Tests = v
|
||||
s.save()
|
||||
}
|
||||
|
||||
func (s *Store) GetOmissions() []Omission {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
return s.data.Omissions
|
||||
}
|
||||
|
||||
func (s *Store) SetOmissions(v []Omission) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.data.Omissions = v
|
||||
s.save()
|
||||
}
|
||||
|
||||
func (s *Store) GetLessons() []Lesson {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
return s.data.Lessons
|
||||
}
|
||||
|
||||
func (s *Store) SetLessons(v []Lesson) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.data.Lessons = v
|
||||
s.save()
|
||||
}
|
||||
|
||||
func (s *Store) GetNotices() []NoticeBoardItem {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
return s.data.Notices
|
||||
}
|
||||
|
||||
func (s *Store) SetNotices(v []NoticeBoardItem) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.data.Notices = v
|
||||
s.save()
|
||||
}
|
||||
|
||||
func (s *Store) GetInfoBoard() []InfoBoardItem {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
return s.data.InfoBoard
|
||||
}
|
||||
|
||||
func (s *Store) SetInfoBoard(v []InfoBoardItem) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.data.InfoBoard = v
|
||||
s.save()
|
||||
}
|
||||
|
||||
func (s *Store) GetDktSubjects() []DktSubject {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
return s.data.DktSubjects
|
||||
}
|
||||
|
||||
func (s *Store) SetDktSubjects(v []DktSubject) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.data.DktSubjects = v
|
||||
s.save()
|
||||
}
|
||||
|
||||
func (s *Store) GetAverages() []ClassGroupSubjectAverage {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
return s.data.Averages
|
||||
}
|
||||
|
||||
func (s *Store) SetAverages(v []ClassGroupSubjectAverage) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.data.Averages = v
|
||||
s.save()
|
||||
}
|
||||
Reference in New Issue
Block a user