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

Form Refactored to not lose its state on scroll #6

Merged
merged 21 commits into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Almost everything done
  • Loading branch information
baumths committed Nov 22, 2020
commit 7807ed275e5f05d8f73bfd13694b5161d3d2ebf7
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*Elaborador de Plano de Classificação de Documentos e Tabela de Temporalidade Documental*
![Ged/A](assets/gedalogo_800x300.png)

O objetivo é que além de um software para a elaboração e gerenciamento de PCDs e TTDs, tenhamos a possibilidade de interoperabilizar estes instrumentos arquivísticos entre sistemas (implementando assim um padrão de dados abertos), através da implementação do Esquema de Metadados do e-ARQ Brasil, aliado ao padrão CSV ISAD(G) do AtoM (Plataforma Arquivística de Descrição, Acesso e Transparência Ativa de Documentos e Informações - [Access To Memory](https://www.accesstomemory.org/))
O objetivo é que além de um software para a elaboração e gerenciamento de PCDs e TTDs, tenhamos a possibilidade de interoperabilizar estes instrumentos arquivísticos entre sistemas (implementando assim um padrão de dados abertos), através da implementação do Esquema de MetadataType do e-ARQ Brasil, aliado ao padrão CSV ISAD(G) do AtoM (Plataforma Arquivística de Descrição, Acesso e Transparência Ativa de Documentos e Informações - [Access To Memory](https://www.accesstomemory.org/))

### METADADOS
- 3.1 Descrição de classe
Expand Down
32 changes: 10 additions & 22 deletions lib/src/entities/classe/classe.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import 'package:flutter/foundation.dart';
import 'package:hive/hive.dart';

import '../../repositories/hive_repository.dart';

part 'metadado.dart';
part 'classe.g.dart';

// Todo: RUN BUILD_RUNNER
Expand All @@ -14,24 +11,21 @@ class Classe with HiveObject {
@required this.name,
@required this.code,
@required this.parentId,
@required this.metadados,
@required this.referenceCode,
}) : children = HiveList<Classe>(HiveRepository.classesBox);
@required this.metadata,
});

factory Classe.root() => Classe(
name: '',
code: '',
parentId: -1,
referenceCode: '',
metadados: <Metadado>[],
metadata: <String, String>{},
);

factory Classe.fromParent(int parentId) => Classe(
name: '',
code: '',
parentId: parentId,
referenceCode: '',
metadados: <Metadado>[],
metadata: <String, String>{},
);

@HiveField(0)
Expand All @@ -46,25 +40,19 @@ class Classe with HiveObject {
@HiveField(3)
String code;

@HiveField(4)
String referenceCode;

@HiveField(5)
List<Metadado> metadados;

@HiveField(6)
HiveList<Classe> children;

bool get hasChildren => children.isNotEmpty;
Map<String, String> metadata;

@override
String toString() {
final String metadadosStr = metadados.map((m) => m.toCsv()).join('');
final String metadadosStr = metadata.entries
.map<String>((md) => '${md.key}: ${md.value}')
.toList()
.join('\n');
return 'id ➜ { $id } '
'parentId ➜ { $parentId } '
'Nome ➜ { $name } '
'Código ➜ { $code } '
'Código de Referência ➜ { $referenceCode }'
'\n $metadadosStr';
'\n⮦ MetadataType\n$metadadosStr';
}
}
15 changes: 4 additions & 11 deletions lib/src/entities/classe/classe.g.dart

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

70 changes: 0 additions & 70 deletions lib/src/entities/classe/metadado.dart

This file was deleted.

2 changes: 2 additions & 0 deletions lib/src/features/app/misc/app_routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ abstract class ElPCDRouter {
case ComposeView.routeName:
final classe = settings.arguments as Classe;
return MaterialPageRoute(builder: (_) => ComposeView(classe: classe));
break;
case HomeView.routeName:
default:
return MaterialPageRoute(builder: (_) => HomeView());
break;
}
}
}
11 changes: 4 additions & 7 deletions lib/src/features/app/view/app_view.dart
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
import 'package:flutter/material.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:provider/provider.dart';

