Skip to content

Commit

Permalink
iot service starting
Browse files Browse the repository at this point in the history
  • Loading branch information
Prasanth-S7 committed Dec 12, 2024
2 parents c683416 + 87ff2de commit f588237
Show file tree
Hide file tree
Showing 39 changed files with 1,904 additions and 89 deletions.
2 changes: 2 additions & 0 deletions admin/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VITE_SECRET_KEY=kldnvslknef090u3q48jasd12
SECRET=kldnvslknef090u3q48jasd12
12 changes: 11 additions & 1 deletion admin/package-lock.json

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

2 changes: 2 additions & 0 deletions admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@
},
"devDependencies": {
"@eslint/js": "^9.13.0",
"@types/crypto-js": "^4.2.2",
"@types/node": "^22.9.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@vitejs/plugin-react": "^4.3.3",
"autoprefixer": "^10.4.20",
"crypto-js": "^4.2.0",
"eslint": "^9.13.0",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.14",
Expand Down
16 changes: 11 additions & 5 deletions admin/src/components/custom/Navbars.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Avatar, AvatarImage } from "../ui/avatar";
import { Button } from "../ui/button";
import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover";
import { Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupContent, SidebarHeader, SidebarMenu, SidebarMenuButton, SidebarMenuItem } from "../ui/sidebar"
import { Calendar, FileTextIcon, FolderCog2Icon, ForkliftIcon, Gauge, PickaxeIcon, ReplaceAll, Settings, SunIcon, TriangleAlert, UserRoundCog } from "lucide-react";
import { Calendar, FileTextIcon, FolderCog2Icon, ForkliftIcon, Gauge, LanguagesIcon, PickaxeIcon, ReplaceAll, Settings, SunIcon, TriangleAlert, UserRoundCog } from "lucide-react";
import { Box } from "lucide-react"
import { useTheme } from "./theme";

