diff --git a/projects/uiowa/uiowa-mfk/src/lib/models/mfk-tools.ts b/projects/uiowa/uiowa-mfk/src/lib/models/mfk-tools.ts index 6c7fc2e..8c1942c 100644 --- a/projects/uiowa/uiowa-mfk/src/lib/models/mfk-tools.ts +++ b/projects/uiowa/uiowa-mfk/src/lib/models/mfk-tools.ts @@ -67,3 +67,46 @@ export function validFormat(mfk: Mfk): boolean { } return true; } + +/** + * checks if each field of an Mfk object is in a valid format + * returns an array of error messages + * If the format is valid, then the returning array is empty. + */ +export function validateStructure(mfk: Mfk): string[] { + const result: string[] = []; + if (mfk.fund?.length !== 3) { + result.push(`Invalid Fund: Length is incorrect (must be 3 digits)`); + } + if (mfk.org?.length !== 2) { + result.push(`Invalid Org: Length is incorrect (must be 2 digits)`); + } + if (mfk.dept?.length !== 4) { + result.push(`Invalid Dept: Length is incorrect (must be 4 digits)`); + } + if (mfk.subdept?.length !== 5) { + result.push(`Invalid Subdept: Length is incorrect (must be 5 digits)`); + } + if (mfk.grantpgm?.length !== 8) { + result.push(`Invalid Grant/Pgm: Length is incorrect (must be 8 digits)`); + } + if (mfk.iact?.length !== 4) { + result.push(`Invalid Iact: Length is incorrect (must be 4 digits)`); + } + if (mfk.oact?.length !== 3) { + result.push(`Invalid Oact: Length is incorrect (must be 3 digits)`); + } + if (mfk.dact?.length !== 5) { + result.push(`Invalid Dact: Length is incorrect (must be 5 digits)`); + } + if (mfk.fn?.length !== 2) { + result.push(`Invalid Fn: Length is incorrect (must be 2 digits)`); + } + if (mfk.cctr?.length !== 4) { + result.push(`Invalid Cctr: Length is incorrect (must be 4 digits)`); + } + if (mfk.brf && mfk.brf.length !== 2) { + result.push(`Invalid Brf: Length is incorrect (must be 2 digits)`); + } + return result; +} diff --git a/src/app/actions/actions.component.html b/src/app/actions/actions.component.html index 7e0f79c..17c8c94 100644 --- a/src/app/actions/actions.component.html +++ b/src/app/actions/actions.component.html @@ -21,16 +21,16 @@

MFK input with configurable options

-
-
-
-
+
-
-
+
+
-
-
-
+
+
-
@@ -69,7 +69,7 @@
+
+

{{ e }}

+
{{ validationResult | json }}
diff --git a/src/app/mfk-validations/mfk-validations.component.ts b/src/app/mfk-validations/mfk-validations.component.ts index da6a540..92f839a 100644 --- a/src/app/mfk-validations/mfk-validations.component.ts +++ b/src/app/mfk-validations/mfk-validations.component.ts @@ -4,6 +4,7 @@ import { Mfk, MfkString, stringify, + validateStructure, } from 'projects/uiowa/uiowa-mfk/src/public-api'; import { emptyMfk } from '@uiowa/uiowa-mfk'; @@ -24,6 +25,7 @@ interface MfkValidationResult { }) export class MfkValidationsComponent implements OnInit { mfk1: Mfk = emptyMfk(); + mfkStructureErrors: string[] = []; validationResult: MfkValidationResult = { statusCode: 0, statusMessage: '', @@ -40,10 +42,11 @@ export class MfkValidationsComponent implements OnInit { } validateMfk1() { - const mfk40String = stringify(this.mfk1).replace(/-/g, ''); - if (mfk40String.length !== 40) { + this.mfkStructureErrors = validateStructure(this.mfk1); + if (this.mfkStructureErrors.length) { return; } + const mfk40String = stringify(this.mfk1).replace(/-/g, ''); const url = `https://apps.its.uiowa.edu/mfk/api-singleDesc.jsp?mfk=10%20%20%20${mfk40String}`; return this.httpClient.get(url, { responseType: 'text' }).subscribe((x) => { const parts = x.split(/\n/); diff --git a/src/app/split-cost/split-cost.component.html b/src/app/split-cost/split-cost.component.html index a680f5d..6afc4f2 100644 --- a/src/app/split-cost/split-cost.component.html +++ b/src/app/split-cost/split-cost.component.html @@ -2,19 +2,19 @@
-
MFK(s)
+
MFK(s)
-
+

Percentage

- Total: + Total:
{{ total }} % @@ -98,7 +98,7 @@