diff --git a/lib/src/views/auth/login_view.dart b/lib/src/views/auth/login_view.dart index 53a172c..8f18e42 100644 --- a/lib/src/views/auth/login_view.dart +++ b/lib/src/views/auth/login_view.dart @@ -207,6 +207,7 @@ class _LoginState extends State { setState(() { Constants.prefs.setString('access_token', jsonData['access_token']); Constants.prefs.setBool("loggedIn", true); + Constants.prefs.setString("userRole", 'Admin'); Navigator.pushReplacementNamed(context, '/home'); }); } else { diff --git a/lib/src/views/indicators/indicator_view.dart b/lib/src/views/indicators/indicator_view.dart index 30ca725..23326b3 100644 --- a/lib/src/views/indicators/indicator_view.dart +++ b/lib/src/views/indicators/indicator_view.dart @@ -10,6 +10,32 @@ class DepartmentList extends StatefulWidget { class _DepartmentListState extends State { final _scaffoldKey = GlobalKey(); + bool isSupervisor = false; + + @override + void initState() { + super.initState(); + WidgetsBinding.instance.addPostFrameCallback((_) async { + getUserRule(); + }); + } + + Future getUserRule() async { + var url = Constants.BASE_URL + "users/me"; + var accessToken = Constants.prefs.getString('access_token'); + var response = await http.get( + url, + headers: { + 'Content-Type': 'application/json', + 'Accept': 'application/json', + 'Authorization': 'Bearer $accessToken', + }, + ); + var data = json.decode(utf8.decode(response.bodyBytes)); + setState(() { + isSupervisor = data['is_superuser']; + }); + } Future getDepartmentData(indicators) async { var url = Constants.BASE_URL + "departments/questions_length"; @@ -168,7 +194,7 @@ class _DepartmentListState extends State { isFromProgressView, isFromSubmittedView, submissionNo) async { - if (!isFromSubmittedView) { + if (!isFromSubmittedView || isSupervisor) { Navigator.pushNamed(context, "/submit-survey", arguments: { "hospital_id": hospitalId, "department_id": departmentId, @@ -179,7 +205,7 @@ class _DepartmentListState extends State { 'submissions': submissions }); } else if (isFromSubmittedView) { - Navigator.pushNamed(context, "/submitted-survey-list", arguments: { + Navigator.pushNamed(context, "/show-survey-details", arguments: { 'hospitalName': hospitalName, 'hospitalId': hospitalId, 'departmentId': departmentId, diff --git a/lib/src/views/survey_submissions/details_view.dart b/lib/src/views/survey_submissions/details_view.dart index 5fe274b..2ed50eb 100644 --- a/lib/src/views/survey_submissions/details_view.dart +++ b/lib/src/views/survey_submissions/details_view.dart @@ -33,7 +33,9 @@ class _ShowSurveyDetailsState extends State { Widget build(BuildContext context) { final Map dataFromHospitalScreen = ModalRoute.of(context).settings.arguments; - var surveyId = dataFromHospitalScreen['survey_id']; + List submissions = dataFromHospitalScreen['submissions']; + var surveyId = + submissions.length > 0 ? submissions[0]['submission_id'] : null; return Scaffold( key: _scaffoldKey, appBar: AppBar( @@ -48,75 +50,83 @@ class _ShowSurveyDetailsState extends State { switch (snapshot.connectionState) { case ConnectionState.none: return Center(child: Text("Getting the survey details")); - break; case ConnectionState.done: if (snapshot.hasError) { return Center( child: Text( "Some unknown error has occurred, please contact your system administrator")); } - final List imageSliders = snapshot.data['images'] - .map((item) => Container( - margin: EdgeInsets.all(5.0), - child: ClipRRect( - borderRadius: - BorderRadius.all(Radius.circular(5.0)), - child: Stack( - children: [ - InkResponse( - child: Image.network( - Constants.BASE_URL + - "utils/image/" + - item, - fit: BoxFit.cover, - width: 1000.0), - onTap: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (_) { - return ImageView( - tag: item, - images: snapshot - .data['images']); - }, - settings: RouteSettings( - name: 'ImageView'))); - }), - Positioned( - bottom: 0.0, - left: 0.0, - right: 0.0, - child: Container( - decoration: BoxDecoration( - gradient: LinearGradient( - colors: [ - Color.fromARGB(200, 0, 0, 0), - Color.fromARGB(0, 0, 0, 0) - ], - begin: Alignment.bottomCenter, - end: Alignment.topCenter, - ), - ), - padding: EdgeInsets.symmetric( - vertical: 10.0, horizontal: 20.0), - child: Text( - '${snapshot.data['images'].indexOf(item) + 1}', - style: TextStyle( - color: Colors.white, - fontSize: 20.0, - fontWeight: FontWeight.bold, + if (!snapshot.hasData || + snapshot.data == null || + (snapshot.data != null && snapshot.data.length == 0)) { + return Center(child: Text("No Submission Found")); + } + final List imageSliders = snapshot.data.length > 0 && + snapshot.data['images'] != null + ? snapshot.data['images'] + .map((item) => Container( + margin: EdgeInsets.all(5.0), + child: ClipRRect( + borderRadius: + BorderRadius.all(Radius.circular(5.0)), + child: Stack( + children: [ + InkResponse( + child: Image.network( + Constants.BASE_URL + + "utils/image/" + + item, + fit: BoxFit.cover, + width: 1000.0), + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (_) { + return ImageView( + tag: item, + images: snapshot + .data['images']); + }, + settings: RouteSettings( + name: 'ImageView'))); + }), + Positioned( + bottom: 0.0, + left: 0.0, + right: 0.0, + child: Container( + decoration: BoxDecoration( + gradient: LinearGradient( + colors: [ + Color.fromARGB(200, 0, 0, 0), + Color.fromARGB(0, 0, 0, 0) + ], + begin: Alignment.bottomCenter, + end: Alignment.topCenter, + ), + ), + padding: EdgeInsets.symmetric( + vertical: 10.0, horizontal: 20.0), + child: Text( + '${snapshot.data['images'].indexOf(item) + 1}', + style: TextStyle( + color: Colors.white, + fontSize: 20.0, + fontWeight: FontWeight.bold, + ), + ), ), ), - ), - ), - ], - )), - )) - .toList(); + ], + )), + )) + .toList() + : []; return Column( children: [ - snapshot.data['images'].length > 0 + snapshot.data['images'] != null && + snapshot.data['images'].length > 0 ? CarouselSlider( options: CarouselOptions( aspectRatio: 3.0, diff --git a/lib/src/views/survey_submissions/survey_view.dart b/lib/src/views/survey_submissions/survey_view.dart index c470009..1648559 100644 --- a/lib/src/views/survey_submissions/survey_view.dart +++ b/lib/src/views/survey_submissions/survey_view.dart @@ -297,10 +297,8 @@ class _MySurveyState extends State { if (response.statusCode == 200) { Toast.show("Survey submitted!", this.context, duration: Toast.LENGTH_LONG, gravity: Toast.BOTTOM); - // var jsonData = json.decode(response.body); setState(() { Navigator.of(this.context).pushReplacementNamed('/home'); - // Navigator.pushReplacementNamed(this.context, '/home'); }); } else { this.processing = false; @@ -386,9 +384,7 @@ class _MySurveyState extends State { {selectedOption = answer['answer']} }); } - } catch (e) { - print('getDefaultSelection' + e.toString()); - } + } catch (e) {} return selectedOption; }