Просмотр исходного кода

Ask for confirmation before flushing history

Frédéric Guillot 6 лет назад
Родитель
Сommit
ac3693562b
4 измененных файлов с 19 добавлено и 8 удалено
  1. 7 1
      template/html/history_entries.html
  2. 8 2
      template/views.go
  3. 3 4
      ui/history_flush.go
  4. 1 1
      ui/ui.go

+ 7 - 1
template/html/history_entries.html

@@ -6,7 +6,13 @@
     {{ if .entries }}
     <ul>
         <li>
-            <a href="{{ route "flushHistory" }}">{{ t "menu.flush_history" }}</a>
+            <a href="#"
+                data-confirm="true"
+                data-url="{{ route "flushHistory" }}"
+                data-label-question="{{ t "confirm.question" }}"
+                data-label-yes="{{ t "confirm.yes" }}"
+                data-label-no="{{ t "confirm.no" }}"
+                data-label-loading="{{ t "confirm.loading" }}">{{ t "menu.flush_history" }}</a>
         </li>
     </ul>
     {{ end }}

+ 8 - 2
template/views.go

@@ -884,7 +884,13 @@ var templateViewsMap = map[string]string{
     {{ if .entries }}
     <ul>
         <li>
-            <a href="{{ route "flushHistory" }}">{{ t "menu.flush_history" }}</a>
+            <a href="#"
+                data-confirm="true"
+                data-url="{{ route "flushHistory" }}"
+                data-label-question="{{ t "confirm.question" }}"
+                data-label-yes="{{ t "confirm.yes" }}"
+                data-label-no="{{ t "confirm.no" }}"
+                data-label-loading="{{ t "confirm.loading" }}">{{ t "menu.flush_history" }}</a>
         </li>
     </ul>
     {{ end }}
@@ -1455,7 +1461,7 @@ var templateViewsMapChecksums = map[string]string{
 	"entry":               "1626bf4dd3223b2f730865676162aa0a9f0a0e009cdea90f705230542922e0f4",
 	"feed_entries":        "4bb6b96ba4d13dbaf22dcf6dd95ae36b6e5a0c99175d502865a164dc68fd4bae",
 	"feeds":               "31acc253c547a6cce5710d72a6f6b3b396162ecd5e5af295b2cf47c1ff55bd06",
-	"history_entries":     "b65ca1d85615caa7c314a33f1cb997aa3477a79e66b9894b2fd387271ad467d2",
+	"history_entries":     "9763d2120cfaeb78d406fdc029197fed2f7cfa7682970eeedae82ae79be65519",
 	"import":              "8349e47a783bb40d8e9248b4771656e5f006185e11079e1c4680dd52633420ed",
 	"integrations":        "f85b4a48ab1fc13b8ca94bfbbc44bd5e8784f35b26a63ec32cbe82b96b45e008",
 	"login":               "2e72d2d4b9786641b696bedbed5e10b04bdfd68254ddbbdb0a53cca621d200c7",

+ 3 - 4
ui/history_flush.go

@@ -8,16 +8,15 @@ import (
 	"net/http"
 
 	"miniflux.app/http/request"
-	"miniflux.app/http/response/html"
-	"miniflux.app/http/route"
+	"miniflux.app/http/response/json"
 )
 
 func (h *handler) flushHistory(w http.ResponseWriter, r *http.Request) {
 	err := h.store.FlushHistory(request.UserID(r))
 	if err != nil {
-		html.ServerError(w, r, err)
+		json.ServerError(w, r, err)
 		return
 	}
 
-	html.Redirect(w, r, route.Path(h.router, "history"))
+	json.OK(w, r, "OK")
 }

+ 1 - 1
ui/ui.go

@@ -45,7 +45,7 @@ func Serve(router *mux.Router, store *storage.Storage, pool *worker.Pool, feedHa
 	// History pages.
 	uiRouter.HandleFunc("/history", handler.showHistoryPage).Name("history").Methods("GET")
 	uiRouter.HandleFunc("/history/entry/{entryID}", handler.showReadEntryPage).Name("readEntry").Methods("GET")
-	uiRouter.HandleFunc("/history/flush", handler.flushHistory).Name("flushHistory").Methods("GET")
+	uiRouter.HandleFunc("/history/flush", handler.flushHistory).Name("flushHistory").Methods("POST")
 
 	// Bookmark pages.
 	uiRouter.HandleFunc("/starred", handler.showStarredPage).Name("starred").Methods("GET")