fix recently added on homescreen

This commit is contained in:
Hayden 2023-04-01 21:42:12 -08:00
parent 84bdb8c9a5
commit 38095c1889
No known key found for this signature in database
GPG key ID: 17CF79474E257545
5 changed files with 27 additions and 9 deletions

View file

@ -58,6 +58,7 @@ func (ctrl *V1Controller) HandleItemsGetAll() errchain.HandlerFunc {
LabelIDs: queryUUIDList(params, "labels"),
IncludeArchived: queryBool(params.Get("includeArchived")),
Fields: filterFieldItems(params["fields"]),
OrderBy: params.Get("orderBy"),
}
if strings.HasPrefix(v.Search, "#") {

View file

@ -29,13 +29,14 @@ type (
ItemQuery struct {
Page int
PageSize int
Search string `json:"search"`
AssetID AssetID `json:"assetId"`
LocationIDs []uuid.UUID `json:"locationIds"`
LabelIDs []uuid.UUID `json:"labelIds"`
SortBy string `json:"sortBy"`
IncludeArchived bool `json:"includeArchived"`
Fields []FieldQuery
Search string `json:"search"`
AssetID AssetID `json:"assetId"`
LocationIDs []uuid.UUID `json:"locationIds"`
LabelIDs []uuid.UUID `json:"labelIds"`
SortBy string `json:"sortBy"`
IncludeArchived bool `json:"includeArchived"`
Fields []FieldQuery `json:"fields"`
OrderBy string `json:"orderBy"`
}
ItemField struct {
@ -385,7 +386,17 @@ func (e *ItemsRepository) QueryByGroup(ctx context.Context, gid uuid.UUID, q Ite
return PaginationResult[ItemSummary]{}, err
}
qb = qb.Order(ent.Asc(item.FieldName)).
// Order
switch q.OrderBy {
case "createdAt":
qb = qb.Order(ent.Desc(item.FieldCreatedAt))
case "updatedAt":
qb = qb.Order(ent.Desc(item.FieldUpdatedAt))
default: // "name"
qb = qb.Order(ent.Asc(item.FieldName))
}
qb = qb.
WithLabel().
WithLocation()

View file

@ -79,7 +79,7 @@
};
const props = defineProps<Props>();
const sortByProperty = ref<keyof ItemSummary>("name");
const sortByProperty = ref<keyof ItemSummary | "">("");
const headers = computed<TableHeader[]>(() => {
return [
@ -136,6 +136,10 @@
}
function itemSort(a: ItemSummary, b: ItemSummary) {
if (!sortByProperty.value) {
return 0;
}
const aLower = extractSortable(a, sortByProperty.value);
const bLower = extractSortable(b, sortByProperty.value);

View file

@ -15,6 +15,7 @@ import { AttachmentTypes, PaginationResult } from "../types/non-generated";
import { Requests } from "~~/lib/requests";
export type ItemsQuery = {
orderBy?: string;
includeArchived?: boolean;
page?: number;
pageSize?: number;

View file

@ -5,6 +5,7 @@ export function itemsTable(api: UserClient) {
const { data } = await api.items.getAll({
page: 1,
pageSize: 5,
orderBy: "createdAt",
});
return data.items;
});