- Statuses can now be bulk-imported/updated via CSV (Name, Color columns; matches and updates existing statuses by name). New internal/statuses/csv.go, tested. - Icon fields (folder create/rename, item type form) are now a searchable dropdown of the 50 most common Bootstrap Icons instead of a free-text box, via a small reusable .icon-picker widget in app.js/app.css. - CSV asset import is now folder-scoped when triggered from the tree: right-click a folder (or its background) > Import CSV... imports every row directly into that folder, so the CSV needs no Folder column at all, and the option no longer appears at the top level. The original global, Folder-path-aware import (with auto-create-missing-folders) moved to a new admin-only Settings > Import / Export page, alongside the new Statuses import and format examples for both. assets.Import gained ImportOptions.TargetFolderID to drive the folder-scoped mode. - Site Name (Settings > General) now actually renders in the navbar brand and <title>, via a per-App "siteName" template func bound in loadTemplates. The brand is plain text now, not a link to /inventory.
96 lines
3.3 KiB
Go
96 lines
3.3 KiB
Go
package web
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
|
|
"inventree/internal/assets"
|
|
"inventree/internal/models"
|
|
)
|
|
|
|
type settingsImportPageData struct {
|
|
User *models.User
|
|
Kind string
|
|
Imported int
|
|
Updated int
|
|
Errs int
|
|
Error string
|
|
}
|
|
|
|
// handleSettingsImportPage backs the admin "Import / Export" settings page:
|
|
// global CSV import for assets (with a Folder column, optionally
|
|
// auto-creating missing folders) and for statuses, plus format examples.
|
|
// This is distinct from the folder-scoped "Import CSV..." context-menu
|
|
// action in the tree, which never needs a Folder column.
|
|
func (a *App) handleSettingsImportPage(w http.ResponseWriter, r *http.Request) {
|
|
q := r.URL.Query()
|
|
a.Render(w, http.StatusOK, "settings_import", settingsImportPageData{
|
|
User: currentUser(r),
|
|
Kind: q.Get("kind"),
|
|
Imported: queryInt(r, "imported", 0),
|
|
Updated: queryInt(r, "updated", 0),
|
|
Errs: queryInt(r, "errs", 0),
|
|
Error: q.Get("error"),
|
|
})
|
|
}
|
|
|
|
func (a *App) handleSettingsImportAssets(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
if err := r.ParseMultipartForm(32 << 20); err != nil {
|
|
http.Redirect(w, r, "/settings/import?kind=assets&error="+url.QueryEscape(err.Error()), http.StatusSeeOther)
|
|
return
|
|
}
|
|
file, _, err := r.FormFile("file")
|
|
if err != nil {
|
|
http.Redirect(w, r, "/settings/import?kind=assets&error="+url.QueryEscape(err.Error()), http.StatusSeeOther)
|
|
return
|
|
}
|
|
defer file.Close()
|
|
|
|
createMissing := r.FormValue("create_missing_folders") == "1"
|
|
|
|
itemTypes, err := a.ItemTypes.List(ctx, true)
|
|
if err != nil {
|
|
http.Redirect(w, r, "/settings/import?kind=assets&error="+url.QueryEscape(err.Error()), http.StatusSeeOther)
|
|
return
|
|
}
|
|
statusList, err := a.Statuses.List(ctx)
|
|
if err != nil {
|
|
http.Redirect(w, r, "/settings/import?kind=assets&error="+url.QueryEscape(err.Error()), http.StatusSeeOther)
|
|
return
|
|
}
|
|
userList, err := a.Users.List(ctx)
|
|
if err != nil {
|
|
http.Redirect(w, r, "/settings/import?kind=assets&error="+url.QueryEscape(err.Error()), http.StatusSeeOther)
|
|
return
|
|
}
|
|
|
|
result, err := a.Assets.Import(ctx, file, assets.ImportOptions{CreateMissingFolders: createMissing}, itemTypes, statusList, userList)
|
|
if err != nil {
|
|
http.Redirect(w, r, "/settings/import?kind=assets&error="+url.QueryEscape(err.Error()), http.StatusSeeOther)
|
|
return
|
|
}
|
|
http.Redirect(w, r, fmt.Sprintf("/settings/import?kind=assets&imported=%d&updated=%d&errs=%d", result.Created, result.Updated, len(result.Errors)), http.StatusSeeOther)
|
|
}
|
|
|
|
func (a *App) handleSettingsImportStatuses(w http.ResponseWriter, r *http.Request) {
|
|
if err := r.ParseMultipartForm(10 << 20); err != nil {
|
|
http.Redirect(w, r, "/settings/import?kind=statuses&error="+url.QueryEscape(err.Error()), http.StatusSeeOther)
|
|
return
|
|
}
|
|
file, _, err := r.FormFile("file")
|
|
if err != nil {
|
|
http.Redirect(w, r, "/settings/import?kind=statuses&error="+url.QueryEscape(err.Error()), http.StatusSeeOther)
|
|
return
|
|
}
|
|
defer file.Close()
|
|
|
|
result, err := a.Statuses.Import(r.Context(), file)
|
|
if err != nil {
|
|
http.Redirect(w, r, "/settings/import?kind=statuses&error="+url.QueryEscape(err.Error()), http.StatusSeeOther)
|
|
return
|
|
}
|
|
http.Redirect(w, r, fmt.Sprintf("/settings/import?kind=statuses&imported=%d&updated=%d&errs=%d", result.Created, result.Updated, len(result.Errors)), http.StatusSeeOther)
|
|
}
|