MainMenu ile entityeditor den seçilebilir hale getirildi.
This commit is contained in:
parent
35dfc600d6
commit
58d3e3c940
3 changed files with 50 additions and 30 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Linq.Dynamic.Core;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Erp.Languages.Entities;
|
using Erp.Languages.Entities;
|
||||||
using Erp.Platform.Entities;
|
using Erp.Platform.Entities;
|
||||||
|
|
@ -206,6 +207,19 @@ public class MenuAppService : CrudAppService<
|
||||||
|
|
||||||
await base.DeleteAsync(id);
|
await base.DeleteAsync(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<List<MenuDto>> GetListMainMenuAsync()
|
||||||
|
{
|
||||||
|
await CheckGetPolicyAsync();
|
||||||
|
|
||||||
|
var query = await _menuRepository.GetQueryableAsync();
|
||||||
|
query = query.Where(a => !a.IsDisabled && a.ShortName != null);
|
||||||
|
|
||||||
|
var entities = await AsyncExecuter.ToListAsync(query);
|
||||||
|
var entityDtos = await MapToGetListOutputDtosAsync(entities);
|
||||||
|
|
||||||
|
return entityDtos;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,8 @@ import { Formik, Form, Field, FieldProps, FieldArray } from 'formik'
|
||||||
import * as Yup from 'yup'
|
import * as Yup from 'yup'
|
||||||
import { FormItem, Input, Select, Checkbox, FormContainer, Button } from '@/components/ui'
|
import { FormItem, Input, Select, Checkbox, FormContainer, Button } from '@/components/ui'
|
||||||
import { SelectBoxOption } from '@/types/shared'
|
import { SelectBoxOption } from '@/types/shared'
|
||||||
import { useStoreState } from '@/store/store'
|
import { MenuService } from '@/services/menu.service'
|
||||||
|
import { MenuDto } from '@/proxy/menus/models'
|
||||||
|
|
||||||
// Validation schema
|
// Validation schema
|
||||||
const validationSchema = Yup.object({
|
const validationSchema = Yup.object({
|
||||||
|
|
@ -50,36 +51,34 @@ const EntityEditor: React.FC = () => {
|
||||||
const { id } = useParams()
|
const { id } = useParams()
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const { translate } = useLocalization()
|
const { translate } = useLocalization()
|
||||||
const { mainMenu } = useStoreState((state) => state.abpConfig.menu)
|
|
||||||
const { getEntity, addEntity, updateEntity } = useEntities()
|
const { getEntity, addEntity, updateEntity } = useEntities()
|
||||||
|
|
||||||
const isEditing = !!id
|
const isEditing = !!id
|
||||||
|
|
||||||
// Convert first level menu items to select options with prefix
|
// Menu options state
|
||||||
const menuOptions = useMemo(() => {
|
const [menuOptions, setMenuOptions] = useState<SelectBoxOption[]>([])
|
||||||
if (!mainMenu || mainMenu.length === 0) return []
|
|
||||||
|
// Fetch menu options on mount
|
||||||
const prefixMap: Record<string, string> = {
|
useEffect(() => {
|
||||||
'Platform': 'Plat',
|
const fetchMenuOptions = async () => {
|
||||||
'Saas': 'Sas',
|
try {
|
||||||
'Administration': 'Adm',
|
const menuService = new MenuService()
|
||||||
'Crm': 'Crm',
|
const response = await menuService.getListMainMenu()
|
||||||
'Coordinator': 'Crd',
|
|
||||||
'SupplyChain': 'Scp',
|
if (response.data && Array.isArray(response.data)) {
|
||||||
'Maintenance': 'Mnt',
|
const options = response.data.map((menuItem: any) => ({
|
||||||
'Warehouse': 'Str',
|
value: menuItem.shortName || menuItem.code,
|
||||||
'Project': 'Prj',
|
label: menuItem.displayName || menuItem.code,
|
||||||
'Hr': 'Hr',
|
}))
|
||||||
'Mrp': 'Mrp',
|
setMenuOptions(options)
|
||||||
'Accounting': 'Acc',
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching menu options:', error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return mainMenu.map((menuItem) => ({
|
fetchMenuOptions()
|
||||||
value: menuItem.key,
|
}, [])
|
||||||
label: menuItem.title,
|
|
||||||
prefix: menuItem.shortName || prefixMap[menuItem.key] || menuItem.key.substring(0, 3),
|
|
||||||
}))
|
|
||||||
}, [mainMenu])
|
|
||||||
|
|
||||||
// Initial values for Formik
|
// Initial values for Formik
|
||||||
const [initialValues, setInitialValues] = useState({
|
const [initialValues, setInitialValues] = useState({
|
||||||
|
|
@ -182,7 +181,7 @@ const EntityEditor: React.FC = () => {
|
||||||
if (!menuValue || !entityName) return ''
|
if (!menuValue || !entityName) return ''
|
||||||
const selectedMenu = menuOptions.find((opt) => opt.value === menuValue)
|
const selectedMenu = menuOptions.find((opt) => opt.value === menuValue)
|
||||||
if (!selectedMenu) return ''
|
if (!selectedMenu) return ''
|
||||||
return `${selectedMenu.prefix}_D_${entityName}`
|
return `${selectedMenu.value}_D_${entityName}`
|
||||||
}
|
}
|
||||||
|
|
||||||
const fieldTypes = [
|
const fieldTypes = [
|
||||||
|
|
@ -365,7 +364,7 @@ const EntityEditor: React.FC = () => {
|
||||||
<p className="text-xs text-slate-500 mt-1">
|
<p className="text-xs text-slate-500 mt-1">
|
||||||
Format:{' '}
|
Format:{' '}
|
||||||
{values.menu
|
{values.menu
|
||||||
? `${menuOptions.find((opt) => opt.value === values.menu)?.prefix || '[Prefix]'}_D_`
|
? `${menuOptions.find((opt) => opt.value === values.menu)?.value || '[Prefix]'}_D_`
|
||||||
: '[Prefix]_D_'}
|
: '[Prefix]_D_'}
|
||||||
EntityName
|
EntityName
|
||||||
</p>
|
</p>
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
import { PagedAndSortedResultRequestDto, PagedResultDto } from '@/proxy/abp'
|
import { PagedAndSortedResultRequestDto, PagedResultDto } from '@/proxy/abp'
|
||||||
import { MenuDto } from '@/proxy/menus/models'
|
import { MenuDto } from '@/proxy/menus/models'
|
||||||
import apiService, { Config } from '@/services/api.service'
|
import apiService, { Config } from '@/services/api.service'
|
||||||
import { useStoreState } from '@/store/store'
|
|
||||||
import { useState } from 'react'
|
|
||||||
|
|
||||||
export class MenuService {
|
export class MenuService {
|
||||||
apiName = 'Default'
|
apiName = 'Default'
|
||||||
|
|
@ -68,6 +66,15 @@ export class MenuService {
|
||||||
},
|
},
|
||||||
{ apiName: this.apiName },
|
{ apiName: this.apiName },
|
||||||
)
|
)
|
||||||
|
|
||||||
|
getListMainMenu = () =>
|
||||||
|
apiService.fetchData<MenuDto[]>(
|
||||||
|
{
|
||||||
|
method: 'GET',
|
||||||
|
url: `/api/app/menu/main-menu`,
|
||||||
|
},
|
||||||
|
{ apiName: this.apiName },
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getMenus = async (skipCount = 0, maxResultCount = 1000, sorting = 'order') => {
|
export const getMenus = async (skipCount = 0, maxResultCount = 1000, sorting = 'order') => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue