Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/staging' into fixes/companySpeak…
Browse files Browse the repository at this point in the history
…erScreen
  • Loading branch information
bvlourenco committed Dec 1, 2022
2 parents d1eb636 + f08323f commit 454c005
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 61 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ docker-compose.yml
deck2.sh

#Frontend macos

/ios/Flutter/Debug.xcconfig
/ios/Flutter/Release.xcconfig
/frontend/ios/Flutter/Debug.xcconfig
/frontend/ios/Flutter/Release.xcconfig
Podfile
2 changes: 1 addition & 1 deletion backend/src/router/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func InitializeRouter() {
memberRouter.HandleFunc("/{id}/participations", authMember(getMembersParticipations)).Methods("GET")
memberRouter.HandleFunc("/{id}", authAdmin(updateMember)).Methods("PUT")
memberRouter.HandleFunc("/{id}", authAdmin(deleteMember)).Methods("DELETE")
memberRouter.HandleFunc("/{id}/image", authMember(setMemberImage)).Methods("POST")
memberRouter.HandleFunc("/{id}/image", authCoordinator(setMemberImage)).Methods("POST")

// item handlers
itemRouter := r.PathPrefix("/items").Subrouter()
Expand Down
157 changes: 99 additions & 58 deletions frontend/lib/routes/member/EditMemberForm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_dropzone/flutter_dropzone.dart';
import 'package:frontend/models/member.dart';
import 'package:frontend/services/authService.dart';
import 'package:frontend/services/memberService.dart';
import 'package:image_picker/image_picker.dart';
import 'package:provider/provider.dart';

class EditMemberForm extends StatefulWidget {
final Member member;
Expand Down Expand Up @@ -49,17 +51,33 @@ class _EditMemberFormState extends State<EditMemberForm> {
const SnackBar(content: Text('Uploading', style: TextStyle(color: Colors.white),)),
);

Member? m = await _memberService.updateMember(
Member me = Provider.of<Member?>(context, listen: false)!;
Member? m;
var role = Provider.of<AuthService>(context, listen: false).role;

if(role==Role.ADMIN || role == Role.COORDINATOR){
m = await _memberService.updateMember(
id: widget.member.id,
name: name,
istid: istId);
}
else{
m = widget.member;
}

if (m != null && _image != null) {
m = kIsWeb
if(me.id == m.id){
m = kIsWeb
? await _memberService.updateMyImageWeb(image: _image!)
: await _memberService.updateMyImage(image: File(_image!.path));
}
else{
m = kIsWeb
? await _memberService.updateImageWeb(
id: m.id, image: _image!)
: await _memberService.updateImage(
id: m.id, image: File(_image!.path));
}
}
if (m != null) {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
Expand All @@ -83,52 +101,67 @@ class _EditMemberFormState extends State<EditMemberForm> {
}

Widget _buildForm() {
return Form(
key: _formKey,
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
controller: _nameController,
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter a name';
}
return null;
},
decoration: const InputDecoration(
icon: const Icon(Icons.person),
labelText: "Name *",
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
controller: _istIdController,
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter ist id';
} else {
return null;
}
},
decoration: const InputDecoration(
icon: const Icon(Icons.school),
labelText: "IstId *",
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
onPressed: () => _submit(),
child: const Text('Submit'),
return FutureBuilder(
future: Provider.of<AuthService>(context).role,
builder:(context, snapshot) {
if(snapshot.hasData){
Role role = snapshot.data as Role;
var adminOrCoord = role==Role.ADMIN || role == Role.COORDINATOR;
return Form(
key: _formKey,
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
readOnly: !adminOrCoord,
controller: _nameController,
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter a name';
}
return null;
},
decoration: InputDecoration(
icon: const Icon(Icons.person),
labelText: "Name *",
border: adminOrCoord ? null : InputBorder.none,
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
readOnly: !adminOrCoord,
controller: _istIdController,
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter ist id';
} else {
return null;
}
},
decoration: InputDecoration(
icon: const Icon(Icons.school),
labelText: "IstId *",
border: adminOrCoord ? null : InputBorder.none,
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
onPressed: () => _submit(),
child: const Text('Submit'),
),
),
],
),
),
],
),
);
}else {
return Container();
}
},
);
}

Expand Down Expand Up @@ -177,7 +210,6 @@ class _EditMemberFormState extends State<EditMemberForm> {
),
]
)

);
}

Expand Down Expand Up @@ -255,27 +287,36 @@ class _EditMemberFormState extends State<EditMemberForm> {

@override
Widget build(BuildContext context) {
bool warning = _image != null && _size != null && _size! > 102400;
bool warning = _image != null && _size != null && _size! > 10485760;
return SingleChildScrollView(
child: LayoutBuilder(
builder: (context, constraints) {
if (constraints.maxWidth < 1000) {
return Column(
children: [_buildPicture(constraints.maxWidth / 3), _buildForm()],
children: [_buildPicture(constraints.maxWidth / 3),
warning
? Text(
'Image selected is too big!',
style: TextStyle(
color: Colors.red,
),
)
: Container(),
_buildForm()],
);
} else {
return Column(
children: [
_buildPicture(constraints.maxWidth / 6),
warning
? Text(
'Image selected is too big!',
style: TextStyle(
color: Colors.red,
),
)
: Container(),
_buildForm()
? Text(
'Image selected is too big!',
style: TextStyle(
color: Colors.red,
),
)
: Container(),
_buildForm()
],
);
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/lib/routes/member/MemberScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import 'package:frontend/components/router.dart';
import 'package:frontend/models/team.dart';

class MemberScreen extends StatefulWidget {
Member member;
late final Member member;

MemberScreen({Key? key, required this.member}) : super(key: key);

Expand Down
51 changes: 51 additions & 0 deletions frontend/lib/services/memberService.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,57 @@ class MemberService extends Service {
}
}

Future<Member?> updateMyImageWeb(
{required XFile image}) async {
Uint8List file = await image.readAsBytes();
FormData formData = FormData.fromMap(
{
'image': MultipartFile.fromBytes(
file,
filename: image.path,
contentType: MediaType('multipart', 'form-data'),
)
},
);
try {
Response<String> response = await dio.post(
'/me/image',
data: formData,
);

return Member.fromJson(json.decode(response.data!));
} on SocketException {
throw DeckException('No Internet connection');
} on HttpException {
throw DeckException('Not found');
} on FormatException {
throw DeckException('Wrong format');
} catch (e) {
if (e is DioError) {
print(e.response);
}
}
}

Future<Member?> updateMyImage(
{required File image}) async {
FormData formData =
FormData.fromMap({'image': await MultipartFile.fromFile(image.path)});

try {
Response<String> response =
await dio.post('/me/image', data: formData);

return Member.fromJson(json.decode(response.data!));
} on SocketException {
throw DeckException('No Internet connection');
} on HttpException {
throw DeckException('Not found');
} on FormatException {
throw DeckException('Wrong format');
}
}

Future<Member?> deleteMember(String id) async {
Response<String> response = await dio.delete("/members/" + id);
try {
Expand Down

0 comments on commit 454c005

Please sign in to comment.