Skip to content

Commit

Permalink
- Refactor Civil Past/Future Appearances to centralize info extraction
Browse files Browse the repository at this point in the history
- Pass commonStore param instead of accessing it using directly from utils
  • Loading branch information
Ronaldo Macapobre committed Dec 9, 2024
1 parent f7aa722 commit 3b5f987
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 130 deletions.
65 changes: 17 additions & 48 deletions web/src/components/civil/CivilFutureAppearances.vue
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,13 @@

<script lang="ts">
import CivilAppearanceDetails from '@/components/civil/CivilAppearanceDetails.vue';
import { beautifyDate } from '@/filters';
import { useCivilFileStore, useCommonStore } from '@/stores';
import { civilAppearancesListType } from '@/types/civil';
import { civilApprDetailType } from '@/types/civil/jsonTypes';
import { extractCivilAppearancesInfo } from '@/utils/utils';
import * as _ from 'underscore';
import { computed, defineComponent, onMounted, ref } from 'vue';
enum appearanceStatus {
UNCF = 'Unconfirmed',
CNCL = 'Canceled',
SCHD = 'Scheduled',
}
export default defineComponent({
components: {
CivilAppearanceDetails,
Expand All @@ -159,7 +153,7 @@
const isDataReady = ref(false);
const futureAppearancesList = ref<civilAppearancesListType[]>([]);
const futureAppearancesJson = ref<civilApprDetailType[]>([]);
let futureAppearancesJson: civilApprDetailType[] = [];
const sortBy = ref('date');
const sortDesc = ref(true);
Expand Down Expand Up @@ -279,7 +273,7 @@
const getFutureAppearances = () => {
const data = civilFileStore.civilFileInformation.detailsData;
futureAppearancesJson.value = data.appearances.apprDetail;
futureAppearancesJson = [...data.appearances.apprDetail];
ExtractFutureAppearancesInfo();
if (futureAppearancesList.value.length) {
isDataReady.value = true;
Expand All @@ -290,45 +284,20 @@
const ExtractFutureAppearancesInfo = () => {
const currentDate = new Date();
for (const appIndex in futureAppearancesJson.value) {
const appInfo = {} as civilAppearancesListType;
const jApp = futureAppearancesJson.value[appIndex];
appInfo.index = appIndex;
appInfo.date = jApp.appearanceDt.split(' ')[0];
if (new Date(appInfo.date) < currentDate) continue;
appInfo.formattedDate = beautifyDate(appInfo.date);
appInfo.documentType = jApp.documentTypeDsc
? jApp.documentTypeDsc
: '';
appInfo.result = jApp.appearanceResultCd;
appInfo.resultDescription = jApp.appearanceResultDsc
? jApp.appearanceResultDsc
: '';
appInfo.time = getTime(jApp.appearanceTm.split(' ')[1].substr(0, 5));
appInfo.reason = jApp.appearanceReasonCd;
appInfo.reasonDescription = jApp.appearanceReasonDsc
? jApp.appearanceReasonDsc
: '';
appInfo.duration = getDuration(
jApp.estimatedTimeHour,
jApp.estimatedTimeMin
);
appInfo.location = jApp.courtLocation ? jApp.courtLocation : '';
appInfo.room = jApp.courtRoomCd;
appInfo.status = jApp.appearanceStatusCd
? appearanceStatus[jApp.appearanceStatusCd]
: '';
appInfo.statusStyle = getStatusStyle(appInfo.status);
appInfo.presider = jApp.judgeInitials ? jApp.judgeInitials : '';
appInfo.judgeFullName = jApp.judgeInitials ? jApp.judgeFullNm : '';
appInfo.appearanceId = jApp.appearanceId;
appInfo.supplementalEquipment = jApp.supplementalEquipmentTxt;
appInfo.securityRestriction = jApp.securityRestrictionTxt;
appInfo.outOfTownJudge = jApp.outOfTownJudgeTxt;
futureAppearancesList.value.push(appInfo);
}
futureAppearancesJson.forEach(
(jApp: civilApprDetailType, index: number) => {
const appearanceDate = jApp.appearanceDt.split(' ')[0];
if (new Date(appearanceDate) < currentDate) return;
const appInfo = extractCivilAppearancesInfo(
jApp,
index,
commonStore
);
futureAppearancesList.value.push(appInfo);
}
);
};
const getStatusStyle = (status) => {
Expand Down
67 changes: 17 additions & 50 deletions web/src/components/civil/CivilPastAppearances.vue
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,12 @@
import { civilAppearancesListType } from '@/types/civil';
import { civilApprDetailType } from '@/types/civil/jsonTypes';
import { CourtDocumentType, DocumentData } from '@/types/shared';
import { extractCivilAppearancesInfo } from '@/utils/utils';
import * as _ from 'underscore';
import { computed, defineComponent, inject, onMounted, ref } from 'vue';
import { useRoute } from 'vue-router';
import shared from '../shared';
enum appearanceStatus {
UNCF = 'Unconfirmed',
CNCL = 'Canceled',
SCHD = 'Scheduled',
}
export default defineComponent({
components: {
CivilAppearanceDetails,
Expand All @@ -194,7 +189,7 @@
const isMounted = ref(false);
const isDataReady = ref(false);
const pastAppearancesJson = ref<civilApprDetailType[]>([]);
let pastAppearancesJson: civilApprDetailType[] = [];
const sortBy = ref('date');
const sortDesc = ref(true);
const fromA2a = ref(false);
Expand Down Expand Up @@ -300,7 +295,7 @@
const getPastAppearances = () => {
const data = civilFileStore.civilFileInformation.detailsData;
pastAppearancesJson.value = data.appearances.apprDetail;
pastAppearancesJson = [...data.appearances.apprDetail];
ExtractPastAppearancesInfo();
if (pastAppearancesList.value.length) {
isDataReady.value = true;
Expand All @@ -310,48 +305,20 @@
const ExtractPastAppearancesInfo = () => {
const currentDate = new Date();
for (const appIndex in pastAppearancesJson.value) {
const appInfo = {} as civilAppearancesListType;
const jApp = pastAppearancesJson.value[appIndex];
appInfo.index = appIndex;
appInfo.date = jApp.appearanceDt.split(' ')[0];
if (new Date(appInfo.date) >= currentDate) continue;
appInfo.formattedDate = beautifyDate(appInfo.date);
appInfo.documentType = jApp.documentTypeDsc
? jApp.documentTypeDsc
: '';
appInfo.result = jApp.appearanceResultCd;
appInfo.resultDescription = jApp.appearanceResultDsc
? jApp.appearanceResultDsc
: '';
appInfo.time = getTime(
jApp.appearanceTm.split(' ')[1].substring(0, 5)
);
appInfo.reason = jApp.appearanceReasonCd;
appInfo.reasonDescription = jApp.appearanceReasonDsc
? jApp.appearanceReasonDsc
: '';
appInfo.duration = getDuration(
jApp.estimatedTimeHour,
jApp.estimatedTimeMin
);
appInfo.location = jApp.courtLocation ? jApp.courtLocation : '';
appInfo.room = jApp.courtRoomCd;
appInfo.status = jApp.appearanceStatusCd
? appearanceStatus[jApp.appearanceStatusCd]
: '';
appInfo.statusStyle = getStatusStyle(appInfo.status);
appInfo.presider = jApp.judgeInitials ? jApp.judgeInitials : '';
appInfo.judgeFullName = jApp.judgeInitials ? jApp.judgeFullNm : '';
appInfo.appearanceId = jApp.appearanceId;
appInfo.supplementalEquipment = jApp.supplementalEquipmentTxt;
appInfo.securityRestriction = jApp.securityRestrictionTxt;
appInfo.outOfTownJudge = jApp.outOfTownJudgeTxt;
pastAppearancesList.value.push(appInfo);
}
pastAppearancesJson.forEach(
(jApp: civilApprDetailType, index: number) => {
const appearanceDate = jApp.appearanceDt.split(' ')[0];
if (new Date(appearanceDate) >= currentDate) return;
const appInfo = extractCivilAppearancesInfo(
jApp,
index,
commonStore
);
pastAppearancesList.value.push(appInfo);
}
);
};
const getStatusStyle = (status) => {
Expand Down
6 changes: 4 additions & 2 deletions web/src/components/criminal/CriminalFutureAppearances.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

<script lang="ts">
import CriminalAppearanceDetails from '@/components/criminal/CriminalAppearanceDetails.vue';
import { useCriminalFileStore } from '@/stores';
import { useCommonStore, useCriminalFileStore } from '@/stores';
import { criminalAppearancesListType } from '@/types/criminal';
import { criminalApprDetailType } from '@/types/criminal/jsonTypes';
import { extractCriminalAppearanceInfo } from '@/utils/utils';
Expand All @@ -50,6 +50,7 @@
},
setup() {
const criminalFileStore = useCriminalFileStore();
const commonStore = useCommonStore();
const futureAppearancesList = ref<criminalAppearancesListType[]>([]);
let futureAppearancesJson: criminalApprDetailType[] = [];
Expand Down Expand Up @@ -81,7 +82,8 @@
const appInfo = extractCriminalAppearanceInfo(
jApp,
index,
appearanceDate
appearanceDate,
commonStore
);
futureAppearancesList.value.push(appInfo);
Expand Down
6 changes: 4 additions & 2 deletions web/src/components/criminal/CriminalPastAppearances.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

<script lang="ts">
import CriminalAppearanceDetails from '@/components/criminal/CriminalAppearanceDetails.vue';
import { useCriminalFileStore } from '@/stores';
import { useCommonStore, useCriminalFileStore } from '@/stores';
import { criminalAppearancesListType } from '@/types/criminal';
import { criminalApprDetailType } from '@/types/criminal/jsonTypes';
import { extractCriminalAppearanceInfo } from '@/utils/utils';
Expand All @@ -56,6 +56,7 @@
},
setup() {
const criminalFileStore = useCriminalFileStore();
const commonStore = useCommonStore();
const pastAppearancesList = ref<criminalAppearancesListType[]>([]);
let pastAppearancesJson: criminalApprDetailType[] = [];
Expand Down Expand Up @@ -88,7 +89,8 @@
const appInfo = extractCriminalAppearanceInfo(
jApp,
index,
appearanceDate
appearanceDate,
commonStore
);
pastAppearancesList.value.push(appInfo);
Expand Down
2 changes: 2 additions & 0 deletions web/src/stores/CommonStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,5 @@ export const useCommonStore = defineStore('CommonStore', {
},
},
});

export type CommonStore = ReturnType<typeof useCommonStore>;
Loading

0 comments on commit 3b5f987

Please sign in to comment.