Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize line endings #32

Open
wants to merge 1 commit into
base: starter
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ yarn-debug.log*
yarn-error.log*

# local env files
.env
.env*.local

# vercel
Expand Down
23 changes: 23 additions & 0 deletions app/api/getMeasurement/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

export async function GET(req) {
try {
const measurements = await prisma.measurement.findMany({
orderBy: {
date: 'desc' // Urutkan berdasarkan tanggal terbaru ke terlama
}
});
return new Response(JSON.stringify(measurements), {
status: 200,
headers: {
'Content-Type': 'application/json',
},
});
} catch (error) {
return new Response(JSON.stringify({ error: "Failed to fetch data" }), {
status: 500,
});
}
}
21 changes: 21 additions & 0 deletions app/api/getUser/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { PrismaClient } from '@prisma/client';
import { NextResponse } from 'next/server';

const prisma = new PrismaClient();

export async function GET() {
try {
// Mengambil semua pengguna dari tabel users
const users = await prisma.user.findMany();

// Mengembalikan respon JSON dengan data pengguna
return NextResponse.json(users);
} catch (error) {
console.error(error);
// Mengembalikan respon JSON dengan status error
return NextResponse.json({ error: error.message }, { status: 500 });
} finally {
// Menutup koneksi Prisma setelah selesai
await prisma.$disconnect();
}
}
32 changes: 32 additions & 0 deletions app/api/postMeasurement/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

export async function POST(req) {
const { waterLevel, waterTemp, airTemp, airHumidity, airPressure, windSpeed, curahHujan, date } = await req.json();

try {
const newMeasurement = await prisma.measurement.create({
data: {
waterLevel,
windSpeed,
airTemp,
airHumidity,
airPressure,
waterTemp,
curahHujan,
date: date ? new Date(date) : new Date(),
},
});
return new Response(JSON.stringify(newMeasurement), {
status: 201,
headers: {
'Content-Type': 'application/json',
},
});
} catch (error) {
return new Response(JSON.stringify({ error: "Failed to save data" }), {
status: 500,
});
}
}
36 changes: 36 additions & 0 deletions app/api/postUser/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

export async function POST(req) {
const { username, email, password, role, status } = await req.json();

try {
// Menambahkan user baru ke tabel users
const newUser = await prisma.user.create({
data: {
username,
email,
password, // Pastikan untuk meng-hash password sebelum menyimpannya
role,
status,
},
});

// Mengembalikan respon sukses dengan data user yang baru ditambahkan
return new Response(JSON.stringify({ message: 'User added successfully', user: newUser }), {
status: 201,
headers: { 'Content-Type': 'application/json' },
});
} catch (error) {
console.error(error);
// Mengembalikan respon error jika terjadi kesalahan
return new Response(JSON.stringify({ error: 'Failed to add user' }), {
status: 500,
headers: { 'Content-Type': 'application/json' },
});
} finally {
// Menutup koneksi Prisma setelah operasi selesai
await prisma.$disconnect();
}
}
57 changes: 57 additions & 0 deletions app/dashboard/charts/page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"use client";
import { useEffect, useState } from "react";
import styles from "@/app/ui/dashboard/charts/charts.module.css";
import { LineChart, Line, XAxis, YAxis, Tooltip, Legend, ResponsiveContainer } from "recharts";

// Fungsi untuk fetch data dari API
const fetchData = async () => {
const response = await fetch("/api/getMeasurement");
const result = await response.json();
return result;
};

