Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/filter #680

Open
wants to merge 20 commits into
base: feature/templatestudies
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/lib/screens/app_onboarding/loading_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ class _LoadingScreenState extends State<LoadingScreen> {
}
} catch (exception) {
debugPrint(
"Could not login and retrieve the study subject: $exception",);
"Could not login and retrieve the study subject: $exception",
);
if (exception is SocketException) {
subject = await Cache.loadSubject();
StudyULogger.info("Offline mode with cached subject: $subject");
Expand Down
12 changes: 11 additions & 1 deletion designer_v2/l10n-missing.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"de": [
"action_button_study_publish"
"substudies_not_found",
"study_type_standalone",
"study_type_template",
"study_type_substudy",
"action_button_study_publish",
"form_section_lock_locked",
"form_section_lock_unlocked",
"form_section_publish_lock_locked",
"form_section_publish_lock_unlocked",
"code_list_closed_parent_template_title",
"monitoring_template_title"
]
}
119 changes: 62 additions & 57 deletions designer_v2/lib/common_views/form_table_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,15 @@ class FormLabel extends StatelessWidget {
}

class FormLock extends StatefulWidget {
const FormLock(
{super.key,
required this.locked,
this.onLockChanged,
this.readOnly = false,
this.helpText,
this.lockedStateText,
this.unlockedStateText,});
const FormLock({
super.key,
required this.locked,
this.onLockChanged,
this.readOnly = false,
this.helpText,
this.lockedStateText,
this.unlockedStateText,
});

final bool locked;
final bool readOnly;
Expand All @@ -318,59 +319,63 @@ class _FormLockState extends State<FormLock> {
@override
Widget build(BuildContext context) {
final lockView = Material(
color: Colors.transparent,
child: Row(
children: [
Container(
decoration: BoxDecoration(
color: Colors.grey[100],
borderRadius: BorderRadius.circular(10.0),
border: Border.all(
color: Theme.of(context).disabledColor.withOpacity(0.05),),
color: Colors.transparent,
child: Row(
children: [
Container(
decoration: BoxDecoration(
color: Colors.grey[100],
borderRadius: BorderRadius.circular(10.0),
border: Border.all(
color: Theme.of(context).disabledColor.withOpacity(0.05),
),
),
padding: const EdgeInsets.all(6),
child: Row(
children: [
Text(
widget.locked
? widget.lockedStateText ?? 'Locked'
: widget.unlockedStateText ?? 'Unlocked',
style: Theme.of(context).textTheme.labelMedium,
),
padding: const EdgeInsets.all(6),
child: Row(
children: [
Text(
widget.locked
? widget.lockedStateText ?? 'Locked'
: widget.unlockedStateText ?? 'Unlocked',
style: Theme.of(context).textTheme.labelMedium,),
const SizedBox(width: 4),
AnimatedSwitcher(
duration: const Duration(milliseconds: 250),
child: Icon(
_locked ? MdiIcons.lock : MdiIcons.lockOpen,
color: _locked
? Theme.of(context).primaryColor
: Theme.of(context).disabledColor,
size: 18.0,
),
),
],
),),
SizedBox(
height: 30,
child: FittedBox(
child: Row(
children: [
Switch(
value: _locked,
onChanged: widget.readOnly
? null
: (value) {
setState(() {
_locked = value;
widget.onLockChanged?.call(_locked);
});
},
),
],
const SizedBox(width: 4),
AnimatedSwitcher(
duration: const Duration(milliseconds: 250),
child: Icon(
_locked ? MdiIcons.lock : MdiIcons.lockOpen,
color: _locked
? Theme.of(context).primaryColor
: Theme.of(context).disabledColor,
size: 18.0,
),
),
],
),
),
SizedBox(
height: 30,
child: FittedBox(
child: Row(
children: [
Switch(
value: _locked,
onChanged: widget.readOnly
? null
: (value) {
setState(() {
_locked = value;
widget.onLockChanged?.call(_locked);
});
},
),
],
),
),
],
),);
),
],
),
);

if (widget.helpText != null) {
return Tooltip(
Expand Down
10 changes: 8 additions & 2 deletions designer_v2/lib/features/dashboard/dashboard_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,15 @@ class DashboardController extends _$DashboardController
searchController.setText(text ?? state.query);
}

void setStudiesFilter(StudiesFilter? filter) {
void setStudiesFilter(List<StudiesFilter>? filters) {
state = state.copyWith(
studiesFilter: () => filter ?? DashboardState.defaultFilter,
studiesFilters: () => filters ?? DashboardState.defaultFilter,
);
}

void setColumnFilter(String filter) {
state = state.copyWith(
columnFilter: filter,
);
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 15 additions & 11 deletions designer_v2/lib/features/dashboard/dashboard_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import 'package:studyu_designer_v2/repositories/user_repository.dart';
import 'package:studyu_designer_v2/utils/performance.dart';

class DashboardScreen extends ConsumerStatefulWidget {
const DashboardScreen({required this.filter, super.key});
const DashboardScreen({required this.filters, super.key});

final StudiesFilter? filter;
final List<StudiesFilter>? filters;

@override
ConsumerState<DashboardScreen> createState() => _DashboardScreenState();
Expand All @@ -28,15 +28,15 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
void initState() {
super.initState();
final controller = ref.read(dashboardControllerProvider.notifier);
runAsync(() => controller.setStudiesFilter(widget.filter));
runAsync(() => controller.setStudiesFilter(widget.filters));
}

@override
void didUpdateWidget(DashboardScreen oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.filter != widget.filter) {
if (oldWidget.filters != widget.filters) {
final controller = ref.read(dashboardControllerProvider.notifier);
runAsync(() => controller.setStudiesFilter(widget.filter));
runAsync(() => controller.setStudiesFilter(widget.filters));
}
}

Expand Down Expand Up @@ -145,15 +145,19 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
onExpand: controller.onExpandStudy,
getActions: controller.availableActions,
getSubActions: controller.availableSubActions,
emptyWidget: (widget.filter == null ||
widget.filter == StudiesFilter.owned)
emptyWidget: (widget.filters == null ||
widget.filters == DashboardState.defaultFilter)
? (state.query.isNotEmpty)
? Padding(
padding: const EdgeInsets.only(top: 24.0),
child: EmptyBody(
icon: Icons.content_paste_search_rounded,
title: tr.studies_not_found,
description: tr.modify_query,
child: Column(
children: [
EmptyBody(
icon: Icons.content_paste_search_rounded,
title: tr.studies_not_found,
description: tr.modify_query,
),
],
),
)
: Padding(
Expand Down
35 changes: 26 additions & 9 deletions designer_v2/lib/features/dashboard/dashboard_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import 'package:studyu_designer_v2/localization/app_translation.dart';
import 'package:supabase_flutter/supabase_flutter.dart';

class DashboardState extends Equatable {
static const defaultFilter = StudiesFilter.owned;
static const defaultFilter = [StudiesFilter.owned];

const DashboardState({
this.studies = const AsyncValue.loading(),
this.studiesFilter = defaultFilter,
this.studiesFilters = defaultFilter,
this.columnFilter = '',
this.query = '',
this.sortByColumn = StudiesTableColumn.title,
this.sortAscending = true,
Expand All @@ -27,7 +28,11 @@ class DashboardState extends Equatable {

/// Currently selected filter to be applied to the list of studies
/// in order to determine the [displayedStudies]
final StudiesFilter studiesFilter;
final List<StudiesFilter> studiesFilters;

/// Currently selected column filter to be applied to the list of studies
/// in order to determine the [displayedStudies]
final String columnFilter;

/// Currently selected sort column to be applied to the list of studies
/// in order to determine the [displayedStudies]
Expand Down Expand Up @@ -57,8 +62,14 @@ class DashboardState extends Equatable {
final localPinnedStudies = pinnedStudies ?? this.pinnedStudies;
return studies.when(
data: (studies) {
List<Study> updatedStudies =
studiesFilter.apply(studies: studies, user: currentUser).toList();
//TODO: Filtering right now just only supports AND operation between filters (no OR)
List<Study> updatedStudies = studies.where((study) {
return studiesFilters.every(
(filter) =>
filter.apply(studies: [study], user: currentUser).isNotEmpty,
);
}).toList();

updatedStudies = sort(
pinnedStudies: localPinnedStudies,
studiesToSort: filter(studiesToFilter: updatedStudies),
Expand Down Expand Up @@ -224,7 +235,8 @@ class DashboardState extends Equatable {

DashboardState copyWith({
AsyncValue<List<Study>> Function()? studies,
StudiesFilter Function()? studiesFilter,
List<StudiesFilter> Function()? studiesFilters,
String? columnFilter,
User Function()? currentUser,
String? query,
StudiesTableColumn? sortByColumn,
Expand All @@ -235,8 +247,9 @@ class DashboardState extends Equatable {
}) {
return DashboardState(
studies: studies != null ? studies() : this.studies,
studiesFilter:
studiesFilter != null ? studiesFilter() : this.studiesFilter,
studiesFilters:
studiesFilters != null ? studiesFilters() : this.studiesFilters,
columnFilter: columnFilter ?? this.columnFilter,
currentUser: currentUser != null ? currentUser() : this.currentUser,
query: query ?? this.query,
sortByColumn: sortByColumn ?? this.sortByColumn,
Expand All @@ -250,11 +263,13 @@ class DashboardState extends Equatable {
// - Equatable

@override
List<Object?> get props => [studies, studiesFilter];
List<Object?> get props => [studies, studiesFilters];
}

extension DashboardStateSafeViewProps on DashboardState {
String get visibleListTitle {
final studiesFilter =
studiesFilters.isEmpty ? StudiesFilter.owned : studiesFilters.first;
switch (studiesFilter) {
case StudiesFilter.public:
return tr.navlink_public_studies;
Expand All @@ -264,6 +279,8 @@ extension DashboardStateSafeViewProps on DashboardState {
return tr.navlink_shared_studies;
case StudiesFilter.all:
return "[StudiesFilter.all]"; // not available in UI
default:
return tr.navlink_my_studies; // not available in UI
}
}
}
35 changes: 34 additions & 1 deletion designer_v2/lib/features/dashboard/studies_filter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,20 @@ import 'package:studyu_core/core.dart';
import 'package:studyu_designer_v2/routing/router_utils.dart';
import 'package:supabase_flutter/supabase_flutter.dart';

enum StudiesFilter with GoRouteParamEnum { all, owned, shared, public }
enum StudiesFilter with GoRouteParamEnum {
all,
owned,
shared,
public,
standalone,
template,
substudy,
live,
draft,
closed,
inviteOnly,
everyone
}

extension StudiesFilterByUser on StudiesFilter {
Iterable<Study> apply({
Expand All @@ -21,6 +34,26 @@ extension StudiesFilterByUser on StudiesFilter {
return studies.where(
(s) => s.registryPublished || s.resultSharing == ResultSharing.public,
);
case StudiesFilter.standalone:
return studies.where((s) => s.type == StudyType.standalone).toList();
case StudiesFilter.template:
return studies.where((s) => s.type == StudyType.template).toList();
case StudiesFilter.substudy:
return studies.where((s) => s.type == StudyType.subStudy).toList();
case StudiesFilter.live:
return studies.where((s) => s.status == StudyStatus.running).toList();
case StudiesFilter.draft:
return studies.where((s) => s.status == StudyStatus.draft).toList();
case StudiesFilter.closed:
return studies.where((s) => s.status == StudyStatus.closed).toList();
case StudiesFilter.inviteOnly:
return studies
.where((s) => s.participation == Participation.invite)
.toList();
case StudiesFilter.everyone:
return studies
.where((s) => s.participation == Participation.open)
.toList();
}
}
}
Loading
Loading