-
-
Notifications
You must be signed in to change notification settings - Fork 333
Feature/add server validation comments #959
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Richard141201
wants to merge
6
commits into
wger-project:master
Choose a base branch
from
Richard141201:feature/add-server-validation-comments
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
40d9261
Pridanie novej funkcionality alebo opravy
Richard141201 8b602fe
Added server side validation to exercise comments
Richard141201 087c123
Added server side validation to exercise comments
Richard141201 cc1c6cb
Added server side validation to exercise comments
Richard141201 1e563f3
New test for validateLanguage
Richard141201 b3a5e15
how validation errors using FormHttpErrorsWidget
Richard141201 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # | ||
| # Generated file, do not edit. | ||
| # | ||
|
|
||
| import lldb | ||
|
|
||
| def handle_new_rx_page(frame: lldb.SBFrame, bp_loc, extra_args, intern_dict): | ||
| """Intercept NOTIFY_DEBUGGER_ABOUT_RX_PAGES and touch the pages.""" | ||
| base = frame.register["x0"].GetValueAsAddress() | ||
| page_len = frame.register["x1"].GetValueAsUnsigned() | ||
|
|
||
| # Note: NOTIFY_DEBUGGER_ABOUT_RX_PAGES will check contents of the | ||
| # first page to see if handled it correctly. This makes diagnosing | ||
| # misconfiguration (e.g. missing breakpoint) easier. | ||
| data = bytearray(page_len) | ||
| data[0:8] = b'IHELPED!' | ||
|
|
||
| error = lldb.SBError() | ||
| frame.GetThread().GetProcess().WriteMemory(base, data, error) | ||
| if not error.Success(): | ||
| print(f'Failed to write into {base}[+{page_len}]', error) | ||
| return | ||
|
|
||
| def __lldb_init_module(debugger: lldb.SBDebugger, _): | ||
| target = debugger.GetDummyTarget() | ||
| # Caveat: must use BreakpointCreateByRegEx here and not | ||
| # BreakpointCreateByName. For some reasons callback function does not | ||
| # get carried over from dummy target for the later. | ||
| bp = target.BreakpointCreateByRegex("^NOTIFY_DEBUGGER_ABOUT_RX_PAGES$") | ||
| bp.SetScriptCallbackFunction('{}.handle_new_rx_page'.format(__name__)) | ||
| bp.SetAutoContinue(True) | ||
| print("-- LLDB integration loaded --") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # | ||
| # Generated file, do not edit. | ||
| # | ||
|
|
||
| command script import --relative-to-command-file flutter_lldb_helper.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,8 +11,8 @@ import 'package:wger/providers/user.dart'; | |
| import 'package:wger/screens/exercise_screen.dart'; | ||
| import 'package:wger/widgets/add_exercise/steps/step_1_basics.dart'; | ||
| import 'package:wger/widgets/add_exercise/steps/step_2_variations.dart'; | ||
| import 'package:wger/widgets/add_exercise/steps/step_3_description.dart'; | ||
| import 'package:wger/widgets/add_exercise/steps/step_4_translations.dart'; | ||
| import 'package:wger/widgets/add_exercise/steps/step_3_description.dart' as step3; | ||
| import 'package:wger/widgets/add_exercise/steps/step_4_translations.dart' as step4; | ||
| import 'package:wger/widgets/add_exercise/steps/step_5_images.dart'; | ||
| import 'package:wger/widgets/add_exercise/steps/step_6_overview.dart'; | ||
| import 'package:wger/widgets/core/app_bar.dart'; | ||
|
|
@@ -46,7 +46,9 @@ class _AddExerciseStepperState extends State<AddExerciseStepper> { | |
| int _currentStep = 0; | ||
| int lastStepIndex = AddExerciseStepper.STEPS_IN_FORM - 1; | ||
| bool _isLoading = false; | ||
| bool _isValidating = false; | ||
| Widget errorWidget = const SizedBox.shrink(); | ||
| WgerHttpException? _validationError; | ||
|
|
||
| final List<GlobalKey<FormState>> _keys = [ | ||
| GlobalKey<FormState>(), | ||
|
|
@@ -57,16 +59,63 @@ class _AddExerciseStepperState extends State<AddExerciseStepper> { | |
| GlobalKey<FormState>(), | ||
| ]; | ||
|
|
||
| Future<bool> _validateLanguageOnServer(BuildContext context) async { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had hoped we could add something to the fields themselves so that the logic would be directly in e.g. Step3Description or AddExerciseTextArea. I find it very baffling that flutter does not have support for async validators, then this would be way easier |
||
| final addExerciseProvider = context.read<AddExerciseProvider>(); | ||
|
|
||
| try { | ||
| if (_currentStep == 2) { | ||
| await addExerciseProvider.validateLanguage( | ||
| addExerciseProvider.descriptionEn ?? '', | ||
| 'en', | ||
| ); | ||
| } | ||
|
|
||
| if (_currentStep == 3 && addExerciseProvider.descriptionTrans != null) { | ||
| final languageCode = addExerciseProvider.languageTranslation?.shortName ?? ''; | ||
| if (languageCode.isNotEmpty) { | ||
| await addExerciseProvider.validateLanguage( | ||
| addExerciseProvider.descriptionTrans ?? '', | ||
| languageCode, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| return true; | ||
| } on WgerHttpException catch (error) { | ||
| if (mounted) { | ||
| setState(() { | ||
| _validationError = error; | ||
| }); | ||
| } | ||
| return false; | ||
| } catch (error) { | ||
| if (mounted) { | ||
| setState(() { | ||
| _validationError = WgerHttpException({'error': [error.toString()]}); | ||
| }); | ||
| } | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| Widget _controlsBuilder(BuildContext context, ControlsDetails details) { | ||
| return Column( | ||
| children: [ | ||
| const SizedBox(height: 10), | ||
|
|
||
| if (_validationError != null && _currentStep != lastStepIndex) | ||
| Padding( | ||
| padding: const EdgeInsets.symmetric(vertical: 8.0), | ||
| child: FormHttpErrorsWidget(_validationError!), | ||
| ), | ||
|
|
||
| if (_currentStep == lastStepIndex) errorWidget, | ||
|
|
||
| Row( | ||
| mainAxisAlignment: MainAxisAlignment.spaceAround, | ||
| children: [ | ||
| OutlinedButton( | ||
| onPressed: details.onStepCancel, | ||
| onPressed: _isValidating ? null : details.onStepCancel, | ||
| child: Text(AppLocalizations.of(context).previous), | ||
| ), | ||
|
|
||
|
|
@@ -76,70 +125,112 @@ class _AddExerciseStepperState extends State<AddExerciseStepper> { | |
| onPressed: _isLoading | ||
| ? null | ||
| : () async { | ||
| setState(() { | ||
| _isLoading = true; | ||
| errorWidget = const SizedBox.shrink(); | ||
| }); | ||
| final addExerciseProvider = context.read<AddExerciseProvider>(); | ||
| final exerciseProvider = context.read<ExercisesProvider>(); | ||
|
|
||
| Exercise? exercise; | ||
| try { | ||
| final exerciseId = await addExerciseProvider.postExerciseToServer(); | ||
| exercise = await exerciseProvider.fetchAndSetExercise(exerciseId); | ||
| } on WgerHttpException catch (error) { | ||
| if (context.mounted) { | ||
| setState(() { | ||
| errorWidget = FormHttpErrorsWidget(error); | ||
| }); | ||
| } | ||
| } finally { | ||
| if (mounted) { | ||
| setState(() { | ||
| _isLoading = false; | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| if (exercise == null || !context.mounted) { | ||
| return; | ||
| } | ||
|
|
||
| final name = exercise | ||
| .getTranslation(Localizations.localeOf(context).languageCode) | ||
| .name; | ||
|
|
||
| return showDialog( | ||
| context: context, | ||
| builder: (BuildContext context) { | ||
| return AlertDialog( | ||
| title: Text(AppLocalizations.of(context).success), | ||
| content: Text(AppLocalizations.of(context).cacheWarning), | ||
| actions: [ | ||
| TextButton( | ||
| child: Text(name), | ||
| onPressed: () { | ||
| Navigator.of(context).pop(); | ||
| Navigator.pushReplacementNamed( | ||
| context, | ||
| ExerciseDetailScreen.routeName, | ||
| arguments: exercise, | ||
| ); | ||
| }, | ||
| ), | ||
| ], | ||
| ); | ||
| }, | ||
| ); | ||
| }, | ||
| setState(() { | ||
| _isLoading = true; | ||
| errorWidget = const SizedBox.shrink(); | ||
| }); | ||
| final addExerciseProvider = context.read<AddExerciseProvider>(); | ||
| final exerciseProvider = context.read<ExercisesProvider>(); | ||
|
|
||
| Exercise? exercise; | ||
| try { | ||
| final exerciseId = await addExerciseProvider.postExerciseToServer(); | ||
| exercise = await exerciseProvider.fetchAndSetExercise(exerciseId); | ||
| } on WgerHttpException catch (error) { | ||
| if (context.mounted) { | ||
| setState(() { | ||
| errorWidget = FormHttpErrorsWidget(error); | ||
| }); | ||
| } | ||
| } finally { | ||
| if (mounted) { | ||
| setState(() { | ||
| _isLoading = false; | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| if (exercise == null || !context.mounted) { | ||
| return; | ||
| } | ||
|
|
||
| final name = exercise | ||
| .getTranslation(Localizations.localeOf(context).languageCode) | ||
| .name; | ||
|
|
||
| return showDialog( | ||
| context: context, | ||
| builder: (BuildContext context) { | ||
| return AlertDialog( | ||
| title: Text(AppLocalizations.of(context).success), | ||
| content: Text(AppLocalizations.of(context).cacheWarning), | ||
| actions: [ | ||
| TextButton( | ||
| child: Text(name), | ||
| onPressed: () { | ||
| Navigator.of(context).pop(); | ||
| Navigator.pushReplacementNamed( | ||
| context, | ||
| ExerciseDetailScreen.routeName, | ||
| arguments: exercise, | ||
| ); | ||
| }, | ||
| ), | ||
| ], | ||
| ); | ||
| }, | ||
| ); | ||
| }, | ||
| child: _isLoading | ||
| ? const SizedBox(height: 20, width: 20, child: CircularProgressIndicator()) | ||
| : Text(AppLocalizations.of(context).save), | ||
| ) | ||
| else | ||
| ElevatedButton( | ||
| onPressed: details.onStepContinue, | ||
| child: Text(AppLocalizations.of(context).next), | ||
| onPressed: _isValidating | ||
| ? null | ||
| : () async { | ||
| setState(() { | ||
| _validationError = null; | ||
| }); | ||
|
|
||
| if (!(_keys[_currentStep].currentState?.validate() ?? false)) { | ||
| return; | ||
| } | ||
|
|
||
| _keys[_currentStep].currentState?.save(); | ||
|
|
||
| if (_currentStep == 2 || _currentStep == 3) { | ||
| setState(() { | ||
| _isValidating = true; | ||
| }); | ||
|
|
||
| final isValid = await _validateLanguageOnServer(context); | ||
|
|
||
| if (mounted) { | ||
| setState(() { | ||
| _isValidating = false; | ||
| }); | ||
| } | ||
|
|
||
| if (!isValid) { | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| if (_currentStep != lastStepIndex) { | ||
| setState(() { | ||
| _currentStep += 1; | ||
| }); | ||
| } | ||
| }, | ||
| child: _isValidating | ||
| ? const SizedBox( | ||
| height: 20, | ||
| width: 20, | ||
| child: CircularProgressIndicator(strokeWidth: 2), | ||
| ) | ||
| : Text(AppLocalizations.of(context).next), | ||
| ), | ||
| ], | ||
| ), | ||
|
|
@@ -164,42 +255,29 @@ class _AddExerciseStepperState extends State<AddExerciseStepper> { | |
| ), | ||
| Step( | ||
| title: Text(AppLocalizations.of(context).description), | ||
| content: Step3Description(formkey: _keys[2]), | ||
| content: step3.Step3Description(formkey: _keys[2]), | ||
| ), | ||
| Step( | ||
| title: Text(AppLocalizations.of(context).translation), | ||
| content: Step4Translation(formkey: _keys[3]), | ||
| content: step4.Step4Translation(formkey: _keys[3]), | ||
| ), | ||
| Step( | ||
| title: Text(AppLocalizations.of(context).images), | ||
| content: Step5Images(formkey: _keys[4]), | ||
| ), | ||
| Step(title: Text(AppLocalizations.of(context).overview), content: Step6Overview()), | ||
| Step( | ||
| title: Text(AppLocalizations.of(context).overview), | ||
| content: Step6Overview(), | ||
| ), | ||
| ], | ||
| currentStep: _currentStep, | ||
| onStepContinue: () { | ||
| if (_keys[_currentStep].currentState?.validate() ?? false) { | ||
| _keys[_currentStep].currentState?.save(); | ||
|
|
||
| if (_currentStep != lastStepIndex) { | ||
| setState(() { | ||
| _currentStep += 1; | ||
| }); | ||
| } | ||
| } | ||
| }, | ||
| onStepContinue: null, // Použijeme vlastnú logiku v _controlsBuilder | ||
| onStepCancel: () => setState(() { | ||
| if (_currentStep != 0) { | ||
| _currentStep -= 1; | ||
| _validationError = null; // Resetovať chybu pri návrate | ||
| } | ||
| }), | ||
| /* | ||
| onStepTapped: (int index) { | ||
| setState(() { | ||
| _currentStep = index; | ||
| }); | ||
| }, | ||
| */ | ||
| ), | ||
| ); | ||
| } | ||
|
|
@@ -256,4 +334,4 @@ class EmailNotVerified extends StatelessWidget { | |
| ), | ||
| ); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was really confused about this till I saw that it's one of flutter's generated files 😅