Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add quick edit mode options #178

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions fastapi_amis_admin/admin/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ async def has_action_permission(self, request: Request, name: str) -> bool:


class ModelAdmin(SqlalchemyCrud, BaseActionAdmin):
list_quick: List[Union[SqlaField, TableColumn]] = [] # Fields to be quick edit mode
list_display: List[Union[SqlaField, TableColumn]] = [] # Fields to be displayed
list_filter: List[Union[SqlaField, FormItem]] = [] # Query filterable fields
list_per_page: int = 10 # Amount of data per page
Expand Down Expand Up @@ -660,6 +661,9 @@ def get_link_model_forms(self) -> List[LinkModelForm]:
)
)
return self.link_model_forms

async def get_list_quick(self, request: Request) -> List[Union[SqlaField, TableColumn]]:
return self.list_quick

async def get_list_display(self, request: Request) -> List[Union[SqlaField, TableColumn]]:
return self.list_display or list(model_fields(self.schema_list).values())
Expand All @@ -678,26 +682,34 @@ async def get_column_quick_edit(self, request: Request, modelfield: ModelField)
item.update({"mode": "inline"})
return item

async def get_list_column(self, request: Request, modelfield: ModelField) -> TableColumn:
async def get_list_column(self, request: Request, modelfield: ModelField, quick_fields: dict={}) -> TableColumn:
column = self.amis_parser.as_table_column(modelfield)
if await self.has_update_permission(request, None, None) and modelfield.name in model_fields( # type: ignore
self.schema_update
):
if column.type == "switch":
column.disabled = False
column.quickEdit = await self.get_column_quick_edit(request, modelfield)

if column.name in quick_fields.keys():
column.quickEdit = await self.get_column_quick_edit(request, modelfield)
return column

async def get_list_columns(self, request: Request) -> List[TableColumn]:
columns = []
quick_fields = await self.get_list_quick(request)

quick_maps = {}
for f in quick_fields:
quick_maps[f.name] = 1

for field in await self.get_list_display(request):
column = None
if isinstance(field, BaseAmisModel):
column = field
else:
modelfield = self.parser.get_modelfield(field)
if modelfield:
column = await self.get_list_column(request, modelfield)
column = await self.get_list_column(request, modelfield, quick_maps)
if column:
columns.append(column)
return columns
Expand Down