Replace on-screen action buttons with right-click context menus
The tree and main panels now behave like a native file manager: right click (or the keyboard Menu key) on a folder, asset, breadcrumb crumb, or empty tree/panel background brings up the relevant actions instead of a row of always-visible buttons. - New generic showContextMenu() in app.js with per-target-kind menu builders (folder/asset/tree background/panel background), gated by admin role the same way the old buttons were. - Removed: the "..." tree-row action button, and the New Folder/Add Asset/Rename/Delete/Edit/Move/Duplicate/Import/Export buttons from the inventory toolbar and every panel. Expand All/Collapse All shrank to two icon-only buttons next to the search box; everything else creation- or mutation-related is right-click only. - Replaced the per-asset embedded "Move" modal with one shared #moveAssetModal populated via a new GET /app/folders/options endpoint, since move can now be triggered from any asset row, not just its own detail view. - Breadcrumb crumbs (including the current folder) and folder/asset table rows are now valid right-click targets too, not just tree rows.
This commit is contained in:
@@ -5,9 +5,9 @@ import "context"
|
||||
// FolderOption is a flattened, indented folder choice for <select> dropdowns
|
||||
// (asset create/edit, move-to pickers).
|
||||
type FolderOption struct {
|
||||
ID int64
|
||||
Path string
|
||||
Depth int
|
||||
ID int64 `json:"id"`
|
||||
Path string `json:"path"`
|
||||
Depth int `json:"depth"`
|
||||
}
|
||||
|
||||
// folderOptions returns every folder as a flat, depth-first ordered list
|
||||
|
||||
@@ -8,6 +8,17 @@ import (
|
||||
"inventree/internal/models"
|
||||
)
|
||||
|
||||
// handleFolderOptions returns every folder as a flat, indented list for
|
||||
// generic "move to..." pickers (e.g. the asset move context-menu action).
|
||||
func (a *App) handleFolderOptions(w http.ResponseWriter, r *http.Request) {
|
||||
opts, err := a.folderOptions(r.Context())
|
||||
if err != nil {
|
||||
jsonErr(w, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
jsonOK(w, opts)
|
||||
}
|
||||
|
||||
func (a *App) handleFolderGet(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := pathID(r, "id")
|
||||
if err != nil {
|
||||
|
||||
@@ -221,9 +221,7 @@ func (a *App) handlePanelFolder(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// AssetPanelData backs the main panel when an asset is selected (view mode).
|
||||
type AssetPanelData struct {
|
||||
Asset *models.Asset
|
||||
CanEdit bool
|
||||
FolderOptions []FolderOption
|
||||
Asset *models.Asset
|
||||
}
|
||||
|
||||
func (a *App) handlePanelAsset(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -238,12 +236,7 @@ func (a *App) handlePanelAsset(w http.ResponseWriter, r *http.Request) {
|
||||
writeErr(w, http.StatusNotFound, err.Error())
|
||||
return
|
||||
}
|
||||
opts, err := a.folderOptions(ctx)
|
||||
if err != nil {
|
||||
writeErr(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
a.RenderFragment(w, http.StatusOK, "panel_asset", AssetPanelData{Asset: asset, CanEdit: currentUser(r).IsAdmin(), FolderOptions: opts})
|
||||
a.RenderFragment(w, http.StatusOK, "panel_asset", AssetPanelData{Asset: asset})
|
||||
}
|
||||
|
||||
// AssetFormData backs both the "new asset" and "edit asset" forms.
|
||||
|
||||
@@ -40,6 +40,7 @@ func (a *App) Router() http.Handler {
|
||||
mux.HandleFunc("GET /app/search", a.requireLogin(a.handleSearch))
|
||||
|
||||
// Folder mutations (JSON in/out)
|
||||
mux.HandleFunc("GET /app/folders/options", a.requireAdmin(a.handleFolderOptions))
|
||||
mux.HandleFunc("GET /app/folders/{id}", a.requireAdmin(a.handleFolderGet))
|
||||
mux.HandleFunc("POST /app/folders", a.requireAdmin(a.handleFolderCreate))
|
||||
mux.HandleFunc("PATCH /app/folders/{id}", a.requireAdmin(a.handleFolderUpdate))
|
||||
|
||||
Reference in New Issue
Block a user