From 8cf5a5be212298496522d28f56ab3cbbd9f19b48 Mon Sep 17 00:00:00 2001 From: Zulalm Date: Sat, 16 Dec 2023 17:22:58 +0300 Subject: [PATCH 1/3] userType and review workspaces --- .../lib/providers/auth.dart | 4 + .../widgets/workspaces_side_bar.dart | 284 +++++++++++++----- 2 files changed, 219 insertions(+), 69 deletions(-) diff --git a/project/FrontEnd/collaborative_science_platform/lib/providers/auth.dart b/project/FrontEnd/collaborative_science_platform/lib/providers/auth.dart index 75c77ca0..901c64c7 100644 --- a/project/FrontEnd/collaborative_science_platform/lib/providers/auth.dart +++ b/project/FrontEnd/collaborative_science_platform/lib/providers/auth.dart @@ -7,9 +7,12 @@ 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; + UserType userType = UserType.guest; //User? user = User(email: "utkangezer@gmail.com", firstName: "utkan", lastName: "gezer"); bool get isSignedIn { @@ -115,6 +118,7 @@ class Auth with ChangeNotifier { void logout() { user = null; + userType = UserType.guest; notifyListeners(); } } diff --git a/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/web_workspace_page/widgets/workspaces_side_bar.dart b/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/web_workspace_page/widgets/workspaces_side_bar.dart index b3916d5f..7f6d4406 100644 --- a/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/web_workspace_page/widgets/workspaces_side_bar.dart +++ b/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/web_workspace_page/widgets/workspaces_side_bar.dart @@ -1,4 +1,6 @@ import 'package:collaborative_science_platform/models/workspaces_page/workspaces.dart'; +import 'package:collaborative_science_platform/models/workspaces_page/workspaces_object.dart'; +import 'package:collaborative_science_platform/providers/auth.dart'; import 'package:collaborative_science_platform/screens/page_with_appbar/widgets/app_bar_button.dart'; import 'package:collaborative_science_platform/screens/workspace_page/web_workspace_page/widgets/create_workspace_form.dart'; import 'package:collaborative_science_platform/screens/workspace_page/workspaces_page.dart'; @@ -10,6 +12,7 @@ import 'package:collaborative_science_platform/widgets/card_container.dart'; import 'package:flutter/cupertino.dart'; import 'package:go_router/go_router.dart'; import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; class WorkspacesSideBar extends StatefulWidget { final ScrollController controller; @@ -32,9 +35,24 @@ class WorkspacesSideBar extends StatefulWidget { } class _WorkspacesSideBarState extends State { + + Workspaces reviewWorkspaces = Workspaces(workspaces: [ + WorkspacesObject(workspaceId: 5, workspaceTitle: "To be reviewed", pending: false), + WorkspacesObject(workspaceId: 5, workspaceTitle: "To be reviewed1", pending: false), + WorkspacesObject(workspaceId: 5, workspaceTitle: "To be reviewed2", pending: false), + WorkspacesObject(workspaceId: 5, workspaceTitle: "To be reviewed3", pending: false), + WorkspacesObject(workspaceId: 5, workspaceTitle: "To be reviewed", pending: false), + WorkspacesObject(workspaceId: 5, workspaceTitle: "To be reviewed1", pending: false), + WorkspacesObject(workspaceId: 5, workspaceTitle: "To be reviewed2", pending: false), + ], pendingWorkspaces: [ + WorkspacesObject(workspaceId: 5, workspaceTitle: "To be reviewed1", pending: true), + WorkspacesObject(workspaceId: 5, workspaceTitle: "To be reviewed2", pending: true), + ]); + TextEditingController textController = TextEditingController(); @override Widget build(BuildContext context) { + final auth = Provider.of(context); return Container( height: widget.height + 100, width: MediaQuery.of(context).size.width / 4, @@ -71,7 +89,9 @@ class _WorkspacesSideBarState extends State { child: Padding( padding: const EdgeInsets.symmetric(vertical: 15), child: AppButton( - text: (MediaQuery.of(context).size.width < Responsive.desktopPageWidth) ? "New" : "New Workspace", + text: (MediaQuery.of(context).size.width < Responsive.desktopPageWidth) + ? "New" + : "New Workspace", height: 40, onTap: () { showDialog( @@ -106,7 +126,11 @@ class _WorkspacesSideBarState extends State { )), ), SizedBox( - height: (widget.workspaces != null) ? widget.height * 0.9 : 40, + height: (widget.workspaces != null) + ? (auth.userType != UserType.reviewer + ? widget.height * 0.9 + : widget.height * 0.45) + : 40, child: (widget.workspaces != null) ? ListView.builder( scrollDirection: Axis.vertical, @@ -134,78 +158,82 @@ class _WorkspacesSideBarState extends State { return Padding( padding: const EdgeInsets.all(5), child: CardContainer( - onTap: () { - context.push( - "${WorkspacesPage.routeName}/${widget.workspaces!.pendingWorkspaces[index - widget.workspaces!.workspaces.length].workspaceId}"); - }, - child: (MediaQuery.of(context).size.width > Responsive.desktopPageWidth) ? Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - Text( - widget - .workspaces! - .pendingWorkspaces[ - index - widget.workspaces!.workspaces.length] - .workspaceTitle, - style: TextStyles.bodyBold, - maxLines: 1, - overflow: TextOverflow.ellipsis, - textAlign: TextAlign.start, - ), - Column(children: [ - IconButton( - icon: const Icon(CupertinoIcons.check_mark_circled, - color: AppColors.infoColor), - onPressed: () { - // function to accept collaboration request - }, - ), - IconButton( - icon: const Icon( - CupertinoIcons.clear_circled, - color: AppColors.warningColor, - ), - onPressed: () { - // function to reject collaboration request - }, - ), - ]) - ], - ) : Column( - children: [ - Text( - widget - .workspaces! - .pendingWorkspaces[ - index - widget.workspaces!.workspaces.length] - .workspaceTitle, - style: TextStyles.bodyBold, - maxLines: 1, - overflow: TextOverflow.ellipsis, - textAlign: TextAlign.start, - ), - Row( + onTap: () { + context.push( + "${WorkspacesPage.routeName}/${widget.workspaces!.pendingWorkspaces[index - widget.workspaces!.workspaces.length].workspaceId}"); + }, + child: (MediaQuery.of(context).size.width > + Responsive.desktopPageWidth) + ? Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ - IconButton( - icon: const Icon(CupertinoIcons.check_mark_circled, - color: AppColors.infoColor), - onPressed: () { - // function to accept collaboration request - }, + Text( + widget + .workspaces! + .pendingWorkspaces[ + index - widget.workspaces!.workspaces.length] + .workspaceTitle, + style: TextStyles.bodyBold, + maxLines: 1, + overflow: TextOverflow.ellipsis, + textAlign: TextAlign.start, ), - IconButton( - icon: const Icon( - CupertinoIcons.clear_circled, - color: AppColors.warningColor, + Column(children: [ + IconButton( + icon: const Icon(CupertinoIcons.check_mark_circled, + color: AppColors.infoColor), + onPressed: () { + // function to accept collaboration request + }, ), - onPressed: () { - // function to reject collaboration request - }, - ), + IconButton( + icon: const Icon( + CupertinoIcons.clear_circled, + color: AppColors.warningColor, + ), + onPressed: () { + // function to reject collaboration request + }, + ), + ]) ], ) - ], - ), + : Column( + children: [ + Text( + widget + .workspaces! + .pendingWorkspaces[ + index - widget.workspaces!.workspaces.length] + .workspaceTitle, + style: TextStyles.bodyBold, + maxLines: 1, + overflow: TextOverflow.ellipsis, + textAlign: TextAlign.start, + ), + Row( + children: [ + IconButton( + icon: const Icon( + CupertinoIcons.check_mark_circled, + color: AppColors.infoColor), + onPressed: () { + // function to accept collaboration request + }, + ), + IconButton( + icon: const Icon( + CupertinoIcons.clear_circled, + color: AppColors.warningColor, + ), + onPressed: () { + // function to reject collaboration request + }, + ), + ], + ) + ], + ), ), ); } else { @@ -214,6 +242,124 @@ class _WorkspacesSideBarState extends State { }) : const CircularProgressIndicator(), ), + if (auth.userType == UserType.reviewer) + const Padding( + padding: EdgeInsets.symmetric(vertical: 5), + child: Text("Review Workspaces", style: TextStyles.title4secondary), + ), + if (auth.userType == UserType.reviewer) + SizedBox( + height: (reviewWorkspaces != null) ? widget.height * 0.45 : 40, + child: (reviewWorkspaces != null) + ? ListView.builder( + scrollDirection: Axis.vertical, + shrinkWrap: true, + padding: const EdgeInsets.all(8), + itemCount: (reviewWorkspaces.workspaces.length + + reviewWorkspaces.pendingWorkspaces.length), + itemBuilder: (BuildContext context, int index) { + if (index < reviewWorkspaces.workspaces.length) { + return Padding( + padding: const EdgeInsets.all(5), + child: CardContainer( + onTap: () { + context.push( + "${WorkspacesPage.routeName}/${reviewWorkspaces.workspaces[index].workspaceId}"); + }, + child: Text( + reviewWorkspaces.workspaces[index].workspaceTitle, + style: TextStyles.title4, + textAlign: TextAlign.start, + ), + ), + ); + } else if (index >= reviewWorkspaces.workspaces.length) { + return Padding( + padding: const EdgeInsets.all(5), + child: CardContainer( + onTap: () { + context.push( + "${WorkspacesPage.routeName}/${reviewWorkspaces.pendingWorkspaces[index - reviewWorkspaces.workspaces.length].workspaceId}"); + }, + child: (MediaQuery.of(context).size.width > + Responsive.desktopPageWidth) + ? Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + Text( + reviewWorkspaces + .pendingWorkspaces[ + index - reviewWorkspaces.workspaces.length] + .workspaceTitle, + style: TextStyles.bodyBold, + maxLines: 1, + overflow: TextOverflow.ellipsis, + textAlign: TextAlign.start, + ), + Column(children: [ + IconButton( + icon: const Icon( + CupertinoIcons.check_mark_circled, + color: AppColors.infoColor), + onPressed: () { + // function to accept collaboration request + }, + ), + IconButton( + icon: const Icon( + CupertinoIcons.clear_circled, + color: AppColors.warningColor, + ), + onPressed: () { + // function to reject collaboration request + }, + ), + ]) + ], + ) + : Column( + children: [ + Text( + reviewWorkspaces + .pendingWorkspaces[ + index - reviewWorkspaces.workspaces.length] + .workspaceTitle, + style: TextStyles.bodyBold, + maxLines: 1, + overflow: TextOverflow.ellipsis, + textAlign: TextAlign.start, + ), + Row( + children: [ + IconButton( + icon: const Icon( + CupertinoIcons.check_mark_circled, + color: AppColors.infoColor), + onPressed: () { + // function to accept collaboration request + }, + ), + IconButton( + icon: const Icon( + CupertinoIcons.clear_circled, + color: AppColors.warningColor, + ), + onPressed: () { + // function to reject collaboration request + }, + ), + ], + ) + ], + ), + ), + ); + } else { + return const SizedBox(); + } + }) + : const CircularProgressIndicator(), + ) ], ))); } From b8c0f7e673f798d607527c7728fc670574f6ceef Mon Sep 17 00:00:00 2001 From: Zulalm Date: Sat, 16 Dec 2023 19:29:28 +0300 Subject: [PATCH 2/3] send workspace to review --- .../lib/providers/workspace_provider.dart | 23 +++ .../mobile_workspace_page.dart | 73 +------- .../widget/mobile_workspace_content.dart | 174 +++++++++++++----- .../web_workspace_page.dart | 69 +++++-- .../workspace_page/workspaces_page.dart | 38 +++- 5 files changed, 253 insertions(+), 124 deletions(-) diff --git a/project/FrontEnd/collaborative_science_platform/lib/providers/workspace_provider.dart b/project/FrontEnd/collaborative_science_platform/lib/providers/workspace_provider.dart index 0fe0c73c..de85a190 100644 --- a/project/FrontEnd/collaborative_science_platform/lib/providers/workspace_provider.dart +++ b/project/FrontEnd/collaborative_science_platform/lib/providers/workspace_provider.dart @@ -277,6 +277,29 @@ class WorkspaceProvider with ChangeNotifier { throw Exception("Something has happened"); } } + Future 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 deleteReference(int workspaceId, int nodeId, String token) async { Uri url = Uri.parse("${Constants.apiUrl}/delete_reference/"); diff --git a/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/mobile_workspace_page/mobile_workspace_page.dart b/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/mobile_workspace_page/mobile_workspace_page.dart index f50b3cc3..fff0bf49 100644 --- a/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/mobile_workspace_page/mobile_workspace_page.dart +++ b/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/mobile_workspace_page/mobile_workspace_page.dart @@ -27,6 +27,7 @@ class MobileWorkspacePage extends StatefulWidget { final Function sendCollaborationRequest; final Function finalizeWorkspace; final Function addSemanticTags; + final Function sendWorkspaceToReview; const MobileWorkspacePage({ super.key, @@ -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 @@ -146,67 +148,6 @@ class _MobileWorkspacesPageState extends State { ], ), ), - 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(); - }, - ), - ], - ), - ); - }, - ), - ), ], ), ), @@ -356,7 +297,7 @@ class _MobileWorkspacesPageState extends State { finalizeWorkspace: widget.finalizeWorkspace, sendCollaborationRequest: widget.sendCollaborationRequest, updateRequest: widget.updateRequest, - + sendWorkspaceToReview: widget.sendWorkspaceToReview, ) : const SizedBox( width: 100, diff --git a/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/mobile_workspace_page/widget/mobile_workspace_content.dart b/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/mobile_workspace_page/widget/mobile_workspace_content.dart index 13b32173..a2de072f 100644 --- a/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/mobile_workspace_page/widget/mobile_workspace_content.dart +++ b/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/mobile_workspace_page/widget/mobile_workspace_content.dart @@ -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'; @@ -28,6 +29,7 @@ class MobileWorkspaceContent extends StatefulWidget { final Function sendCollaborationRequest; final Function finalizeWorkspace; final Function addSemanticTags; + final Function sendWorkspaceToReview; const MobileWorkspaceContent({ super.key, @@ -43,7 +45,7 @@ class MobileWorkspaceContent extends StatefulWidget { required this.finalizeWorkspace, required this.sendCollaborationRequest, required this.updateRequest, - + required this.sendWorkspaceToReview, }); @override @@ -103,7 +105,11 @@ class _MobileWorkspaceContentState extends State { Widget semanticTagList() { List tags = [ - 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"), ]; @@ -119,7 +125,7 @@ class _MobileWorkspaceContentState extends State { return SemanticTagCard( tag: tags[index], backgroundColor: const Color.fromARGB(255, 220, 235, 220), - onDelete: () { /* delete the semantic tag */ }, + onDelete: () {/* delete the semantic tag */}, ); }, ), @@ -137,21 +143,23 @@ class _MobileWorkspaceContentState extends State { 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: [ @@ -168,8 +176,8 @@ class _MobileWorkspaceContentState extends State { backgroundColor: const Color.fromARGB(255, 220, 220, 240), isMobile: true, ), - ], - ); + ], + ); } Widget contributorList() { @@ -190,18 +198,20 @@ class _MobileWorkspaceContentState extends State { 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() { @@ -259,12 +269,12 @@ class _MobileWorkspaceContentState extends State { 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) @@ -276,6 +286,84 @@ class _MobileWorkspaceContentState extends State { }); }, 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( @@ -292,14 +380,14 @@ class _MobileWorkspaceContentState extends State { 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), ), ) ], diff --git a/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/web_workspace_page/web_workspace_page.dart b/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/web_workspace_page/web_workspace_page.dart index a7e2de36..36e8524a 100644 --- a/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/web_workspace_page/web_workspace_page.dart +++ b/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/web_workspace_page/web_workspace_page.dart @@ -16,7 +16,6 @@ import 'package:collaborative_science_platform/models/semantic_tag.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; - class WebWorkspacePage extends StatefulWidget { final Workspace? workspace; final Workspaces? workspaces; @@ -32,7 +31,7 @@ class WebWorkspacePage extends StatefulWidget { final Function sendCollaborationRequest; final Function finalizeWorkspace; final Function addSemanticTags; - + final Function sendWorkspaceToReview; const WebWorkspacePage({ super.key, @@ -50,6 +49,7 @@ class WebWorkspacePage extends StatefulWidget { required this.finalizeWorkspace, required this.sendCollaborationRequest, required this.updateRequest, + required this.sendWorkspaceToReview, }); @override @@ -231,15 +231,45 @@ class _WebWorkspacePageState extends State { ) ], ), - SizedBox( - width: MediaQuery.of(context).size.width / 5, - child: AppButton( - text: (MediaQuery.of(context).size.width > Responsive.desktopPageWidth) ? "Send Review" : "Send", - height: 45, - onTap: () {}, - type: "primary", + if (widget.workspace!.status == WorkspaceStatus.workable || + widget.workspace!.status == WorkspaceStatus.finalized || + widget.workspace!.status == WorkspaceStatus.inReview) + SizedBox( + width: MediaQuery.of(context).size.width / 5, + child: AppButton( + isActive: widget.workspace!.status == + WorkspaceStatus.workable || + widget.workspace!.status == WorkspaceStatus.finalized, + text: widget.workspace!.status == WorkspaceStatus.workable + ? ((MediaQuery.of(context).size.width > + Responsive.desktopPageWidth) + ? "Finalize Workspace" + : "Finalize") + : widget.workspace!.status == WorkspaceStatus.finalized + ? ((MediaQuery.of(context).size.width > + Responsive.desktopPageWidth) + ? "Send to Review" + : "Send") + : ((MediaQuery.of(context).size.width > + Responsive.desktopPageWidth) + ? "In Review" + : "In Review"), + height: 45, + onTap: () { + /* finalize workspace*/ + if (widget.workspace!.status == + WorkspaceStatus.workable) { + widget.finalizeWorkspace(); + } + /*send workspace to review */ + else if (widget.workspace!.status == + WorkspaceStatus.finalized) { + widget.sendWorkspaceToReview(); + } + }, + type: "primary", + ), ), - ), ], ), ), @@ -260,10 +290,21 @@ class _WebWorkspacePageState extends State { crossAxisAlignment: CrossAxisAlignment.center, children: [ SemanticTagListView( - tags: [ - 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"), + tags: [ + 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"), ], addSemanticTags: widget.addSemanticTags, height: minHeight / 2, diff --git a/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/workspaces_page.dart b/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/workspaces_page.dart index b906625b..4e1c01cf 100644 --- a/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/workspaces_page.dart +++ b/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/workspaces_page.dart @@ -305,6 +305,41 @@ class _WorkspacesPageState extends State { isLoading = true; }); await workspaceProvider.finalizeWorkspace(widget.workspaceId, auth.user!.token); + await workspaceProvider.getWorkspaceById(widget.workspaceId, auth.user!.token); + setState(() { + workspace = (workspaceProvider.workspace ?? {} as Workspace); + }); + } on FinalizeWorkspaceException { + setState(() { + error = true; + errorMessage = FinalizeWorkspaceException().message; + }); + } catch (e) { + setState(() { + error = true; + errorMessage = "Something went wrong!"; + }); + } finally { + setState(() { + isLoading = false; + }); + } + } + + void sendWorkspaceToReview() async { + try { + final auth = Provider.of(context, listen: false); + final workspaceProvider = Provider.of(context, listen: false); + setState(() { + error = false; + isLoading = true; + }); + await workspaceProvider.sendWorkspaceToReview( + widget.workspaceId, auth.basicUser!.basicUserId, auth.user!.token); + await workspaceProvider.getWorkspaceById(widget.workspaceId, auth.user!.token); + setState(() { + workspace = (workspaceProvider.workspace ?? {} as Workspace); + }); } on FinalizeWorkspaceException { setState(() { error = true; @@ -442,7 +477,7 @@ class _WorkspacesPageState extends State { updateRequest: updateCollaborationRequest, sendCollaborationRequest: sendCollaborationRequest, finalizeWorkspace: finalizeWorkspace, - + sendWorkspaceToReview: sendWorkspaceToReview, ), desktop: WebWorkspacePage( isLoading: isLoading, @@ -459,6 +494,7 @@ class _WorkspacesPageState extends State { updateRequest: updateCollaborationRequest, sendCollaborationRequest: sendCollaborationRequest, finalizeWorkspace: finalizeWorkspace, + sendWorkspaceToReview: sendWorkspaceToReview, ), ); } From 3aec3c1d2dc6573ed3d6af2b4841bbd9b6db628a Mon Sep 17 00:00:00 2001 From: Zulalm Date: Sat, 16 Dec 2023 21:01:36 +0300 Subject: [PATCH 3/3] add review button --- .../lib/models/workspaces_page/workspace.dart | 1 + .../lib/providers/workspace_provider.dart | 60 +++- .../mobile_workspace_page.dart | 3 + .../widget/mobile_workspace_content.dart | 279 +++++++++++------- .../web_workspace_page.dart | 73 +++++ .../workspace_page/workspaces_page.dart | 28 +- 6 files changed, 335 insertions(+), 109 deletions(-) diff --git a/project/FrontEnd/collaborative_science_platform/lib/models/workspaces_page/workspace.dart b/project/FrontEnd/collaborative_science_platform/lib/models/workspaces_page/workspace.dart index de970972..94edd9f1 100644 --- a/project/FrontEnd/collaborative_science_platform/lib/models/workspaces_page/workspace.dart +++ b/project/FrontEnd/collaborative_science_platform/lib/models/workspaces_page/workspace.dart @@ -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; diff --git a/project/FrontEnd/collaborative_science_platform/lib/providers/workspace_provider.dart b/project/FrontEnd/collaborative_science_platform/lib/providers/workspace_provider.dart index de85a190..982d4e90 100644 --- a/project/FrontEnd/collaborative_science_platform/lib/providers/workspace_provider.dart +++ b/project/FrontEnd/collaborative_science_platform/lib/providers/workspace_provider.dart @@ -85,9 +85,18 @@ class WorkspaceProvider with ChangeNotifier { } } - Future updateRequest(int id, String status, String token) async { + Future 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", @@ -95,7 +104,7 @@ class WorkspaceProvider with ChangeNotifier { }); request.fields.addAll({ 'id': "$id", - 'status': status, + 'status': requestStatus, }); http.StreamedResponse response = await request.send(); @@ -109,8 +118,16 @@ class WorkspaceProvider with ChangeNotifier { } } - Future updateCollaborationRequest(int id, String status, String token) async { + Future 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({ @@ -119,7 +136,7 @@ class WorkspaceProvider with ChangeNotifier { }); request.fields.addAll({ 'id': "$id", - 'status': status, + 'status': requestStatus, }); http.StreamedResponse response = await request.send(); @@ -277,6 +294,7 @@ class WorkspaceProvider with ChangeNotifier { throw Exception("Something has happened"); } } + Future sendWorkspaceToReview(int workspaceId, int userId, String token) async { Uri url = Uri.parse("${Constants.apiUrl}/send_rev_req/"); @@ -371,4 +389,38 @@ class WorkspaceProvider with ChangeNotifier { throw Exception("Something has happened"); } } + + Future 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"); + } + } } diff --git a/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/mobile_workspace_page/mobile_workspace_page.dart b/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/mobile_workspace_page/mobile_workspace_page.dart index fff0bf49..14110bb5 100644 --- a/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/mobile_workspace_page/mobile_workspace_page.dart +++ b/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/mobile_workspace_page/mobile_workspace_page.dart @@ -28,6 +28,7 @@ class MobileWorkspacePage extends StatefulWidget { final Function finalizeWorkspace; final Function addSemanticTags; final Function sendWorkspaceToReview; + final Function addReview; const MobileWorkspacePage({ super.key, @@ -45,6 +46,7 @@ class MobileWorkspacePage extends StatefulWidget { required this.sendCollaborationRequest, required this.updateRequest, required this.sendWorkspaceToReview, + required this.addReview, }); @override @@ -298,6 +300,7 @@ class _MobileWorkspacesPageState extends State { sendCollaborationRequest: widget.sendCollaborationRequest, updateRequest: widget.updateRequest, sendWorkspaceToReview: widget.sendWorkspaceToReview, + addReview: widget.addReview, ) : const SizedBox( width: 100, diff --git a/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/mobile_workspace_page/widget/mobile_workspace_content.dart b/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/mobile_workspace_page/widget/mobile_workspace_content.dart index a2de072f..8599c576 100644 --- a/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/mobile_workspace_page/widget/mobile_workspace_content.dart +++ b/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/mobile_workspace_page/widget/mobile_workspace_content.dart @@ -30,6 +30,7 @@ class MobileWorkspaceContent extends StatefulWidget { final Function finalizeWorkspace; final Function addSemanticTags; final Function sendWorkspaceToReview; + final Function addReview; const MobileWorkspaceContent({ super.key, @@ -46,6 +47,7 @@ class MobileWorkspaceContent extends StatefulWidget { required this.sendCollaborationRequest, required this.updateRequest, required this.sendWorkspaceToReview, + required this.addReview, }); @override @@ -63,11 +65,15 @@ class _MobileWorkspaceContentState extends State { FocusNode titleFocusNode = FocusNode(); bool newEntryOpen = false; + FocusNode reviewFocusNode = FocusNode(); + TextEditingController reviewController = TextEditingController(); @override void dispose() { titleController.dispose(); titleFocusNode.dispose(); + reviewController.dispose(); + reviewFocusNode.dispose(); super.dispose(); } @@ -263,7 +269,8 @@ class _MobileWorkspaceContentState extends State { children: [ Padding( padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0), - child: Row( + child: Column(children: [ + Row( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: titleReadOnly @@ -286,112 +293,176 @@ class _MobileWorkspaceContentState extends State { }); }, 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( + width: 300, + height: 80, + child: AppTextField( + controller: titleController, + focusNode: titleFocusNode, + hintText: "", + obscureText: false, + height: 200), ), - ), - ] - : [ - SizedBox( - width: 300, - height: 80, - child: AppTextField( - controller: titleController, - focusNode: titleFocusNode, - hintText: "", + SizedBox( + width: 50, + height: 50, + child: IconButton( + onPressed: () { + widget.editTitle(titleController.text); + widget.workspace.workspaceTitle = titleController.text; + setState(() { + titleReadOnly = true; + }); + }, + icon: const Icon(Icons.save), + ), + ) + ], + ), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 5.0, vertical: 4.0), + child: AppButton( + height: 40, + text: widget.pending + ? "Accept Workspace" + : (widget.workspace.status == WorkspaceStatus.workable + ? "Finalize Workspace" + : "Send to Review"), + icon: widget.pending + ? const Icon(Icons.approval) + : (widget.workspace.status == WorkspaceStatus.workable + ? const Icon(Icons.lock) + : const Icon(Icons.send)), + onTap: 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(); + }, + ), + ), + ], + ), + ); + }, + ), + + ), + if (true) + /** adjust it to check if the user is reviewer of this workspace */ + Padding( + padding: const EdgeInsets.symmetric(horizontal: 5.0, vertical: 4.0), + child: AppButton( + isActive: widget.workspace!.status == WorkspaceStatus.workable || + widget.workspace!.status == WorkspaceStatus.finalized, + text: "Review Workspace", + height: 40, + onTap: () { + showDialog( + context: context, + builder: (context) => AppAlertDialog( + text: "Review Workspace", + content: AppTextField( + controller: reviewController, + focusNode: reviewFocusNode, + hintText: "Your Review", obscureText: false, - height: 200), - ), - SizedBox( - width: 50, - height: 50, - child: IconButton( - onPressed: () { - widget.editTitle(titleController.text); - widget.workspace.workspaceTitle = titleController.text; - setState(() { - titleReadOnly = true; - }); - }, - icon: const Icon(Icons.save), + height: 200, + maxLines: 10, + ), + actions: [ + Padding( + padding: const EdgeInsets.symmetric(vertical: 5), + child: AppButton( + text: "Approve Workspace", + height: 40, + onTap: () { + /** Approve workspace*/ + widget.addReview(widget.workspace!.workspaceId, + RequestStatus.approved, reviewController.text); + Navigator.of(context).pop(); + }, + ), + ), + Padding( + padding: const EdgeInsets.symmetric(vertical: 5), + child: AppButton( + text: "Reject Workspace", + height: 40, + type: "outlined", + onTap: () { + /** Reject workspace*/ + widget.addReview(widget.workspace!.workspaceId, + RequestStatus.rejected, reviewController.text); + Navigator.of(context).pop(); + }, + ), + ), + ], ), - ) - ], - ), + ); + }, + type: "primary", + ), + ), + ]), ), const Padding( padding: EdgeInsets.symmetric(horizontal: 12.0), diff --git a/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/web_workspace_page/web_workspace_page.dart b/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/web_workspace_page/web_workspace_page.dart index 36e8524a..c355919a 100644 --- a/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/web_workspace_page/web_workspace_page.dart +++ b/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/web_workspace_page/web_workspace_page.dart @@ -3,6 +3,7 @@ import 'package:collaborative_science_platform/models/workspaces_page/workspaces import 'package:collaborative_science_platform/screens/home_page/widgets/home_page_appbar.dart'; import 'package:collaborative_science_platform/screens/page_with_appbar/page_with_appbar.dart'; import 'package:collaborative_science_platform/screens/page_with_appbar/widgets/app_bar_button.dart'; +import 'package:collaborative_science_platform/screens/workspace_page/mobile_workspace_page/widget/app_alert_dialog.dart'; import 'package:collaborative_science_platform/screens/workspace_page/web_workspace_page/widgets/contributors_list_view.dart'; import 'package:collaborative_science_platform/screens/workspace_page/web_workspace_page/widgets/entries_list_view.dart'; import 'package:collaborative_science_platform/screens/workspace_page/web_workspace_page/widgets/references_list_view.dart'; @@ -32,6 +33,7 @@ class WebWorkspacePage extends StatefulWidget { final Function finalizeWorkspace; final Function addSemanticTags; final Function sendWorkspaceToReview; + final Function addReview; const WebWorkspacePage({ super.key, @@ -50,6 +52,7 @@ class WebWorkspacePage extends StatefulWidget { required this.sendCollaborationRequest, required this.updateRequest, required this.sendWorkspaceToReview, + required this.addReview, }); @override @@ -72,7 +75,10 @@ class _WebWorkspacePageState extends State { bool titleReadOnly = true; TextEditingController titleController = TextEditingController(); + TextEditingController reviewController = TextEditingController(); + FocusNode titleFocusNode = FocusNode(); + FocusNode reviewFocusNode = FocusNode(); @override void dispose() { @@ -82,6 +88,8 @@ class _WebWorkspacePageState extends State { controller4.dispose(); titleController.dispose(); titleFocusNode.dispose(); + reviewController.dispose(); + reviewFocusNode.dispose(); super.dispose(); } @@ -270,6 +278,71 @@ class _WebWorkspacePageState extends State { type: "primary", ), ), + if (true) + /** adjust it to check if the user is reviewer of this workspace */ + SizedBox( + width: MediaQuery.of(context).size.width / 5, + child: AppButton( + isActive: widget.workspace!.status == + WorkspaceStatus.workable || + widget.workspace!.status == WorkspaceStatus.finalized, + text: (MediaQuery.of(context).size.width > + Responsive.desktopPageWidth) + ? "Review Workspace" + : "Review", + height: 45, + onTap: () { + showDialog( + context: context, + builder: (context) => AppAlertDialog( + text: "Review Workspace", + content: AppTextField( + controller: reviewController, + focusNode: reviewFocusNode, + hintText: "Your Review", + obscureText: false, + height: 200, + maxLines: 10, + ), + actions: [ + Padding( + padding: const EdgeInsets.symmetric(vertical: 5), + child: AppButton( + text: "Approve Workspace", + height: 40, + onTap: () { + /** Approve workspace*/ + widget.addReview( + widget.workspace!.workspaceId, + RequestStatus.approved, + reviewController.text); + Navigator.of(context).pop(); + }, + ), + ), + Padding( + padding: const EdgeInsets.symmetric(vertical: 5), + child: AppButton( + text: "Reject Workspace", + height: 40, + type: "outlined", + onTap: () { + /** Reject workspace*/ + widget.addReview( + widget.workspace!.workspaceId, + RequestStatus.rejected, + reviewController.text); + Navigator.of(context).pop(); + }, + ), + ), + ], + ), + ); + }, + type: "primary", + ), + ), ], ), ), diff --git a/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/workspaces_page.dart b/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/workspaces_page.dart index 4e1c01cf..722a3055 100644 --- a/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/workspaces_page.dart +++ b/project/FrontEnd/collaborative_science_platform/lib/screens/workspace_page/workspaces_page.dart @@ -389,7 +389,7 @@ class _WorkspacesPageState extends State { } } - void updateCollaborationRequest(int id, String status) async { + void updateCollaborationRequest(int id, RequestStatus status) async { try { final auth = Provider.of(context, listen: false); final workspaceProvider = Provider.of(context, listen: false); @@ -447,6 +447,30 @@ class _WorkspacesPageState extends State { } } + +void addReview(int id, RequestStatus status, String comment) async { + try { + final auth = Provider.of(context, listen: false); + final workspaceProvider = Provider.of(context, listen: false); + setState(() { + error = false; + }); + await workspaceProvider.addReview(id, status, comment, auth.user!.token); + await workspaceProvider.getWorkspaceById(widget.workspaceId, auth.user!.token); + setState(() { + workspace = (workspaceProvider.workspace ?? {} as Workspace); + }); + } catch (e) { + setState(() { + error = true; + errorMessage = "Something went wrong!"; + }); + } finally { + setState(() { + isLoading = false; + }); + } + } @override void didChangeDependencies() { if (_isFirstTime) { @@ -478,6 +502,7 @@ class _WorkspacesPageState extends State { sendCollaborationRequest: sendCollaborationRequest, finalizeWorkspace: finalizeWorkspace, sendWorkspaceToReview: sendWorkspaceToReview, + addReview: addReview, ), desktop: WebWorkspacePage( isLoading: isLoading, @@ -495,6 +520,7 @@ class _WorkspacesPageState extends State { sendCollaborationRequest: sendCollaborationRequest, finalizeWorkspace: finalizeWorkspace, sendWorkspaceToReview: sendWorkspaceToReview, + addReview: addReview, ), ); }