-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #918 from ae-utbm/taiste
Ajax search input enhancement, promo 25 logo and small improvements
- Loading branch information
Showing
74 changed files
with
1,774 additions
and
1,014 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
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,23 @@ | ||
from typing import Annotated | ||
|
||
from annotated_types import MinLen | ||
from ninja_extra import ControllerBase, api_controller, paginate, route | ||
from ninja_extra.pagination import PageNumberPaginationExtra | ||
from ninja_extra.schemas import PaginatedResponseSchema | ||
|
||
from accounting.models import ClubAccount, Company | ||
from accounting.schemas import ClubAccountSchema, CompanySchema | ||
from core.api_permissions import CanAccessLookup | ||
|
||
|
||
@api_controller("/lookup", permissions=[CanAccessLookup]) | ||
class AccountingController(ControllerBase): | ||
@route.get("/club-account", response=PaginatedResponseSchema[ClubAccountSchema]) | ||
@paginate(PageNumberPaginationExtra, page_size=50) | ||
def search_club_account(self, search: Annotated[str, MinLen(1)]): | ||
return ClubAccount.objects.filter(name__icontains=search).values() | ||
|
||
@route.get("/company", response=PaginatedResponseSchema[CompanySchema]) | ||
@paginate(PageNumberPaginationExtra, page_size=50) | ||
def search_company(self, search: Annotated[str, MinLen(1)]): | ||
return Company.objects.filter(name__icontains=search).values() |
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,15 @@ | ||
from ninja import ModelSchema | ||
|
||
from accounting.models import ClubAccount, Company | ||
|
||
|
||
class ClubAccountSchema(ModelSchema): | ||
class Meta: | ||
model = ClubAccount | ||
fields = ["id", "name"] | ||
|
||
|
||
class CompanySchema(ModelSchema): | ||
class Meta: | ||
model = Company | ||
fields = ["id", "name"] |
60 changes: 60 additions & 0 deletions
60
accounting/static/webpack/accounting/components/ajax-select-index.ts
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,60 @@ | ||
import { AjaxSelect } from "#core:core/components/ajax-select-base"; | ||
import { registerComponent } from "#core:utils/web-components"; | ||
import type { TomOption } from "tom-select/dist/types/types"; | ||
import type { escape_html } from "tom-select/dist/types/utils"; | ||
import { | ||
type ClubAccountSchema, | ||
type CompanySchema, | ||
accountingSearchClubAccount, | ||
accountingSearchCompany, | ||
} from "#openapi"; | ||
|
||
@registerComponent("club-account-ajax-select") | ||
export class ClubAccountAjaxSelect extends AjaxSelect { | ||
protected valueField = "id"; | ||
protected labelField = "name"; | ||
protected searchField = ["code", "name"]; | ||
|
||
protected async search(query: string): Promise<TomOption[]> { | ||
const resp = await accountingSearchClubAccount({ query: { search: query } }); | ||
if (resp.data) { | ||
return resp.data.results; | ||
} | ||
return []; | ||
} | ||
|
||
protected renderOption(item: ClubAccountSchema, sanitize: typeof escape_html) { | ||
return `<div class="select-item"> | ||
<span class="select-item-text">${sanitize(item.name)}</span> | ||
</div>`; | ||
} | ||
|
||
protected renderItem(item: ClubAccountSchema, sanitize: typeof escape_html) { | ||
return `<span>${sanitize(item.name)}</span>`; | ||
} | ||
} | ||
|
||
@registerComponent("company-ajax-select") | ||
export class CompanyAjaxSelect extends AjaxSelect { | ||
protected valueField = "id"; | ||
protected labelField = "name"; | ||
protected searchField = ["code", "name"]; | ||
|
||
protected async search(query: string): Promise<TomOption[]> { | ||
const resp = await accountingSearchCompany({ query: { search: query } }); | ||
if (resp.data) { | ||
return resp.data.results; | ||
} | ||
return []; | ||
} | ||
|
||
protected renderOption(item: CompanySchema, sanitize: typeof escape_html) { | ||
return `<div class="select-item"> | ||
<span class="select-item-text">${sanitize(item.name)}</span> | ||
</div>`; | ||
} | ||
|
||
protected renderItem(item: CompanySchema, sanitize: typeof escape_html) { | ||
return `<span>${sanitize(item.name)}</span>`; | ||
} | ||
} |
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,39 @@ | ||
from pydantic import TypeAdapter | ||
|
||
from accounting.models import ClubAccount, Company | ||
from accounting.schemas import ClubAccountSchema, CompanySchema | ||
from core.views.widgets.select import AutoCompleteSelect, AutoCompleteSelectMultiple | ||
|
||
_js = ["webpack/accounting/components/ajax-select-index.ts"] | ||
|
||
|
||
class AutoCompleteSelectClubAccount(AutoCompleteSelect): | ||
component_name = "club-account-ajax-select" | ||
model = ClubAccount | ||
adapter = TypeAdapter(list[ClubAccountSchema]) | ||
|
||
js = _js | ||
|
||
|
||
class AutoCompleteSelectMultipleClubAccount(AutoCompleteSelectMultiple): | ||
component_name = "club-account-ajax-select" | ||
model = ClubAccount | ||
adapter = TypeAdapter(list[ClubAccountSchema]) | ||
|
||
js = _js | ||
|
||
|
||
class AutoCompleteSelectCompany(AutoCompleteSelect): | ||
component_name = "company-ajax-select" | ||
model = Company | ||
adapter = TypeAdapter(list[CompanySchema]) | ||
|
||
js = _js | ||
|
||
|
||
class AutoCompleteSelectMultipleCompany(AutoCompleteSelectMultiple): | ||
component_name = "company-ajax-select" | ||
model = Company | ||
adapter = TypeAdapter(list[CompanySchema]) | ||
|
||
js = _js |
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,22 @@ | ||
from typing import Annotated | ||
|
||
from annotated_types import MinLen | ||
from ninja_extra import ControllerBase, api_controller, paginate, route | ||
from ninja_extra.pagination import PageNumberPaginationExtra | ||
from ninja_extra.schemas import PaginatedResponseSchema | ||
|
||
from club.models import Club | ||
from club.schemas import ClubSchema | ||
from core.api_permissions import CanAccessLookup | ||
|
||
|
||
@api_controller("/club") | ||
class ClubController(ControllerBase): | ||
@route.get( | ||
"/search", | ||
response=PaginatedResponseSchema[ClubSchema], | ||
permissions=[CanAccessLookup], | ||
) | ||
@paginate(PageNumberPaginationExtra, page_size=50) | ||
def search_club(self, search: Annotated[str, MinLen(1)]): | ||
return Club.objects.filter(name__icontains=search).values() |
Oops, something went wrong.