Clean code + fix image section bug + change windows title + add host field login (and update client)
This commit is contained in:
parent
25b3c1546c
commit
3323aae3ed
@ -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,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@ -29,7 +29,6 @@ class SectionDetailScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _SectionDetailScreenState extends State<SectionDetailScreen> {
|
||||
SectionDTO sectionDTO;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -47,7 +46,7 @@ class _SectionDetailScreenState extends State<SectionDetailScreen> {
|
||||
alignment: AlignmentDirectional.bottomCenter,
|
||||
child: Container(
|
||||
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 : "",
|
||||
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<SectionDetailScreen> {
|
||||
textColor: Colors.white,
|
||||
fontSize: 15,
|
||||
press: () {
|
||||
print(sectionDTO);
|
||||
delete(sectionDTO, appContext);
|
||||
},
|
||||
),
|
||||
@ -293,9 +292,6 @@ class _SectionDetailScreenState extends State<SectionDetailScreen> {
|
||||
}
|
||||
|
||||
Future<void> 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();
|
||||
|
||||
@ -317,9 +317,7 @@ class _ConfigurationDetailScreenState extends State<ConfigurationDetailScreen> {
|
||||
}
|
||||
|
||||
Future<List<SectionDTO>> getSections(ConfigurationDTO configurationDTO, Client client) async {
|
||||
print("getSections");
|
||||
List<SectionDTO> sections = await client.sectionApi.sectionGetFromConfiguration(configurationDTO.id);
|
||||
print(sections);
|
||||
sections.sort((a, b) => a.order.compareTo(b.order));
|
||||
return sections;
|
||||
}
|
||||
|
||||
@ -40,10 +40,6 @@ void showNewSection(String configurationId, AppContext appContext, BuildContext
|
||||
onChanged: (value) {
|
||||
var tempOutput = new List<String>.from(value);
|
||||
sectionDTO.type = SectionType.fromJson(tempOutput[0]);
|
||||
|
||||
print("TYPE CREATE");
|
||||
print(value);
|
||||
print(sectionDTO.type);
|
||||
},
|
||||
),
|
||||
],
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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<LoginScreen> {
|
||||
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<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(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) {
|
||||
return MainScreen();
|
||||
},
|
||||
),
|
||||
(Route<dynamic> route) => false // For pushAndRemoveUntil
|
||||
);
|
||||
}
|
||||
catch (e) {
|
||||
print("error auth");
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (!isError) {
|
||||
@ -135,7 +160,14 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
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<LoginScreen> {
|
||||
},
|
||||
),
|
||||
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<LoginScreen> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
isValidApi(Client client) async {
|
||||
print("TEST URL");
|
||||
try {
|
||||
var configs = await client.configurationApi.configurationGet();
|
||||
return configs != null;
|
||||
} catch (ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
|
||||
@ -14,7 +14,7 @@ Future<void> main() async {
|
||||
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
if (Platform.isWindows) {
|
||||
setWindowTitle("My Desktop App");
|
||||
setWindowTitle("Manager");
|
||||
setWindowMinSize(Size(1100, 900));
|
||||
setWindowMaxSize(Size(3840, 2160));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user