diff --git a/locales/en.yml b/locales/en.yml index 5942ec0..8539df1 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -96,4 +96,16 @@ brands: url: Url is required image: Image is required +colors: + title: Colors + createButton: Create + create: + buttonTitle: Create + title: Create New Color + color: Color + name: Name + validations: + nameRequired: Name is required + colorRequired: Color not selected + not-found: Not found diff --git a/src/auto-imports.d.ts b/src/auto-imports.d.ts index 8c42384..aa2bd66 100644 --- a/src/auto-imports.d.ts +++ b/src/auto-imports.d.ts @@ -144,6 +144,7 @@ declare global { const useClipboard: typeof import('@vueuse/core')['useClipboard'] const useCloned: typeof import('@vueuse/core')['useCloned'] const useColorMode: typeof import('@vueuse/core')['useColorMode'] + const useColorStore: typeof import('./store/color.store')['useColorStore'] const useConfirmDialog: typeof import('@vueuse/core')['useConfirmDialog'] const useCounter: typeof import('@vueuse/core')['useCounter'] const useCssModule: typeof import('vue')['useCssModule'] @@ -454,6 +455,7 @@ declare module 'vue' { readonly useClipboard: UnwrapRef readonly useCloned: UnwrapRef readonly useColorMode: UnwrapRef + readonly useColorStore: UnwrapRef readonly useConfirmDialog: UnwrapRef readonly useCounter: UnwrapRef readonly useCssModule: UnwrapRef @@ -758,6 +760,7 @@ declare module '@vue/runtime-core' { readonly useClipboard: UnwrapRef readonly useCloned: UnwrapRef readonly useColorMode: UnwrapRef + readonly useColorStore: UnwrapRef readonly useConfirmDialog: UnwrapRef readonly useCounter: UnwrapRef readonly useCssModule: UnwrapRef diff --git a/src/components.d.ts b/src/components.d.ts index ecadbd5..f5c9310 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -12,8 +12,10 @@ declare module 'vue' { Card: typeof import('./components/Card.vue')['default'] CategoryManagement: typeof import('./components/Category/CategoryManagement.vue')['default'] CategoryStatics: typeof import('./components/Category/CategoryStatics.vue')['default'] + ColorManagement: typeof import('./components/Color/ColorManagement.vue')['default'] CreateBrand: typeof import('./components/Brand/CreateBrand.vue')['default'] CreateCategory: typeof import('./components/Category/CreateCategory.vue')['default'] + CreateColor: typeof import('./components/Color/CreateColor.vue')['default'] DashboardCard: typeof import('./components/DashboardCard.vue')['default'] DonutChart: typeof import('./components/DonutChart.vue')['default'] LanguageSelect: typeof import('./components/LanguageSelect.vue')['default'] @@ -21,6 +23,7 @@ declare module 'vue' { Navbar: typeof import('./components/Navbar.vue')['default'] NBadge: typeof import('naive-ui')['NBadge'] NButton: typeof import('naive-ui')['NButton'] + NColorPicker: typeof import('naive-ui')['NColorPicker'] NConfigProvider: typeof import('naive-ui')['NConfigProvider'] NDataTable: typeof import('naive-ui')['NDataTable'] NDialogProvider: typeof import('naive-ui')['NDialogProvider'] diff --git a/src/components/Brand/CreateBrand.vue b/src/components/Brand/CreateBrand.vue index 4863724..93222ac 100644 --- a/src/components/Brand/CreateBrand.vue +++ b/src/components/Brand/CreateBrand.vue @@ -1,12 +1,13 @@ + + + + diff --git a/src/components/Color/CreateColor.vue b/src/components/Color/CreateColor.vue new file mode 100644 index 0000000..e04812a --- /dev/null +++ b/src/components/Color/CreateColor.vue @@ -0,0 +1,75 @@ + + + + + diff --git a/src/mocks/handlers/color.handler.ts b/src/mocks/handlers/color.handler.ts new file mode 100644 index 0000000..ff2657b --- /dev/null +++ b/src/mocks/handlers/color.handler.ts @@ -0,0 +1,52 @@ +import { rest } from 'msw' +import _ from 'lodash' +import { faker } from '@faker-js/faker' +import { CreatePagedResponse } from '../handlers.utility' +import type { Color, ColorCreateModel } from '~/models/Color' + +const colors = _.times(7, createFakeColor) +const handlers = [ + rest.get('/api/Color', (req, res, ctx) => { + const response = CreatePagedResponse(req, colors) + return res( + ctx.status(200), + ctx.delay(200), + ctx.json(response), + ) + }), + rest.post('/api/color', async (req, res, ctx) => { + const newItem = await req.json() + const color: Color = { + id: faker.datatype.number({ max: 2000 }).toString(), + name: newItem.name, + color: newItem.color, + } + colors.push(color) + return res( + ctx.status(200), + ctx.delay(200), + ctx.json(color), + ) + }), + rest.delete('/api/Color/:id', (req, res, ctx) => { + const id = req.params.id.toString() + const itemIndex = colors.findIndex(x => x.id === id) + colors.splice(itemIndex, 1) + return res( + ctx.delay(1000), + ctx.status(200), + ctx.json(true), + ) + }), + +] + +function createFakeColor(): Color { + return { + id: faker.datatype.number().toString(), + name: faker.color.human(), + color: faker.color.rgb(), + } +} + +export default handlers diff --git a/src/models/Brand.ts b/src/models/Brand.ts index 248014c..14d62fb 100644 --- a/src/models/Brand.ts +++ b/src/models/Brand.ts @@ -5,4 +5,8 @@ export interface Brand { url: string } -export interface BrandCreateModel extends Brand {} +export interface BrandCreateModel { + name: string + image?: string + url: string +} diff --git a/src/models/Color.ts b/src/models/Color.ts new file mode 100644 index 0000000..8184826 --- /dev/null +++ b/src/models/Color.ts @@ -0,0 +1,10 @@ +export interface Color { + id: string + name: string + color: string +} + +export interface ColorCreateModel { + name: string + color: string +} diff --git a/src/pages/Colors/index.vue b/src/pages/Colors/index.vue new file mode 100644 index 0000000..4b9b825 --- /dev/null +++ b/src/pages/Colors/index.vue @@ -0,0 +1,10 @@ + + + + + diff --git a/src/services/color.service.ts b/src/services/color.service.ts new file mode 100644 index 0000000..090b091 --- /dev/null +++ b/src/services/color.service.ts @@ -0,0 +1,11 @@ +import GenericService from './generic.service' +import type { Color } from '~/models/Color' +import { ApiService } from '~/common/api/api-service' + +const apiService = new ApiService('Color') +class ColorService extends GenericService { + constructor() { + super(apiService) + } +} +export default new ColorService() diff --git a/src/store/brand.store.ts b/src/store/brand.store.ts index 02f6440..ce5effa 100644 --- a/src/store/brand.store.ts +++ b/src/store/brand.store.ts @@ -17,7 +17,7 @@ export const useBrandStore = defineStore('Brand', () => { try { const response = await brandService.getList(options) brands.value = response.items - options.pageSize = Number.parseInt(response.totalCount / options.itemsPerPage) + options.pageSize = Math.trunc(response.totalCount / options.itemsPerPage) } finally { isLoading.value = false diff --git a/src/store/category.store.ts b/src/store/category.store.ts index fb35a0a..95cb980 100644 --- a/src/store/category.store.ts +++ b/src/store/category.store.ts @@ -18,7 +18,7 @@ export const useCategoryStore = defineStore('Category', () => { try { const response = await categoryService.getList(options) categories.value = response.items - options.pageSize = Number.parseInt(response.totalCount / options.itemsPerPage) + options.pageSize = Math.trunc(response.totalCount / options.itemsPerPage) } finally { isLoading.value = false diff --git a/src/store/color.store.ts b/src/store/color.store.ts new file mode 100644 index 0000000..5e55755 --- /dev/null +++ b/src/store/color.store.ts @@ -0,0 +1,65 @@ +import { acceptHMRUpdate, defineStore } from 'pinia' +import type { Color, ColorCreateModel } from '~/models/Color' +import type { PagedAndSortedRequest } from '~/models/PagedAndSortedRequest' +import colorService from '~/services/color.service' + +export interface ColorState { +} +export const useColorStore = defineStore('Color', () => { + const colors = ref([]) + const colorItem = ref() + const isLoading = ref(false) + const isSaving = ref(false) + const { options } = useOptions() + + async function getColors(options: PagedAndSortedRequest) { + isLoading.value = true + try { + const response = await colorService.getList(options) + colors.value = response.items + options.pageSize = Math.trunc(response.totalCount / options.itemsPerPage) + } + finally { + isLoading.value = false + } + } + + function getColor() { + + } + + async function createColor(colorItem: ColorCreateModel) { + isLoading.value = true + try { + await colorService.create(colorItem) + getColors(options.value) + } + finally { + isLoading.value = false + } + } + + async function deleteColor(id: string) { + await colorService.delete(id) + getColors(options.value) + } + + function editColor() { + + } + + return { + isLoading, + isSaving, + colors, + options, + colorItem, + getColors, + getColor, + createColor, + deleteColor, + editColor, + } +}) +if (import.meta.hot) + import.meta.hot.accept(acceptHMRUpdate(useColorStore, import.meta.hot))