asset search done & filter assets need to be discussed
parent
5cf84e6988
commit
fb3f442ed5
@ -0,0 +1,185 @@
|
||||
import 'package:test_sa/models/lookup.dart';
|
||||
|
||||
class AssetSearch {
|
||||
AssetSearch({
|
||||
this.code,
|
||||
this.assetSerialNumber,
|
||||
this.assetName,
|
||||
this.supplyDateSymbol,
|
||||
this.supplyDateFrom,
|
||||
this.supplyDateTo,
|
||||
this.warrantyEndDateSymbol,
|
||||
this.warrantyEndDateFrom,
|
||||
this.warrantyEndDateTo,
|
||||
this.delieveryInspectionDateSymbol,
|
||||
this.deliveryInspectionDateFrom,
|
||||
this.deliveryInspectionDateTo,
|
||||
this.maintenanceContract,
|
||||
this.assetClassification,
|
||||
this.assetStatus,
|
||||
this.assetNotScraped,
|
||||
this.assetNo,
|
||||
this.modelDefinition,
|
||||
this.site,
|
||||
this.manufacturer,
|
||||
this.model,
|
||||
this.department,
|
||||
this.supplier,
|
||||
this.tagCode,
|
||||
this.assetGroupName,
|
||||
this.assetGroup,
|
||||
});
|
||||
|
||||
AssetSearch.fromJson(dynamic json) {
|
||||
code = json['code'];
|
||||
assetSerialNumber = json['assetSerialNumber'];
|
||||
assetName = json['assetName'];
|
||||
supplyDateSymbol = json['supplyDateSymbol'] != null ? Lookup.fromJson(json['supplyDateSymbol']) : null;
|
||||
supplyDateFrom = json['supplyDateFrom'];
|
||||
supplyDateTo = json['supplyDateTo'];
|
||||
warrantyEndDateSymbol = json['warrantyEndDateSymbol'];
|
||||
warrantyEndDateFrom = json['warrantyEndDateFrom'];
|
||||
warrantyEndDateTo = json['warrantyEndDateTo'];
|
||||
delieveryInspectionDateSymbol = json['delieveryInspectionDateSymbol'];
|
||||
deliveryInspectionDateFrom = json['deliveryInspectionDateFrom'];
|
||||
deliveryInspectionDateTo = json['deliveryInspectionDateTo'];
|
||||
maintenanceContract = json['maintenanceContract'] != null ? Lookup.fromJson(json['maintenanceContract']) : null;
|
||||
assetClassification = json['assetClassification'] != null ? Lookup.fromJson(json['assetClassification']) : null;
|
||||
assetStatus = json['assetStatus'] != null ? Lookup.fromJson(json['assetStatus']) : null;
|
||||
assetNotScraped = json['assetNotScraped'] != null ? Lookup.fromJson(json['assetNotScraped']) : null;
|
||||
assetNo = json['assetNo'];
|
||||
modelDefinition = json['modelDefinition'];
|
||||
site = json['site'];
|
||||
manufacturer = json['manufacturer'];
|
||||
model = json['model'];
|
||||
department = json['department'];
|
||||
supplier = json['supplier'];
|
||||
tagCode = json['tagCode'];
|
||||
assetGroupName = json['assetGroupName'];
|
||||
assetGroup = json['assetGroup'] != null ? Lookup.fromJson(json['assetGroup']) : null;
|
||||
}
|
||||
String code;
|
||||
String assetSerialNumber;
|
||||
String assetName;
|
||||
Lookup supplyDateSymbol;
|
||||
String supplyDateFrom;
|
||||
String supplyDateTo;
|
||||
num warrantyEndDateSymbol;
|
||||
String warrantyEndDateFrom;
|
||||
String warrantyEndDateTo;
|
||||
num delieveryInspectionDateSymbol;
|
||||
String deliveryInspectionDateFrom;
|
||||
String deliveryInspectionDateTo;
|
||||
Lookup maintenanceContract;
|
||||
Lookup assetClassification;
|
||||
Lookup assetStatus;
|
||||
Lookup assetNotScraped;
|
||||
String assetNo;
|
||||
String modelDefinition;
|
||||
String site;
|
||||
String manufacturer;
|
||||
String model;
|
||||
String department;
|
||||
String supplier;
|
||||
String tagCode;
|
||||
String assetGroupName;
|
||||
Lookup assetGroup;
|
||||
AssetSearch copyWith({
|
||||
String code,
|
||||
String assetSerialNumber,
|
||||
String assetName,
|
||||
Lookup supplyDateSymbol,
|
||||
String supplyDateFrom,
|
||||
String supplyDateTo,
|
||||
num warrantyEndDateSymbol,
|
||||
String warrantyEndDateFrom,
|
||||
String warrantyEndDateTo,
|
||||
num delieveryInspectionDateSymbol,
|
||||
String deliveryInspectionDateFrom,
|
||||
String deliveryInspectionDateTo,
|
||||
Lookup maintenanceContract,
|
||||
Lookup assetClassification,
|
||||
Lookup assetStatus,
|
||||
Lookup assetNotScraped,
|
||||
String assetNo,
|
||||
String modelDefinition,
|
||||
String site,
|
||||
String manufacturer,
|
||||
String model,
|
||||
String department,
|
||||
String supplier,
|
||||
String tagCode,
|
||||
String assetGroupName,
|
||||
Lookup assetGroup,
|
||||
}) =>
|
||||
AssetSearch(
|
||||
code: code ?? this.code,
|
||||
assetSerialNumber: assetSerialNumber ?? this.assetSerialNumber,
|
||||
assetName: assetName ?? this.assetName,
|
||||
supplyDateSymbol: supplyDateSymbol ?? this.supplyDateSymbol,
|
||||
supplyDateFrom: supplyDateFrom ?? this.supplyDateFrom,
|
||||
supplyDateTo: supplyDateTo ?? this.supplyDateTo,
|
||||
warrantyEndDateSymbol: warrantyEndDateSymbol ?? this.warrantyEndDateSymbol,
|
||||
warrantyEndDateFrom: warrantyEndDateFrom ?? this.warrantyEndDateFrom,
|
||||
warrantyEndDateTo: warrantyEndDateTo ?? this.warrantyEndDateTo,
|
||||
delieveryInspectionDateSymbol: delieveryInspectionDateSymbol ?? this.delieveryInspectionDateSymbol,
|
||||
deliveryInspectionDateFrom: deliveryInspectionDateFrom ?? this.deliveryInspectionDateFrom,
|
||||
deliveryInspectionDateTo: deliveryInspectionDateTo ?? this.deliveryInspectionDateTo,
|
||||
maintenanceContract: maintenanceContract ?? this.maintenanceContract,
|
||||
assetClassification: assetClassification ?? this.assetClassification,
|
||||
assetStatus: assetStatus ?? this.assetStatus,
|
||||
assetNotScraped: assetNotScraped ?? this.assetNotScraped,
|
||||
assetNo: assetNo ?? this.assetNo,
|
||||
modelDefinition: modelDefinition ?? this.modelDefinition,
|
||||
site: site ?? this.site,
|
||||
manufacturer: manufacturer ?? this.manufacturer,
|
||||
model: model ?? this.model,
|
||||
department: department ?? this.department,
|
||||
supplier: supplier ?? this.supplier,
|
||||
tagCode: tagCode ?? this.tagCode,
|
||||
assetGroupName: assetGroupName ?? this.assetGroupName,
|
||||
assetGroup: assetGroup ?? this.assetGroup,
|
||||
);
|
||||
Map<String, dynamic> toJson() {
|
||||
final map = <String, dynamic>{};
|
||||
if (code != null && code.isNotEmpty) map['code'] = code;
|
||||
if (assetSerialNumber != null && assetSerialNumber.isNotEmpty) map['assetSerialNumber'] = assetSerialNumber;
|
||||
if (assetName != null && assetName.isNotEmpty) map['assetName'] = assetName;
|
||||
if (supplyDateSymbol != null) {
|
||||
map['supplyDateSymbol'] = supplyDateSymbol.toJson();
|
||||
}
|
||||
if (supplyDateFrom != null && supplyDateFrom.isNotEmpty) map['supplyDateFrom'] = supplyDateFrom;
|
||||
if (supplyDateTo != null && supplyDateTo.isNotEmpty) map['supplyDateTo'] = supplyDateTo;
|
||||
if (warrantyEndDateSymbol != null) map['warrantyEndDateSymbol'] = warrantyEndDateSymbol;
|
||||
if (warrantyEndDateFrom != null && warrantyEndDateFrom.isNotEmpty) map['warrantyEndDateFrom'] = warrantyEndDateFrom;
|
||||
if (warrantyEndDateTo != null && warrantyEndDateTo.isNotEmpty) map['warrantyEndDateTo'] = warrantyEndDateTo;
|
||||
if (delieveryInspectionDateSymbol != null) map['delieveryInspectionDateSymbol'] = delieveryInspectionDateSymbol;
|
||||
if (deliveryInspectionDateFrom != null && deliveryInspectionDateFrom.isNotEmpty) map['deliveryInspectionDateFrom'] = deliveryInspectionDateFrom;
|
||||
if (deliveryInspectionDateTo != null && deliveryInspectionDateTo.isNotEmpty) map['deliveryInspectionDateTo'] = deliveryInspectionDateTo;
|
||||
if (maintenanceContract != null) {
|
||||
map['maintenanceContract'] = maintenanceContract.toJson();
|
||||
}
|
||||
if (assetClassification != null) {
|
||||
map['assetClassification'] = assetClassification.toJson();
|
||||
}
|
||||
if (assetStatus != null) {
|
||||
map['assetStatus'] = assetStatus.toJson();
|
||||
}
|
||||
if (assetNotScraped != null) {
|
||||
map['assetNotScraped'] = assetNotScraped.toJson();
|
||||
}
|
||||
if (assetNo != null && assetNo.isNotEmpty) map['assetNo'] = assetNo;
|
||||
if (modelDefinition != null && modelDefinition.isNotEmpty) map['modelDefinition'] = modelDefinition;
|
||||
if (site != null && site.isNotEmpty) map['site'] = site;
|
||||
if (manufacturer != null && manufacturer.isNotEmpty) map['manufacturer'] = manufacturer;
|
||||
if (model != null && model.isNotEmpty) map['model'] = model;
|
||||
if (department != null && department.isNotEmpty) map['department'] = department;
|
||||
if (supplier != null && supplier.isNotEmpty) map['supplier'] = supplier;
|
||||
if (tagCode != null && tagCode.isNotEmpty) map['tagCode'] = tagCode;
|
||||
if (assetGroupName != null && assetGroupName.isNotEmpty) map['assetGroupName'] = assetGroupName;
|
||||
if (assetGroup != null) {
|
||||
map['assetGroup'] = assetGroup.toJson();
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,85 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:test_sa/controllers/providers/api/devices_provider.dart';
|
||||
import 'package:test_sa/extensions/context_extension.dart';
|
||||
import 'package:test_sa/extensions/int_extensions.dart';
|
||||
import 'package:test_sa/extensions/widget_extensions.dart';
|
||||
import 'package:test_sa/models/new_models/department.dart';
|
||||
import 'package:test_sa/models/new_models/site.dart';
|
||||
import 'package:test_sa/new_views/common_widgets/app_filled_button.dart';
|
||||
import 'package:test_sa/new_views/common_widgets/single_item_drop_down_menu.dart';
|
||||
import 'package:test_sa/providers/department_provider.dart';
|
||||
import 'package:test_sa/providers/gas_request_providers/site_provider.dart';
|
||||
|
||||
import '../../../models/device/asset_search.dart';
|
||||
import '../../../new_views/common_widgets/app_lazy_loading.dart';
|
||||
import '../../../new_views/common_widgets/default_app_bar.dart';
|
||||
|
||||
class AssetFilterScreen extends StatefulWidget {
|
||||
static const String id = "asset_filter_screen";
|
||||
final AssetSearch data;
|
||||
const AssetFilterScreen({Key key, this.data}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<AssetFilterScreen> createState() => _AssetFilterScreenState();
|
||||
}
|
||||
|
||||
class _AssetFilterScreenState extends State<AssetFilterScreen> {
|
||||
AssetSearch filter;
|
||||
Site _site;
|
||||
Department _department;
|
||||
@override
|
||||
void initState() {
|
||||
filter = widget.data ?? AssetSearch();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: DefaultAppBar(title: context.translation.filter),
|
||||
body: Column(
|
||||
children: [
|
||||
SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
// context.translation.equipmentStatus.heading5(context),
|
||||
// 16.height,
|
||||
SingleItemDropDownMenu<Department, DepartmentProvider>(
|
||||
context: context,
|
||||
title: context.translation.byDepartment,
|
||||
initialValue: _department,
|
||||
onSelect: (value) {
|
||||
_department = value;
|
||||
},
|
||||
),
|
||||
8.height,
|
||||
SingleItemDropDownMenu<Site, SiteProvider>(
|
||||
context: context,
|
||||
title: context.translation.bySite,
|
||||
initialValue: _site,
|
||||
onSelect: (value) {
|
||||
_site = value;
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
).expanded,
|
||||
AppFilledButton(onPressed: _search, label: context.translation.applyFilter),
|
||||
],
|
||||
).paddingAll(16),
|
||||
);
|
||||
}
|
||||
|
||||
void _search() async {
|
||||
filter.site = _site?.name;
|
||||
filter.department = _department?.departmentName;
|
||||
final deviceProvider = Provider.of<AssetProvider>(context, listen: false);
|
||||
deviceProvider.reset();
|
||||
showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading());
|
||||
await deviceProvider.getAssets(search: filter);
|
||||
Navigator.pop(context);
|
||||
Navigator.of(context).pop(filter);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,149 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:test_sa/controllers/providers/api/devices_provider.dart';
|
||||
import 'package:test_sa/extensions/context_extension.dart';
|
||||
import 'package:test_sa/extensions/int_extensions.dart';
|
||||
import 'package:test_sa/extensions/text_extensions.dart';
|
||||
import 'package:test_sa/extensions/widget_extensions.dart';
|
||||
import 'package:test_sa/new_views/common_widgets/app_filled_button.dart';
|
||||
import 'package:test_sa/new_views/common_widgets/app_text_form_field.dart';
|
||||
|
||||
import '../../../models/device/asset_search.dart';
|
||||
import '../../../new_views/common_widgets/app_lazy_loading.dart';
|
||||
import '../../../new_views/common_widgets/default_app_bar.dart';
|
||||
|
||||
class AssetSearchScreen extends StatefulWidget {
|
||||
static const String id = "asset_search_screen";
|
||||
final AssetSearch data;
|
||||
const AssetSearchScreen({Key key, this.data}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<AssetSearchScreen> createState() => _AssetSearchScreenState();
|
||||
}
|
||||
|
||||
class _AssetSearchScreenState extends State<AssetSearchScreen> {
|
||||
AssetSearch search;
|
||||
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
search = widget.data ?? AssetSearch();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: DefaultAppBar(title: context.translation.search),
|
||||
body: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
children: [
|
||||
SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
context.translation.searchBy.heading5(context),
|
||||
8.height,
|
||||
context.translation.searchByDesc.bodyText(context),
|
||||
16.height,
|
||||
AppTextFormField(
|
||||
labelText: context.translation.assetName,
|
||||
initialValue: search.assetName,
|
||||
onSaved: (value) {
|
||||
search.assetName = value;
|
||||
},
|
||||
),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
labelText: context.translation.assetNumber,
|
||||
initialValue: search.assetNo,
|
||||
onSaved: (value) {
|
||||
search.assetNo = value;
|
||||
},
|
||||
),
|
||||
8.height,
|
||||
|
||||
/// todo : TBD (no matched parameter)
|
||||
AppTextFormField(
|
||||
labelText: context.translation.oracleCode,
|
||||
onSaved: (value) {},
|
||||
),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
labelText: context.translation.snNumber,
|
||||
initialValue: search.assetSerialNumber,
|
||||
onSaved: (value) {
|
||||
search.assetSerialNumber = value;
|
||||
},
|
||||
),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
labelText: context.translation.model,
|
||||
initialValue: search.model,
|
||||
onSaved: (value) {
|
||||
search.model = value;
|
||||
},
|
||||
),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
labelText: context.translation.supplier,
|
||||
initialValue: search.supplier,
|
||||
onSaved: (value) {
|
||||
search.supplier = value;
|
||||
},
|
||||
),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
labelText: context.translation.site,
|
||||
initialValue: search.site,
|
||||
onSaved: (value) {
|
||||
search.site = value;
|
||||
},
|
||||
),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
labelText: context.translation.manufacture,
|
||||
initialValue: search.manufacturer,
|
||||
onSaved: (value) {
|
||||
search.manufacturer = value;
|
||||
},
|
||||
),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
labelText: context.translation.md,
|
||||
initialValue: search.modelDefinition,
|
||||
onSaved: (value) {
|
||||
search.modelDefinition = value;
|
||||
},
|
||||
),
|
||||
8.height,
|
||||
|
||||
/// todo : TBD (no matched parameter)
|
||||
AppTextFormField(
|
||||
labelText: context.translation.location,
|
||||
onSaved: (value) {},
|
||||
),
|
||||
8.height,
|
||||
],
|
||||
),
|
||||
).expanded,
|
||||
AppFilledButton(onPressed: _search, label: context.translation.search),
|
||||
],
|
||||
).paddingAll(16),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _search() async {
|
||||
if (_formKey.currentState.validate()) {
|
||||
_formKey.currentState.save();
|
||||
final deviceProvider = Provider.of<AssetProvider>(context, listen: false);
|
||||
deviceProvider.reset();
|
||||
showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading());
|
||||
await deviceProvider.getAssets(search: search);
|
||||
Navigator.pop(context);
|
||||
Navigator.of(context).pop(search);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue