Skip to content

Commit

Permalink
limit connections, WO details, update system select list
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanmajh committed May 23, 2024
1 parent 087667d commit 16b79cb
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 20 deletions.
Binary file modified lib/admin/ObservationList2.xlsx
Binary file not shown.
4 changes: 3 additions & 1 deletion lib/admin/generate_job_plans.dart
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,9 @@ Future<PMMaximo> 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') {
Expand Down
6 changes: 6 additions & 0 deletions lib/admin/upload_maximo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -770,6 +771,10 @@ Future<Map<String, dynamic>> 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') {
Expand All @@ -781,6 +786,7 @@ Future<Map<String, dynamic>> 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) {
Expand Down
7 changes: 4 additions & 3 deletions lib/bin/consts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -162,7 +161,6 @@ final siteIDAndDescription = {
'PBM': 'Senica',
'GC': 'Sumas',
'GS': 'Sylacauga',
'GJ': 'CRC Toronto',
};

const tableHeaders = {
Expand Down Expand Up @@ -308,13 +306,16 @@ const tableHeaders = {
Map<String, String> 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<String, String> apiKeys = {
'MASDEV': '', //'n075qt6edkgf931ike9pegc3vejbbtgalabbrrrf'
'MASTEST': '', //'n075qt6edkgf931ike9pegc3vejbbtgalabbrrrf'
'MASPROD': '',
'DEV 8.11': '',
};

Map<int, Map<String, dynamic>> frequencyRating = {
Expand Down
24 changes: 22 additions & 2 deletions lib/bin/db_drift.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Column> get primaryKey => {siteid, wonum};
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand All @@ -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'<[^>]+>'), '')),
),
);
}
Expand Down
52 changes: 45 additions & 7 deletions lib/bin/db_drift.g.dart

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

16 changes: 11 additions & 5 deletions lib/criticality/asset_criticality.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ class _AssetCriticalityPageState extends State<AssetCriticalityPage> {
field: 'included',
type: PlutoColumnType.text(),
),
PlutoColumn(
width: 400,
readOnly: true,
title: 'Details',
field: 'details',
type: PlutoColumnType.text(),
),
]);

// Columns for Assets
Expand Down Expand Up @@ -421,6 +428,7 @@ class _AssetCriticalityPageState extends State<AssetCriticalityPage> {
'downtime': PlutoCell(value: wo.downtime),
'site': PlutoCell(value: siteIDAndDescription[wo.siteid]),
'included': PlutoCell(value: ('Yes')),
'details': PlutoCell(value: wo.details),
},
));
} else {
Expand All @@ -434,6 +442,7 @@ class _AssetCriticalityPageState extends State<AssetCriticalityPage> {
'downtime': PlutoCell(value: wo.downtime),
'site': PlutoCell(value: siteIDAndDescription[wo.siteid]),
'included': PlutoCell(value: ('No')),
'details': PlutoCell(value: wo.details),
},
));
}
Expand Down Expand Up @@ -523,11 +532,8 @@ class _AssetCriticalityPageState extends State<AssetCriticalityPage> {
);
} 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) {
Expand Down
Loading

0 comments on commit 16b79cb

Please sign in to comment.