const ChartsPage = () => {
const [chartData, setChartData] = useState([]);

useEffect(() => {
fetchData().then((data) => {
// Urutkan data berdasarkan 'date' atau ID dan ambil 10 data terbaru
const sortedData = data
.sort((a, b) => new Date(b.date) - new Date(a.date)) // Mengurutkan berdasarkan tanggal terbaru
.slice(0, 10); // Ambil hanya 10 data terbaru
setChartData(sortedData);
});
}, []);

// Fungsi untuk menampilkan tiap chart dengan data dan judul
const renderChart = (title, dataKey) => (
<div className={styles.container}>
<h2 className={styles.title}>{title}</h2>
<ResponsiveContainer width="100%" height="90%">
<LineChart data={chartData}>
<XAxis dataKey="date" />
<YAxis />
<Tooltip contentStyle={{ background: "#151c2c", border: "none" }} />
<Legend />
<Line type="monotone" dataKey={dataKey} stroke="#8884d8" />
</LineChart>
</ResponsiveContainer>
</div>
);

return (
<div className={styles.wrapper}>
<div className={styles.main}>
{renderChart("Water Level", "waterLevel")}
{renderChart("Water Temperature", "waterTemp")}
{renderChart("Air Temperature", "airTemp")}
{renderChart("Air Humidity", "airHumidity")}
{renderChart("Air Pressure", "airPressure")}
{renderChart("Wind Speed", "windSpeed")}
{renderChart("Rainfall", "curahHujan")}
</div>
</div>
);
};

export default ChartsPage;
19 changes: 19 additions & 0 deletions app/dashboard/layout.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Navbar from "../ui/dashboard/navbar/navbar"
import Sidebar from "../ui/dashboard/sidebar/sidebar"
import styles from "../ui/dashboard/dashboard.module.css"

const Layout= ({children}) => {
return (
<div className={styles.container}>
<div className={styles.menu}>
<Sidebar/>
</div>
<div className={styles.content}>
<Navbar/>
{children}
</div>
</div>
)
}

export default Layout
55 changes: 55 additions & 0 deletions app/dashboard/map/page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"use client"; // Menandakan sebagai Client Component

import React, { useEffect, useState } from 'react';
import { MapContainer, TileLayer, Marker, Popup } from 'react-leaflet';
import 'leaflet/dist/leaflet.css';
import L from 'leaflet';

// Configure Leaflet's default icon
delete L.Icon.Default.prototype._getIconUrl;
L.Icon.Default.mergeOptions({
iconRetinaUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/images/marker-icon-2x.png',
iconUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/images/marker-icon.png',
shadowUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/images/marker-shadow.png',
});

const MapPage = () => {
const [isClient, setIsClient] = useState(false);

useEffect(() => {
setIsClient(true);
}, []);

const awsData = [
{ awsNumber: 1, location: [-6.971200, 107.631100], suhu: '28°C', kelembapan: '70%' },
{ awsNumber: 2, location: [-6.972000, 107.632000], suhu: '27°C', kelembapan: '65%' },
{ awsNumber: 3, location: [-6.973500, 107.629800], suhu: '27°C', kelembapan: '65%' },
// Tambahkan data AWS lainnya di sini
];

if (!isClient) {
return null; // Render nothing on the server
}

return (
<div style={{ height: '100vh', width: '100%' }}>
<MapContainer center={[-6.973022, 107.630348]} zoom={18} style={{ height: '100%', width: '100%' }}>
<TileLayer
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
/>
{awsData.map(({ awsNumber, location, suhu, kelembapan }) => (
<Marker key={awsNumber} position={location}>
<Popup>
AWS Station {awsNumber} <br />
Suhu: {suhu} <br />
Kelembapan: {kelembapan}
</Popup>
</Marker>
))}
</MapContainer>
</div>
);
};

export default MapPage;
22 changes: 22 additions & 0 deletions app/dashboard/page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import styles from '../ui/dashboard/dashboard.module.css'
import Card from '../ui/dashboard/card/card'
import Table from '../ui/dashboard/table/table'
import Card2 from '../ui/dashboard/card/card2'
import Card3 from '../ui/dashboard/card/card3'

const Dashboard = () => {
return (
<div className={styles.wrapper}>
<div className={styles.main}>
<div className={styles.cards}>
<Card/>
<Card2/>
<Card3/>
</div>
<Table/>
</div>
</div>
)
}

export default Dashboard
7 changes: 7 additions & 0 deletions app/dashboard/setting/page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const SettingPage= () => {
return (
<div>Ini pengaturan</div>
)
}

export default SettingPage
Loading