-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: sync develop with master (#1070)
* feat: connect Users to the backend (cherry picked from commit 45956f1) * feat: connect Projects to the backend (#1063) (cherry picked from commit 5554ae4) * fix: move sorting/pagination to hooks (#1064) (cherry picked from commit e83ed7b) * feat: implement files uploading integration (#1065) (cherry picked from commit 42fa1cb) * fix(EditUserForm): filter out removed projects (cherry picked from commit b52bd07) * fix(UserAvatar): make sure avatar is not null (cherry picked from commit 1b931db) * chore: sync master with develop (#1069) * chore(deps): bump ws from 6.2.2 to 6.2.3 (#1040) Bumps [ws](https://github.com/websockets/ws) from 6.2.2 to 6.2.3. - [Release notes](https://github.com/websockets/ws/releases) - [Commits](websockets/ws@6.2.2...6.2.3) --- updated-dependencies: - dependency-name: ws dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump braces from 3.0.2 to 3.0.3 (#1039) Bumps [braces](https://github.com/micromatch/braces) from 3.0.2 to 3.0.3. - [Changelog](https://github.com/micromatch/braces/blob/master/CHANGELOG.md) - [Commits](micromatch/braces@3.0.2...3.0.3) --- updated-dependencies: - dependency-name: braces dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump ejs from 3.1.9 to 3.1.10 (#1034) Bumps [ejs](https://github.com/mde/ejs) from 3.1.9 to 3.1.10. - [Release notes](https://github.com/mde/ejs/releases) - [Commits](mde/ejs@v3.1.9...v3.1.10) --- updated-dependencies: - dependency-name: ejs dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump tar from 6.2.0 to 6.2.1 (#1033) Bumps [tar](https://github.com/isaacs/node-tar) from 6.2.0 to 6.2.1. - [Release notes](https://github.com/isaacs/node-tar/releases) - [Changelog](https://github.com/isaacs/node-tar/blob/main/CHANGELOG.md) - [Commits](isaacs/node-tar@v6.2.0...v6.2.1) --- updated-dependencies: - dependency-name: tar dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump express from 4.18.2 to 4.19.2 (#1031) Bumps [express](https://github.com/expressjs/express) from 4.18.2 to 4.19.2. - [Release notes](https://github.com/expressjs/express/releases) - [Changelog](https://github.com/expressjs/express/blob/master/History.md) - [Commits](expressjs/express@4.18.2...4.19.2) --- updated-dependencies: - dependency-name: express dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump express from 4.19.2 to 4.21.1 (#1057) Bumps [express](https://github.com/expressjs/express) from 4.19.2 to 4.21.1. - [Release notes](https://github.com/expressjs/express/releases) - [Changelog](https://github.com/expressjs/express/blob/4.21.1/History.md) - [Commits](expressjs/express@4.19.2...4.21.1) --- updated-dependencies: - dependency-name: express dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump pug from 3.0.2 to 3.0.3 (#1058) Bumps [pug](https://github.com/pugjs/pug) from 3.0.2 to 3.0.3. - [Release notes](https://github.com/pugjs/pug/releases) - [Commits](https://github.com/pugjs/pug/compare/pug@3.0.2...pug@3.0.3) --- updated-dependencies: - dependency-name: pug dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * feat: connect Users to the backend * feat: connect Projects to the backend (#1063) * fix: move sorting/pagination to hooks (#1064) * feat: implement files uploading integration (#1065) * fix(EditUserForm): filter out removed projects * fix(UserAvatar): make sure avatar is not null * Revert "fix(UserAvatar): make sure avatar is not null" This reverts commit 1b931db. * Revert "fix(EditUserForm): filter out removed projects" This reverts commit b52bd07. * Revert "feat: implement files uploading integration (#1065)" This reverts commit 42fa1cb. * Revert "fix: move sorting/pagination to hooks (#1064)" This reverts commit e83ed7b. * Revert "feat: connect Projects to the backend (#1063)" This reverts commit 5554ae4. * Revert "feat: connect Users to the backend" This reverts commit 45956f1. --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: raichev-dima <raichevdp@gmail.com> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: raichev-dima <raichevdp@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
524f96f
commit 229daa6
Showing
23 changed files
with
501 additions
and
323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,5 @@ VITE_APP_INCLUDE_DEMOS= | |
VITE_APP_ROUTER_MODE_HISTORY= | ||
|
||
VITE_APP_BUILD_VERSION= | ||
|
||
VITE_API_BASE_URL= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +1,43 @@ | ||
import { sleep } from '../../services/utils' | ||
import projectsDb from './projects-db.json' | ||
import usersDb from './users-db.json' | ||
import api from '../../services/api' | ||
import { Project } from '../../pages/projects/types' | ||
|
||
// Simulate API calls | ||
export type Pagination = { | ||
page: number | ||
perPage: number | ||
total: number | ||
} | ||
|
||
export type Sorting = { | ||
sortBy: keyof (typeof projectsDb)[number] | undefined | ||
sortBy: 'project_owner' | 'team' | 'created_at' | ||
sortingOrder: 'asc' | 'desc' | null | ||
} | ||
|
||
const getSortItem = (obj: any, sortBy: keyof (typeof projectsDb)[number]) => { | ||
if (sortBy === 'project_owner') { | ||
return obj.project_owner.fullname | ||
} | ||
|
||
if (sortBy === 'team') { | ||
return obj.team.map((user: any) => user.fullname).join(', ') | ||
} | ||
|
||
if (sortBy === 'creation_date') { | ||
return new Date(obj[sortBy]) | ||
} | ||
|
||
return obj[sortBy] | ||
} | ||
|
||
export const getProjects = async (options: Sorting & Pagination) => { | ||
await sleep(1000) | ||
|
||
const projects = projectsDb.map((project) => ({ | ||
...project, | ||
project_owner: usersDb.find((user) => user.id === project.project_owner)! as (typeof usersDb)[number], | ||
team: usersDb.filter((user) => project.team.includes(user.id)) as (typeof usersDb)[number][], | ||
})) | ||
|
||
if (options.sortBy && options.sortingOrder) { | ||
projects.sort((a, b) => { | ||
a = getSortItem(a, options.sortBy!) | ||
b = getSortItem(b, options.sortBy!) | ||
if (a < b) { | ||
return options.sortingOrder === 'asc' ? -1 : 1 | ||
} | ||
if (a > b) { | ||
return options.sortingOrder === 'asc' ? 1 : -1 | ||
} | ||
return 0 | ||
}) | ||
} | ||
|
||
const normalizedProjects = projects.slice((options.page - 1) * options.perPage, options.page * options.perPage) | ||
export const getProjects = async (options: Partial<Sorting> & Pagination) => { | ||
const projects: Project[] = await fetch(api.allProjects()).then((r) => r.json()) | ||
|
||
return { | ||
data: normalizedProjects, | ||
data: projects, | ||
pagination: { | ||
page: options.page, | ||
perPage: options.perPage, | ||
total: projectsDb.length, | ||
total: projects.length, | ||
}, | ||
} | ||
} | ||
|
||
export const addProject = async (project: Omit<(typeof projectsDb)[number], 'id' | 'creation_date'>) => { | ||
await sleep(1000) | ||
|
||
const newProject = { | ||
...project, | ||
id: projectsDb.length + 1, | ||
creation_date: new Date().toLocaleDateString('gb', { day: 'numeric', month: 'short', year: 'numeric' }), | ||
} | ||
export const addProject = async (project: Omit<Project, 'id' | 'created_at'>) => { | ||
const headers = new Headers() | ||
headers.append('Content-Type', 'application/json') | ||
|
||
projectsDb.push(newProject) | ||
|
||
return { | ||
...newProject, | ||
project_owner: usersDb.find((user) => user.id === project.project_owner)! as (typeof usersDb)[number], | ||
team: usersDb.filter((user) => project.team.includes(user.id)) as (typeof usersDb)[number][], | ||
} | ||
return fetch(api.allProjects(), { method: 'POST', body: JSON.stringify(project), headers }).then((r) => r.json()) | ||
} | ||
|
||
export const updateProject = async (project: (typeof projectsDb)[number]) => { | ||
await sleep(1000) | ||
|
||
const index = projectsDb.findIndex((p) => p.id === project.id) | ||
projectsDb[index] = project | ||
|
||
return project | ||
export const updateProject = async (project: Omit<Project, 'created_at'>) => { | ||
const headers = new Headers() | ||
headers.append('Content-Type', 'application/json') | ||
return fetch(api.project(project.id), { method: 'PUT', body: JSON.stringify(project), headers }).then((r) => r.json()) | ||
} | ||
|
||
export const removeProject = async (project: (typeof projectsDb)[number]) => { | ||
await sleep(1000) | ||
|
||
const index = projectsDb.findIndex((p) => p.id === project.id) | ||
projectsDb.splice(index, 1) | ||
|
||
return project | ||
export const removeProject = async (project: Project) => { | ||
return fetch(api.project(project.id), { method: 'DELETE' }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { useUsers } from '../../users/composables/useUsers' | ||
import { Project } from '../types' | ||
|
||
export function useProjectUsers() { | ||
const { users } = useUsers() | ||
|
||
const getUserById = (userId: string) => { | ||
return users.value.find(({ id }) => userId === id) | ||
} | ||
|
||
const avatarColor = (userName: string) => { | ||
const colors = ['primary', '#FFD43A', '#ADFF00', '#262824', 'danger'] | ||
const index = userName.charCodeAt(0) % colors.length | ||
return colors[index] | ||
} | ||
|
||
const getTeamOptions = (team: Project['team']) => { | ||
return team.reduce( | ||
(acc, userId) => { | ||
const user = getUserById(userId) | ||
|
||
if (user) { | ||
acc.push({ | ||
label: user.fullname, | ||
src: user.avatar, | ||
fallbackText: user.fullname[0], | ||
color: avatarColor(user.fullname), | ||
}) | ||
} | ||
|
||
return acc | ||
}, | ||
[] as Record<string, string>[], | ||
) | ||
} | ||
|
||
return { | ||
users, | ||
getUserById, | ||
getTeamOptions, | ||
} | ||
} |
Oops, something went wrong.