67 lines
2.2 KiB
Dart
67 lines
2.2 KiB
Dart
// Flutter imports:
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_redux/flutter_redux.dart';
|
|
|
|
// Project imports:
|
|
import 'package:invoiceninja_flutter/data/models/models.dart';
|
|
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
|
import 'package:invoiceninja_flutter/ui/app/link_text.dart';
|
|
import 'package:invoiceninja_flutter/ui/app/presenters/entity_presenter.dart';
|
|
|
|
class DocumentPresenter extends EntityPresenter {
|
|
static List<String> getDefaultTableFields(UserCompanyEntity userCompany) {
|
|
return [
|
|
DocumentFields.name,
|
|
DocumentFields.type,
|
|
DocumentFields.linkedTo,
|
|
DocumentFields.size,
|
|
DocumentFields.width,
|
|
DocumentFields.height,
|
|
];
|
|
}
|
|
|
|
static List<String> getAllTableFields(UserCompanyEntity userCompany) {
|
|
return [
|
|
...getDefaultTableFields(userCompany),
|
|
...EntityPresenter.getBaseFields(),
|
|
DocumentFields.id,
|
|
DocumentFields.updatedAt,
|
|
DocumentFields.archivedAt,
|
|
DocumentFields.isDeleted,
|
|
DocumentFields.hash,
|
|
];
|
|
}
|
|
|
|
@override
|
|
Widget getField({String field, BuildContext context}) {
|
|
final store = StoreProvider.of<AppState>(context);
|
|
final state = store.state;
|
|
final document = entity as DocumentEntity;
|
|
|
|
switch (field) {
|
|
case DocumentFields.name:
|
|
return Text(document.name);
|
|
case DocumentFields.type:
|
|
return Text(document.type);
|
|
case DocumentFields.size:
|
|
return Text(document.prettySize);
|
|
case DocumentFields.width:
|
|
return Text(document.width > 0 ? '${document.width}' : '');
|
|
case DocumentFields.height:
|
|
return Text(document.height > 0 ? '${document.height}' : '');
|
|
case DocumentFields.id:
|
|
return Text(document.id);
|
|
case DocumentFields.hash:
|
|
return Text(document.hash);
|
|
case DocumentFields.linkedTo:
|
|
final parentEntity =
|
|
state.getEntity(document.parentType, document.parentId);
|
|
print(
|
|
'## ${document.parentType} ${document.parentId} => $parentEntity');
|
|
return LinkTextRelatedEntity(entity: parentEntity, relation: document);
|
|
}
|
|
|
|
return super.getField(field: field, context: context);
|
|
}
|
|
}
|