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 6 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
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
6 changes: 6 additions & 0 deletions designer_v2/lib/features/dashboard/dashboard_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ class DashboardController extends _$DashboardController
);
}

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

void setPinnedStudies(Set<String> pinnedStudies) {
state = state.copyWith(pinnedStudies: pinnedStudies);
}
Expand Down
45 changes: 43 additions & 2 deletions designer_v2/lib/features/dashboard/dashboard_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class DashboardState extends Equatable {
const DashboardState({
this.studies = const AsyncValue.loading(),
this.studiesFilter = defaultFilter,
this.columnFilter = '',
this.query = '',
this.sortByColumn = StudiesTableColumn.title,
this.sortAscending = true,
Expand All @@ -29,6 +30,10 @@ class DashboardState extends Equatable {
/// in order to determine the [displayedStudies]
final StudiesFilter studiesFilter;

/// 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]
final StudiesTableColumn sortByColumn;
Expand Down Expand Up @@ -57,8 +62,15 @@ class DashboardState extends Equatable {
final localPinnedStudies = pinnedStudies ?? this.pinnedStudies;
return studies.when(
data: (studies) {
List<Study> updatedStudies =
studiesFilter.apply(studies: studies, user: currentUser).toList();
final List<Study> filteredStudies = [];

columnFilter.split(',').forEach((element) {
filteredStudies.addAll(filterStudyByColumn(studies, element));
});

List<Study> updatedStudies = studiesFilter
.apply(studies: filteredStudies, user: currentUser)
.toList();
updatedStudies = sort(
pinnedStudies: localPinnedStudies,
studiesToSort: filter(studiesToFilter: updatedStudies),
Expand Down Expand Up @@ -89,6 +101,33 @@ class DashboardState extends Equatable {
return result;
}

List<Study> filterStudyByColumn(List<Study> studies, String filter) {
switch (filter) {
case "Standalone":
return studies.where((s) => s.type == StudyType.standalone).toList();
case "Template":
return studies.where((s) => s.type == StudyType.template).toList();
case "Substudy":
return studies.where((s) => s.type == StudyType.subStudy).toList();
case "Live":
return studies.where((s) => s.status == StudyStatus.running).toList();
case "Draft":
return studies.where((s) => s.status == StudyStatus.draft).toList();
case "Closed":
return studies.where((s) => s.status == StudyStatus.closed).toList();
case "Invite-Only":
return studies
.where((s) => s.participation == Participation.invite)
.toList();
case "Everyone":
return studies
.where((s) => s.participation == Participation.open)
.toList();
default:
return studies;
}
}

List<Study> filter({List<Study>? studiesToFilter}) {
studiesToFilter = studiesToFilter ?? studies.value!;
if (query.isEmpty) return studiesToFilter;
Expand Down Expand Up @@ -225,6 +264,7 @@ class DashboardState extends Equatable {
DashboardState copyWith({
AsyncValue<List<Study>> Function()? studies,
StudiesFilter Function()? studiesFilter,
String Function()? columnFilter,
User Function()? currentUser,
String? query,
StudiesTableColumn? sortByColumn,
Expand All @@ -237,6 +277,7 @@ class DashboardState extends Equatable {
studies: studies != null ? studies() : this.studies,
studiesFilter:
studiesFilter != null ? studiesFilter() : this.studiesFilter,
columnFilter: columnFilter != null ? columnFilter() : this.columnFilter,
currentUser: currentUser != null ? currentUser() : this.currentUser,
query: query ?? this.query,
sortByColumn: sortByColumn ?? this.sortByColumn,
Expand Down
Loading
Loading