Skip to content

Commit

Permalink
Store progress for downloading survey results [#4799]
Browse files Browse the repository at this point in the history
  • Loading branch information
dobromirdobrev committed Feb 18, 2025
1 parent 876eb80 commit b5357a8
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 5 deletions.
3 changes: 3 additions & 0 deletions assets/strings.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,9 @@
"panel.event2.detail.attendance.prompt.event_capacity_reached.description": "Mark as attended?",
"panel.event2.detail.attendance.prompt.attendee_already_registered.description": "Already marked as attended.",

"panel.event2.detail.admin_settings.header.title": "There is no survey for this event.",
"panel.event2.detail.admin_settings.survey.responses.missing.msg": "There are no survey responses available.",

"panel.event2.detail.button.register.title": "Register",
"panel.event2.detail.button.login.register.title": "Sign In to Register",
"panel.event2.detail.button.unregister.title": "Unregister",
Expand Down
3 changes: 3 additions & 0 deletions assets/strings.es.json
Original file line number Diff line number Diff line change
Expand Up @@ -1642,6 +1642,9 @@
"panel.event2.detail.attendance.prompt.event_capacity_reached.description": "Mark as attended?",
"panel.event2.detail.attendance.prompt.attendee_already_registered.description": "Already marked as attended.",

"panel.event2.detail.admin_settings.header.title": "No hay ninguna encuesta para este evento.",
"panel.event2.detail.admin_settings.survey.responses.missing.msg": "No hay respuestas de encuesta disponibles.",

"panel.event2.detail.button.register.title": "Registrarse",
"panel.event2.detail.button.login.register.title": "Iniciar Sesión para Registrarse",
"panel.event2.detail.button.unregister.title": "Cancelar el Registro",
Expand Down
3 changes: 3 additions & 0 deletions assets/strings.zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -1629,6 +1629,9 @@
"panel.event2.detail.attendance.prompt.event_capacity_reached.description": "Mark as attended?",
"panel.event2.detail.attendance.prompt.attendee_already_registered.description": "Already marked as attended.",

"panel.event2.detail.admin_settings.header.title": "此活動沒有調查。",
"panel.event2.detail.admin_settings.survey.responses.missing.msg": "尚無可用的調查回覆。",

"panel.event2.detail.button.register.title": "注册",
"panel.event2.detail.button.login.register.title": "请登入以注册",
"panel.event2.detail.button.unregister.title": "取消注册",
Expand Down
48 changes: 43 additions & 5 deletions lib/ui/events2/Event2AdminSettingsPanel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ import 'package:illinois/ui/events2/Even2SetupSuperEvent.dart';
import 'package:illinois/ui/events2/Event2SetupNotificationsPanel.dart';
import 'package:illinois/ui/events2/Event2Widgets.dart';
import 'package:illinois/utils/AppUtils.dart';
import 'package:rokwire_plugin/model/auth2.directory.dart';
import 'package:rokwire_plugin/model/event2.dart';
import 'package:rokwire_plugin/model/survey.dart';
import 'package:rokwire_plugin/service/auth2.dart';
import 'package:rokwire_plugin/service/auth2.directory.dart';
import 'package:rokwire_plugin/service/events2.dart';
import 'package:rokwire_plugin/service/localization.dart';
import 'package:rokwire_plugin/service/styles.dart';
import 'package:rokwire_plugin/service/surveys.dart';
import 'package:rokwire_plugin/utils/utils.dart';

import '../../service/Analytics.dart';
Expand All @@ -18,15 +23,17 @@ import 'Event2CreatePanel.dart';

class Event2AdminSettingsPanel extends StatefulWidget{
final Event2? event;
final String? surveyId;

const Event2AdminSettingsPanel({super.key, this.event});
const Event2AdminSettingsPanel({super.key, this.event, this.surveyId});

@override
State<StatefulWidget> createState() => Event2AdminSettingsState();
}

class Event2AdminSettingsState extends State<Event2AdminSettingsPanel>{
bool _duplicating = false;
bool _loadingSurveyResponses = false;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -75,10 +82,11 @@ class Event2AdminSettingsState extends State<Event2AdminSettingsPanel>{
title: 'UPLOAD ATTENDANCE .csv',
onTap: _onUploadAttendance),
),
Visibility(visible: _canUploadCsv,
Visibility(visible: (_canUploadCsv && _hasSurvey),
child: _ButtonWidget(
title: 'DOWNLOAD SURVEY RESULTS',
onTap: _onDownloadSurveyResults),
onTap: _onDownloadSurveyResults,
progress: _loadingSurveyResponses),
)
]),
)
Expand Down Expand Up @@ -124,9 +132,37 @@ class Event2AdminSettingsState extends State<Event2AdminSettingsPanel>{
AppToast.showMessage("TBD");
}

void _onDownloadSurveyResults() {
void _onDownloadSurveyResults() async {
Analytics().logSelect(target: "Download Survey Results");
AppToast.showMessage("TBD");
String? surveyId = widget.surveyId;
if (StringUtils.isEmpty(surveyId)) {
AppAlert.showDialogResult(context,
Localization().getStringEx('panel.event2.detail.admin_settings.survey.missing.msg', 'There is no survey for this event.'));
return;
}
setStateIfMounted(() {
_loadingSurveyResponses = true;
});
List<SurveyResponse>? responses = await Surveys().loadAllSurveyResponses(surveyId!);
if (CollectionUtils.isEmpty(responses)) {
setStateIfMounted(() {
_loadingSurveyResponses = false;
});
AppAlert.showDialogResult(
context,
Localization()
.getStringEx('panel.event2.detail.admin_settings.survey.responses.missing.msg', 'There are no survey responses available.'));
return;
}
List<String>? accountIds = responses!.map((response) => StringUtils.ensureNotEmpty(response.userId)).toList();
List<Auth2PublicAccount>? accounts = await Auth2().loadDirectoryAccounts(ids: accountIds);
if (CollectionUtils.isEmpty(accounts)) {
debugPrint('Download survey responses - failed to load public accounts.');
}
//TBD: DD - continue implementation
setStateIfMounted(() {
_loadingSurveyResponses = false;
});
}

void _onSettingDuplicateEvent() {
Expand Down Expand Up @@ -189,6 +225,8 @@ class Event2AdminSettingsState extends State<Event2AdminSettingsPanel>{
bool get _showSuperEvent => true /*_event?.isSuperEventChild == false*/;

bool get _canUploadCsv => PlatformUtils.isWeb;

bool get _hasSurvey => StringUtils.isNotEmpty(widget.surveyId);
}

class _ButtonWidget extends StatelessWidget{
Expand Down
1 change: 1 addition & 0 deletions lib/ui/events2/Event2DetailPanel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,7 @@ class _Event2DetailPanelState extends Event2Selector2State<Event2DetailPanel> im
if (_event != null) {
Navigator.push(context, CupertinoPageRoute(builder: (context) => Event2AdminSettingsPanel(
event: _event,
surveyId: _survey?.id,
)));
}
}
Expand Down

0 comments on commit b5357a8

Please sign in to comment.