Expand Down Expand Up @@ -104,10 +104,16 @@ const SideNavbar = () => {
<SidebarMenu>
<SidebarMenuItem>
<SidebarMenuButton asChild>
<Button onClick={toggleTheme} variant={'ghost'} className="flex items-center justify-start">
<SunIcon />
<span className="text-sm font-medium">Change Theme</span>
</Button>
<div>
<Button className="flex items-center justify-start" variant='ghost'>
<LanguagesIcon />
<span className="text-sm font-medium">Change Language</span>
</Button>
<Button onClick={toggleTheme} variant={'ghost'} className="flex items-center justify-start">
<SunIcon />
<span className="text-sm font-medium">Change Theme</span>
</Button>
</div>
</SidebarMenuButton>
</SidebarMenuItem>
</SidebarMenu>
Expand Down
172 changes: 172 additions & 0 deletions admin/src/components/custom/ShiftAssignmentDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
'use client'

import React, { useEffect, useState } from "react"
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from "@/components/ui/dialog"
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
import { Checkbox } from "@/components/ui/checkbox"
import { Label } from "@/components/ui/label"
import { Button } from "@/components/ui/button"
import { ScrollArea } from "@/components/ui/scroll-area"
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"

interface User {
userId: string
username: string
}

interface ShiftTemplate {
shiftTemplateId: string
form_name: string
}

interface ShiftData {
supervisor: string | null
workers: string[]
selectedTemplates: string[]
}

export default function ShiftAssignmentDialog() {
const [users, setUsers] = useState<User[]>([])
const [shiftTemplates, setShiftTemplates] = useState<ShiftTemplate[]>([])
const [shiftData, setShiftData] = useState<Record<string, ShiftData>>({
morning: { supervisor: null, workers: [], selectedTemplates: [] },
afternoon: { supervisor: null, workers: [], selectedTemplates: [] },
night: { supervisor: null, workers: [], selectedTemplates: [] },
})

useEffect(() => {
// Simulating API calls
setUsers([
{ userId: "1", username: "John Doe" },
{ userId: "2", username: "Jane Smith" },
{ userId: "3", username: "Bob Johnson" },
])
setShiftTemplates([
{ shiftTemplateId: "1", form_name: "Standard Shift" },
{ shiftTemplateId: "2", form_name: "Extended Shift" },
{ shiftTemplateId: "3", form_name: "Special Operations" },
])
}, [])

const handleSupervisorChange = (shift: string, userId: string) => {
setShiftData((prev) => ({
...prev,
[shift]: { ...prev[shift], supervisor: userId },
}))
}

const handleWorkerChange = (shift: string, userId: string) => {
setShiftData((prev) => {
const currentWorkers = prev[shift].workers
const updatedWorkers = currentWorkers.includes(userId)
? currentWorkers.filter((id) => id !== userId)
: [...currentWorkers, userId]
return {
...prev,
[shift]: { ...prev[shift], workers: updatedWorkers },
}
})
}

const handleTemplateChange = (shift: string, templateId: string) => {
setShiftData((prev) => {
const currentTemplates = prev[shift].selectedTemplates
const updatedTemplates = currentTemplates.includes(templateId)
? currentTemplates.filter((id) => id !== templateId)
: [...currentTemplates, templateId]
return {
...prev,
[shift]: { ...prev[shift], selectedTemplates: updatedTemplates },
}
})
}

const handleSave = () => {
console.log("Saving shift data:", shiftData)
// Implement your save logic here
}

return (
<Dialog>
<DialogContent className="sm:max-w-[800px]">
<DialogHeader>
<DialogTitle>Assign Shifts</DialogTitle>
</DialogHeader>
<Tabs defaultValue="morning">
<TabsList className="grid w-full grid-cols-3">
<TabsTrigger value="morning">Morning Shift</TabsTrigger>
<TabsTrigger value="afternoon">Afternoon Shift</TabsTrigger>
<TabsTrigger value="night">Night Shift</TabsTrigger>
</TabsList>
{Object.entries(shiftData).map(([shift, data]) => (
<TabsContent key={shift} value={shift}>
<div className="space-y-4">
<div>
<Label htmlFor={`${shift}-supervisor`}>Supervisor</Label>
<Select
value={data.supervisor || ""}
onValueChange={(value) => handleSupervisorChange(shift, value)}
>
<SelectTrigger id={`${shift}-supervisor`}>
<SelectValue placeholder="Select Supervisor" />
</SelectTrigger>
<SelectContent>
{users.map((user) => (
<SelectItem key={user.userId} value={user.userId}>
{user.username}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
<div>
<Label>Workers</Label>
<ScrollArea className="h-[200px] w-full border rounded-md p-4">
{users.map((user) => (
<div key={user.userId} className="flex items-center space-x-2 mb-2">
<Checkbox
id={`${shift}-worker-${user.userId}`}
checked={data.workers.includes(user.userId)}
onCheckedChange={() => handleWorkerChange(shift, user.userId)}
/>
<Label
htmlFor={`${shift}-worker-${user.userId}`}
className="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
>
{user.username}
</Label>
</div>
))}
</ScrollArea>
</div>
<div>
<Label>Shift Templates</Label>
<ScrollArea className="h-[150px] w-full border rounded-md p-4">
{shiftTemplates.map((template) => (
<div key={template.shiftTemplateId} className="flex items-center space-x-2 mb-2">
<Checkbox
id={`${shift}-template-${template.shiftTemplateId}`}
checked={data.selectedTemplates.includes(template.shiftTemplateId)}
onCheckedChange={() => handleTemplateChange(shift, template.shiftTemplateId)}
/>
<Label
htmlFor={`${shift}-template-${template.shiftTemplateId}`}
className="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
>
{template.form_name}
</Label>
</div>
))}
</ScrollArea>
</div>
</div>
</TabsContent>
))}
</Tabs>
<DialogFooter>
<Button onClick={handleSave}>Save Assignments</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
}
16 changes: 11 additions & 5 deletions admin/src/components/custom/riskPlanAnalyticsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const RiskPlanAnalyticsModal: React.FC<{ id: number; open: boolean; onOpenChange
return acc;
}, [] as FormSubmission[]);

const PDFDocument = () => (
const PDFDocument = ({uniqueSubmissions, completionData}: {uniqueSubmissions: FormSubmission[], completionData: CompletionData | null}) => (
<Document>
<Page size="A4" style={styles.page}>
<View style={styles.section}>
Expand All @@ -80,6 +80,13 @@ const RiskPlanAnalyticsModal: React.FC<{ id: number; open: boolean; onOpenChange
<Text style={styles.submissionText}>Description: {submission.response.description_of_the_control_plan}</Text>
</View>
))}
{completionData && (
<View>
<Text style={styles.subtitle}>Completion Data</Text>
<Text style={styles.submissionText}>Completed Sections: {completionData.noOfSectionsCompleted}</Text>
<Text style={styles.submissionText}>Total Sections: {completionData.noOfSections}</Text>
</View>
)}
</View>
</Page>
</Document>
Expand Down Expand Up @@ -152,10 +159,10 @@ const RiskPlanAnalyticsModal: React.FC<{ id: number; open: boolean; onOpenChange
</div>

<div className="flex justify-end">
<PDFDownloadLink document={<PDFDocument />} fileName="risk_plan_report.pdf">
<PDFDownloadLink document={<PDFDocument uniqueSubmissions={uniqueSubmissions} completionData={completionData} />} fileName="coal_mine_risk_plan_report.pdf">
{({ blob, url, loading, error }) =>
<Button className="bg-red-700 text-white hover:bg-primary-dark">
{loading ? 'Generating PDF...' : 'Download PDF Report'}
{loading ? 'Generating PDF...' : 'Download Detailed PDF Report'}
</Button>
}
</PDFDownloadLink>
Expand Down Expand Up @@ -200,5 +207,4 @@ const styles = StyleSheet.create({
},
});

export default RiskPlanAnalyticsModal;

export default RiskPlanAnalyticsModal;
5 changes: 4 additions & 1 deletion admin/src/lib/login.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { encryptData } from "@/utils/encryptData";

const login = async (data: any) => {
const encryptedData = encryptData(data);
try {
const res = await fetch('/api/data/admin/op/login', {
headers: {
'Content-type': 'application/json'
},
method: 'POST',
body: JSON.stringify(data)
body: JSON.stringify({encrypted: encryptedData})
})
if(res.ok) {
const d = await res.json();
Expand Down
Loading

0 comments on commit f588237

Please sign in to comment.