diff --git a/lib/admin/ObservationList2.xlsx b/lib/admin/ObservationList2.xlsx index e8dc10f..61eeb8e 100644 Binary files a/lib/admin/ObservationList2.xlsx and b/lib/admin/ObservationList2.xlsx differ diff --git a/lib/admin/generate_job_plans.dart b/lib/admin/generate_job_plans.dart index f27335d..a392304 100644 --- a/lib/admin/generate_job_plans.dart +++ b/lib/admin/generate_job_plans.dart @@ -373,7 +373,9 @@ Future generatePM(ParsedTemplate pmDetails, PMName pmName, if (!frequencyUnits.contains(pmDetails.frequencyUnit)) { throw Exception('Frequency Unit "${pmDetails.frequency}" is invalid'); } - if ((pmDetails.frequency ?? 0) < 1 && pmDetails.frequencyUnit != 'J') { + if ((pmDetails.frequency ?? 0) < 1 && + pmDetails.frequencyUnit != 'J' && + pmDetails.frequencyUnit != 'D') { throw Exception('Frequency "${pmDetails.frequency}" is invalid'); } if (pmDetails.frequencyUnit == 'J') { diff --git a/lib/admin/upload_maximo.dart b/lib/admin/upload_maximo.dart index 61482d1..83ff07e 100644 --- a/lib/admin/upload_maximo.dart +++ b/lib/admin/upload_maximo.dart @@ -4,6 +4,7 @@ import 'package:flutter/widgets.dart'; import 'package:iko_reliability_flutter/bin/db_drift.dart'; import 'package:iko_reliability_flutter/admin/settings.dart'; import 'package:iko_reliability_flutter/admin/template_notifier.dart'; +import 'package:iko_reliability_flutter/main.dart'; import '../creation/asset_creation_notifier.dart'; import '../bin/consts.dart'; import 'package:http/http.dart' as http; @@ -770,6 +771,10 @@ Future> maximoRequest(String url, String type, String env, } else { header['apikey'] = login.password; } + while (connectionPool > 1) { + await Future.delayed(const Duration(milliseconds: 100)); + } + connectionPool++; http.Response response; if (type == 'get' || type == 'api') { if (type == 'api') { @@ -781,6 +786,7 @@ Future> maximoRequest(String url, String type, String env, return {'status': 'Failed to Connect'}; } debugPrint('get response received'); + connectionPool--; var parsed = jsonDecode(response.body); if (response.statusCode == 200) { if (parsed['member'] != null) { diff --git a/lib/bin/consts.dart b/lib/bin/consts.dart index d763da9..d615aeb 100644 --- a/lib/bin/consts.dart +++ b/lib/bin/consts.dart @@ -127,7 +127,6 @@ final siteIDAndOrgID = { 'GE': 'IKO-CAD', 'GH': 'IKO-CAD', 'GI': 'IKO-CAD', - 'GJ': 'IKO-CAD', 'GK': 'IKO-CAD', 'GM': 'IKO-CAD', 'GP': 'IKO-CAD', @@ -162,7 +161,6 @@ final siteIDAndDescription = { 'PBM': 'Senica', 'GC': 'Sumas', 'GS': 'Sylacauga', - 'GJ': 'CRC Toronto', }; const tableHeaders = { @@ -308,13 +306,16 @@ const tableHeaders = { Map maximoServerDomains = { 'MASDEV': 'https://dev.manage.dev.iko.max-it-eam.com/maximo/api/os/', 'MASTEST': 'https://test.manage.test.iko.max-it-eam.com/maximo/api/os/', - 'MASPROD': 'https://prod.manage.prod.iko.max-it-eam.com/maximo/api/os/' + 'MASPROD': 'https://prod.manage.prod.iko.max-it-eam.com/maximo/api/os/', + 'DEV 8.11': + 'https://development.manage.development.iko.max-it-eam.com/maximo/api/os/', }; Map apiKeys = { 'MASDEV': '', //'n075qt6edkgf931ike9pegc3vejbbtgalabbrrrf' 'MASTEST': '', //'n075qt6edkgf931ike9pegc3vejbbtgalabbrrrf' 'MASPROD': '', + 'DEV 8.11': '', }; Map> frequencyRating = { diff --git a/lib/bin/db_drift.dart b/lib/bin/db_drift.dart index c5f8715..40d9fd1 100644 --- a/lib/bin/db_drift.dart +++ b/lib/bin/db_drift.dart @@ -165,6 +165,7 @@ class Workorders extends Table { RealColumn get downtime => real()(); TextColumn get type => text()(); TextColumn get assetnum => text()(); + TextColumn get details => text().nullable()(); @override Set get primaryKey => {siteid, wonum}; @@ -388,7 +389,23 @@ class MyDatabase extends _$MyDatabase { MyDatabase.forTesting(DatabaseConnection super.connection); // you should bump this number whenever you change or add a table definition. @override - int get schemaVersion => 1; + int get schemaVersion => 2; + + @override + MigrationStrategy get migration { + return MigrationStrategy( + onCreate: (Migrator m) async { + await m.createAll(); + }, + onUpgrade: (Migrator m, int from, int to) async { + if (from < 2) { + // we added the details property in the change from version 1 to + // version 2 + await m.addColumn(workorders, workorders.details); + } + }, + ); + } void clearMeters() { delete(meterDBs).go(); @@ -792,7 +809,7 @@ class MyDatabase extends _$MyDatabase { Future getWorkOrderMaximo(String assetnum, String env) async { // maybe a return to indicate completion final result = await maximoRequest( - 'iko_wo?oslc.select=wonum,siteid,description,status,reportdate,IKO_DOWNTIME,WORKTYPE,assetnum&oslc.where=assetnum="$assetnum" and IKO_DOWNTIME>0', + 'iko_wo?oslc.select=wonum,siteid,description,status,reportdate,IKO_DOWNTIME,WORKTYPE,assetnum,DESCRIPTION_LONGDESCRIPTION&oslc.where=assetnum="$assetnum" and IKO_DOWNTIME>0', 'get', env); if (result['member'].length > 0) { @@ -809,6 +826,9 @@ class MyDatabase extends _$MyDatabase { type: row['worktype'], reportdate: row['reportdate'], assetnum: row['assetnum'], + details: Value(row['description_longdescription'] + .toString() + .replaceAll(RegExp(r'<[^>]+>'), '')), ), ); } diff --git a/lib/bin/db_drift.g.dart b/lib/bin/db_drift.g.dart index 0cada9f..be867ed 100644 --- a/lib/bin/db_drift.g.dart +++ b/lib/bin/db_drift.g.dart @@ -1546,6 +1546,12 @@ class $WorkordersTable extends Workorders late final GeneratedColumn assetnum = GeneratedColumn( 'assetnum', aliasedName, false, type: DriftSqlType.string, requiredDuringInsert: true); + static const VerificationMeta _detailsMeta = + const VerificationMeta('details'); + @override + late final GeneratedColumn details = GeneratedColumn( + 'details', aliasedName, true, + type: DriftSqlType.string, requiredDuringInsert: false); @override List get $columns => [ wonum, @@ -1555,7 +1561,8 @@ class $WorkordersTable extends Workorders reportdate, downtime, type, - assetnum + assetnum, + details ]; @override String get aliasedName => _alias ?? actualTableName; @@ -1619,6 +1626,10 @@ class $WorkordersTable extends Workorders } else if (isInserting) { context.missing(_assetnumMeta); } + if (data.containsKey('details')) { + context.handle(_detailsMeta, + details.isAcceptableOrUnknown(data['details']!, _detailsMeta)); + } return context; } @@ -1644,6 +1655,8 @@ class $WorkordersTable extends Workorders .read(DriftSqlType.string, data['${effectivePrefix}type'])!, assetnum: attachedDatabase.typeMapping .read(DriftSqlType.string, data['${effectivePrefix}assetnum'])!, + details: attachedDatabase.typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}details']), ); } @@ -1662,6 +1675,7 @@ class Workorder extends DataClass implements Insertable { final double downtime; final String type; final String assetnum; + final String? details; const Workorder( {required this.wonum, required this.description, @@ -1670,7 +1684,8 @@ class Workorder extends DataClass implements Insertable { required this.reportdate, required this.downtime, required this.type, - required this.assetnum}); + required this.assetnum, + this.details}); @override Map toColumns(bool nullToAbsent) { final map = {}; @@ -1682,6 +1697,9 @@ class Workorder extends DataClass implements Insertable { map['downtime'] = Variable(downtime); map['type'] = Variable(type); map['assetnum'] = Variable(assetnum); + if (!nullToAbsent || details != null) { + map['details'] = Variable(details); + } return map; } @@ -1695,6 +1713,9 @@ class Workorder extends DataClass implements Insertable { downtime: Value(downtime), type: Value(type), assetnum: Value(assetnum), + details: details == null && nullToAbsent + ? const Value.absent() + : Value(details), ); } @@ -1710,6 +1731,7 @@ class Workorder extends DataClass implements Insertable { downtime: serializer.fromJson(json['downtime']), type: serializer.fromJson(json['type']), assetnum: serializer.fromJson(json['assetnum']), + details: serializer.fromJson(json['details']), ); } @override @@ -1724,6 +1746,7 @@ class Workorder extends DataClass implements Insertable { 'downtime': serializer.toJson(downtime), 'type': serializer.toJson(type), 'assetnum': serializer.toJson(assetnum), + 'details': serializer.toJson(details), }; } @@ -1735,7 +1758,8 @@ class Workorder extends DataClass implements Insertable { String? reportdate, double? downtime, String? type, - String? assetnum}) => + String? assetnum, + Value details = const Value.absent()}) => Workorder( wonum: wonum ?? this.wonum, description: description ?? this.description, @@ -1745,6 +1769,7 @@ class Workorder extends DataClass implements Insertable { downtime: downtime ?? this.downtime, type: type ?? this.type, assetnum: assetnum ?? this.assetnum, + details: details.present ? details.value : this.details, ); @override String toString() { @@ -1756,14 +1781,15 @@ class Workorder extends DataClass implements Insertable { ..write('reportdate: $reportdate, ') ..write('downtime: $downtime, ') ..write('type: $type, ') - ..write('assetnum: $assetnum') + ..write('assetnum: $assetnum, ') + ..write('details: $details') ..write(')')) .toString(); } @override - int get hashCode => Object.hash( - wonum, description, status, siteid, reportdate, downtime, type, assetnum); + int get hashCode => Object.hash(wonum, description, status, siteid, + reportdate, downtime, type, assetnum, details); @override bool operator ==(Object other) => identical(this, other) || @@ -1775,7 +1801,8 @@ class Workorder extends DataClass implements Insertable { other.reportdate == this.reportdate && other.downtime == this.downtime && other.type == this.type && - other.assetnum == this.assetnum); + other.assetnum == this.assetnum && + other.details == this.details); } class WorkordersCompanion extends UpdateCompanion { @@ -1787,6 +1814,7 @@ class WorkordersCompanion extends UpdateCompanion { final Value downtime; final Value type; final Value assetnum; + final Value details; final Value rowid; const WorkordersCompanion({ this.wonum = const Value.absent(), @@ -1797,6 +1825,7 @@ class WorkordersCompanion extends UpdateCompanion { this.downtime = const Value.absent(), this.type = const Value.absent(), this.assetnum = const Value.absent(), + this.details = const Value.absent(), this.rowid = const Value.absent(), }); WorkordersCompanion.insert({ @@ -1808,6 +1837,7 @@ class WorkordersCompanion extends UpdateCompanion { required double downtime, required String type, required String assetnum, + this.details = const Value.absent(), this.rowid = const Value.absent(), }) : wonum = Value(wonum), description = Value(description), @@ -1826,6 +1856,7 @@ class WorkordersCompanion extends UpdateCompanion { Expression? downtime, Expression? type, Expression? assetnum, + Expression? details, Expression? rowid, }) { return RawValuesInsertable({ @@ -1837,6 +1868,7 @@ class WorkordersCompanion extends UpdateCompanion { if (downtime != null) 'downtime': downtime, if (type != null) 'type': type, if (assetnum != null) 'assetnum': assetnum, + if (details != null) 'details': details, if (rowid != null) 'rowid': rowid, }); } @@ -1850,6 +1882,7 @@ class WorkordersCompanion extends UpdateCompanion { Value? downtime, Value? type, Value? assetnum, + Value? details, Value? rowid}) { return WorkordersCompanion( wonum: wonum ?? this.wonum, @@ -1860,6 +1893,7 @@ class WorkordersCompanion extends UpdateCompanion { downtime: downtime ?? this.downtime, type: type ?? this.type, assetnum: assetnum ?? this.assetnum, + details: details ?? this.details, rowid: rowid ?? this.rowid, ); } @@ -1891,6 +1925,9 @@ class WorkordersCompanion extends UpdateCompanion { if (assetnum.present) { map['assetnum'] = Variable(assetnum.value); } + if (details.present) { + map['details'] = Variable(details.value); + } if (rowid.present) { map['rowid'] = Variable(rowid.value); } @@ -1908,6 +1945,7 @@ class WorkordersCompanion extends UpdateCompanion { ..write('downtime: $downtime, ') ..write('type: $type, ') ..write('assetnum: $assetnum, ') + ..write('details: $details, ') ..write('rowid: $rowid') ..write(')')) .toString(); diff --git a/lib/criticality/asset_criticality.dart b/lib/criticality/asset_criticality.dart index 0acef69..ab328e2 100644 --- a/lib/criticality/asset_criticality.dart +++ b/lib/criticality/asset_criticality.dart @@ -111,6 +111,13 @@ class _AssetCriticalityPageState extends State { field: 'included', type: PlutoColumnType.text(), ), + PlutoColumn( + width: 400, + readOnly: true, + title: 'Details', + field: 'details', + type: PlutoColumnType.text(), + ), ]); // Columns for Assets @@ -421,6 +428,7 @@ class _AssetCriticalityPageState extends State { 'downtime': PlutoCell(value: wo.downtime), 'site': PlutoCell(value: siteIDAndDescription[wo.siteid]), 'included': PlutoCell(value: ('Yes')), + 'details': PlutoCell(value: wo.details), }, )); } else { @@ -434,6 +442,7 @@ class _AssetCriticalityPageState extends State { 'downtime': PlutoCell(value: wo.downtime), 'site': PlutoCell(value: siteIDAndDescription[wo.siteid]), 'included': PlutoCell(value: ('No')), + 'details': PlutoCell(value: wo.details), }, )); } @@ -523,11 +532,8 @@ class _AssetCriticalityPageState extends State { ); } catch (e) { previousStatus = AssetStatus.refreshError; - ScaffoldMessenger.of(navigatorKey.currentContext!).showSnackBar(SnackBar( - content: Text( - 'Error retriving Work Orders from Maximo for: $assetnum \n ${e.toString()}'), - )); - return; + throw Exception( + 'Error retriving Work Orders from Maximo for: $assetnum \n ${e.toString()}'); } // bring back previous status Icon if (context.mounted) { diff --git a/lib/criticality/system_criticality.dart b/lib/criticality/system_criticality.dart index dbe14cc..6938c1d 100644 --- a/lib/criticality/system_criticality.dart +++ b/lib/criticality/system_criticality.dart @@ -387,7 +387,7 @@ class _SystemCriticalityPageState extends State { ? const PlutoGridStyleConfig.dark() : const PlutoGridStyleConfig(), ), - onChanged: (PlutoGridOnChangedEvent event) { + onChanged: (PlutoGridOnChangedEvent event) async { // score should auto calcualte when values change event.row.cells['score']!.value = sqrt( (event.row.cells['safety']?.value * @@ -403,6 +403,9 @@ class _SystemCriticalityPageState extends State { 5); updateSystem(event.row) .then((value) => event.row.cells['id']!.value = value); + context.read().systems = + await database!.getSystemCriticalitiesFiltered( + context.read().selectedSite); debugPrint('$event'); }, onLoaded: (PlutoGridOnLoadedEvent event) { diff --git a/lib/main.dart b/lib/main.dart index 405d31e..b0e2676 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -30,6 +30,7 @@ import 'routes/route.dart'; MyDatabase? database; final navigatorKey = GlobalKey(); Logger? logger; +int connectionPool = 0; void main() async { WidgetsFlutterBinding.ensureInitialized(); diff --git a/pubspec.yaml b/pubspec.yaml index caee23d..9cdff28 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: IKO Reliability Tool publish_to: 'none' # Remove this line if you wish to publish to pub.dev -version: 1.3.1 +version: 1.3.2 environment: sdk: '>=3.0.0 <=4.0.0'