Initial commit
This commit is contained in:
86
resources/js/plugins/fake-api/handlers/dashboard/db.js
Normal file
86
resources/js/plugins/fake-api/handlers/dashboard/db.js
Normal file
@@ -0,0 +1,86 @@
|
||||
import avatar1 from '@images/avatars/avatar-1.png'
|
||||
import avatar2 from '@images/avatars/avatar-2.png'
|
||||
import avatar3 from '@images/avatars/avatar-3.png'
|
||||
import avatar4 from '@images/avatars/avatar-4.png'
|
||||
import avatar5 from '@images/avatars/avatar-5.png'
|
||||
import avatar6 from '@images/avatars/avatar-6.png'
|
||||
import avatar7 from '@images/avatars/avatar-7.png'
|
||||
import avatar8 from '@images/avatars/avatar-8.png'
|
||||
import figma from '@images/icons/project-icons/figma.png'
|
||||
import html5 from '@images/icons/project-icons/html5.png'
|
||||
import python from '@images/icons/project-icons/python.png'
|
||||
import react from '@images/icons/project-icons/react.png'
|
||||
import sketch from '@images/icons/project-icons/sketch.png'
|
||||
import vue from '@images/icons/project-icons/vue.png'
|
||||
import xamarin from '@images/icons/project-icons/xamarin.png'
|
||||
|
||||
export const db = {
|
||||
analytics: [
|
||||
{
|
||||
logo: react,
|
||||
name: 'BGC eCommerce App',
|
||||
project: 'React Project',
|
||||
leader: 'Eileen',
|
||||
progress: 78,
|
||||
hours: '18:42',
|
||||
team: [avatar1, avatar8, avatar6],
|
||||
extraMembers: 3,
|
||||
},
|
||||
{
|
||||
logo: figma,
|
||||
name: 'Falcon Logo Design',
|
||||
project: 'Figma Project',
|
||||
leader: 'Owen',
|
||||
progress: 25,
|
||||
hours: '20:42',
|
||||
team: [avatar5, avatar2],
|
||||
},
|
||||
{
|
||||
logo: vue,
|
||||
name: 'Dashboard Design',
|
||||
project: 'Vuejs Project',
|
||||
leader: 'Keith',
|
||||
progress: 62,
|
||||
hours: '120:87',
|
||||
team: [avatar8, avatar2, avatar1],
|
||||
},
|
||||
{
|
||||
logo: xamarin,
|
||||
name: 'Foodista mobile app',
|
||||
project: 'Xamarin Project',
|
||||
leader: 'Merline',
|
||||
progress: 8,
|
||||
hours: '120:87',
|
||||
team: [avatar3, avatar4, avatar7],
|
||||
extraMembers: 8,
|
||||
},
|
||||
{
|
||||
logo: python,
|
||||
name: 'Dojo Email App',
|
||||
project: 'Python Project',
|
||||
leader: 'Harmonia',
|
||||
progress: 51,
|
||||
hours: '230:10',
|
||||
team: [avatar4, avatar3, avatar1],
|
||||
extraMembers: 5,
|
||||
},
|
||||
{
|
||||
logo: sketch,
|
||||
name: 'Blockchain Website',
|
||||
project: 'Sketch Project',
|
||||
leader: 'Allyson',
|
||||
progress: 92,
|
||||
hours: '342:41',
|
||||
team: [avatar1, avatar8],
|
||||
},
|
||||
{
|
||||
logo: html5,
|
||||
name: 'Hoffman Website',
|
||||
project: 'HTML Project',
|
||||
leader: 'Georgie',
|
||||
progress: 80,
|
||||
hours: '12:45',
|
||||
team: [avatar1, avatar8, avatar6],
|
||||
},
|
||||
],
|
||||
}
|
||||
63
resources/js/plugins/fake-api/handlers/dashboard/index.js
Normal file
63
resources/js/plugins/fake-api/handlers/dashboard/index.js
Normal file
@@ -0,0 +1,63 @@
|
||||
import is from '@sindresorhus/is'
|
||||
import destr from 'destr'
|
||||
import { HttpResponse, http } from 'msw'
|
||||
import { db } from '@db/dashboard/db'
|
||||
import { paginateArray } from '@api-utils/paginateArray'
|
||||
|
||||
export const handlerDashboard = [
|
||||
http.get('/api/dashboard/analytics/projects', ({ request }) => {
|
||||
const url = new URL(request.url)
|
||||
const q = url.searchParams.get('q')
|
||||
const sortBy = url.searchParams.get('sortBy')
|
||||
const itemsPerPage = url.searchParams.get('itemsPerPage')
|
||||
const page = url.searchParams.get('page')
|
||||
const orderBy = url.searchParams.get('orderBy')
|
||||
const searchQuery = is.string(q) ? q : undefined
|
||||
const queryLower = (searchQuery ?? '').toString().toLowerCase()
|
||||
const parsedSortBy = destr(sortBy)
|
||||
const sortByLocal = is.string(parsedSortBy) ? parsedSortBy : ''
|
||||
const parsedOrderBy = destr(orderBy)
|
||||
const orderByLocal = is.string(parsedOrderBy) ? parsedOrderBy : ''
|
||||
const parsedItemsPerPage = destr(itemsPerPage)
|
||||
const parsedPage = destr(page)
|
||||
const itemsPerPageLocal = is.number(parsedItemsPerPage) ? parsedItemsPerPage : 10
|
||||
const pageLocal = is.number(parsedPage) ? parsedPage : 1
|
||||
let filteredProjects = db.analytics.filter(project => ((project.name.toLowerCase().includes(queryLower) || project.leader.toLowerCase().includes(queryLower)) || project.project.toLowerCase().includes(queryLower))).reverse()
|
||||
if (sortByLocal) {
|
||||
console.log(sortByLocal)
|
||||
if (sortByLocal === 'project') {
|
||||
filteredProjects = filteredProjects.sort((a, b) => {
|
||||
if (orderByLocal === 'asc')
|
||||
return a.name.localeCompare(b.name)
|
||||
else
|
||||
return b.name.localeCompare(a.name)
|
||||
})
|
||||
}
|
||||
if (sortByLocal === 'leader') {
|
||||
filteredProjects = filteredProjects.sort((a, b) => {
|
||||
if (orderByLocal === 'asc')
|
||||
return a.leader.localeCompare(b.leader)
|
||||
else
|
||||
return b.leader.localeCompare(a.leader)
|
||||
})
|
||||
}
|
||||
if (sortByLocal === 'progress') {
|
||||
filteredProjects = filteredProjects.sort((a, b) => {
|
||||
if (orderByLocal === 'asc')
|
||||
return a.progress - b.progress
|
||||
else
|
||||
return b.progress - a.progress
|
||||
})
|
||||
}
|
||||
}
|
||||
const totalProjects = filteredProjects.length
|
||||
const totalPages = Math.ceil(totalProjects / itemsPerPageLocal)
|
||||
|
||||
return HttpResponse.json({
|
||||
projects: paginateArray(filteredProjects, itemsPerPageLocal, pageLocal),
|
||||
totalPages,
|
||||
totalProjects,
|
||||
page: pageLocal > Math.ceil(totalProjects / itemsPerPageLocal) ? 1 : page,
|
||||
}, { status: 200 })
|
||||
}),
|
||||
]
|
||||
1
resources/js/plugins/fake-api/handlers/dashboard/type.js
Normal file
1
resources/js/plugins/fake-api/handlers/dashboard/type.js
Normal file
@@ -0,0 +1 @@
|
||||
export {}
|
||||
Reference in New Issue
Block a user