Documentation
¶
Index ¶
- Constants
- Variables
- func RegisterAdminRoutes(r modulekit.Mux, gc *GalleryController, admin func(http.Handler) http.Handler)
- func RegisterGalleryRoutes(r modulekit.Mux, gc *GalleryController)
- func RegisterHooks(settings SettingsRepository, galleries GalleryService, ...)
- func Wire(d modulekit.Deps) modulekit.Parts
- type ContentTypeIDs
- type DefaultGalleriesService
- func (s *DefaultGalleriesService) AddItem(ctx context.Context, input GalleryItemCreateInput) (*GalleryItem, error)
- func (s *DefaultGalleriesService) ByID(ctx context.Context, id int) (*Gallery, error)
- func (s *DefaultGalleriesService) ByNodeID(ctx context.Context, nodeID int) (Galleries, error)
- func (s *DefaultGalleriesService) CountsByNodeIDs(ctx context.Context, ids []int) (map[int]NodeGalleryCounts, error)
- func (s *DefaultGalleriesService) Create(ctx context.Context, input GalleryCreateInput) (*Gallery, error)
- func (s *DefaultGalleriesService) Delete(ctx context.Context, id int) error
- func (s *DefaultGalleriesService) DeleteByNodeIDWithItems(ctx context.Context, nodeID int) error
- func (s *DefaultGalleriesService) DeleteWithItems(ctx context.Context, id int) error
- func (s *DefaultGalleriesService) Find(ctx context.Context, filter GalleriesFilter) (Galleries, error)
- func (s *DefaultGalleriesService) GetCover(ctx context.Context, galleryID int) (*GalleryItem, error)
- func (s *DefaultGalleriesService) GetItemByID(ctx context.Context, itemID int) (*GalleryItem, error)
- func (s *DefaultGalleriesService) GetItems(ctx context.Context, galleryID int) (GalleryItems, error)
- func (s *DefaultGalleriesService) RemoveItem(ctx context.Context, id int) error
- func (s *DefaultGalleriesService) ReorderItems(ctx context.Context, items []GalleryItemReorder) error
- func (s *DefaultGalleriesService) SetCover(ctx context.Context, galleryID, itemID int) error
- func (s *DefaultGalleriesService) SummaryByNodeID(ctx context.Context, nodeID int) (Galleries, error)
- func (s *DefaultGalleriesService) TotalCount(ctx context.Context, filter GalleriesFilter) (int, error)
- func (s *DefaultGalleriesService) Update(ctx context.Context, id int, input GalleryUpdateInput) (*Gallery, error)
- func (s *DefaultGalleriesService) UpdateItem(ctx context.Context, id int, input GalleryItemUpdateInput) (*GalleryItem, error)
- type EntGalleryRepository
- func (r *EntGalleryRepository) AddItem(ctx context.Context, input GalleryItemCreateInput) (*GalleryItem, error)
- func (r *EntGalleryRepository) ByID(ctx context.Context, id int) (*Gallery, error)
- func (r *EntGalleryRepository) ByNodeID(ctx context.Context, nodeID int) (Galleries, error)
- func (r *EntGalleryRepository) CountsByNodeIDs(ctx context.Context, ids []int) (map[int]NodeGalleryCounts, error)
- func (r *EntGalleryRepository) Create(ctx context.Context, input GalleryCreateInput) (*Gallery, error)
- func (r *EntGalleryRepository) Delete(ctx context.Context, id int) error
- func (r *EntGalleryRepository) DeleteByNodeIDWithItems(ctx context.Context, nodeID int) error
- func (r *EntGalleryRepository) DeleteWithItems(ctx context.Context, id int) error
- func (r *EntGalleryRepository) Find(ctx context.Context, filter GalleriesFilter) (Galleries, error)
- func (r *EntGalleryRepository) GetCover(ctx context.Context, galleryID int) (*GalleryItem, error)
- func (r *EntGalleryRepository) GetItemByID(ctx context.Context, itemID int) (*GalleryItem, error)
- func (r *EntGalleryRepository) GetItemsByGalleryID(ctx context.Context, galleryID int) (GalleryItems, error)
- func (r *EntGalleryRepository) RemoveItem(ctx context.Context, id int) error
- func (r *EntGalleryRepository) ReorderItems(ctx context.Context, items []GalleryItemReorder) error
- func (r *EntGalleryRepository) SetCover(ctx context.Context, galleryID, itemID int) error
- func (r *EntGalleryRepository) SummaryByNodeID(ctx context.Context, nodeID int) (Galleries, error)
- func (r *EntGalleryRepository) TotalCount(ctx context.Context, filter GalleriesFilter) (int, error)
- func (r *EntGalleryRepository) Update(ctx context.Context, id int, input GalleryUpdateInput) (*Gallery, error)
- func (r *EntGalleryRepository) UpdateItem(ctx context.Context, id int, input GalleryItemUpdateInput) (*GalleryItem, error)
- type EntSettingsRepository
- func (r *EntSettingsRepository) EnabledNodeIDs(ctx context.Context) ([]int, error)
- func (r *EntSettingsRepository) NodeEnabled(ctx context.Context, nodeID int) (bool, error)
- func (r *EntSettingsRepository) SaveTypeSettings(ctx context.Context, contentTypeID int, s TypeSettings) error
- func (r *EntSettingsRepository) SetNodeEnabled(ctx context.Context, nodeID int, enabled bool) error
- func (r *EntSettingsRepository) TypeSettings(ctx context.Context, contentType string) (TypeSettings, error)
- type FileRefs
- type Galleries
- type GalleriesFilter
- type GalleriesRepository
- type Gallery
- func (g *Gallery) CoverListURI() string
- func (g *Gallery) GetCoverImage() *modulekit.File
- func (g *Gallery) GetCoverItem() *GalleryItem
- func (g *Gallery) GetDescription() string
- func (g *Gallery) GetFirstItem() *GalleryItem
- func (g *Gallery) GetPreviewItems(limit int) GalleryItems
- func (g *Gallery) GetRandomItems(limit int) GalleryItems
- func (g *Gallery) GetTitle() string
- func (g *Gallery) HasItems() bool
- func (g *Gallery) ItemsCount() int
- func (g *Gallery) PreviewLimit() int
- type GalleryController
- func (c *GalleryController) EditGallery(w http.ResponseWriter, r *http.Request)
- func (c *GalleryController) GalleriesEmbedHTML(w http.ResponseWriter, r *http.Request)
- func (c *GalleryController) GalleriesList(w http.ResponseWriter, r *http.Request)
- func (c *GalleryController) GalleriesOverview(w http.ResponseWriter, r *http.Request)
- func (c *GalleryController) GalleriesOverviewToggle(w http.ResponseWriter, r *http.Request)
- func (c *GalleryController) GalleryAddItem(w http.ResponseWriter, r *http.Request)
- func (c *GalleryController) GalleryCreate(w http.ResponseWriter, r *http.Request)
- func (c *GalleryController) GalleryDeleteConfirm(w http.ResponseWriter, r *http.Request)
- func (c *GalleryController) GalleryDeletePage(w http.ResponseWriter, r *http.Request)
- func (c *GalleryController) GalleryRemoveItem(w http.ResponseWriter, r *http.Request)
- func (c *GalleryController) GalleryReorder(w http.ResponseWriter, r *http.Request)
- func (c *GalleryController) GallerySetCover(w http.ResponseWriter, r *http.Request)
- func (c *GalleryController) GallerySetNodeMainImage(w http.ResponseWriter, r *http.Request)
- func (c *GalleryController) GalleryUpdate(w http.ResponseWriter, r *http.Request)
- func (c *GalleryController) GalleryUpdateItem(w http.ResponseWriter, r *http.Request)
- func (c *GalleryController) ViewGallery(w http.ResponseWriter, r *http.Request)
- type GalleryCreateInput
- type GalleryDeps
- type GalleryItem
- type GalleryItemCreateInput
- type GalleryItemReorder
- type GalleryItemUpdateInput
- type GalleryItems
- type GalleryService
- type GalleryUpdateInput
- type NodeGalleryCounts
- type NodeRefs
- type SettingsRepository
- type StyleNames
- type StyleRefs
- type TypeSettings
Constants ¶
const CoverListStyle = "gallery_cover"
CoverListStyle - the image style of a gallery's cover in a node's galleries list (/node/{id}/galleries).
Variables ¶
var Assets embed.FS
Assets - the module's templates/ and static/, built into the binary (modules.Assets, paths.SetModuleAssets): a site runs without the module's source directory.
var ErrGalleryFieldTooLong = errors.New("gallery field too long")
ErrGalleryFieldTooLong - a gallery/item title exceeds its column; wrapped with the field name and limit.
var ErrGalleryStyle = errors.New("no such image style")
ErrGalleryStyle - a gallery's preview style the site has no image style of.
Functions ¶
func RegisterAdminRoutes ¶
func RegisterAdminRoutes(r modulekit.Mux, gc *GalleryController, admin func(http.Handler) http.Handler)
RegisterAdminRoutes registers the galleries overview behind admin (sign-in and the admin permission).
func RegisterGalleryRoutes ¶
func RegisterGalleryRoutes(r modulekit.Mux, gc *GalleryController)
RegisterGalleryRoutes registers the galleries' routes on r: a node's galleries list, editing and deleting a gallery, its public page, the lazy-loaded galleries block of a node page and the JSON API of galleries and their images.
func RegisterHooks ¶
func RegisterHooks(settings SettingsRepository, galleries GalleryService, contentTypes modulekit.ContentTypeService, logger *slog.Logger)
RegisterHooks adds the module's parts of the core's pages: its section of the content type form and of the node form, the galleries button and links of node pages and their data for the block (wiring, at startup).
Types ¶
type ContentTypeIDs ¶
type ContentTypeIDs interface {
ContentTypeByMachineName(ctx context.Context, machineName string) (*modulekit.ContentTypeDef, error)
}
ContentTypeIDs - a content type's ID by its machine name (the core's content types).
type DefaultGalleriesService ¶
type DefaultGalleriesService struct {
// contains filtered or unexported fields
}
DefaultGalleriesService - GalleryService on a GalleriesRepository.
func (*DefaultGalleriesService) AddItem ¶
func (s *DefaultGalleriesService) AddItem(ctx context.Context, input GalleryItemCreateInput) (*GalleryItem, error)
AddItem adds an image (a file) to a gallery (an over-long title - ErrGalleryFieldTooLong).
func (*DefaultGalleriesService) CountsByNodeIDs ¶
func (s *DefaultGalleriesService) CountsByNodeIDs(ctx context.Context, ids []int) (map[int]NodeGalleryCounts, error)
CountsByNodeIDs - the galleries and images of the nodes among ids that have any (the admin's galleries overview).
func (*DefaultGalleriesService) Create ¶
func (s *DefaultGalleriesService) Create(ctx context.Context, input GalleryCreateInput) (*Gallery, error)
Create creates a gallery of the node: empty preview styles get the defaults, a style the site lacks is ErrGalleryStyle, an over-long title ErrGalleryFieldTooLong.
func (*DefaultGalleriesService) Delete ¶
func (s *DefaultGalleriesService) Delete(ctx context.Context, id int) error
Delete deletes the gallery (its items go by cascade).
func (*DefaultGalleriesService) DeleteByNodeIDWithItems ¶
func (s *DefaultGalleriesService) DeleteByNodeIDWithItems(ctx context.Context, nodeID int) error
DeleteByNodeIDWithItems deletes all the node's galleries with their items.
func (*DefaultGalleriesService) DeleteWithItems ¶
func (s *DefaultGalleriesService) DeleteWithItems(ctx context.Context, id int) error
DeleteWithItems deletes the gallery together with its items.
func (*DefaultGalleriesService) Find ¶
func (s *DefaultGalleriesService) Find(ctx context.Context, filter GalleriesFilter) (Galleries, error)
Find - the galleries matching filter, with their items and nodes.
func (*DefaultGalleriesService) GetCover ¶
func (s *DefaultGalleriesService) GetCover(ctx context.Context, galleryID int) (*GalleryItem, error)
GetCover - the gallery's cover: the item marked as cover, else its first item by weight.
func (*DefaultGalleriesService) GetItemByID ¶
func (s *DefaultGalleriesService) GetItemByID(ctx context.Context, itemID int) (*GalleryItem, error)
GetItemByID - the gallery item with its file and previews.
func (*DefaultGalleriesService) GetItems ¶
func (s *DefaultGalleriesService) GetItems(ctx context.Context, galleryID int) (GalleryItems, error)
GetItems - the gallery's items in their order, with their files and previews.
func (*DefaultGalleriesService) RemoveItem ¶
func (s *DefaultGalleriesService) RemoveItem(ctx context.Context, id int) error
RemoveItem removes the item from its gallery.
func (*DefaultGalleriesService) ReorderItems ¶
func (s *DefaultGalleriesService) ReorderItems(ctx context.Context, items []GalleryItemReorder) error
ReorderItems sets the items' weights (none to set, a bad ID or a negative weight - an error).
func (*DefaultGalleriesService) SetCover ¶
func (s *DefaultGalleriesService) SetCover(ctx context.Context, galleryID, itemID int) error
SetCover makes the item the gallery's only cover.
func (*DefaultGalleriesService) SummaryByNodeID ¶
func (s *DefaultGalleriesService) SummaryByNodeID(ctx context.Context, nodeID int) (Galleries, error)
SummaryByNodeID - the node's shown galleries without their images' files and previews (their titles and image counts).
func (*DefaultGalleriesService) TotalCount ¶
func (s *DefaultGalleriesService) TotalCount(ctx context.Context, filter GalleriesFilter) (int, error)
TotalCount - the number of galleries of filter's node and status.
func (*DefaultGalleriesService) Update ¶
func (s *DefaultGalleriesService) Update(ctx context.Context, id int, input GalleryUpdateInput) (*Gallery, error)
Update changes the gallery's fields set in input (a style the site lacks - ErrGalleryStyle, an over-long title - ErrGalleryFieldTooLong).
func (*DefaultGalleriesService) UpdateItem ¶
func (s *DefaultGalleriesService) UpdateItem(ctx context.Context, id int, input GalleryItemUpdateInput) (*GalleryItem, error)
UpdateItem changes the item's fields set in input (an over-long title - ErrGalleryFieldTooLong).
type EntGalleryRepository ¶
type EntGalleryRepository struct {
// contains filtered or unexported fields
}
EntGalleryRepository provides database access to galleries.
func NewGalleryRepository ¶
func NewGalleryRepository(db *sql.DB, nodes NodeRefs, files FileRefs, styles StyleRefs) *EntGalleryRepository
NewGalleryRepository - the galleries on db, on the module's own ent schema (ent/); their nodes, items' files and preview styles come from the core.
func (*EntGalleryRepository) AddItem ¶
func (r *EntGalleryRepository) AddItem(ctx context.Context, input GalleryItemCreateInput) (*GalleryItem, error)
AddItem adds an item to a gallery.
func (*EntGalleryRepository) CountsByNodeIDs ¶
func (r *EntGalleryRepository) CountsByNodeIDs(ctx context.Context, ids []int) (map[int]NodeGalleryCounts, error)
CountsByNodeIDs - per node of ids, its galleries and their images.
func (*EntGalleryRepository) Create ¶
func (r *EntGalleryRepository) Create(ctx context.Context, input GalleryCreateInput) (*Gallery, error)
Create creates a gallery.
func (*EntGalleryRepository) Delete ¶
func (r *EntGalleryRepository) Delete(ctx context.Context, id int) error
Delete deletes a gallery (items are removed by cascade).
func (*EntGalleryRepository) DeleteByNodeIDWithItems ¶
func (r *EntGalleryRepository) DeleteByNodeIDWithItems(ctx context.Context, nodeID int) error
DeleteByNodeIDWithItems deletes all galleries of a node with their items.
func (*EntGalleryRepository) DeleteWithItems ¶
func (r *EntGalleryRepository) DeleteWithItems(ctx context.Context, id int) error
DeleteWithItems deletes a gallery together with all its items.
func (*EntGalleryRepository) Find ¶
func (r *EntGalleryRepository) Find(ctx context.Context, filter GalleriesFilter) (Galleries, error)
Find returns galleries matching the filter.
func (*EntGalleryRepository) GetCover ¶
func (r *EntGalleryRepository) GetCover(ctx context.Context, galleryID int) (*GalleryItem, error)
GetCover returns the gallery cover.
func (*EntGalleryRepository) GetItemByID ¶
func (r *EntGalleryRepository) GetItemByID(ctx context.Context, itemID int) (*GalleryItem, error)
GetItemByID returns a gallery item by ID with its file and its previews in its gallery's styles.
func (*EntGalleryRepository) GetItemsByGalleryID ¶
func (r *EntGalleryRepository) GetItemsByGalleryID(ctx context.Context, galleryID int) (GalleryItems, error)
GetItemsByGalleryID returns all items of a gallery.
func (*EntGalleryRepository) RemoveItem ¶
func (r *EntGalleryRepository) RemoveItem(ctx context.Context, id int) error
RemoveItem removes an item from a gallery.
func (*EntGalleryRepository) ReorderItems ¶
func (r *EntGalleryRepository) ReorderItems(ctx context.Context, items []GalleryItemReorder) error
ReorderItems updates the weight of several items at once.
func (*EntGalleryRepository) SetCover ¶
func (r *EntGalleryRepository) SetCover(ctx context.Context, galleryID, itemID int) error
SetCover marks an item as the gallery cover.
func (*EntGalleryRepository) SummaryByNodeID ¶
SummaryByNodeID returns galleries for a node without loading item files/previews - cheap enough to call synchronously (e.g. for a "gallery name + link" list under the main image).
func (*EntGalleryRepository) TotalCount ¶
func (r *EntGalleryRepository) TotalCount(ctx context.Context, filter GalleriesFilter) (int, error)
TotalCount returns the number of galleries matching the filter.
func (*EntGalleryRepository) Update ¶
func (r *EntGalleryRepository) Update(ctx context.Context, id int, input GalleryUpdateInput) (*Gallery, error)
Update updates a gallery.
func (*EntGalleryRepository) UpdateItem ¶
func (r *EntGalleryRepository) UpdateItem(ctx context.Context, id int, input GalleryItemUpdateInput) (*GalleryItem, error)
UpdateItem updates a gallery item.
type EntSettingsRepository ¶
type EntSettingsRepository struct {
// contains filtered or unexported fields
}
EntSettingsRepository - SettingsRepository on the module's own ent schema (ent/).
func NewSettingsRepository ¶
func NewSettingsRepository(db *sql.DB, types ContentTypeIDs) *EntSettingsRepository
NewSettingsRepository creates the settings repository on db; the content types come from the core.
func (*EntSettingsRepository) EnabledNodeIDs ¶
func (r *EntSettingsRepository) EnabledNodeIDs(ctx context.Context) ([]int, error)
EnabledNodeIDs - see SettingsRepository.EnabledNodeIDs.
func (*EntSettingsRepository) NodeEnabled ¶
NodeEnabled - see SettingsRepository.NodeEnabled.
func (*EntSettingsRepository) SaveTypeSettings ¶
func (r *EntSettingsRepository) SaveTypeSettings(ctx context.Context, contentTypeID int, s TypeSettings) error
SaveTypeSettings writes the content type's galleries settings (its row, created if missing).
func (*EntSettingsRepository) SetNodeEnabled ¶
SetNodeEnabled turns the node's galleries on or off (whether it can have galleries).
func (*EntSettingsRepository) TypeSettings ¶
func (r *EntSettingsRepository) TypeSettings(ctx context.Context, contentType string) (TypeSettings, error)
TypeSettings - see SettingsRepository.TypeSettings.
type Galleries ¶
type Galleries []*Gallery
Galleries - a list of galleries (a node's, a page of a search).
func ToGalleriesEntity ¶
ToGalleriesEntity converts generated galleries to domain entities (ToGalleryEntity each).
func (Galleries) FilterByStatus ¶
FilterByStatus - the galleries whose Status is status (true - shown).
type GalleriesFilter ¶
type GalleriesFilter struct {
NodeID int
Status *bool
Offset int
Limit int
// Query - galleries whose title has it, or (NodeIDs) of these nodes:
// a search ("" - any).
Query string
NodeIDs []int
}
GalleriesFilter - which galleries Find returns: of a node (0 - any), shown or hidden (Status nil - both), a page (Offset, Limit 0 - all).
type GalleriesRepository ¶
type GalleriesRepository interface {
Find(ctx context.Context, filter GalleriesFilter) (Galleries, error)
TotalCount(ctx context.Context, filter GalleriesFilter) (int, error)
ByID(ctx context.Context, id int) (*Gallery, error)
ByNodeID(ctx context.Context, nodeID int) (Galleries, error)
// SummaryByNodeID returns galleries for a node without loading item files/previews.
SummaryByNodeID(ctx context.Context, nodeID int) (Galleries, error)
// CountsByNodeIDs - the galleries and images of the nodes among ids
// that have any.
CountsByNodeIDs(ctx context.Context, ids []int) (map[int]NodeGalleryCounts, error)
Create(ctx context.Context, input GalleryCreateInput) (*Gallery, error)
Update(ctx context.Context, id int, input GalleryUpdateInput) (*Gallery, error)
Delete(ctx context.Context, id int) error
DeleteWithItems(ctx context.Context, id int) error
DeleteByNodeIDWithItems(ctx context.Context, nodeID int) error
AddItem(ctx context.Context, input GalleryItemCreateInput) (*GalleryItem, error)
UpdateItem(ctx context.Context, id int, input GalleryItemUpdateInput) (*GalleryItem, error)
RemoveItem(ctx context.Context, id int) error
GetItemsByGalleryID(ctx context.Context, galleryID int) (GalleryItems, error)
GetItemByID(ctx context.Context, itemID int) (*GalleryItem, error)
ReorderItems(ctx context.Context, items []GalleryItemReorder) error
SetCover(ctx context.Context, galleryID, itemID int) error
GetCover(ctx context.Context, galleryID int) (*GalleryItem, error)
}
GalleriesRepository - the store of galleries and their items.
type Gallery ¶
type Gallery struct {
ID int
NodeID int
// PreviewSmallStyle/PreviewMediumStyle - the image styles of the
// grid previews and of the larger previews (image_styles.name).
PreviewSmallStyle string
PreviewMediumStyle string
Title *string
Description *string
Weight int
Status bool
CreatedAt time.Time
UpdatedAt time.Time
Node *modulekit.Node
Cover *modulekit.File
Items GalleryItems
// PreviewWidth/PreviewHeight - PreviewSmallStyle's size, read with
// the gallery (0 - unknown); IsPortrait - the style is taller than
// wide: the portrait grid, cells of its proportions.
PreviewWidth int
PreviewHeight int
IsPortrait bool
// NodePreviewCount - the previews on the content's page the block
// asks for (0 - the default, PreviewLimit).
NodePreviewCount int
}
Gallery - a gallery of images attached to a node: its title, its previews' image styles, its place among the node's galleries and its items.
func ToGalleryEntity ¶
ToGalleryEntity converts a generated gallery to its domain entity.
func (*Gallery) CoverListURI ¶
CoverListURI - the gallery's cover in CoverListStyle ("" - no cover).
func (*Gallery) GetCoverImage ¶
GetCoverImage - the file of the gallery's cover: the item marked as cover, else the first image (nil - none).
func (*Gallery) GetCoverItem ¶
func (g *Gallery) GetCoverItem() *GalleryItem
GetCoverItem - the gallery's cover item: the one marked as cover, else the first (nil - no items).
func (*Gallery) GetDescription ¶
GetDescription - the gallery's description ("" - none).
func (*Gallery) GetFirstItem ¶
func (g *Gallery) GetFirstItem() *GalleryItem
GetFirstItem - the gallery's first image (nil - none).
func (*Gallery) GetPreviewItems ¶
func (g *Gallery) GetPreviewItems(limit int) GalleryItems
GetPreviewItems returns first N items for preview
func (*Gallery) GetRandomItems ¶
func (g *Gallery) GetRandomItems(limit int) GalleryItems
GetRandomItems returns N random items for preview
func (*Gallery) ItemsCount ¶
ItemsCount - the number of the gallery's loaded images.
func (*Gallery) PreviewLimit ¶
PreviewLimit - how many previews the gallery shows on its content's page: the block's count, else the default for its grid. With more images the last preview leads to the whole gallery.
type GalleryController ¶
type GalleryController struct {
*modulekit.BaseController
// contains filtered or unexported fields
}
GalleryController serves node galleries: management pages, the JSON API and public gallery pages.
func NewGalleryController ¶
func NewGalleryController(deps modulekit.BaseDeps, d GalleryDeps) *GalleryController
NewGalleryController creates a GalleryController.
func (*GalleryController) EditGallery ¶
func (c *GalleryController) EditGallery(w http.ResponseWriter, r *http.Request)
EditGallery displays the edit page for a gallery.
func (*GalleryController) GalleriesEmbedHTML ¶
func (c *GalleryController) GalleriesEmbedHTML(w http.ResponseWriter, r *http.Request)
GalleriesEmbedHTML returns the node page's galleries block (lazy-loaded on scroll by block_node_galleries); ?previews=N - the previews of each.
func (*GalleryController) GalleriesList ¶
func (c *GalleryController) GalleriesList(w http.ResponseWriter, r *http.Request)
GalleriesList displays the overview page with all galleries of a node.
func (*GalleryController) GalleriesOverview ¶
func (c *GalleryController) GalleriesOverview(w http.ResponseWriter, r *http.Request)
GalleriesOverview handles GET /admin/content/galleries: the content with its galleries - whether each can have them, how many and their images - by title, filtered by type and, with ?show=on, to the content that can have galleries.
func (*GalleryController) GalleriesOverviewToggle ¶
func (c *GalleryController) GalleriesOverviewToggle(w http.ResponseWriter, r *http.Request)
GalleriesOverviewToggle handles POST /admin/content/galleries/{nid}: whether the content can have galleries (enabled=1), as its form's switch sets it; back to the overview's page it came from (query).
func (*GalleryController) GalleryAddItem ¶
func (c *GalleryController) GalleryAddItem(w http.ResponseWriter, r *http.Request)
GalleryAddItem adds an image to a gallery (API endpoint).
func (*GalleryController) GalleryCreate ¶
func (c *GalleryController) GalleryCreate(w http.ResponseWriter, r *http.Request)
GalleryCreate creates a new gallery for a node (API endpoint).
func (*GalleryController) GalleryDeleteConfirm ¶
func (c *GalleryController) GalleryDeleteConfirm(w http.ResponseWriter, r *http.Request)
GalleryDeleteConfirm displays the gallery delete confirmation page.
func (*GalleryController) GalleryDeletePage ¶
func (c *GalleryController) GalleryDeletePage(w http.ResponseWriter, r *http.Request)
GalleryDeletePage deletes the gallery (form submission).
func (*GalleryController) GalleryRemoveItem ¶
func (c *GalleryController) GalleryRemoveItem(w http.ResponseWriter, r *http.Request)
GalleryRemoveItem removes an image from a gallery (API endpoint).
func (*GalleryController) GalleryReorder ¶
func (c *GalleryController) GalleryReorder(w http.ResponseWriter, r *http.Request)
GalleryReorder reorders images in a gallery (API endpoint).
func (*GalleryController) GallerySetCover ¶
func (c *GalleryController) GallerySetCover(w http.ResponseWriter, r *http.Request)
GallerySetCover sets an image as the gallery cover (API endpoint).
func (*GalleryController) GallerySetNodeMainImage ¶
func (c *GalleryController) GallerySetNodeMainImage(w http.ResponseWriter, r *http.Request)
GallerySetNodeMainImage sets a gallery item as the node's main image (API endpoint).
func (*GalleryController) GalleryUpdate ¶
func (c *GalleryController) GalleryUpdate(w http.ResponseWriter, r *http.Request)
GalleryUpdate updates gallery metadata (API endpoint).
func (*GalleryController) GalleryUpdateItem ¶
func (c *GalleryController) GalleryUpdateItem(w http.ResponseWriter, r *http.Request)
GalleryUpdateItem updates gallery item metadata (API endpoint).
func (*GalleryController) ViewGallery ¶
func (c *GalleryController) ViewGallery(w http.ResponseWriter, r *http.Request)
ViewGallery displays the public gallery page.
type GalleryCreateInput ¶
type GalleryCreateInput struct {
NodeID int
PreviewSmallStyle string
PreviewMediumStyle string
Title *string
Description *string
Weight int
Status bool
}
GalleryCreateInput - a new gallery of a node (empty styles - the defaults; GalleriesRepository.Create).
type GalleryDeps ¶
type GalleryDeps struct {
FileUploadService modulekit.FileUploader
FileRepo modulekit.FileRepository
NodeService modulekit.NodesService
GalleryService GalleryService
ContentTypes modulekit.ContentTypeService
Settings SettingsRepository
ImageStyles modulekit.ImageStyleService
}
GalleryDeps - what NewGalleryController needs besides the BaseDeps.
type GalleryItem ¶
type GalleryItem struct {
ID int
GalleryID int
FileID int
Title *string
Description *string
Weight int
IsCover bool
CreatedAt time.Time
Gallery *Gallery
File *modulekit.File
PreviewSmall *modulekit.File
PreviewMedium *modulekit.File
// Picture - the grid's preview (PreviewSmall) for the template
// function img: with its style's other widths and its size.
Picture modulekit.Picture
}
GalleryItem - an image of a gallery: its file, caption and place in the gallery, with its previews in the gallery's styles.
func ToGalleryItemEntity ¶
func ToGalleryItemEntity(item *generated.GalleryItem, refs coreRefs) *GalleryItem
ToGalleryItemEntity converts a generated gallery item to its domain entity.
func (*GalleryItem) GetDescription ¶
func (item *GalleryItem) GetDescription() string
GetDescription - the image's description ("" - none).
func (*GalleryItem) GetFileURI ¶
func (item *GalleryItem) GetFileURI() string
GetFileURI - the URI of the item's file ("" - no file).
func (*GalleryItem) GetTitle ¶
func (item *GalleryItem) GetTitle() string
GetTitle - the image's title ("" - none).
func (*GalleryItem) HasFile ¶
func (item *GalleryItem) HasFile() bool
HasFile reports whether the item has its image file (found among the core's files).
type GalleryItemCreateInput ¶
type GalleryItemCreateInput struct {
GalleryID int
FileID int
Title *string
Description *string
Weight int
IsCover bool
}
GalleryItemCreateInput - a new image of a gallery: its file and caption (GalleriesRepository.AddItem).
type GalleryItemReorder ¶
GalleryItemReorder - an item's new weight in its gallery (GalleriesRepository.ReorderItems).
type GalleryItemUpdateInput ¶
GalleryItemUpdateInput - changes to a gallery's image (nil - unchanged; GalleriesRepository.UpdateItem).
type GalleryItems ¶
type GalleryItems []*GalleryItem
GalleryItems - a gallery's images, in their order.
func ToGalleryItemsEntity ¶
func ToGalleryItemsEntity(items []*generated.GalleryItem, refs coreRefs) GalleryItems
ToGalleryItemsEntity converts generated gallery items to domain entities; an item loaded with its gallery gets its previews in the gallery's styles (else the original image).
func (*GalleryItems) GetCover ¶
func (items *GalleryItems) GetCover() *modulekit.File
GetCover - the file of the cover among the items: the one marked as cover, else the first image (nil - none).
func (GalleryItems) GetFiles ¶
func (items GalleryItems) GetFiles() []*modulekit.File
GetFiles - the items' files, skipping items without one.
func (GalleryItems) GetURIs ¶
func (items GalleryItems) GetURIs() []string
GetURIs - the URIs of the items' files, skipping items without one.
func (GalleryItems) IsEmpty ¶
func (items GalleryItems) IsEmpty() bool
IsEmpty reports whether the list has no items.
type GalleryService ¶
type GalleryService interface {
Find(ctx context.Context, filter GalleriesFilter) (Galleries, error)
TotalCount(ctx context.Context, filter GalleriesFilter) (int, error)
ByID(ctx context.Context, id int) (*Gallery, error)
ByNodeID(ctx context.Context, nodeID int) (Galleries, error)
SummaryByNodeID(ctx context.Context, nodeID int) (Galleries, error)
CountsByNodeIDs(ctx context.Context, ids []int) (map[int]NodeGalleryCounts, error)
Create(ctx context.Context, input GalleryCreateInput) (*Gallery, error)
Update(ctx context.Context, id int, input GalleryUpdateInput) (*Gallery, error)
Delete(ctx context.Context, id int) error
DeleteWithItems(ctx context.Context, id int) error
DeleteByNodeIDWithItems(ctx context.Context, nodeID int) error
AddItem(ctx context.Context, input GalleryItemCreateInput) (*GalleryItem, error)
UpdateItem(ctx context.Context, id int, input GalleryItemUpdateInput) (*GalleryItem, error)
RemoveItem(ctx context.Context, id int) error
GetItems(ctx context.Context, galleryID int) (GalleryItems, error)
GetItemByID(ctx context.Context, itemID int) (*GalleryItem, error)
ReorderItems(ctx context.Context, items []GalleryItemReorder) error
SetCover(ctx context.Context, galleryID, itemID int) error
GetCover(ctx context.Context, galleryID int) (*GalleryItem, error)
}
GalleryService - the galleries of nodes and their images, the input checked (title lengths, IDs, preview styles) before the store.
func NewGalleryService ¶
func NewGalleryService(r GalleriesRepository, styles StyleNames, baseLogger *slog.Logger) GalleryService
NewGalleryService - the galleries service on r; a gallery's preview styles are checked against styles (the core's image styles).
type GalleryUpdateInput ¶
type GalleryUpdateInput struct {
PreviewSmallStyle *string
PreviewMediumStyle *string
Title *string
Description *string
Weight *int
Status *bool
}
GalleryUpdateInput - changes to a gallery (nil - unchanged; GalleriesRepository.Update).
type NodeGalleryCounts ¶
NodeGalleryCounts - a node's galleries and their images (the admin's galleries overview).
type NodeRefs ¶
NodeRefs and FileRefs - the core's nodes and files a gallery and its items reference, by ID (NodesRepository.ByIDs, FileRepository.ByIDs).
type SettingsRepository ¶
type SettingsRepository interface {
// TypeSettings - the type's settings (DefaultTypeSettings without a
// row).
TypeSettings(ctx context.Context, contentType string) (TypeSettings, error)
SaveTypeSettings(ctx context.Context, contentTypeID int, s TypeSettings) error
// NodeEnabled - whether the node can have galleries.
NodeEnabled(ctx context.Context, nodeID int) (bool, error)
// EnabledNodeIDs - the nodes that can have galleries.
EnabledNodeIDs(ctx context.Context) ([]int, error)
SetNodeEnabled(ctx context.Context, nodeID int, enabled bool) error
}
SettingsRepository - the module's settings of content types and nodes.
type StyleNames ¶
type StyleNames interface {
ImageStyleByName(ctx context.Context, name string) (*modulekit.ImageStyleDef, error)
}
StyleNames - the core's image styles by name (a gallery's preview styles must exist).
type StyleRefs ¶
type StyleRefs interface {
ImageStyles(ctx context.Context) (modulekit.ImageStyleDefs, error)
}
StyleRefs - the core's image styles (their sizes).
type TypeSettings ¶
type TypeSettings struct {
// DefaultEnabled - whether a new node of the type can have galleries
// (the node's own switch starts from it).
DefaultEnabled bool
// PictureField - the type's image field the "Main content image"
// button of gallery management writes into ("" - no button).
PictureField string
}
TypeSettings - the galleries settings of a content type (gallery_content_types).
func DefaultTypeSettings ¶
func DefaultTypeSettings() TypeSettings
DefaultTypeSettings - the settings of a type without a row.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package ent - the galleries module's own ent schema (schema/), its generated client (generated/, go generate) and migration files (migrations/<dialect>/, scripts/migrations_gen.sh writes them), apart from the core's: the module's set of migrations (Schema).
|
Package ent - the galleries module's own ent schema (schema/), its generated client (generated/, go generate) and migration files (migrations/<dialect>/, scripts/migrations_gen.sh writes them), apart from the core's: the module's set of migrations (Schema). |
|
schema
Package schema - the galleries module's own ent schema: its tables, apart from the core's.
|
Package schema - the galleries module's own ent schema: its tables, apart from the core's. |
|
Package manifest declares the galleries module (its registry entry).
|
Package manifest declares the galleries module (its registry entry). |