Sfoglia il codice sorgente

added option to list folders

turos.robert 3 settimane fa
parent
commit
7b04a613b3

File diff suppressed because it is too large
+ 2 - 0
cmds/webservice/bin/notes_folder/TestFinal/notita-2026-03-07-180009.965642.json


+ 5 - 0
cmds/webservice/bin/notes_folder/istorie/Lala/notita-2026-03-06-211318.356942.json

@@ -0,0 +1,5 @@
+{
+  "titlu": "Dada",
+  "continut": "dasdwads",
+  "director": "./istorie"
+}

+ 29 - 16
cmds/webservice/bin/templates/list_notes.tmpl

@@ -10,24 +10,37 @@
 <body class="bg-[#0f0f0f] text-white p-10 font-sans">
   <h1 class="text-3xl mb-8 text-[#9974d0] font-bold">Notițele existente</h1>
 
-  {{range .}}
-  <div class="mb-8 bg-[#1a1a1a] border border-[#303030] rounded-xl p-5 shadow-lg">
-    <h2 class="text-xl font-bold text-[#c7a6ff] mb-4">
-      Folder: {{.Folder}}
-    </h2>
-
-    <div class="space-y-2">
-      {{range .Files}}
-      <div class="bg-[#202020] border border-[#3e3e3e] rounded-lg p-3">
-        <a href="/notes/{{.FullPath}}" class="text-gray-200 hover:text-[#9974d0] hover:underline">
-          {{.Name}}
-        </a>
-      </div>
-      {{end}}
+  {{template "folder" .}}
+
+</body>
+
+</html>
+
+
+{{define "folder"}}
+
+<div class="ml-4 mb-6">
+
+  <h2 class="text-xl font-bold text-[#c7a6ff] mb-2">
+    {{.Nume}}
+  </h2>
+
+  {{if .Fisiere}}
+  <div class="space-y-2 mb-4">
+    {{range .Fisiere}}
+    <div class="bg-[#202020] border border-[#3e3e3e] rounded-lg p-3">
+      <a href="/notes/?note={{.Path}}" class="text-gray-200 hover:text-[#9974d0] hover:underline">
+        {{.Nume}}
+      </a>
     </div>
+    {{end}}
   </div>
   {{end}}
 
-</body>
+  {{range .Subfoldere}}
+    {{template "folder" .}}
+  {{end}}
+
+</div>
 
-</html>
+{{end}}

+ 7 - 2
cmds/webservice/types/types.go

@@ -8,6 +8,11 @@ type Notita struct {
 }
 type Folder struct {
 	Nume       string
-	Fisiere    []string
-	Subfoldere string
+	Fisiere    []Fisier
+	Subfoldere []Folder
+}
+
+type Fisier struct {
+	Nume string
+	Path string
 }

+ 45 - 13
lib/server/handlers.go

@@ -132,28 +132,60 @@ func safeDirectory(path string) error {
 }
 
 func ListNotes(w http.ResponseWriter, r *http.Request) {
+
 	if r.Method == "GET" {
-		w.Write(inout.FileToBytes("./templates/list_notes.tmpl"))
-		buildFolderStructure("./notes_folder", w)
+		f := types.Folder{}
+		err := buildFolderStructure("./notes_folder", &f)
+		if err != nil {
+			fmt.Println("EROARE la buildFolderStructure:", err)
+			w.WriteHeader(http.StatusBadRequest)
+			fmt.Fprintf(w, "%+v", err)
+			return
+		}
+		tmpl := template.New("list_notes_test")
+		_, err = tmpl.ParseFiles("./templates/list_notes.tmpl")
+		if err != nil {
+			fmt.Println("EROARE la buildFolderStructure:", err)
+			w.WriteHeader(http.StatusBadRequest)
+			fmt.Fprintf(w, "%+v", err)
+			return
+		}
+		err = tmpl.ExecuteTemplate(w, "list_notes.tmpl", f)
+		if err != nil {
+			fmt.Println("EROARE la buildFolderStructure:", err)
+			w.WriteHeader(http.StatusBadRequest)
+			fmt.Fprintf(w, "%+v", err)
+			return
+		}
+		return
 	}
+	w.WriteHeader(http.StatusMethodNotAllowed)
+	w.Write([]byte("methoda nepermisa"))
 }
 
-func buildFolderStructure(path string, w http.ResponseWriter /*f []types.Folder*/) {
+func buildFolderStructure(path string, f *types.Folder) error {
 	entries, err := os.ReadDir(path)
 	if err != nil {
-		w.WriteHeader(http.StatusBadRequest)
-		fmt.Fprintf(w, "%+v", err)
-		return
+		return err
 	}
+	f.Nume = filepath.Clean(path)
+
 	for _, entry := range entries {
-		/*if entry.IsDir() {
-			w.WriteHeader(http.StatusNotImplemented)
-			fmt.Fprint(w, "Functie Neimplementata - Subdirectorii")
-		}*/
-		fmt.Fprintln(w, entry, entry.IsDir())
+
 		if entry.IsDir() {
-			buildFolderStructure(filepath.Join(path, entry.Name()), w)
+			sub := types.Folder{}
+			err = buildFolderStructure(filepath.Join(path, entry.Name()), &sub)
+			if err != nil {
+				return err
+			}
+			f.Subfoldere = append(f.Subfoldere, sub)
+		} else {
+			fisier := types.Fisier{
+				Nume: entry.Name(),
+				Path: filepath.Join(path, entry.Name()),
+			}
+			f.Fisiere = append(f.Fisiere, fisier)
 		}
-
 	}
+	return nil
 }

Some files were not shown because too many files changed in this diff