mirror of
https://github.com/hay-kot/homebox.git
synced 2025-06-04 19:42:29 +00:00
feat: QR Codes (#226)
* code gen updates * qrcode support * remove opacity on toast * update item view to use tab-like pages * adjust view for cards * fix old API calls for ioutils * move embed * extract QR code * add docs for QR codes * add QR code
This commit is contained in:
parent
f532b39c46
commit
c19fe94c08
88 changed files with 3151 additions and 6454 deletions
|
@ -26,6 +26,7 @@ type LocationQuery struct {
|
|||
unique *bool
|
||||
order []OrderFunc
|
||||
fields []string
|
||||
inters []Interceptor
|
||||
predicates []predicate.Location
|
||||
withParent *LocationQuery
|
||||
withChildren *LocationQuery
|
||||
|
@ -43,13 +44,13 @@ func (lq *LocationQuery) Where(ps ...predicate.Location) *LocationQuery {
|
|||
return lq
|
||||
}
|
||||
|
||||
// Limit adds a limit step to the query.
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (lq *LocationQuery) Limit(limit int) *LocationQuery {
|
||||
lq.limit = &limit
|
||||
return lq
|
||||
}
|
||||
|
||||
// Offset adds an offset step to the query.
|
||||
// Offset to start from.
|
||||
func (lq *LocationQuery) Offset(offset int) *LocationQuery {
|
||||
lq.offset = &offset
|
||||
return lq
|
||||
|
@ -62,7 +63,7 @@ func (lq *LocationQuery) Unique(unique bool) *LocationQuery {
|
|||
return lq
|
||||
}
|
||||
|
||||
// Order adds an order step to the query.
|
||||
// Order specifies how the records should be ordered.
|
||||
func (lq *LocationQuery) Order(o ...OrderFunc) *LocationQuery {
|
||||
lq.order = append(lq.order, o...)
|
||||
return lq
|
||||
|
@ -70,7 +71,7 @@ func (lq *LocationQuery) Order(o ...OrderFunc) *LocationQuery {
|
|||
|
||||
// QueryParent chains the current query on the "parent" edge.
|
||||
func (lq *LocationQuery) QueryParent() *LocationQuery {
|
||||
query := &LocationQuery{config: lq.config}
|
||||
query := (&LocationClient{config: lq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := lq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
|
@ -92,7 +93,7 @@ func (lq *LocationQuery) QueryParent() *LocationQuery {
|
|||
|
||||
// QueryChildren chains the current query on the "children" edge.
|
||||
func (lq *LocationQuery) QueryChildren() *LocationQuery {
|
||||
query := &LocationQuery{config: lq.config}
|
||||
query := (&LocationClient{config: lq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := lq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
|
@ -114,7 +115,7 @@ func (lq *LocationQuery) QueryChildren() *LocationQuery {
|
|||
|
||||
// QueryGroup chains the current query on the "group" edge.
|
||||
func (lq *LocationQuery) QueryGroup() *GroupQuery {
|
||||
query := &GroupQuery{config: lq.config}
|
||||
query := (&GroupClient{config: lq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := lq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
|
@ -136,7 +137,7 @@ func (lq *LocationQuery) QueryGroup() *GroupQuery {
|
|||
|
||||
// QueryItems chains the current query on the "items" edge.
|
||||
func (lq *LocationQuery) QueryItems() *ItemQuery {
|
||||
query := &ItemQuery{config: lq.config}
|
||||
query := (&ItemClient{config: lq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := lq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
|
@ -159,7 +160,7 @@ func (lq *LocationQuery) QueryItems() *ItemQuery {
|
|||
// First returns the first Location entity from the query.
|
||||
// Returns a *NotFoundError when no Location was found.
|
||||
func (lq *LocationQuery) First(ctx context.Context) (*Location, error) {
|
||||
nodes, err := lq.Limit(1).All(ctx)
|
||||
nodes, err := lq.Limit(1).All(newQueryContext(ctx, TypeLocation, "First"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -182,7 +183,7 @@ func (lq *LocationQuery) FirstX(ctx context.Context) *Location {
|
|||
// Returns a *NotFoundError when no Location ID was found.
|
||||
func (lq *LocationQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
|
||||
var ids []uuid.UUID
|
||||
if ids, err = lq.Limit(1).IDs(ctx); err != nil {
|
||||
if ids, err = lq.Limit(1).IDs(newQueryContext(ctx, TypeLocation, "FirstID")); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
|
@ -205,7 +206,7 @@ func (lq *LocationQuery) FirstIDX(ctx context.Context) uuid.UUID {
|
|||
// Returns a *NotSingularError when more than one Location entity is found.
|
||||
// Returns a *NotFoundError when no Location entities are found.
|
||||
func (lq *LocationQuery) Only(ctx context.Context) (*Location, error) {
|
||||
nodes, err := lq.Limit(2).All(ctx)
|
||||
nodes, err := lq.Limit(2).All(newQueryContext(ctx, TypeLocation, "Only"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -233,7 +234,7 @@ func (lq *LocationQuery) OnlyX(ctx context.Context) *Location {
|
|||
// Returns a *NotFoundError when no entities are found.
|
||||
func (lq *LocationQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
|
||||
var ids []uuid.UUID
|
||||
if ids, err = lq.Limit(2).IDs(ctx); err != nil {
|
||||
if ids, err = lq.Limit(2).IDs(newQueryContext(ctx, TypeLocation, "OnlyID")); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
|
@ -258,10 +259,12 @@ func (lq *LocationQuery) OnlyIDX(ctx context.Context) uuid.UUID {
|
|||
|
||||
// All executes the query and returns a list of Locations.
|
||||
func (lq *LocationQuery) All(ctx context.Context) ([]*Location, error) {
|
||||
ctx = newQueryContext(ctx, TypeLocation, "All")
|
||||
if err := lq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return lq.sqlAll(ctx)
|
||||
qr := querierAll[[]*Location, *LocationQuery]()
|
||||
return withInterceptors[[]*Location](ctx, lq, qr, lq.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
|
@ -276,6 +279,7 @@ func (lq *LocationQuery) AllX(ctx context.Context) []*Location {
|
|||
// IDs executes the query and returns a list of Location IDs.
|
||||
func (lq *LocationQuery) IDs(ctx context.Context) ([]uuid.UUID, error) {
|
||||
var ids []uuid.UUID
|
||||
ctx = newQueryContext(ctx, TypeLocation, "IDs")
|
||||
if err := lq.Select(location.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -293,10 +297,11 @@ func (lq *LocationQuery) IDsX(ctx context.Context) []uuid.UUID {
|
|||
|
||||
// Count returns the count of the given query.
|
||||
func (lq *LocationQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = newQueryContext(ctx, TypeLocation, "Count")
|
||||
if err := lq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return lq.sqlCount(ctx)
|
||||
return withInterceptors[int](ctx, lq, querierCount[*LocationQuery](), lq.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
|
@ -310,10 +315,15 @@ func (lq *LocationQuery) CountX(ctx context.Context) int {
|
|||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (lq *LocationQuery) Exist(ctx context.Context) (bool, error) {
|
||||
if err := lq.prepareQuery(ctx); err != nil {
|
||||
return false, err
|
||||
ctx = newQueryContext(ctx, TypeLocation, "Exist")
|
||||
switch _, err := lq.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
return false, nil
|
||||
case err != nil:
|
||||
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
return lq.sqlExist(ctx)
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
|
@ -336,6 +346,7 @@ func (lq *LocationQuery) Clone() *LocationQuery {
|
|||
limit: lq.limit,
|
||||
offset: lq.offset,
|
||||
order: append([]OrderFunc{}, lq.order...),
|
||||
inters: append([]Interceptor{}, lq.inters...),
|
||||
predicates: append([]predicate.Location{}, lq.predicates...),
|
||||
withParent: lq.withParent.Clone(),
|
||||
withChildren: lq.withChildren.Clone(),
|
||||
|
@ -351,7 +362,7 @@ func (lq *LocationQuery) Clone() *LocationQuery {
|
|||
// WithParent tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "parent" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (lq *LocationQuery) WithParent(opts ...func(*LocationQuery)) *LocationQuery {
|
||||
query := &LocationQuery{config: lq.config}
|
||||
query := (&LocationClient{config: lq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
|
@ -362,7 +373,7 @@ func (lq *LocationQuery) WithParent(opts ...func(*LocationQuery)) *LocationQuery
|
|||
// WithChildren tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "children" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (lq *LocationQuery) WithChildren(opts ...func(*LocationQuery)) *LocationQuery {
|
||||
query := &LocationQuery{config: lq.config}
|
||||
query := (&LocationClient{config: lq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
|
@ -373,7 +384,7 @@ func (lq *LocationQuery) WithChildren(opts ...func(*LocationQuery)) *LocationQue
|
|||
// WithGroup tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "group" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (lq *LocationQuery) WithGroup(opts ...func(*GroupQuery)) *LocationQuery {
|
||||
query := &GroupQuery{config: lq.config}
|
||||
query := (&GroupClient{config: lq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
|
@ -384,7 +395,7 @@ func (lq *LocationQuery) WithGroup(opts ...func(*GroupQuery)) *LocationQuery {
|
|||
// WithItems tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "items" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (lq *LocationQuery) WithItems(opts ...func(*ItemQuery)) *LocationQuery {
|
||||
query := &ItemQuery{config: lq.config}
|
||||
query := (&ItemClient{config: lq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
|
@ -407,16 +418,11 @@ func (lq *LocationQuery) WithItems(opts ...func(*ItemQuery)) *LocationQuery {
|
|||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (lq *LocationQuery) GroupBy(field string, fields ...string) *LocationGroupBy {
|
||||
grbuild := &LocationGroupBy{config: lq.config}
|
||||
grbuild.fields = append([]string{field}, fields...)
|
||||
grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||
if err := lq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return lq.sqlQuery(ctx), nil
|
||||
}
|
||||
lq.fields = append([]string{field}, fields...)
|
||||
grbuild := &LocationGroupBy{build: lq}
|
||||
grbuild.flds = &lq.fields
|
||||
grbuild.label = location.Label
|
||||
grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
|
@ -434,10 +440,10 @@ func (lq *LocationQuery) GroupBy(field string, fields ...string) *LocationGroupB
|
|||
// Scan(ctx, &v)
|
||||
func (lq *LocationQuery) Select(fields ...string) *LocationSelect {
|
||||
lq.fields = append(lq.fields, fields...)
|
||||
selbuild := &LocationSelect{LocationQuery: lq}
|
||||
selbuild.label = location.Label
|
||||
selbuild.flds, selbuild.scan = &lq.fields, selbuild.Scan
|
||||
return selbuild
|
||||
sbuild := &LocationSelect{LocationQuery: lq}
|
||||
sbuild.label = location.Label
|
||||
sbuild.flds, sbuild.scan = &lq.fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a LocationSelect configured with the given aggregations.
|
||||
|
@ -446,6 +452,16 @@ func (lq *LocationQuery) Aggregate(fns ...AggregateFunc) *LocationSelect {
|
|||
}
|
||||
|
||||
func (lq *LocationQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range lq.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, lq); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range lq.fields {
|
||||
if !location.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
|
@ -656,17 +672,6 @@ func (lq *LocationQuery) sqlCount(ctx context.Context) (int, error) {
|
|||
return sqlgraph.CountNodes(ctx, lq.driver, _spec)
|
||||
}
|
||||
|
||||
func (lq *LocationQuery) sqlExist(ctx context.Context) (bool, error) {
|
||||
switch _, err := lq.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
return false, nil
|
||||
case err != nil:
|
||||
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (lq *LocationQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := &sqlgraph.QuerySpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
|
@ -749,13 +754,8 @@ func (lq *LocationQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
|||
|
||||
// LocationGroupBy is the group-by builder for Location entities.
|
||||
type LocationGroupBy struct {
|
||||
config
|
||||
selector
|
||||
fields []string
|
||||
fns []AggregateFunc
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
build *LocationQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
|
@ -764,58 +764,46 @@ func (lgb *LocationGroupBy) Aggregate(fns ...AggregateFunc) *LocationGroupBy {
|
|||
return lgb
|
||||
}
|
||||
|
||||
// Scan applies the group-by query and scans the result into the given value.
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (lgb *LocationGroupBy) Scan(ctx context.Context, v any) error {
|
||||
query, err := lgb.path(ctx)
|
||||
if err != nil {
|
||||
ctx = newQueryContext(ctx, TypeLocation, "GroupBy")
|
||||
if err := lgb.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
lgb.sql = query
|
||||
return lgb.sqlScan(ctx, v)
|
||||
return scanWithInterceptors[*LocationQuery, *LocationGroupBy](ctx, lgb.build, lgb, lgb.build.inters, v)
|
||||
}
|
||||
|
||||
func (lgb *LocationGroupBy) sqlScan(ctx context.Context, v any) error {
|
||||
for _, f := range lgb.fields {
|
||||
if !location.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)}
|
||||
}
|
||||
func (lgb *LocationGroupBy) sqlScan(ctx context.Context, root *LocationQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(lgb.fns))
|
||||
for _, fn := range lgb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
selector := lgb.sqlQuery()
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*lgb.flds)+len(lgb.fns))
|
||||
for _, f := range *lgb.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*lgb.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := lgb.driver.Query(ctx, query, args, rows); err != nil {
|
||||
if err := lgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
func (lgb *LocationGroupBy) sqlQuery() *sql.Selector {
|
||||
selector := lgb.sql.Select()
|
||||
aggregation := make([]string, 0, len(lgb.fns))
|
||||
for _, fn := range lgb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(lgb.fields)+len(lgb.fns))
|
||||
for _, f := range lgb.fields {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
return selector.GroupBy(selector.Columns(lgb.fields...)...)
|
||||
}
|
||||
|
||||
// LocationSelect is the builder for selecting fields of Location entities.
|
||||
type LocationSelect struct {
|
||||
*LocationQuery
|
||||
selector
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
|
@ -826,26 +814,27 @@ func (ls *LocationSelect) Aggregate(fns ...AggregateFunc) *LocationSelect {
|
|||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (ls *LocationSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = newQueryContext(ctx, TypeLocation, "Select")
|
||||
if err := ls.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
ls.sql = ls.LocationQuery.sqlQuery(ctx)
|
||||
return ls.sqlScan(ctx, v)
|
||||
return scanWithInterceptors[*LocationQuery, *LocationSelect](ctx, ls.LocationQuery, ls, ls.inters, v)
|
||||
}
|
||||
|
||||
func (ls *LocationSelect) sqlScan(ctx context.Context, v any) error {
|
||||
func (ls *LocationSelect) sqlScan(ctx context.Context, root *LocationQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(ls.fns))
|
||||
for _, fn := range ls.fns {
|
||||
aggregation = append(aggregation, fn(ls.sql))
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*ls.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
ls.sql.Select(aggregation...)
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
ls.sql.AppendSelect(aggregation...)
|
||||
selector.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := ls.sql.Query()
|
||||
query, args := selector.Query()
|
||||
if err := ls.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue