Clean code + fix image section bug + change windows title + add host field login (and update client)

This commit is contained in:
Thomas Fransolet 2021-07-28 17:33:41 +02:00
parent 25b3c1546c
commit 3323aae3ed
8 changed files with 86 additions and 52 deletions

View File

@ -49,6 +49,7 @@ void showEditSubSection(SectionDTO subSectionDTO, Function getResult, AppContext
subSectionDTO.imageId = resource.id; subSectionDTO.imageId = resource.id;
subSectionDTO.imageSource = resource.type == ResourceType.imageUrl ? resource.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resource.id; subSectionDTO.imageSource = resource.type == ResourceType.imageUrl ? resource.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resource.id;
}, },
isSmall: true,
), ),
], ],
), ),

View File

@ -29,7 +29,6 @@ class SectionDetailScreen extends StatefulWidget {
} }
class _SectionDetailScreenState extends State<SectionDetailScreen> { class _SectionDetailScreenState extends State<SectionDetailScreen> {
SectionDTO sectionDTO;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -47,7 +46,7 @@ class _SectionDetailScreenState extends State<SectionDetailScreen> {
alignment: AlignmentDirectional.bottomCenter, alignment: AlignmentDirectional.bottomCenter,
child: Container( child: Container(
height: 80, height: 80,
child: getButtons(sectionDTO, appContext), child: getButtons(snapshot.data, appContext),
), ),
) )
], ],
@ -187,7 +186,6 @@ class _SectionDetailScreenState extends State<SectionDetailScreen> {
initialValue: sectionDTO != null ? sectionDTO.imageId : "", initialValue: sectionDTO != null ? sectionDTO.imageId : "",
color: kPrimaryColor, color: kPrimaryColor,
onChanged: (ResourceDTO resource) { onChanged: (ResourceDTO resource) {
print("received value in grant older");
sectionDTO.imageId = resource.id; sectionDTO.imageId = resource.id;
sectionDTO.imageSource = resource.type == ResourceType.imageUrl ? resource.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ 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<SectionDetailScreen> {
textColor: Colors.white, textColor: Colors.white,
fontSize: 15, fontSize: 15,
press: () { press: () {
print(sectionDTO);
delete(sectionDTO, appContext); delete(sectionDTO, appContext);
}, },
), ),
@ -293,9 +292,6 @@ class _SectionDetailScreenState extends State<SectionDetailScreen> {
} }
Future<void> save(bool isTraduction, SectionDTO sectionDTO, AppContext appContext) async { Future<void> save(bool isTraduction, SectionDTO sectionDTO, AppContext appContext) async {
print("SAVE");
print(sectionDTO);
if (sectionDTO != null) { if (sectionDTO != null) {
SectionDTO section = await appContext.getContext().clientAPI.sectionApi.sectionUpdate(sectionDTO); SectionDTO section = await appContext.getContext().clientAPI.sectionApi.sectionUpdate(sectionDTO);
ManagerAppContext managerAppContext = appContext.getContext(); ManagerAppContext managerAppContext = appContext.getContext();

View File

@ -317,9 +317,7 @@ class _ConfigurationDetailScreenState extends State<ConfigurationDetailScreen> {
} }
Future<List<SectionDTO>> getSections(ConfigurationDTO configurationDTO, Client client) async { Future<List<SectionDTO>> getSections(ConfigurationDTO configurationDTO, Client client) async {
print("getSections");
List<SectionDTO> sections = await client.sectionApi.sectionGetFromConfiguration(configurationDTO.id); List<SectionDTO> sections = await client.sectionApi.sectionGetFromConfiguration(configurationDTO.id);
print(sections);
sections.sort((a, b) => a.order.compareTo(b.order)); sections.sort((a, b) => a.order.compareTo(b.order));
return sections; return sections;
} }

View File

@ -40,10 +40,6 @@ void showNewSection(String configurationId, AppContext appContext, BuildContext
onChanged: (value) { onChanged: (value) {
var tempOutput = new List<String>.from(value); var tempOutput = new List<String>.from(value);
sectionDTO.type = SectionType.fromJson(tempOutput[0]); sectionDTO.type = SectionType.fromJson(tempOutput[0]);
print("TYPE CREATE");
print(value);
print(sectionDTO.type);
}, },
), ),
], ],

View File

@ -23,8 +23,6 @@ dynamic showSelectResourceModal (String text, int maxLines, bool onlyImage, Buil
child: ResourcesScreen( child: ResourcesScreen(
isAddButton: false, isAddButton: false,
onGetResult: (ResourceDTO resource) { onGetResult: (ResourceDTO resource) {
print("SELECT RESOURCE");
print(resource);
if (resource != null) { if (resource != null) {
var result = resource; var result = resource;
Navigator.pop(context, result); Navigator.pop(context, result);

View File

@ -1,4 +1,6 @@
import 'package:flutter/material.dart'; 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_button.dart';
import 'package:manager_app/Components/rounded_input_field.dart'; import 'package:manager_app/Components/rounded_input_field.dart';
import 'package:manager_app/Components/rounded_password_field.dart'; import 'package:manager_app/Components/rounded_password_field.dart';
@ -18,49 +20,72 @@ class LoginScreen extends StatefulWidget {
} }
class _LoginScreenState extends State<LoginScreen> { class _LoginScreenState extends State<LoginScreen> {
String email = "test@email.be"; String email = "test@email.be"; // DEV
String password = "kljqsdkljqsd"; String password = "kljqsdkljqsd"; // DEV
final clientAPI = Client(); String host = "http://192.168.31.96"; // DEV
Client clientAPI;
bool isLoading = false;
void authenticateTRY(dynamic appContext) async { void authenticateTRY(dynamic appContext) async {
print("try auth.. "); print("try auth.. ");
print(this.email); print(this.email);
print(this.password); print(this.password);
// if () {} // Add if token exist and not null + not expired clientAPI = Client(this.host);
var isError = true; var isError = true;
try { if (this.email != null && this.password != null && this.host != null) {
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);
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<dynamic> 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( setState(() {
context, isLoading = false;
MaterialPageRoute( });
builder: (context) { }
return MainScreen();
},
),
(Route<dynamic> route) => false // For pushAndRemoveUntil
);
}
catch (e) {
print("error auth");
} }
if (!isError) { if (!isError) {
@ -135,7 +160,14 @@ class _LoginScreenState extends State<LoginScreen> {
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
RoundedInputField( RoundedInputField(
hintText: "Your Email", hintText: "Host",
onChanged: (value) {
host = value;
},
icon: Icons.home
),
RoundedInputField(
hintText: "Email",
onChanged: (value) { onChanged: (value) {
email = value; email = value;
}, },
@ -147,12 +179,15 @@ class _LoginScreenState extends State<LoginScreen> {
}, },
), ),
SizedBox(height: size.height * 0.02), SizedBox(height: size.height * 0.02),
RoundedButton( !isLoading ? RoundedButton(
text: "LOGIN", text: "LOGIN",
fontSize: 25, fontSize: 25,
press: () { press: () {
authenticateTRY(appContext); authenticateTRY(appContext);
}, },
): Container(
height: size.height * 0.1,
child: Loading()
), ),
], ],
), ),
@ -162,4 +197,14 @@ class _LoginScreenState extends State<LoginScreen> {
), ),
); );
} }
isValidApi(Client client) async {
print("TEST URL");
try {
var configs = await client.configurationApi.configurationGet();
return configs != null;
} catch (ex) {
return false;
}
}
} }

View File

@ -23,9 +23,9 @@ class Client {
DeviceApi _deviceApi; DeviceApi _deviceApi;
DeviceApi get deviceApi => _deviceApi; DeviceApi get deviceApi => _deviceApi;
Client() { Client(String path) {
_apiClient = ApiClient( _apiClient = ApiClient(
basePath: "http://192.168.31.96"); basePath: path);
//basePath: "https://localhost:44339"); //basePath: "https://localhost:44339");
_authenticationApi = AuthenticationApi(_apiClient); _authenticationApi = AuthenticationApi(_apiClient);
_userApi = UserApi(_apiClient); _userApi = UserApi(_apiClient);

View File

@ -14,7 +14,7 @@ Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
if (Platform.isWindows) { if (Platform.isWindows) {
setWindowTitle("My Desktop App"); setWindowTitle("Manager");
setWindowMinSize(Size(1100, 900)); setWindowMinSize(Size(1100, 900));
setWindowMaxSize(Size(3840, 2160)); setWindowMaxSize(Size(3840, 2160));
} }