conversion data
This commit is contained in:
@@ -2,6 +2,27 @@
|
|||||||
import { goto } from "$app/navigation";
|
import { goto } from "$app/navigation";
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
|
|
||||||
|
// get local storage user
|
||||||
|
let user: any = null;
|
||||||
|
onMount(() => {
|
||||||
|
const userStr = localStorage.getItem("user");
|
||||||
|
if (userStr) {
|
||||||
|
user = JSON.parse(userStr);
|
||||||
|
if (user?.role) {
|
||||||
|
userRole = user.role;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
activeUrl = window.location.pathname;
|
||||||
|
|
||||||
|
// Expand parent menu if current path matches sub menu
|
||||||
|
for (const item of fullMenu) {
|
||||||
|
if (item.sub?.some((s) => s.url === activeUrl)) {
|
||||||
|
openMenus[item.name] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
type SubMenuItem = {
|
type SubMenuItem = {
|
||||||
name: string;
|
name: string;
|
||||||
icon: string;
|
icon: string;
|
||||||
@@ -13,18 +34,42 @@
|
|||||||
icon: string;
|
icon: string;
|
||||||
url: string;
|
url: string;
|
||||||
sub?: SubMenuItem[];
|
sub?: SubMenuItem[];
|
||||||
|
roles?: string[]; // <- tambahkan ini
|
||||||
};
|
};
|
||||||
|
|
||||||
let menuItems: MenuItem[] = [
|
// Contoh role yang sedang aktif (bisa dari Supabase atau session)
|
||||||
{ name: "Beranda", icon: "🏠", url: "/" },
|
let userRole: "admin" | "user" | "guest" = "user";
|
||||||
{ name: "Profile", icon: "🧑", url: "/profile" },
|
// Semua menu
|
||||||
{ name: "Issues", icon: "📂", url: "/backoffice/issue" },
|
const fullMenu: MenuItem[] = [
|
||||||
{ name: "Issue View", icon: "📂", url: "/backoffice/issue/view" },
|
{
|
||||||
{ name: "Projects", icon: "📂", url: "/backoffice/project" },
|
name: "Beranda",
|
||||||
|
icon: "🏠",
|
||||||
|
url: "/",
|
||||||
|
roles: ["admin", "user", "guest"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Profile",
|
||||||
|
icon: "🧑",
|
||||||
|
url: "/profile",
|
||||||
|
roles: ["admin", "user"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Issues",
|
||||||
|
icon: "📂",
|
||||||
|
url: "/backoffice/issue",
|
||||||
|
roles: ["admin", "user"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Projects",
|
||||||
|
icon: "📂",
|
||||||
|
url: "/backoffice/project",
|
||||||
|
roles: ["admin"],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "Purchase Orders",
|
name: "Purchase Orders",
|
||||||
icon: "📦",
|
icon: "📦",
|
||||||
url: "/backoffice/purchaseorder",
|
url: "/backoffice/purchaseorder",
|
||||||
|
roles: ["admin", "user"],
|
||||||
sub: [
|
sub: [
|
||||||
{
|
{
|
||||||
name: "Approval",
|
name: "Approval",
|
||||||
@@ -48,18 +93,18 @@
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{ name: "Timesheets", icon: "📂", url: "/backoffice/timesheets" },
|
|
||||||
{
|
{
|
||||||
name: "Timesheets View",
|
name: "Users",
|
||||||
icon: "📂",
|
icon: "👤",
|
||||||
url: "/backoffice/timesheets/view",
|
url: "/backoffice/account",
|
||||||
|
roles: ["admin"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Logout",
|
||||||
|
icon: "🚪",
|
||||||
|
url: "/logout",
|
||||||
|
roles: ["admin", "user", "guest"],
|
||||||
},
|
},
|
||||||
{ name: "Villa", icon: "📂", url: "/backoffice/villa" },
|
|
||||||
{ name: "Inventories", icon: "📂", url: "/backoffice/inventories" },
|
|
||||||
{ name: "Vendor", icon: "📂", url: "/backoffice/vendor" },
|
|
||||||
{ name: "Booking", icon: "📂", url: "/backoffice/booking" },
|
|
||||||
{ name: "Users", icon: "👤", url: "/backoffice/account" },
|
|
||||||
{ name: "Logout", icon: "🚪", url: "/logout" },
|
|
||||||
];
|
];
|
||||||
|
|
||||||
let activeUrl = "/";
|
let activeUrl = "/";
|
||||||
@@ -95,7 +140,7 @@
|
|||||||
<p class="text-sm text-gray-500">Manage your application</p>
|
<p class="text-sm text-gray-500">Manage your application</p>
|
||||||
</div>
|
</div>
|
||||||
<ul class="p-2 space-y-1">
|
<ul class="p-2 space-y-1">
|
||||||
{#each menuItems as item}
|
{#each fullMenu as item}
|
||||||
<li>
|
<li>
|
||||||
<a
|
<a
|
||||||
href={item.url}
|
href={item.url}
|
||||||
|
|||||||
22
src/lib/utils/conversion.ts
Normal file
22
src/lib/utils/conversion.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
// function 2025-05-27T04:40:33.413511 to YYYY-MM-DD HH:mm:ss
|
||||||
|
export function timestampToDateTime(timestamp: string): string {
|
||||||
|
const date = new Date(timestamp);
|
||||||
|
const year = date.getFullYear();
|
||||||
|
const month = String(date.getMonth() + 1).padStart(2, '0'); // Months are zero-based
|
||||||
|
const day = String(date.getDate()).padStart(2, '0');
|
||||||
|
const hours = String(date.getHours()).padStart(2, '0');
|
||||||
|
const minutes = String(date.getMinutes()).padStart(2, '0');
|
||||||
|
const seconds = String(date.getSeconds()).padStart(2, '0');
|
||||||
|
|
||||||
|
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to convert a timestamp to a date string in YYYY-MM-DD format
|
||||||
|
export function timestampToDate(timestamp: number): string {
|
||||||
|
const date = new Date(timestamp * 1000); // Convert seconds to milliseconds
|
||||||
|
const year = date.getFullYear();
|
||||||
|
const month = String(date.getMonth() + 1).padStart(2, '0'); // Months are zero-based
|
||||||
|
const day = String(date.getDate()).padStart(2, '0');
|
||||||
|
|
||||||
|
return `${year}-${month}-${day}`;
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
import Select from "svelte-select";
|
import Select from "svelte-select";
|
||||||
import { supabase } from "$lib/supabaseClient";
|
import { supabase } from "$lib/supabaseClient";
|
||||||
|
import { timestampToDateTime } from "$lib/utils/conversion";
|
||||||
|
|
||||||
type PurchaseOrderInsert = {
|
type PurchaseOrderInsert = {
|
||||||
issue_id: string;
|
issue_id: string;
|
||||||
@@ -70,6 +71,7 @@
|
|||||||
completed_status: string;
|
completed_status: string;
|
||||||
received: boolean;
|
received: boolean;
|
||||||
received_by: string;
|
received_by: string;
|
||||||
|
created_at: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
let allRows: PurchaseOrderDisplay[] = [];
|
let allRows: PurchaseOrderDisplay[] = [];
|
||||||
@@ -766,6 +768,14 @@
|
|||||||
🗑️ Delete
|
🗑️ Delete
|
||||||
</button>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
|
{:else if col.key === "created_at"}
|
||||||
|
<td class="px-4 py-2 text-gray-500"
|
||||||
|
>{timestampToDateTime(
|
||||||
|
row[
|
||||||
|
col.key as keyof PurchaseOrderDisplay
|
||||||
|
] as string,
|
||||||
|
)}</td
|
||||||
|
>
|
||||||
{:else}
|
{:else}
|
||||||
<td class="px-4 py-2 text-gray-700"
|
<td class="px-4 py-2 text-gray-700"
|
||||||
>{row[
|
>{row[
|
||||||
|
|||||||
@@ -98,7 +98,7 @@
|
|||||||
{ key: "completed_status", title: "Completed Status" },
|
{ key: "completed_status", title: "Completed Status" },
|
||||||
{ key: "acknowledge_by", title: "Acknowledged By" },
|
{ key: "acknowledge_by", title: "Acknowledged By" },
|
||||||
{ key: "created_at", title: "Created At" },
|
{ key: "created_at", title: "Created At" },
|
||||||
{ key: "actions", title: "Actions" }, // For edit/delete buttons
|
// { key: "actions", title: "Actions" }, // For edit/delete buttons
|
||||||
];
|
];
|
||||||
|
|
||||||
let currentPage = 1;
|
let currentPage = 1;
|
||||||
|
|||||||
@@ -98,7 +98,7 @@
|
|||||||
{ key: "received", title: "Received" },
|
{ key: "received", title: "Received" },
|
||||||
{ key: "received_by", title: "Received By" },
|
{ key: "received_by", title: "Received By" },
|
||||||
{ key: "created_at", title: "Created At" },
|
{ key: "created_at", title: "Created At" },
|
||||||
{ key: "actions", title: "Actions" }, // For edit/delete buttons
|
// { key: "actions", title: "Actions" }, // For edit/delete buttons
|
||||||
];
|
];
|
||||||
|
|
||||||
let currentPage = 1;
|
let currentPage = 1;
|
||||||
|
|||||||
@@ -14,6 +14,20 @@
|
|||||||
if (loginError) {
|
if (loginError) {
|
||||||
error = loginError.message;
|
error = loginError.message;
|
||||||
} else {
|
} else {
|
||||||
|
const { data: dataUser, error: eror } = await supabase
|
||||||
|
.from("users")
|
||||||
|
.select("*")
|
||||||
|
.eq("id", data.user.id)
|
||||||
|
.single();
|
||||||
|
|
||||||
|
if (eror) {
|
||||||
|
error = "Failed to fetch user data.";
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
// Set user data in local storage or a store
|
||||||
|
localStorage.setItem("user", JSON.stringify(dataUser));
|
||||||
|
}
|
||||||
|
|
||||||
goto("/backoffice/issue");
|
goto("/backoffice/issue");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user