Skip to content

Commit

Permalink
Merge pull request #644 from bounswe/596-fe-add-review-feature-to-wor…
Browse files Browse the repository at this point in the history
…kspace-page

596 fe add review feature to workspace page
  • Loading branch information
laylaylo authored Dec 19, 2023
2 parents 118dd1f + a6a9aa7 commit b429957
Show file tree
Hide file tree
Showing 8 changed files with 718 additions and 212 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:collaborative_science_platform/models/user.dart';
import 'package:collaborative_science_platform/models/workspaces_page/entry.dart';

enum WorkspaceStatus {finalized, workable, inReview, published, rejected}
enum RequestStatus { approved, rejected, pending }

class Workspace {
int workspaceId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ import 'package:collaborative_science_platform/utils/constants.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

enum UserType { guest, basicUser, contributor, reviewer, admin }

class Auth with ChangeNotifier {
User? user;
BasicUser? basicUser;
//User? user =
// User(email: "[email protected]", firstName: "utkan", lastName: "gezer", token: "token");
UserType userType = UserType.guest;
//User? user = User(email: "[email protected]", firstName: "utkan", lastName: "gezer");



bool get isSignedIn {
return user != null && user!.token.isNotEmpty;
Expand Down Expand Up @@ -116,6 +120,7 @@ class Auth with ChangeNotifier {

void logout() {
user = null;
userType = UserType.guest;
notifyListeners();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,26 @@ class WorkspaceProvider with ChangeNotifier {
}
}

Future<void> updateRequest(int id, String status, String token) async {
Future<void> updateRequest(int id, RequestStatus status, String token) async {
Uri url = Uri.parse("${Constants.apiUrl}/update_req");

String requestStatus = "";
if (status == RequestStatus.approved) {
requestStatus = "A";
} else if (status == RequestStatus.rejected) {
requestStatus = "R";
} else {
requestStatus = "P";
}

var request = http.MultipartRequest('POST', url);
request.headers.addAll({
"Authorization": "Token $token",
"content-type": "application/json",
});
request.fields.addAll({
'id': "$id",
'status': status,
'status': requestStatus,
});

http.StreamedResponse response = await request.send();
Expand All @@ -109,8 +118,16 @@ class WorkspaceProvider with ChangeNotifier {
}
}

Future<void> updateCollaborationRequest(int id, String status, String token) async {
Future<void> updateCollaborationRequest(int id, RequestStatus status, String token) async {
Uri url = Uri.parse("${Constants.apiUrl}/update_collab_req/");
String requestStatus = "";
if (status == RequestStatus.approved) {
requestStatus = "A";
} else if (status == RequestStatus.rejected) {
requestStatus = "R";
} else {
requestStatus = "P";
}

var request = http.MultipartRequest('POST', url);
request.headers.addAll({
Expand All @@ -119,7 +136,7 @@ class WorkspaceProvider with ChangeNotifier {
});
request.fields.addAll({
'id': "$id",
'status': status,
'status': requestStatus,
});

http.StreamedResponse response = await request.send();
Expand Down Expand Up @@ -302,6 +319,30 @@ class WorkspaceProvider with ChangeNotifier {
}
}

Future<void> sendWorkspaceToReview(int workspaceId, int userId, String token) async {
Uri url = Uri.parse("${Constants.apiUrl}/send_rev_req/");

var request = http.MultipartRequest('POST', url);
request.headers.addAll({
"Authorization": "Token $token",
"content-type": "application/json",
});
request.fields.addAll({
'workspace_id': "$workspaceId",
'sender': "$userId",
});

http.StreamedResponse response = await request.send();
if (response.statusCode == 200) {
//print(await response.stream.bytesToString());
notifyListeners();
} else if (response.statusCode == 400) {
throw FinalizeWorkspaceException();
} else {
throw Exception("Something has happened");
}
}

Future<void> deleteReference(int workspaceId, int nodeId, String token) async {
Uri url = Uri.parse("${Constants.apiUrl}/delete_reference/");

Expand Down Expand Up @@ -372,4 +413,38 @@ class WorkspaceProvider with ChangeNotifier {
throw Exception("Something has happened");
}
}

Future<void> addReview(int id, RequestStatus status, String comment, String token) async {
Uri url = Uri.parse("${Constants.apiUrl}/update_review_req/");

String requestStatus = "";
if (status == RequestStatus.approved) {
requestStatus = "A";
} else if (status == RequestStatus.rejected) {
requestStatus = "R";
} else {
requestStatus = "P";
}

var request = http.MultipartRequest('PUT', url);
request.headers.addAll({
"Authorization": "Token $token",
"content-type": "application/json",
});
request.fields.addAll({
'id': "$id",
'status': requestStatus,
'comment': comment,
});

http.StreamedResponse response = await request.send();
if (response.statusCode == 200) {
//print(await response.stream.bytesToString());
notifyListeners();
} else if (response.statusCode == 400) {
throw DeleteEntryException();
} else {
throw Exception("Something has happened");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class MobileWorkspacePage extends StatefulWidget {
final Function sendCollaborationRequest;
final Function finalizeWorkspace;
final Function addSemanticTags;
final Function sendWorkspaceToReview;
final Function addReview;

const MobileWorkspacePage({
super.key,
Expand All @@ -39,10 +41,12 @@ class MobileWorkspacePage extends StatefulWidget {
required this.addReference,
required this.deleteReference,
required this.editTitle,
required this.addSemanticTags,
required this.finalizeWorkspace,
required this.sendCollaborationRequest,
required this.updateRequest
required this.addSemanticTags,
required this.finalizeWorkspace,
required this.sendCollaborationRequest,
required this.updateRequest,
required this.sendWorkspaceToReview,
required this.addReview,
});

@override
Expand Down Expand Up @@ -146,67 +150,6 @@ class _MobileWorkspacesPageState extends State<MobileWorkspacePage> {
],
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 3.0),
child: IconButton(
icon: pending
? const Icon(Icons.keyboard_arrow_right)
: const Icon(Icons.send),
onPressed: pending
? () {
// accept or reject the review
showDialog(
context: context,
builder: (context) => AppAlertDialog(
text: "Do you accept the work?",
actions: [
AppButton(
text: "Accept",
height: 40,
onTap: () {
/* Send to review */
Navigator.of(context).pop();
},
),
AppButton(
text: "Reject",
height: 40,
onTap: () {
Navigator.of(context).pop();
},
),
],
),
);
}
: () {
// send to review
showDialog(
context: context,
builder: (context) => AppAlertDialog(
text: "Do you want to send it to review?",
actions: [
AppButton(
text: "Yes",
height: 40,
onTap: () {
/* Send to review */
Navigator.of(context).pop();
},
),
AppButton(
text: "No",
height: 40,
onTap: () {
Navigator.of(context).pop();
},
),
],
),
);
},
),
),
],
),
),
Expand Down Expand Up @@ -356,7 +299,8 @@ class _MobileWorkspacesPageState extends State<MobileWorkspacePage> {
finalizeWorkspace: widget.finalizeWorkspace,
sendCollaborationRequest: widget.sendCollaborationRequest,
updateRequest: widget.updateRequest,

sendWorkspaceToReview: widget.sendWorkspaceToReview,
addReview: widget.addReview,
)
: const SizedBox(
width: 100,
Expand Down
Loading

0 comments on commit b429957

Please sign in to comment.