diff --git a/lib/Screens/Configurations/Section/SubSection/Menu/showEditSubSection.dart b/lib/Screens/Configurations/Section/SubSection/Menu/showEditSubSection.dart index 71bf57e..3a79737 100644 --- a/lib/Screens/Configurations/Section/SubSection/Menu/showEditSubSection.dart +++ b/lib/Screens/Configurations/Section/SubSection/Menu/showEditSubSection.dart @@ -49,6 +49,7 @@ void showEditSubSection(SectionDTO subSectionDTO, Function getResult, AppContext subSectionDTO.imageId = resource.id; subSectionDTO.imageSource = resource.type == ResourceType.imageUrl ? resource.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resource.id; }, + isSmall: true, ), ], ), diff --git a/lib/Screens/Configurations/Section/section_detail_screen.dart b/lib/Screens/Configurations/Section/section_detail_screen.dart index 85f8a58..dc192af 100644 --- a/lib/Screens/Configurations/Section/section_detail_screen.dart +++ b/lib/Screens/Configurations/Section/section_detail_screen.dart @@ -29,7 +29,6 @@ class SectionDetailScreen extends StatefulWidget { } class _SectionDetailScreenState extends State { - SectionDTO sectionDTO; @override Widget build(BuildContext context) { @@ -47,7 +46,7 @@ class _SectionDetailScreenState extends State { alignment: AlignmentDirectional.bottomCenter, child: Container( height: 80, - child: getButtons(sectionDTO, appContext), + child: getButtons(snapshot.data, appContext), ), ) ], @@ -187,7 +186,6 @@ class _SectionDetailScreenState extends State { initialValue: sectionDTO != null ? sectionDTO.imageId : "", color: kPrimaryColor, onChanged: (ResourceDTO resource) { - print("received value in grant older"); sectionDTO.imageId = resource.id; sectionDTO.imageSource = resource.type == ResourceType.imageUrl ? resource.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resource.id; }, @@ -249,6 +247,7 @@ class _SectionDetailScreenState extends State { textColor: Colors.white, fontSize: 15, press: () { + print(sectionDTO); delete(sectionDTO, appContext); }, ), @@ -293,9 +292,6 @@ class _SectionDetailScreenState extends State { } Future save(bool isTraduction, SectionDTO sectionDTO, AppContext appContext) async { - print("SAVE"); - print(sectionDTO); - if (sectionDTO != null) { SectionDTO section = await appContext.getContext().clientAPI.sectionApi.sectionUpdate(sectionDTO); ManagerAppContext managerAppContext = appContext.getContext(); diff --git a/lib/Screens/Configurations/configuration_detail_screen.dart b/lib/Screens/Configurations/configuration_detail_screen.dart index 57557c5..f7f4e47 100644 --- a/lib/Screens/Configurations/configuration_detail_screen.dart +++ b/lib/Screens/Configurations/configuration_detail_screen.dart @@ -317,9 +317,7 @@ class _ConfigurationDetailScreenState extends State { } Future> getSections(ConfigurationDTO configurationDTO, Client client) async { - print("getSections"); List sections = await client.sectionApi.sectionGetFromConfiguration(configurationDTO.id); - print(sections); sections.sort((a, b) => a.order.compareTo(b.order)); return sections; } diff --git a/lib/Screens/Configurations/new_section_popup.dart b/lib/Screens/Configurations/new_section_popup.dart index 49a3b5a..4b4dcdc 100644 --- a/lib/Screens/Configurations/new_section_popup.dart +++ b/lib/Screens/Configurations/new_section_popup.dart @@ -40,10 +40,6 @@ void showNewSection(String configurationId, AppContext appContext, BuildContext onChanged: (value) { var tempOutput = new List.from(value); sectionDTO.type = SectionType.fromJson(tempOutput[0]); - - print("TYPE CREATE"); - print(value); - print(sectionDTO.type); }, ), ], diff --git a/lib/Screens/Resources/select_resource_modal.dart b/lib/Screens/Resources/select_resource_modal.dart index efcdc1b..3957777 100644 --- a/lib/Screens/Resources/select_resource_modal.dart +++ b/lib/Screens/Resources/select_resource_modal.dart @@ -23,8 +23,6 @@ dynamic showSelectResourceModal (String text, int maxLines, bool onlyImage, Buil child: ResourcesScreen( isAddButton: false, onGetResult: (ResourceDTO resource) { - print("SELECT RESOURCE"); - print(resource); if (resource != null) { var result = resource; Navigator.pop(context, result); diff --git a/lib/Screens/login_screen.dart b/lib/Screens/login_screen.dart index b49da9f..58cc0e5 100644 --- a/lib/Screens/login_screen.dart +++ b/lib/Screens/login_screen.dart @@ -1,4 +1,6 @@ import 'package:flutter/material.dart'; +import 'package:manager_app/Components/loading.dart'; +import 'package:manager_app/Components/message_notification.dart'; import 'package:manager_app/Components/rounded_button.dart'; import 'package:manager_app/Components/rounded_input_field.dart'; import 'package:manager_app/Components/rounded_password_field.dart'; @@ -18,49 +20,72 @@ class LoginScreen extends StatefulWidget { } class _LoginScreenState extends State { - String email = "test@email.be"; - String password = "kljqsdkljqsd"; - final clientAPI = Client(); + String email = "test@email.be"; // DEV + String password = "kljqsdkljqsd"; // DEV + String host = "http://192.168.31.96"; // DEV + Client clientAPI; + bool isLoading = false; void authenticateTRY(dynamic appContext) async { print("try auth.. "); print(this.email); print(this.password); - // if () {} // Add if token exist and not null + not expired + clientAPI = Client(this.host); + var isError = true; - try { - LoginDTO loginDTO = new LoginDTO(email: email, password: password); - TokenDTO token = await clientAPI.authenticationApi.authenticationAuthenticateWithJson(loginDTO); - print("Token ??"); - print(token); - print(token.accessToken); - setAccessToken(token.accessToken); - isError = false; - // Set the appContext - if (appContext.getContext() == null) { - ManagerAppContext managerAppContext = new ManagerAppContext(); - // store user info locally - managerAppContext.email = email; - managerAppContext.token = token; - managerAppContext.clientAPI = clientAPI; - print(managerAppContext); + if (this.email != null && this.password != null && this.host != null) { - appContext.setContext(managerAppContext); + // if () {} // Add if token exist and not null + not expired + try { + setState(() { + isLoading = true; + }); + LoginDTO loginDTO = new LoginDTO(email: email, password: password); + TokenDTO token = await clientAPI.authenticationApi.authenticationAuthenticateWithJson(loginDTO); + print("Token ??"); + print(token); + print(token.accessToken); + setAccessToken(token.accessToken); + + showNotification(Colors.lightGreen, kWhite, 'Connexion réussie', context); + + isError = false; + // Set the appContext + if (appContext.getContext() == null) { + ManagerAppContext managerAppContext = new ManagerAppContext(); + // store user info locally + managerAppContext.email = email; + managerAppContext.token = token; + managerAppContext.clientAPI = clientAPI; + print(managerAppContext); + + appContext.setContext(managerAppContext); + } + + setState(() { + isLoading = false; + }); + + Navigator.pushAndRemoveUntil( + context, + MaterialPageRoute( + builder: (context) { + return MainScreen(); + }, + ), + (Route route) => false // For pushAndRemoveUntil + ); } + catch (e) { + print("error auth"); + print(e); + showNotification(Colors.orange, kWhite, 'Un problème est survenu lors de la connexion', context); - Navigator.pushAndRemoveUntil( - context, - MaterialPageRoute( - builder: (context) { - return MainScreen(); - }, - ), - (Route route) => false // For pushAndRemoveUntil - ); - } - catch (e) { - print("error auth"); + setState(() { + isLoading = false; + }); + } } if (!isError) { @@ -135,7 +160,14 @@ class _LoginScreenState extends State { mainAxisAlignment: MainAxisAlignment.center, children: [ RoundedInputField( - hintText: "Your Email", + hintText: "Host", + onChanged: (value) { + host = value; + }, + icon: Icons.home + ), + RoundedInputField( + hintText: "Email", onChanged: (value) { email = value; }, @@ -147,12 +179,15 @@ class _LoginScreenState extends State { }, ), SizedBox(height: size.height * 0.02), - RoundedButton( + !isLoading ? RoundedButton( text: "LOGIN", fontSize: 25, press: () { authenticateTRY(appContext); }, + ): Container( + height: size.height * 0.1, + child: Loading() ), ], ), @@ -162,4 +197,14 @@ class _LoginScreenState extends State { ), ); } + + isValidApi(Client client) async { + print("TEST URL"); + try { + var configs = await client.configurationApi.configurationGet(); + return configs != null; + } catch (ex) { + return false; + } + } } \ No newline at end of file diff --git a/lib/client.dart b/lib/client.dart index 84b5974..52a6241 100644 --- a/lib/client.dart +++ b/lib/client.dart @@ -23,9 +23,9 @@ class Client { DeviceApi _deviceApi; DeviceApi get deviceApi => _deviceApi; - Client() { + Client(String path) { _apiClient = ApiClient( - basePath: "http://192.168.31.96"); + basePath: path); //basePath: "https://localhost:44339"); _authenticationApi = AuthenticationApi(_apiClient); _userApi = UserApi(_apiClient); diff --git a/lib/main.dart b/lib/main.dart index b6d7c6f..0961131 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -14,7 +14,7 @@ Future main() async { WidgetsFlutterBinding.ensureInitialized(); if (Platform.isWindows) { - setWindowTitle("My Desktop App"); + setWindowTitle("Manager"); setWindowMinSize(Size(1100, 900)); setWindowMaxSize(Size(3840, 2160)); }