Skip to content

Commit

Permalink
Merge pull request #29 from CoderJava/feature/tambahkan-note-di-fitur…
Browse files Browse the repository at this point in the history
…-add-manual-time

Feature - Tambahkan note di fitur add manual track
  • Loading branch information
CoderJava authored Oct 5, 2023
2 parents 77b1ea8 + ffe554a commit 38e7a94
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 62 deletions.
4 changes: 3 additions & 1 deletion assets/translations/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -291,5 +291,7 @@
"set_finish_date": "Set finish date",
"please_set_start_date": "Please set start date",
"please_set_finish_date": "Please set finish date",
"finish_date_time_must_be_after_of_start_date_time": "The finish date time must be after the start date time"
"finish_date_time_must_be_after_of_start_date_time": "The finish date time must be after the start date time",
"reason": "Reason",
"why_are_you_adding_manual_track": "e.g. Forgot to start timer"
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ class ManualCreateTrackBody extends Equatable {
final String finishDate;
@JsonKey(name: 'duration')
final int duration;
@JsonKey(name: 'note')
final String? note;

ManualCreateTrackBody({
required this.taskId,
required this.startDate,
required this.finishDate,
required this.duration,
required this.note,
});

factory ManualCreateTrackBody.fromJson(Map<String, dynamic> json) => _$ManualCreateTrackBodyFromJson(json);
Expand All @@ -31,10 +34,12 @@ class ManualCreateTrackBody extends Equatable {
startDate,
finishDate,
duration,
note,
];

@override
String toString() {
return 'ManualCreateTrackBody{taskId: $taskId, startDate: $startDate, finishDate: $finishDate, duration: $duration}';
return 'ManualCreateTrackBody{taskId: $taskId, startDate: $startDate, finishDate: $finishDate, duration: $duration, '
'note: $note}';
}
}
6 changes: 5 additions & 1 deletion lib/feature/data/model/track_user/track_user_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class ItemTrackUserResponse extends Equatable {
final String? user;
@JsonKey(name: 'files')
final List<ItemFileTrackUserResponse>? files;
@JsonKey(name: 'note')
final String? note;

ItemTrackUserResponse({
required this.id,
Expand All @@ -67,6 +69,7 @@ class ItemTrackUserResponse extends Equatable {
required this.userId,
required this.user,
required this.files,
required this.note,
});

factory ItemTrackUserResponse.fromJson(Map<String, dynamic> json) => _$ItemTrackUserResponseFromJson(json);
Expand All @@ -87,14 +90,15 @@ class ItemTrackUserResponse extends Equatable {
userId,
user,
files,
note,
];

@override
String toString() {
return 'ItemTrackUserResponse{id: $id, taskId: $taskId, taskName: $taskName, projectId: $projectId, '
'projectName: $projectName, startDate: $startDate, finishDate: $finishDate, '
'activityInPercent: $activityInPercent, durationInSeconds: $durationInSeconds, userId: $userId, user: $user, '
'files: $files}';
'files: $files, note: $note}';
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class _ManualTrackingPageState extends State<ManualTrackingPage> {
final controllerFinishDate = TextEditingController();
final controllerFinishTime = TextEditingController();
final controllerDuration = TextEditingController();
final controllerNote = TextEditingController();
final valueNotifierEnableButtonSave = ValueNotifier(false);

var isLoading = false;
Expand Down Expand Up @@ -412,6 +413,20 @@ class _ManualTrackingPageState extends State<ManualTrackingPage> {
isEnabled: false,
),
const SizedBox(height: 24),
buildWidgetField(
controllerNote,
label: 'reason'.tr(),
hint: 'why_are_you_adding_manual_track'.tr(),
isEnabled: true,
readOnly: false,
maxLength: 100,
onChanged: (_) {
doCheckEnableButtonSubmit();
},
minLines: 1,
maxLines: 3,
),
const SizedBox(height: 24),
buildWidgetButtonSave(),
],
),
Expand Down Expand Up @@ -551,6 +566,7 @@ class _ManualTrackingPageState extends State<ManualTrackingPage> {
startDate: formattedStartDateTime,
finishDate: formattedFinishDateTime,
duration: durationInSeconds!,
note: controllerNote.text.trim(),
);
manualTrackingBloc.add(
CreateManualTrackingEvent(
Expand Down Expand Up @@ -612,18 +628,27 @@ class _ManualTrackingPageState extends State<ManualTrackingPage> {
Function()? onTap,
bool isEnabled = true,
FormFieldValidator<String>? validator,
bool readOnly = true,
int? maxLength,
ValueChanged<String>? onChanged,
int? minLines,
int? maxLines,
}) {
return TextFormField(
controller: controller,
decoration: widgetHelper.setDefaultTextFieldDecoration(
labelText: label,
hintText: hint,
),
readOnly: true,
readOnly: readOnly,
mouseCursor: MaterialStateMouseCursor.clickable,
onTap: onTap,
validator: validator,
enabled: isEnabled,
maxLength: maxLength,
onChanged: onChanged,
minLines: minLines,
maxLines: maxLines,
);
}

Expand Down Expand Up @@ -655,22 +680,24 @@ class _ManualTrackingPageState extends State<ManualTrackingPage> {
validator: validator,
autovalidateMode: AutovalidateMode.onUserInteraction,
padding: EdgeInsets.zero,
hint: Text(hintText),
decoration: widgetHelper.setDefaultTextFieldDecoration(
labelText: labelText,
hintText: hintText,
floatingLabelBehavior: FloatingLabelBehavior.always,
),
);
}

void doCheckEnableButtonSubmit() {
var isEnableTemp = false;
final reason = controllerNote.text.trim();
if (selectedProject != null &&
selectedTask != null &&
startDate != null &&
finishDate != null &&
durationInSeconds != null &&
durationInSeconds! > 0) {
durationInSeconds! > 0 &&
reason.isNotEmpty) {
isEnableTemp = true;
}
if (isEnableTemp != valueNotifierEnableButtonSave.value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -808,71 +808,97 @@ class _ReportScreenshotPageState extends State<ReportScreenshotPage> {
}

final trackId = element.id;
final note = element.note ?? '';
return Align(
alignment: Alignment.center,
child: Padding(
padding: EdgeInsets.only(top: heightImage),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Material(
borderRadius: BorderRadius.circular(999),
child: InkWell(
borderRadius: BorderRadius.circular(999),
onTap: () {
if (trackId == null) {
widgetHelper.showSnackBar(
context,
'track_id_invalid'.tr(),
);
return;
}
note.isEmpty
? Container()
: Tooltip(
message: note,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: FaIcon(
FontAwesomeIcons.penToSquare,
color: Theme.of(context).colorScheme.primary,
size: 14,
),
),
),
buildWidgetIconDelete(
const FaIcon(
FontAwesomeIcons.trashCan,
color: Colors.red,
size: 14,
),
onTap: () {
if (trackId == null) {
widgetHelper.showSnackBar(
context,
'track_id_invalid'.tr(),
);
return;
}

showDialog<bool?>(
context: context,
builder: (context) {
return AlertDialog(
title: Text('title_delete_track'.tr()),
content: Text('content_delete_track'.tr()),
actions: [
TextButton(
onPressed: () => context.pop(false),
child: Text('cancel'.tr()),
),
TextButton(
onPressed: () => context.pop(true),
style: TextButton.styleFrom(
foregroundColor: Colors.red,
),
child: Text('delete'.tr()),
showDialog<bool?>(
context: context,
builder: (context) {
return AlertDialog(
title: Text('title_delete_track'.tr()),
content: Text('content_delete_track'.tr()),
actions: [
TextButton(
onPressed: () => context.pop(false),
child: Text('cancel'.tr()),
),
TextButton(
onPressed: () => context.pop(true),
style: TextButton.styleFrom(
foregroundColor: Colors.red,
),
],
);
},
).then((value) {
if (value != null && value) {
trackingBloc.add(
DeleteTrackUserTrackingEvent(
trackId: trackId,
child: Text('delete'.tr()),
),
);
}
});
},
child: const Padding(
padding: EdgeInsets.all(8.0),
child: FaIcon(
FontAwesomeIcons.trashCan,
color: Colors.red,
size: 14,
),
),
),
],
);
},
).then((value) {
if (value != null && value) {
trackingBloc.add(
DeleteTrackUserTrackingEvent(
trackId: trackId,
),
);
}
});
},
),
],
),
),
);
}

Widget buildWidgetIconDelete(
Widget icon, {
Function()? onTap,
ValueChanged<bool>? onHover,
}) {
return Material(
borderRadius: BorderRadius.circular(999),
child: InkWell(
borderRadius: BorderRadius.circular(999),
onTap: onTap,
onHover: onHover,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: icon,
),
),
);
}
}
4 changes: 2 additions & 2 deletions macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ SPEC CHECKSUMS:
tray_manager: 9064e219c56d75c476e46b9a21182087930baf90
window_manager: 3a1844359a6295ab1e47659b1a777e36773cd6e8

PODFILE CHECKSUM: 8d40c19d3cbdb380d870685c3a564c989f1efa52
PODFILE CHECKSUM: 7b8886a4ad89b3a2f7a16642e81ab6bed5c5d3ac

COCOAPODS: 1.12.1
COCOAPODS: 1.13.0
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ void main() {
tModel.startDate,
tModel.finishDate,
tModel.duration,
tModel.note,
],
);
},
Expand All @@ -36,7 +37,7 @@ void main() {
expect(
tModel.toString(),
'ManualCreateTrackBody{taskId: ${tModel.taskId}, startDate: ${tModel.startDate}, '
'finishDate: ${tModel.finishDate}, duration: ${tModel.duration}}',
'finishDate: ${tModel.finishDate}, duration: ${tModel.duration}, note: ${tModel.note}}',
);
},
);
Expand Down
3 changes: 2 additions & 1 deletion test/fixture/manual_create_track_body.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"task_id": 1,
"start_date": "testStartDate",
"finish_date": "testFinishDate",
"duration": 0
"duration": 0,
"note": "testNote"
}
3 changes: 2 additions & 1 deletion test/fixture/track_user_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"url_blur": "testUrlBlur",
"size_blur": 1
}
]
],
"note": "testNote"
}
]
}

0 comments on commit 38e7a94

Please sign in to comment.