Calling API in LatestReportColumn.dart
and improving UI
This commit is contained in:
@@ -12,6 +12,7 @@ export 'package:ac_web/Api/Dtos/AgentDto.dart';
|
||||
export 'package:ac_web/Api/Dtos/AgentTaskDto.dart';
|
||||
export 'package:ac_web/Api/Dtos/EAgentStatus.dart';
|
||||
export 'package:ac_web/Api/Dtos/EAgentType.dart';
|
||||
export 'package:ac_web/Api/Dtos/EReportType.dart';
|
||||
export 'package:ac_web/Api/Dtos/ReportDto.dart';
|
||||
export 'package:ac_web/Api/Services/AgentsService.dart';
|
||||
export 'package:ac_web/Api/Services/ApiServiceBase.dart';
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/// Mirror of the backend `EReportType` enum.
|
||||
///
|
||||
/// The order of the values has to match the order in the .Net enum, because
|
||||
/// the api may serialize enums as their numeric value. [unknown] is kept last
|
||||
/// so that it never shadows a real backend value and acts as fallback for
|
||||
/// values this client does not know yet.
|
||||
enum EReportType {
|
||||
log,
|
||||
codeReview,
|
||||
projectPlan,
|
||||
research,
|
||||
newspaper,
|
||||
unknown;
|
||||
|
||||
/// Name as it is written in the .Net enum, used for json (de)serialization.
|
||||
String get wireName {
|
||||
switch (this) {
|
||||
case EReportType.log:
|
||||
return 'LOG';
|
||||
case EReportType.codeReview:
|
||||
return 'CODE_REVIEW';
|
||||
case EReportType.projectPlan:
|
||||
return 'PROJECT_PLAN';
|
||||
case EReportType.research:
|
||||
return 'RESEARCH';
|
||||
case EReportType.newspaper:
|
||||
return 'NEWSPAPER';
|
||||
case EReportType.unknown:
|
||||
return 'UNKNOWN';
|
||||
}
|
||||
}
|
||||
|
||||
/// Human readable label, e.g. for chips or table cells.
|
||||
String get displayName {
|
||||
switch (this) {
|
||||
case EReportType.log:
|
||||
return 'Log';
|
||||
case EReportType.codeReview:
|
||||
return 'Code Review';
|
||||
case EReportType.projectPlan:
|
||||
return 'Project Plan';
|
||||
case EReportType.research:
|
||||
return 'Research';
|
||||
case EReportType.newspaper:
|
||||
return 'Newspaper';
|
||||
case EReportType.unknown:
|
||||
return 'Unknown';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
import 'package:ac_web/Api/Dtos/EReportType.dart';
|
||||
import 'package:ac_web/Api/JsonReader.dart';
|
||||
|
||||
/// Dart counterpart of the backend `ReportDto` returned by `GET /reports`.
|
||||
class ReportDto {
|
||||
const ReportDto({
|
||||
required this.id,
|
||||
required this.title,
|
||||
required this.author,
|
||||
required this.timestamp,
|
||||
required this.type,
|
||||
@@ -11,21 +13,27 @@ class ReportDto {
|
||||
});
|
||||
|
||||
final String id;
|
||||
final String title;
|
||||
final String author;
|
||||
final DateTime timestamp;
|
||||
|
||||
/// Free form report type. The backend sends this as a plain string, so it is
|
||||
/// intentionally not modelled as an enum here.
|
||||
final String type;
|
||||
final EReportType type;
|
||||
|
||||
final String text;
|
||||
|
||||
factory ReportDto.fromJson(Map<String, dynamic> json) {
|
||||
return ReportDto(
|
||||
id: JsonReader.requireString(json, 'Id'),
|
||||
title: JsonReader.optionalString(json, 'Title') ?? '',
|
||||
author: JsonReader.requireString(json, 'Author'),
|
||||
timestamp: JsonReader.requireDateTime(json, 'Timestamp'),
|
||||
type: JsonReader.optionalString(json, 'Type') ?? '',
|
||||
type: JsonReader.enumValue(
|
||||
json,
|
||||
'Type',
|
||||
EReportType.values,
|
||||
(value) => value.wireName,
|
||||
EReportType.unknown,
|
||||
),
|
||||
text: JsonReader.optionalString(json, 'Text') ?? '',
|
||||
);
|
||||
}
|
||||
@@ -33,13 +41,15 @@ class ReportDto {
|
||||
Map<String, dynamic> toJson() {
|
||||
return <String, dynamic>{
|
||||
'Id': id,
|
||||
'Title': title,
|
||||
'Author': author,
|
||||
'Timestamp': timestamp.toIso8601String(),
|
||||
'Type': type,
|
||||
'Type': type.wireName,
|
||||
'Text': text,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() => 'ReportDto(id: $id, author: $author, type: $type)';
|
||||
String toString() =>
|
||||
'ReportDto(id: $id, title: $title, author: $author, type: ${type.wireName})';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user