mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
The web dashboard now fully supports project-level skills. When launched with `-p` or when `.skillshare/config.yaml` is auto-detected, the UI adapts: Git Sync and Backup pages are hidden, Config edits the project config, Install reconciles ProjectConfig.Skills[], and targets resolve from project-level definitions. Server: add NewProject constructor, IsProjectMode/configPath/saveConfig/ reloadConfig helpers, branch all handlers for project mode. Frontend: AppContext propagates isProjectMode, Layout filters nav items, Git/Backup pages show unavailable message, Config/Dashboard adapt. Extract ReconcileProjectSkills to internal/config for reuse by both CLI and server. Add unit tests and integration tests for project UI. Update docs, README, and Docker playground with project mode demo project and skillshare-ui-p alias.
93 lines
2.0 KiB
Go
93 lines
2.0 KiB
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"skillshare/internal/git"
|
|
"skillshare/internal/install"
|
|
"skillshare/internal/sync"
|
|
"skillshare/internal/utils"
|
|
versioncheck "skillshare/internal/version"
|
|
)
|
|
|
|
type trackedRepoItem struct {
|
|
Name string `json:"name"`
|
|
SkillCount int `json:"skillCount"`
|
|
Dirty bool `json:"dirty"`
|
|
}
|
|
|
|
func (s *Server) handleOverview(w http.ResponseWriter, r *http.Request) {
|
|
// Count skills
|
|
skills, err := sync.DiscoverSourceSkills(s.cfg.Source)
|
|
if err != nil {
|
|
writeError(w, http.StatusInternalServerError, err.Error())
|
|
return
|
|
}
|
|
|
|
// Count top-level source entries (for display)
|
|
topLevelCount := 0
|
|
entries, _ := os.ReadDir(s.cfg.Source)
|
|
for _, e := range entries {
|
|
if e.IsDir() && !utils.IsHidden(e.Name()) {
|
|
topLevelCount++
|
|
}
|
|
}
|
|
|
|
mode := s.cfg.Mode
|
|
if mode == "" {
|
|
mode = "merge"
|
|
}
|
|
|
|
// Tracked repos
|
|
trackedRepos := buildTrackedRepos(s.cfg.Source, skills)
|
|
|
|
resp := map[string]any{
|
|
"source": s.cfg.Source,
|
|
"skillCount": len(skills),
|
|
"topLevelCount": topLevelCount,
|
|
"targetCount": len(s.cfg.Targets),
|
|
"mode": mode,
|
|
"version": versioncheck.Version,
|
|
"trackedRepos": trackedRepos,
|
|
"isProjectMode": s.IsProjectMode(),
|
|
}
|
|
if s.IsProjectMode() {
|
|
resp["projectRoot"] = s.projectRoot
|
|
}
|
|
|
|
writeJSON(w, resp)
|
|
}
|
|
|
|
func buildTrackedRepos(sourceDir string, skills []sync.DiscoveredSkill) []trackedRepoItem {
|
|
repoNames, err := install.GetTrackedRepos(sourceDir)
|
|
if err != nil || len(repoNames) == 0 {
|
|
return []trackedRepoItem{}
|
|
}
|
|
|
|
items := make([]trackedRepoItem, 0, len(repoNames))
|
|
for _, repoName := range repoNames {
|
|
repoPath := filepath.Join(sourceDir, repoName)
|
|
|
|
// Count skills belonging to this repo
|
|
skillCount := 0
|
|
for _, sk := range skills {
|
|
if sk.IsInRepo && strings.HasPrefix(sk.RelPath, repoName+"/") {
|
|
skillCount++
|
|
}
|
|
}
|
|
|
|
// Check git dirty status
|
|
dirty, _ := git.IsDirty(repoPath)
|
|
|
|
items = append(items, trackedRepoItem{
|
|
Name: repoName,
|
|
SkillCount: skillCount,
|
|
Dirty: dirty,
|
|
})
|
|
}
|
|
return items
|
|
}
|