Skip to content

Commit

Permalink
feat: add event journal entity type
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasn committed May 28, 2024
1 parent 59f777c commit 8c00632
Show file tree
Hide file tree
Showing 21 changed files with 1,116 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/blocs/journal/journal_page_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ class JournalPageCubit extends Cubit<JournalPageState> {
final List<String> entryTypes = [
'Task',
'JournalEntry',
'JournalEvent',
'JournalAudio',
'JournalImage',
'MeasurementEntry',
Expand Down
17 changes: 17 additions & 0 deletions lib/classes/event_data.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:lotti/classes/event_status.dart';

part 'event_data.freezed.dart';
part 'event_data.g.dart';

@freezed
class EventData with _$EventData {
const factory EventData({
required String title,
required int stars,
required EventStatus status,
}) = _EventData;

factory EventData.fromJson(Map<String, dynamic> json) =>
_$EventDataFromJson(json);
}
186 changes: 186 additions & 0 deletions lib/classes/event_data.freezed.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark

part of 'event_data.dart';

// **************************************************************************
// FreezedGenerator
// **************************************************************************

T _$identity<T>(T value) => value;

final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');

EventData _$EventDataFromJson(Map<String, dynamic> json) {
return _EventData.fromJson(json);
}

/// @nodoc
mixin _$EventData {
String get title => throw _privateConstructorUsedError;
int get stars => throw _privateConstructorUsedError;
EventStatus get status => throw _privateConstructorUsedError;

Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$EventDataCopyWith<EventData> get copyWith =>
throw _privateConstructorUsedError;
}

/// @nodoc
abstract class $EventDataCopyWith<$Res> {
factory $EventDataCopyWith(EventData value, $Res Function(EventData) then) =
_$EventDataCopyWithImpl<$Res, EventData>;
@useResult
$Res call({String title, int stars, EventStatus status});
}

/// @nodoc
class _$EventDataCopyWithImpl<$Res, $Val extends EventData>
implements $EventDataCopyWith<$Res> {
_$EventDataCopyWithImpl(this._value, this._then);

// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;

@pragma('vm:prefer-inline')
@override
$Res call({
Object? title = null,
Object? stars = null,
Object? status = null,
}) {
return _then(_value.copyWith(
title: null == title
? _value.title
: title // ignore: cast_nullable_to_non_nullable
as String,
stars: null == stars
? _value.stars
: stars // ignore: cast_nullable_to_non_nullable
as int,
status: null == status
? _value.status
: status // ignore: cast_nullable_to_non_nullable
as EventStatus,
) as $Val);
}
}

/// @nodoc
abstract class _$$EventDataImplCopyWith<$Res>
implements $EventDataCopyWith<$Res> {
factory _$$EventDataImplCopyWith(
_$EventDataImpl value, $Res Function(_$EventDataImpl) then) =
__$$EventDataImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({String title, int stars, EventStatus status});
}

/// @nodoc
class __$$EventDataImplCopyWithImpl<$Res>
extends _$EventDataCopyWithImpl<$Res, _$EventDataImpl>
implements _$$EventDataImplCopyWith<$Res> {
__$$EventDataImplCopyWithImpl(
_$EventDataImpl _value, $Res Function(_$EventDataImpl) _then)
: super(_value, _then);

@pragma('vm:prefer-inline')
@override
$Res call({
Object? title = null,
Object? stars = null,
Object? status = null,
}) {
return _then(_$EventDataImpl(
title: null == title
? _value.title
: title // ignore: cast_nullable_to_non_nullable
as String,
stars: null == stars
? _value.stars
: stars // ignore: cast_nullable_to_non_nullable
as int,
status: null == status
? _value.status
: status // ignore: cast_nullable_to_non_nullable
as EventStatus,
));
}
}

/// @nodoc
@JsonSerializable()
class _$EventDataImpl implements _EventData {
const _$EventDataImpl(
{required this.title, required this.stars, required this.status});

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

@override
final String title;
@override
final int stars;
@override
final EventStatus status;

@override
String toString() {
return 'EventData(title: $title, stars: $stars, status: $status)';
}

@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$EventDataImpl &&
(identical(other.title, title) || other.title == title) &&
(identical(other.stars, stars) || other.stars == stars) &&
(identical(other.status, status) || other.status == status));
}

@JsonKey(ignore: true)
@override
int get hashCode => Object.hash(runtimeType, title, stars, status);

@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$EventDataImplCopyWith<_$EventDataImpl> get copyWith =>
__$$EventDataImplCopyWithImpl<_$EventDataImpl>(this, _$identity);

@override
Map<String, dynamic> toJson() {
return _$$EventDataImplToJson(
this,
);
}
}

abstract class _EventData implements EventData {
const factory _EventData(
{required final String title,
required final int stars,
required final EventStatus status}) = _$EventDataImpl;

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

@override
String get title;
@override
int get stars;
@override
EventStatus get status;
@override
@JsonKey(ignore: true)
_$$EventDataImplCopyWith<_$EventDataImpl> get copyWith =>
throw _privateConstructorUsedError;
}
32 changes: 32 additions & 0 deletions lib/classes/event_data.g.dart

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

56 changes: 56 additions & 0 deletions lib/classes/event_status.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import 'package:flutter/material.dart';

enum EventStatus {
tentative,
planned,
ongoing,
completed,
cancelled,
postponed,
rescheduled,
missed,
}

extension EventStatusX on EventStatus {
String get label {
switch (this) {
case EventStatus.tentative:
return 'TENTATIVE';
case EventStatus.planned:
return 'PLANNED';
case EventStatus.ongoing:
return 'ONGOING';
case EventStatus.completed:
return 'COMPLETED';
case EventStatus.cancelled:
return 'CANCELLED';
case EventStatus.postponed:
return 'POSTPONED';
case EventStatus.rescheduled:
return 'RESCHEDULED';
case EventStatus.missed:
return 'MISSED';
}
}

Color get color {
switch (this) {
case EventStatus.tentative:
return Colors.grey;
case EventStatus.planned:
return Colors.blue;
case EventStatus.ongoing:
return Colors.orange;
case EventStatus.completed:
return Colors.green;
case EventStatus.cancelled:
return Colors.red;
case EventStatus.postponed:
return Colors.yellow;
case EventStatus.rescheduled:
return Colors.purple;
case EventStatus.missed:
return Colors.red;
}
}
}
8 changes: 8 additions & 0 deletions lib/classes/journal_entities.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:lotti/classes/checklist_item.dart';
import 'package:lotti/classes/entity_definitions.dart';
import 'package:lotti/classes/entry_text.dart';
import 'package:lotti/classes/event_data.dart';
import 'package:lotti/classes/geolocation.dart';
import 'package:lotti/classes/health.dart';
import 'package:lotti/classes/task.dart';
Expand Down Expand Up @@ -126,6 +127,13 @@ class JournalEntity with _$JournalEntity {
Geolocation? geolocation,
}) = Task;

const factory JournalEntity.event({
required Metadata meta,
required EventData data,
EntryText? entryText,
Geolocation? geolocation,
}) = JournalEvent;

const factory JournalEntity.checklistItem({
required Metadata meta,
required ChecklistItemData data,
Expand Down
Loading

0 comments on commit 8c00632

Please sign in to comment.