Skip to content

Commit

Permalink
send workspace to review
Browse files Browse the repository at this point in the history
  • Loading branch information
Zulalm committed Dec 16, 2023
1 parent 8cf5a5b commit b8c0f7e
Show file tree
Hide file tree
Showing 5 changed files with 253 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,29 @@ class WorkspaceProvider with ChangeNotifier {
throw Exception("Something has happened");
}
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class MobileWorkspacePage extends StatefulWidget {
final Function sendCollaborationRequest;
final Function finalizeWorkspace;
final Function addSemanticTags;
final Function sendWorkspaceToReview;

const MobileWorkspacePage({
super.key,
Expand All @@ -39,10 +40,11 @@ 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,
});

@override
Expand Down Expand Up @@ -146,67 +148,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 +297,7 @@ class _MobileWorkspacesPageState extends State<MobileWorkspacePage> {
finalizeWorkspace: widget.finalizeWorkspace,
sendCollaborationRequest: widget.sendCollaborationRequest,
updateRequest: widget.updateRequest,

sendWorkspaceToReview: widget.sendWorkspaceToReview,
)
: const SizedBox(
width: 100,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:collaborative_science_platform/screens/workspace_page/mobile_wor
import 'package:collaborative_science_platform/screens/workspace_page/mobile_workspace_page/widget/semantic_tag_card.dart';
import 'package:collaborative_science_platform/screens/workspace_page/mobile_workspace_page/widget/subsection_title.dart';
import 'package:collaborative_science_platform/utils/text_styles.dart';
import 'package:collaborative_science_platform/widgets/app_button.dart';
import 'package:collaborative_science_platform/widgets/app_text_field.dart';
import 'package:collaborative_science_platform/widgets/semantic_search_bar.dart';
import 'package:flutter/material.dart';
Expand All @@ -28,6 +29,7 @@ class MobileWorkspaceContent extends StatefulWidget {
final Function sendCollaborationRequest;
final Function finalizeWorkspace;
final Function addSemanticTags;
final Function sendWorkspaceToReview;

const MobileWorkspaceContent({
super.key,
Expand All @@ -43,7 +45,7 @@ class MobileWorkspaceContent extends StatefulWidget {
required this.finalizeWorkspace,
required this.sendCollaborationRequest,
required this.updateRequest,

required this.sendWorkspaceToReview,
});

@override
Expand Down Expand Up @@ -103,7 +105,11 @@ class _MobileWorkspaceContentState extends State<MobileWorkspaceContent> {

Widget semanticTagList() {
List<SemanticTag> tags = <SemanticTag>[
SemanticTag(id: "1", label: "Looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong Label 1", description: "Looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong Description 1"),
SemanticTag(
id: "1",
label: "Looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong Label 1",
description:
"Looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong Description 1"),
SemanticTag(id: "2", label: "Label 2", description: "Description 2"),
SemanticTag(id: "2", label: "Label 3", description: "Description 3"),
];
Expand All @@ -119,7 +125,7 @@ class _MobileWorkspaceContentState extends State<MobileWorkspaceContent> {
return SemanticTagCard(
tag: tags[index],
backgroundColor: const Color.fromARGB(255, 220, 235, 220),
onDelete: () { /* delete the semantic tag */ },
onDelete: () {/* delete the semantic tag */},
);
},
),
Expand All @@ -137,21 +143,23 @@ class _MobileWorkspaceContentState extends State<MobileWorkspaceContent> {
physics: const NeverScrollableScrollPhysics(),
itemCount: length + 1,
itemBuilder: (context, index) {
return (index < length) ? MobileEntryCard(
entry: widget.workspace.entries[index],
onDelete: () async {
await widget.deleteEntry(
widget.workspace.entries[index].entryId);
},
editEntry: widget.editEntry,
) : NewEntry(
onCreate: widget.createNewEntry,
backgroundColor: const Color.fromARGB(255, 220, 220, 240),
isMobile: true,
);
return (index < length)
? MobileEntryCard(
entry: widget.workspace.entries[index],
onDelete: () async {
await widget.deleteEntry(widget.workspace.entries[index].entryId);
},
editEntry: widget.editEntry,
)
: NewEntry(
onCreate: widget.createNewEntry,
backgroundColor: const Color.fromARGB(255, 220, 220, 240),
isMobile: true,
);
},
),
) : Column(
)
: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expand All @@ -168,8 +176,8 @@ class _MobileWorkspaceContentState extends State<MobileWorkspaceContent> {
backgroundColor: const Color.fromARGB(255, 220, 220, 240),
isMobile: true,
),
],
);
],
);
}