import '../../../repositories/hive_repository.dart';
import '../../features.dart';
import '../misc/app_routes.dart';
import '../misc/app_theme.dart';

class ElPCDApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
final _repository = context.watch<HiveRepository>();
return ValueListenableBuilder(
valueListenable: _repository.listenToSettings(keys: ['darkMode']),
valueListenable: HiveRepository.classesBox.listenable(keys: ['darkMode']),
builder: (_, __, ___) {
return MaterialApp(
title: 'ElPCD',
debugShowCheckedModeBanner: false,
themeMode: _repository.isDarkMode ? ThemeMode.dark : ThemeMode.light,
theme: AppTheme.themeData(darkMode: _repository.isDarkMode),
initialRoute: HomeView.routeName,
initialRoute: ElPCDRouter.home,
onGenerateRoute: ElPCDRouter.onGenerateRoute,
routes: {
HomeView.routeName: (_) => HomeView(),
ComposeView.routeName: (_) => const ComposeView(classe: null),
},
);
},
);
Expand Down
48 changes: 30 additions & 18 deletions lib/src/features/compose/bloc/compose_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';

import '../../../entities/entities.dart';
import '../../../repositories/hive_repository.dart';
import '../misc/metadata_viewmodel.dart';

part 'compose_event.dart';
part 'compose_state.dart';
Expand All @@ -18,52 +19,63 @@ class ComposeBloc extends Bloc<ComposeEvent, ComposeState> {
@override
Stream<ComposeState> mapEventToState(ComposeEvent event) async* {
if (event is ComposeStarted) {
yield state.copyWith(
classe: event.classe,
name: event.classe.name,
code: event.classe.code,
metadados: event.classe.metadados,
isEditing: true,
);
if (event.classe == null) {
yield state.copyWith(
classe: Classe.root(),
);
} else {
yield state.copyWith(
classe: event.classe,
name: event.classe.name,
code: event.classe.code,
metadata: metadataFromMap(event.classe.metadata),
isEditing: true,
);
}
} else if (event is NameChanged) {
yield state.copyWith(name: event.name);
} else if (event is CodeChanged) {
yield state.copyWith(code: event.code);
} else if (event is SavePressed) {
yield state.copyWith(
isSaving: true,
successOrFailure: ComposeSuccessOrFailure.none,
);
yield state.copyWith(isSaving: true, shouldValidate: true);

if (state.isFormValid) {
Future.delayed(const Duration(seconds: 2)); //! remove
await saveClasse(event.metadados);
yield state.copyWith(
isSaving: false,
successOrFailure: ComposeSuccessOrFailure.success,
status: ComposeStatus.success,
);
} else {
yield state.copyWith(
isSaving: false,
successOrFailure: ComposeSuccessOrFailure.failure,
status: ComposeStatus.failure,
);
}
}
}

Future<void> saveClasse(List<Metadado> metadados) async {
Future<void> saveClasse(List<MetadataViewModel> metadata) async {
final classe = state.classe
..name = state.name
..code = state.code
..referenceCode = _repository.buildReferenceCode(state.classe)
..metadados = clearEmptyMetadados(state.metadados);
..metadata = metadataToMap(metadata);

state.isEditing
? await _repository.update(classe)
: await _repository.insert(classe);
}

List<Metadado> clearEmptyMetadados(List<Metadado> metadados) {
return metadados.where((m) => m.content.isNotEmpty).toList();
Map<String, String> metadataToMap(List<MetadataViewModel> metadata) {
return {
for (final md in metadata)
if (md.isNotEmpty) ...md.toMap()
};
}

List<MetadataViewModel> metadataFromMap(Map<String, String> metadata) {
return metadata.entries.map<MetadataViewModel>((md) {
return MetadataViewModel(type: md.key, content: md.value);
}).toList();
}
}
2 changes: 1 addition & 1 deletion lib/src/features/compose/bloc/compose_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CodeChanged extends ComposeEvent {
class SavePressed extends ComposeEvent {
const SavePressed({@required this.metadados});

final List<Metadado> metadados;
final List<MetadataViewModel> metadados;

@override
List<Object> get props => [metadados];
Expand Down
Loading