Skip to content

Commit

Permalink
Merge pull request #457 from hpi-studyu/issue/432-feature-designer-da…
Browse files Browse the repository at this point in the history
…shboard-improvements

feat: Designer Dashboard Improvements
  • Loading branch information
johannesvedder committed Aug 16, 2023
2 parents 3f9f4a9 + 35f74ea commit c57401b
Show file tree
Hide file tree
Showing 83 changed files with 39,332 additions and 37,141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,13 @@ class AverageSectionWidget extends ReportSectionWidget {
showTitles: true,
getTitlesWidget: getTitles,
)),
// ignore: prefer_const_constructors
topTitles: AxisTitles(
// ignore: prefer_const_constructors
sideTitles: SideTitles(
showTitles: false,
))),
// ignore: prefer_const_constructors
gridData: charts.FlGridData(
drawHorizontalLine: false,
drawVerticalLine: false,
Expand Down
8 changes: 0 additions & 8 deletions app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.10.2"
freezed_annotation:
dependency: transitive
description:
name: freezed_annotation
sha256: "70776c4541e5cacfe45bcaf00fe79137b8c61aa34fb5765a05ce6c57fd72c6e9"
url: "https://pub.dev"
source: hosted
version: "0.14.3"
functions_client:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions core/lib/src/models/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export 'tables/study.dart';
export 'tables/study_invite.dart';
export 'tables/study_subject.dart';
export 'tables/subject_progress.dart';
export 'tables/user.dart';
export 'tasks/tasks.dart';
4 changes: 2 additions & 2 deletions core/lib/src/models/tables/repo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class Repo extends SupabaseObjectFunctions<Repo> {
String studyId;
GitProvider provider;
@JsonKey(name: 'web_url')
String webUrl;
String? webUrl;
@JsonKey(name: 'git_url')
String gitUrl;
String? gitUrl;

Repo(this.projectId, this.userId, this.studyId, this.provider, this.webUrl, this.gitUrl);

Expand Down
30 changes: 20 additions & 10 deletions core/lib/src/models/tables/repo.g.dart

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

17 changes: 16 additions & 1 deletion core/lib/src/models/tables/study.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ enum ResultSharing {
}

@JsonSerializable()
class Study extends SupabaseObjectFunctions<Study> {
class Study extends SupabaseObjectFunctions<Study> implements Comparable<Study> {
static const String tableName = 'study';

@override
Expand Down Expand Up @@ -99,45 +99,55 @@ class Study extends SupabaseObjectFunctions<Study> {

factory Study.fromJson(Map<String, dynamic> json) {
final study = _$StudyFromJson(json);

final List? repo = json['repo'] as List?;
if (repo != null && repo.isNotEmpty) {
study.repo = Repo.fromJson((json['repo'] as List)[0] as Map<String, dynamic>);
}

final List? invites = json['study_invite'] as List?;
if (invites != null) {
study.invites = invites.map((json) => StudyInvite.fromJson(json as Map<String, dynamic>)).toList();
}

final List? participants = json['study_subject'] as List?;
if (participants != null) {
study.participants = participants.map((json) => StudySubject.fromJson(json as Map<String, dynamic>)).toList();
}

List? participantsProgress = json['study_progress'] as List?;
participantsProgress = json['study_progress_export'] as List?;
participantsProgress ??= json['subject_progress'] as List?;
if (participantsProgress != null) {
study.participantsProgress =
participantsProgress.map((json) => SubjectProgress.fromJson(json as Map<String, dynamic>)).toList();
}

final int? participantCount = json['study_participant_count'] as int?;
if (participantCount != null) {
study.participantCount = participantCount;
}

final int? endedCount = json['study_ended_count'] as int?;
if (endedCount != null) {
study.endedCount = endedCount;
}

final int? activeSubjectCount = json['active_subject_count'] as int?;
if (activeSubjectCount != null) {
study.activeSubjectCount = activeSubjectCount;
}

final List? missedDays = json['study_missed_days'] as List?;
if (missedDays != null) {
study.missedDays = List<int>.from(json['study_missed_days'] as List);
}

final String? createdAt = json['created_at'] as String?;
if (createdAt != null && createdAt.isNotEmpty) {
study.createdAt = DateTime.parse(createdAt);
}

return study;
}

Expand Down Expand Up @@ -236,4 +246,9 @@ class Study extends SupabaseObjectFunctions<Study> {
String toString() {
return 'Study{id: $id, title: $title, description: $description, userId: $userId, participation: $participation, resultSharing: $resultSharing, contact: $contact, iconName: $iconName, published: $published, questionnaire: $questionnaire, eligibilityCriteria: $eligibilityCriteria, consent: $consent, interventions: $interventions, observations: $observations, schedule: $schedule, reportSpecification: $reportSpecification, results: $results, collaboratorEmails: $collaboratorEmails, registryPublished: $registryPublished, participantCount: $participantCount, endedCount: $endedCount, activeSubjectCount: $activeSubjectCount, missedDays: $missedDays, repo: $repo, invites: $invites, participants: $participants, participantsProgress: $participantsProgress, createdAt: $createdAt}';
}

@override
int compareTo(Study other) {
return id.compareTo(other.id);
}
}
51 changes: 51 additions & 0 deletions core/lib/src/models/tables/user.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import 'package:json_annotation/json_annotation.dart';

import 'package:studyu_core/core.dart';

part 'user.g.dart';

@JsonSerializable()
class StudyUUser extends SupabaseObjectFunctions<StudyUUser> {
static const String tableName = 'user';

@override
Map<String, dynamic> get primaryKeys => {'id': id};

@JsonKey(name: 'id')
String id;
@JsonKey(name: 'email')
String email;
@JsonKey(name: 'preferences')
Preferences preferences;

StudyUUser({required this.id, required this.email, Preferences? preferences})
: preferences = preferences ?? Preferences();

factory StudyUUser.fromJson(Map<String, dynamic> json) => _$StudyUUserFromJson(json);

@override
Map<String, dynamic> toJson() => _$StudyUUserToJson(this);
}

@JsonSerializable()
class Preferences {
// todo store preferred user language in database
@JsonKey(name: 'lang')
String language;

@JsonKey(name: 'pinned_studies')
Set<String> pinnedStudies;

Preferences({this.language = '', this.pinnedStudies = const {}});

factory Preferences.fromJson(Map<String, dynamic> json) => _$PreferencesFromJson(json);

Map<String, dynamic> toJson() {
final Map<String, dynamic> json = _$PreferencesToJson(this);
// Remove empty fields from the JSON map
json.removeWhere(
(key, value) => value == null || value is String && value.isEmpty || value is Set && value.isEmpty,
);
return json;
}
}
36 changes: 36 additions & 0 deletions core/lib/src/models/tables/user.g.dart

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

12 changes: 5 additions & 7 deletions core/lib/src/util/supabase_object.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import 'dart:io';

import 'package:studyu_core/core.dart';
import 'package:studyu_core/src/env/env.dart' as env;
import 'package:studyu_core/src/models/tables/app_config.dart';
import 'package:studyu_core/src/models/tables/repo.dart';
import 'package:studyu_core/src/models/tables/study.dart';
import 'package:studyu_core/src/models/tables/study_invite.dart';
import 'package:studyu_core/src/models/tables/study_subject.dart';
import 'package:studyu_core/src/models/tables/subject_progress.dart';
import 'package:studyu_core/src/util/analytics.dart';
import 'package:supabase/supabase.dart';

abstract class SupabaseObject {
Expand All @@ -30,6 +24,8 @@ String tableName(Type cls) {
return Repo.tableName;
case StudyInvite:
return StudyInvite.tableName;
case StudyUUser:
return StudyUUser.tableName;
default:
print('$cls is not a supported Supabase type');
throw TypeError();
Expand All @@ -51,6 +47,8 @@ abstract class SupabaseObjectFunctions<T extends SupabaseObject> implements Supa
return Repo.fromJson(json) as T;
case StudyInvite:
return StudyInvite.fromJson(json) as T;
case StudyUUser:
return StudyUUser.fromJson(json) as T;
default:
print('$T is not a supported Supabase type');
throw TypeError();
Expand Down
12 changes: 12 additions & 0 deletions database/migration/migrate-user_preferences.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ALTER TABLE public."user" ADD COLUMN preferences jsonb;


--
-- Name: Allow users to manage their own user; Type: POLICY; Schema: public; Owner: supabase_admin
--

CREATE POLICY "Allow users to manage their own user"
ON public."user" FOR ALL
USING (
auth.uid() = id
);
15 changes: 13 additions & 2 deletions database/studyu-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ SET default_table_access_method = heap;
--

CREATE TABLE public.study (
id uuid DEFAULT gen_random_uuid() NOT NULL,
id uuid DEFAULT gen_random_uuid() NOT NULL UNIQUE,
contact jsonb NOT NULL,
title text NOT NULL,
description text NOT NULL,
Expand Down Expand Up @@ -580,7 +580,8 @@ ALTER TABLE public.study_progress_export OWNER TO postgres;

CREATE TABLE public."user" (
id uuid NOT NULL,
email text
email text,
preferences jsonb
);


Expand Down Expand Up @@ -831,6 +832,16 @@ CREATE POLICY "Users can do everything with their progress" ON public.subject_pr
WHERE (study_subject.id = subject_progress.subject_id))));


--
-- Name: Allow users to manage their own user; Type: POLICY; Schema: public; Owner:
--

CREATE POLICY "Allow users to manage their own user"
ON public."user" FOR ALL
USING (
auth.uid() = id
);

--
-- Name: app_config; Type: ROW SECURITY; Schema: public; Owner: postgres
--
Expand Down
Loading

0 comments on commit c57401b

Please sign in to comment.