Skip to content

Commit

Permalink
Merge pull request #7 from icefoganalytics/main
Browse files Browse the repository at this point in the history
Pre demo fixes
  • Loading branch information
datajohnson authored Jun 25, 2024
2 parents 82e275e + 10b7201 commit f3350ad
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 54 deletions.
12 changes: 11 additions & 1 deletion api/src/routes/report-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { isArray } from "lodash";

import { db as knex } from "../data";
import { IncidentService } from "../services";
import { Incident, IncidentAttachment } from "../data/models";
import { Incident, IncidentAttachment, UserRole } from "../data/models";
import { InsertableDate } from "../utils/formatters";

export const reportRouter = express.Router();
Expand All @@ -20,6 +20,16 @@ reportRouter.get("/my-supervisor-reports", async (req: Request, res: Response) =
return res.json({ data: list });
});

reportRouter.get("/role/:role", async (req: Request, res: Response) => {
const { role } = req.params;

const match = req.user.roles.find((r: UserRole) => r.name == role);
if (!match) return res.json({ data: [] });

const list = await db.getAll();
res.json({ data: list });
});

reportRouter.get("/:id", async (req: Request, res: Response) => {
const { id } = req.params;
const list = await db.getById(id);
Expand Down
8 changes: 3 additions & 5 deletions api/src/routes/role-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ roleRouter.post("/user/:user_id", async (req: Request, res: Response) => {

for (const role of roles) {
role.create_user_id = req.user.id;

// TODO: implement date-based activations if necessary
//role.start_date = InsertableDate(role.start_date);
//role.end_date = InsertableDate(role.end_date);
role.start_date = InsertableDate(role.start_date);
role.end_date = InsertableDate(role.end_date);
role.created_at = InsertableDate(new Date().toISOString());

if (isEmpty(role.department_code)) role.department_code = null;
Expand All @@ -50,6 +48,6 @@ function roleForInsert(input: any): UserRole {
created_at: input.created_at,
create_user_id: input.create_user_id,
start_date: input.start_date,
end_date: input.start_date,
end_date: input.end_date,
};
}
25 changes: 23 additions & 2 deletions api/src/services/incident-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@ import { db } from "../data";

export class IncidentService {
async getAll(): Promise<Incident[]> {
return db.from("incidents");
return db<Incident>("incidents")
.innerJoin("incident_types", "incident_types.id", "incidents.incident_type_id")
.innerJoin("incident_statuses", "incident_statuses.code", "incidents.status_code")
.innerJoin("departments", "departments.code", "incidents.department_code")
.select(
"incidents.*",
"incident_types.name as incident_type_name",
"incident_types.description as incident_type_description",
"incident_statuses.name as status_name",
"departments.name as department_name"
);
}

async getById(id: number | string): Promise<Incident | undefined> {
Expand Down Expand Up @@ -46,7 +56,18 @@ export class IncidentService {
}

async getBySupervisorEmail(email: string): Promise<Incident[]> {
return db<Incident>("incidents").where({ supervisor_email: email });
return db<Incident>("incidents")
.where({ supervisor_email: email })
.innerJoin("incident_types", "incident_types.id", "incidents.incident_type_id")
.innerJoin("incident_statuses", "incident_statuses.code", "incidents.status_code")
.innerJoin("departments", "departments.code", "incidents.department_code")
.select(
"incidents.*",
"incident_types.name as incident_type_name",
"incident_types.description as incident_type_description",
"incident_statuses.name as status_name",
"departments.name as department_name"
);
}

async create(item: any): Promise<Incident[]> {
Expand Down
40 changes: 10 additions & 30 deletions web/src/components/incident/DetailsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,14 @@
<v-label>Supervisor</v-label>
<v-text-field :value="selectedReport.supervisor_email" />

<v-label>Supporting images</v-label>

<div class="d-flex pt-2">
<v-chip color="info" variant="flat" v-for="attach of selectedReport.attachments" class="mr-3">{{
attach.file_name
}}</v-chip>
<div v-if="selectedReport.attachments && selectedReport.attachments.length > 0">
<v-label>Supporting images</v-label>

<div class="d-flex pt-2">
<v-chip color="info" variant="flat" v-for="attach of selectedReport.attachments" class="mr-3">{{
attach.file_name
}}</v-chip>
</div>
</div>
</v-col>
</v-row>
Expand Down Expand Up @@ -143,16 +145,12 @@
</template>

<script setup>
import { computed, ref, watch } from "vue";
import { computed } from "vue";
import { storeToRefs } from "pinia";
import { DateTime } from "luxon";
import { useAuth0 } from "@auth0/auth0-vue";
import { AuthHelper } from "@/plugins/auth";
import { useRoute } from "vue-router";
import { useReportStore } from "@/store/ReportStore";
import DateSelector from "@/components/DateSelector.vue";
import DirectorySelector from "@/components/DirectorySelector.vue";
const reportStore = useReportStore();
const { initialize, loadReport } = reportStore;
Expand All @@ -173,30 +171,12 @@ const stepperValue = computed(() => {
return 0;
});
const canSave = computed(() => {
return selectedReport.value.eventType && isAuthenticated.value == true;
});
const auth = useAuth0();
const isAuthenticated = computed(() => {
return AuthHelper.isAuthenticated.value;
});
function formatDate(input) {
if (!input) return "";
return DateTime.fromISO(input.toString()).toFormat("MMMM dd, yyyy");
}
async function saveReport() {
selectedReport.value.createDate = new Date();
await addReport(selectedReport.value).then(() => {
//router.push("/report-an-incident/complete");
});
}
function supervisorClick() {
console.log("HERE");
selectedReport.value.status_code = "SUP";
selectedReport.value.status_name = "Supervisor Review";
}
Expand Down
26 changes: 21 additions & 5 deletions web/src/components/report/SMTListCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
<h4 class="text-h5 mb-4">SMT Reports</h4>

<v-list v-if="myReports && myReports.length > 0" bg-color="#ddd" style="border: 1px #aaa solid" rounded>
<div v-for="(report, idx) of myReports" class="">
<v-list-item :title="makeTitle(report)" :subtitle="makeSubtitle(report)"></v-list-item>
<div v-for="(report, idx) of myReports">
<v-list-item
:title="makeTitle(report)"
:subtitle="makeSubtitle(report)"
@click="openReportClick(report)"></v-list-item>
<v-divider v-if="idx < myReports.length - 1" class="mt-2 mb-1" />
</div>
</v-list>
Expand All @@ -22,12 +25,17 @@
<script lang="ts" setup>
import { DateTime } from "luxon";
import { useReportStore, Incident } from "@/store/ReportStore";
import { storeToRefs } from "pinia";
import { onMounted } from "vue";
import { ref } from "vue";
import { useRouter } from "vue-router";
const router = useRouter();
const reportStore = useReportStore();
const { loadReportsForRole } = reportStore;
const myReports = ref([] as any[]);
const { myReports } = storeToRefs(reportStore);
await loadReports();
function makeTitle(input: Incident) {
let title = input.incident_type_description;
Expand All @@ -38,4 +46,12 @@ function makeTitle(input: Incident) {
function makeSubtitle(input: Incident) {
return `Created: ${DateTime.fromISO(input.created_at.toString()).toRelative()}, Status: ${input.status_name}`;
}
function openReportClick(input: Incident) {
router.push(`/reports/${input.id}`);
}
async function loadReports() {
myReports.value = await loadReportsForRole("SMT");
}
</script>
23 changes: 18 additions & 5 deletions web/src/components/report/SupervisorCard.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
<template>
<v-card class="default mb-5">
<v-card class="default mb-5" v-if="mySupervisorReports && mySupervisorReports.length > 0">
<v-card-text>
<h4 class="text-h5 mb-4">Supervior Reports</h4>

<v-list v-if="mySupervisorReports && mySupervisorReports.length > 0" bg-color="#ddd" style="border: 1px #aaa solid" rounded>
<div v-for="(report, idx) of mySupervisorReports" class="">
<v-list-item :title="makeTitle(report)" :subtitle="makeSubtitle(report)"></v-list-item>
<v-list
v-if="mySupervisorReports && mySupervisorReports.length > 0"
bg-color="#ddd"
style="border: 1px #aaa solid"
rounded>
<div v-for="(report, idx) of mySupervisorReports">
<v-list-item
:title="makeTitle(report)"
:subtitle="makeSubtitle(report)"
@click="openReportClick(report)"></v-list-item>
<v-divider v-if="idx < mySupervisorReports.length - 1" class="mt-2 mb-1" />
</div>
</v-list>
Expand All @@ -23,7 +30,9 @@
import { DateTime } from "luxon";
import { useReportStore, Incident } from "@/store/ReportStore";
import { storeToRefs } from "pinia";
import { onMounted } from "vue";
import { useRouter } from "vue-router";
const router = useRouter();
const reportStore = useReportStore();
Expand All @@ -38,4 +47,8 @@ function makeTitle(input: Incident) {
function makeSubtitle(input: Incident) {
return `Created: ${DateTime.fromISO(input.created_at.toString()).toRelative()}, Status: ${input.status_name}`;
}
function openReportClick(input: Incident) {
router.push(`/reports/${input.id}`);
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
label="Status"
v-model="selectedUser.is_active"
:items="[
{ value: true, title: 'Active' },
{ value: false, title: 'Inactive' },
{ value: 1, title: 'Active' },
{ value: 0, title: 'Inactive' },
]"
variant="outlined"
density="comfortable" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const useUserAdminStore = defineStore("userAdmin", {
});
},
selectUser(user: any) {
user.is_active = user.is_active === true || user.is_active == 1 || user.is_active == "1" ? 1 : 0;
this.selectedUser = user;
},
unselectUser() {
Expand Down
15 changes: 13 additions & 2 deletions web/src/store/ReportStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const useReportStore = defineStore("reports", {
await this.loadLocations();
await this.loadUrgency();
await this.loadMyReports();
await this.loadMySupervisorReports();
},

async loadLocations() {
Expand Down Expand Up @@ -86,8 +87,6 @@ export const useReportStore = defineStore("reports", {
},

async loadReport(reportId: number) {
console.log("LOADING REPORT", reportId);

const api = useApiStore();
return api
.secureCall("get", `${REPORTS_URL}/${reportId}`)
Expand All @@ -98,6 +97,18 @@ export const useReportStore = defineStore("reports", {
console.log("Error in loadReport");
});
},

async loadReportsForRole(roleName: string) {
const api = useApiStore();
return api
.secureCall("get", `${REPORTS_URL}/role/${roleName}`)
.then((resp) => {
return resp.data;
})
.catch(() => {
console.log(`Error in loadReportsForRole/${roleName}`);
});
},
},
});

Expand Down
11 changes: 9 additions & 2 deletions web/src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
<SupervisorCard></SupervisorCard>
</div>

<RouterLink v-else to="/sign-in">
<div v-else @click="loginClick" class="ma-0 cursor-pointer">
<v-alert type="success" prominent color="primary" title="Sign in" icon="mdi-login">
to see your submissions and cases assigned to you
</v-alert>
</RouterLink>
</div>
</v-col>
</v-row>
</template>
Expand All @@ -41,6 +41,7 @@ import ReportListCard from "@/components/report/ReportListCard.vue";
import SMTListCard from "@/components/report/SMTListCard.vue";
import SupervisorCard from "@/components/report/SupervisorCard.vue";
import { AuthHelper } from "@/plugins/auth";
import { useAuth0 } from "@auth0/auth0-vue";
import { useUserStore } from "@/store/UserStore";
import { useReportStore } from "@/store/ReportStore";
Expand All @@ -63,4 +64,10 @@ await initialize();
/* const isAuthenticated = computed(() => {
return AuthHelper.isAuthenticated;
}); */
function loginClick() {
AuthHelper.loginWithRedirect({
appState: { target: window.location.pathname },
});
}
</script>

0 comments on commit f3350ad

Please sign in to comment.