Skip to content

High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.

SSR: Port media management page.

Kailash Nadh2e8fb141bf88
diff --git a/cmd/admin.go b/cmd/admin.go
index c01d01e3..9e0398ff 100644
--- a/cmd/admin.go
+++ b/cmd/admin.go
@@ -49,6 +49,7 @@ var adminJSI18nKeys = []string{
"globals.messages.created",
"globals.messages.deleted",
"globals.messages.deletedCount",
+ "globals.messages.done",
"globals.messages.numSelected",
"globals.messages.selectAll",
"globals.messages.updated",
diff --git a/cmd/handlers.go b/cmd/handlers.go
index 68c05af0..c6414731 100644
--- a/cmd/handlers.go
+++ b/cmd/handlers.go
@@ -75,6 +75,7 @@ func initHTTPHandlers(e *echo.Echo, a *App) {
g.GET(path.Join(uriAdmin, "/lists"), a.ViewLists)
g.GET(path.Join(uriAdmin, "/lists/:id"), hasID(a.ViewList))
g.GET(path.Join(uriAdmin, "/lists/forms"), a.ViewForms)
+ g.GET(path.Join(uriAdmin, "/campaigns/media"), a.ViewMedia)
g.GET(path.Join(uriAdmin, "/subscribers/import"), a.ViewImport)
g.GET(path.Join(uriAdmin, "/subscribers/bounces"), a.ViewBounces)
g.GET(path.Join(uriAdmin, "/subscribers"), a.ViewSubscribers)
diff --git a/cmd/media.go b/cmd/media.go
index b458a318..8361761d 100644
--- a/cmd/media.go
+++ b/cmd/media.go
@@ -8,6 +8,7 @@ import (
"strings"
"github.com/disintegration/imaging"
+ "github.com/knadh/listmonk/internal/media"
"github.com/knadh/listmonk/models"
"github.com/labstack/echo/v4"
)
@@ -22,6 +23,48 @@ var (
imageExts = []string{"gif", "png", "jpg", "jpeg"}
)
+// mediaView is the admin view for the media gallery page.
+type mediaView struct {
+ adminView
+
+ Media []media.Media
+ Provider string
+ Page models.PageProps
+}
+
+// ViewMedia renders the HTML gallery view for uploaded media.
+func (a *App) ViewMedia(c echo.Context) error {
+ res, props, err := a.getMedia(c)
+ if err != nil {
+ return err
+ }
+
+ data := mediaView{
+ adminView: newAdminView(c, a.i18n.T("media.title"), ""),
+ Media: res,
+ Provider: a.cfg.MediaUpload.Provider,
+ Page: props,
+ }
+
+ return c.Render(http.StatusOK, "admin-media", data)
+}
+
+// getMedia queries paginated media items from the DB.
+func (a *App) getMedia(c echo.Context) ([]media.Media, models.PageProps, error) {
+ q := makeQuery(c.Request().URL.Query(), map[string]string{
+ "page": "",
+ "query": "",
+ })
+
+ pg := a.pg.NewFromURL(q)
+ res, total, err := a.core.QueryMedia(a.cfg.MediaUpload.Provider, a.media, q.Get("query"), pg.Offset, pg.Limit)
+ if err != nil {
+ return nil, models.PageProps{}, err
+ }
+
+ return res, models.NewPageProps(q, total, pg.Page, pg.PerPage), nil
+}
+
// UploadMedia handles media file uploads.
func (a *App) UploadMedia(c echo.Context) error {
file, err := c.FormFile("file")
diff --git a/frontend-vue/src/router/index.js b/frontend-vue/src/router/index.js
index b0fbbc85..6b9c4822 100644
--- a/frontend-vue/src/router/index.js
+++ b/frontend-vue/src/router/index.js
@@ -23,12 +23,6 @@ const routes = [
meta: { title: 'globals.terms.campaigns', group: 'campaigns' },
component: () => import('../views/Campaigns.vue'),
},
- {
- path: '/campaigns/media',
- name: 'media',
- meta: { title: 'globals.terms.media', group: 'campaigns' },
- component: () => import('../views/Media.vue'),
- },
{
path: '/campaigns/templates',
name: 'templates',
diff --git a/static/admin/partials/sidebar.html b/static/admin/partials/sidebar.html
index 707fd46d..e3560e81 100644
--- a/static/admin/partials/sidebar.html
+++ b/static/admin/partials/sidebar.html
@@ -48,7 +48,7 @@
<li><a href="{{ URI "/admin/campaigns/new" }}" data-cy="new-campaign">{{ .L.T "menu.newCampaign" }}</a></li>
{{ end }}
{{ if Can $u "media:get" "media:manage" }}
- <li><a href="{{ URI "/admin/media" }}" data-cy="media">{{ .L.T "menu.media" }}</a></li>
+ <li><a href="{{ URI "/admin/campaigns/media" }}" data-cy="media">{{ .L.T "menu.media" }}</a></li>
{{ end }}
{{ if Can $u "templates:get" }}
<li><a href="{{ URI "/admin/templates" }}" data-cy="templates">{{ .L.T "globals.terms.templates" }}</a></li>
diff --git a/static/admin/src/css/style.css b/static/admin/src/css/style.css
index 759927bc..6dd7549a 100644
--- a/static/admin/src/css/style.css
+++ b/static/admin/src/css/style.css
@@ -1109,108 +1109,54 @@ section.import {
}
.media-files {
- img {
- border-radius: var(--radius-small);
- height: 100%;
- max-height: 170px;
- max-width: 170px;
- object-fit: cover;
- transition: transform var(--transition);
- width: 100%;
- }
-
- .grid {
+ .gallery {
display: grid;
- gap: var(--space-6);
- grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
- padding-block: var(--space-4);
- }
-
- .item {
- background: var(--card);
- border: 1px solid var(--border);
- border-radius: var(--radius-medium);
- box-shadow: var(--shadow-small);
- overflow: hidden;
- transition: transform var(--transition), box-shadow var(--transition);
-
- &:hover {
- box-shadow: var(--shadow-medium);
- transform: translateY(-2px);
-
- img {
- transform: scale(1.05);
- }
-
- .actions {
- opacity: 1;
- }
- }
+ gap: var(--space-4);
+ grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
+ list-style: none;
}
- .thumb {
- aspect-ratio: 1;
- overflow: hidden;
+ figure {
position: relative;
}
- .thumb-link,
- .thumb-container {
- display: block;
- height: 100%;
- width: 100%;
- }
-
- .thumb-container,
- .thumb-placeholder {
+ .thumb {
align-items: center;
+ aspect-ratio: 1;
background: var(--faint);
+ border-radius: var(--radius-medium);
display: flex;
justify-content: center;
+ overflow: hidden;
+
+ img {
+ height: 100%;
+ object-fit: cover;
+ width: 100%;
+ }
}
- .thumb-placeholder {
- background: var(--muted-foreground);
- color: var(--background);
- height: 100%;
- width: 100%;
+ figcaption {
+ display: grid;
+ padding-block: var(--space-2);
}
- .file-ext {
- text-transform: uppercase;
+ .filename {
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
}
.actions {
- align-items: center;
- background: color-mix(in srgb, var(--background) 90%, transparent);
- border-radius: var(--radius-full);
- display: flex;
- height: 28px;
- justify-content: center;
opacity: 0;
position: absolute;
right: var(--space-2);
top: var(--space-2);
- transition: opacity var(--transition);
- width: 28px;
- }
-
- .info {
- padding: var(--space-3);
- }
-
- .filename {
- font-size: var(--text-7);
- margin-block-end: var(--space-1);
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
}
- .date {
- color: var(--faint-foreground);
- font-size: var(--text-8);
- margin-block-end: 0;
+ figure:hover .actions,
+ figure:focus-within .actions {
+ opacity: 1;
}
}