Skip to content

Commit

Permalink
Merge pull request #51 from codeforpakistan/submitted-view
Browse files Browse the repository at this point in the history
Admin can modify submitted survey
  • Loading branch information
mubassirhayat authored Mar 4, 2022
2 parents ec7da40 + 0bfa029 commit f998d8d
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 67 deletions.
1 change: 1 addition & 0 deletions lib/src/views/auth/login_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ class _LoginState extends State<Login> {
setState(() {
Constants.prefs.setString('access_token', jsonData['access_token']);
Constants.prefs.setBool("loggedIn", true);
Constants.prefs.setString("userRole", 'Admin');
Navigator.pushReplacementNamed(context, '/home');
});
} else {
Expand Down
30 changes: 28 additions & 2 deletions lib/src/views/indicators/indicator_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,32 @@ class DepartmentList extends StatefulWidget {

class _DepartmentListState extends State<DepartmentList> {
final _scaffoldKey = GlobalKey<ScaffoldState>();
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";
Expand Down Expand Up @@ -168,7 +194,7 @@ class _DepartmentListState extends State<DepartmentList> {
isFromProgressView,
isFromSubmittedView,
submissionNo) async {
if (!isFromSubmittedView) {
if (!isFromSubmittedView || isSupervisor) {
Navigator.pushNamed(context, "/submit-survey", arguments: {
"hospital_id": hospitalId,
"department_id": departmentId,
Expand All @@ -179,7 +205,7 @@ class _DepartmentListState extends State<DepartmentList> {
'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,
Expand Down
130 changes: 70 additions & 60 deletions lib/src/views/survey_submissions/details_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class _ShowSurveyDetailsState extends State<ShowSurveyDetails> {
Widget build(BuildContext context) {
final Map<String, Object> dataFromHospitalScreen =
ModalRoute.of(context).settings.arguments;
var surveyId = dataFromHospitalScreen['survey_id'];
List<dynamic> submissions = dataFromHospitalScreen['submissions'];
var surveyId =
submissions.length > 0 ? submissions[0]['submission_id'] : null;
return Scaffold(
key: _scaffoldKey,
appBar: AppBar(
Expand All @@ -48,75 +50,83 @@ class _ShowSurveyDetailsState extends State<ShowSurveyDetails> {
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<Widget> imageSliders = snapshot.data['images']
.map<Widget>((item) => Container(
margin: EdgeInsets.all(5.0),
child: ClipRRect(
borderRadius:
BorderRadius.all(Radius.circular(5.0)),
child: Stack(
children: <Widget>[
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<Widget> imageSliders = snapshot.data.length > 0 &&
snapshot.data['images'] != null
? snapshot.data['images']
.map<Widget>((item) => Container(
margin: EdgeInsets.all(5.0),
child: ClipRRect(
borderRadius:
BorderRadius.all(Radius.circular(5.0)),
child: Stack(
children: <Widget>[
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,
Expand Down
6 changes: 1 addition & 5 deletions lib/src/views/survey_submissions/survey_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,8 @@ class _MySurveyState extends State<SurveyView> {
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;
Expand Down Expand Up @@ -386,9 +384,7 @@ class _MySurveyState extends State<SurveyView> {
{selectedOption = answer['answer']}
});
}
} catch (e) {
print('getDefaultSelection' + e.toString());
}
} catch (e) {}
return selectedOption;
}

Expand Down

0 comments on commit f998d8d

Please sign in to comment.