Widget contributorList() {
Expand All @@ -190,18 +198,20 @@ class _MobileWorkspaceContentState extends State<MobileWorkspaceContent> {
physics: const NeverScrollableScrollPhysics(),
itemCount: length + pendingLength + 1,
itemBuilder: (context, index) => (index < length)
? ContributorCard(
contributor: widget.workspace.contributors[index],
pending: false,
)
: (index < length + pendingLength) ? ContributorCard(
contributor: widget.workspace.pendingContributors[index-length],
pending: true,
) : addIcon(() {
showDialog(context: context, builder: (context) => alertDialog);
}),
),
);
? ContributorCard(
contributor: widget.workspace.contributors[index],
pending: false,
)
: (index < length + pendingLength)
? ContributorCard(
contributor: widget.workspace.pendingContributors[index - length],
pending: true,
)
: addIcon(() {
showDialog(context: context, builder: (context) => alertDialog);
}),
),
);
}

Widget referenceList() {
Expand Down Expand Up @@ -259,12 +269,12 @@ class _MobileWorkspaceContentState extends State<MobileWorkspaceContent> {
children: titleReadOnly
? [
SizedBox(
width: Responsive.getGenericPageWidth(context)-100,
width: Responsive.getGenericPageWidth(context) - 150,
child: Text(
widget.workspace.workspaceTitle,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyles.title2,
widget.workspace.workspaceTitle,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyles.title2,
),
),
if (widget.workspace.status == WorkspaceStatus.workable)
Expand All @@ -276,6 +286,84 @@ class _MobileWorkspaceContentState extends State<MobileWorkspaceContent> {
});
},
icon: const Icon(Icons.edit)),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 3.0),
child: IconButton(
icon: widget.pending
? const Icon(Icons.approval)
: (widget.workspace.status == WorkspaceStatus.workable
? const Icon(Icons.lock)
: const Icon(Icons.send)),
onPressed: widget.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: widget.workspace.status == WorkspaceStatus.workable
? "Do you want to finalize the workspace?"
: "Do you want to send it to review?",
actions: [
Padding(
padding: const EdgeInsets.symmetric(vertical: 5),
child: AppButton(
text: "Yes",
height: 40,
onTap: () {
if (widget.workspace.status ==
WorkspaceStatus.workable) {
widget.finalizeWorkspace();
Navigator.of(context).pop();
} else {
/* Send to review */
widget.sendWorkspaceToReview();
Navigator.of(context).pop();
}
},
),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 5),
child: AppButton(
text: "No",
height: 40,
onTap: () {
Navigator.of(context).pop();
},
),
),
],
),
);
},
),
),
]
: [
SizedBox(
Expand All @@ -292,14 +380,14 @@ class _MobileWorkspaceContentState extends State<MobileWorkspaceContent> {
width: 50,
height: 50,
child: IconButton(
onPressed: () {
widget.editTitle(titleController.text);
widget.workspace.workspaceTitle = titleController.text;
setState(() {
titleReadOnly = true;
});
},
icon: const Icon(Icons.save),
onPressed: () {
widget.editTitle(titleController.text);
widget.workspace.workspaceTitle = titleController.text;
setState(() {
titleReadOnly = true;
});
},
icon: const Icon(Icons.save),
),
)
],
Expand Down
Loading

0 comments on commit b8c0f7e

Please sign in to comment.