Make it possible to reload the popup window without initiating a new download
This commit is contained in:
parent
c88a801e97
commit
4069109509
27
main.go
27
main.go
@ -55,6 +55,7 @@ func main() {
|
|||||||
r.HandleFunc("/", homeHandler)
|
r.HandleFunc("/", homeHandler)
|
||||||
r.HandleFunc("/config", configHandler)
|
r.HandleFunc("/config", configHandler)
|
||||||
r.HandleFunc("/fetch", fetchHandler)
|
r.HandleFunc("/fetch", fetchHandler)
|
||||||
|
r.HandleFunc("/fetch/{id}", fetchHandler)
|
||||||
|
|
||||||
// info for the list
|
// info for the list
|
||||||
r.HandleFunc("/rest/fetch", fetchInfoRESTHandler)
|
r.HandleFunc("/rest/fetch", fetchInfoRESTHandler)
|
||||||
@ -241,6 +242,32 @@ func fetchInfoRESTHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
func fetchHandler(w http.ResponseWriter, r *http.Request) {
|
func fetchHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
// if they refreshed the popup, just load the existing object, don't
|
||||||
|
// create a new one
|
||||||
|
vars := mux.Vars(r)
|
||||||
|
idString := vars["id"]
|
||||||
|
|
||||||
|
idInt, err := strconv.ParseInt(idString, 10, 32)
|
||||||
|
if err == nil && idInt > 0 {
|
||||||
|
for _, dl := range downloads {
|
||||||
|
if dl.Id == int(idInt) {
|
||||||
|
t, err := template.ParseFS(webFS, "web/layout.tmpl", "web/popup.html")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
templateData := map[string]interface{}{"dl": dl, "config": conf}
|
||||||
|
|
||||||
|
err = t.ExecuteTemplate(w, "layout", templateData)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
query := r.URL.Query()
|
query := r.URL.Query()
|
||||||
url, present := query["url"]
|
url, present := query["url"]
|
||||||
|
|
||||||
|
@ -81,4 +81,4 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
@ -30,11 +30,11 @@
|
|||||||
{{ define "js" }}
|
{{ define "js" }}
|
||||||
<script>
|
<script>
|
||||||
function popup() {
|
function popup() {
|
||||||
|
history.replaceState(null, '', ['/fetch/{{ .dl.Id }}'])
|
||||||
return {
|
return {
|
||||||
eta: '', percent: 0.0, state: '??', filename: '', finished: false, log :'',
|
eta: '', percent: 0.0, state: '??', filename: '', finished: false, log :'',
|
||||||
profile_chosen: null,
|
profile_chosen: null,
|
||||||
watch_profile() {
|
watch_profile() {
|
||||||
console.log('will wtch profile');
|
|
||||||
this.$watch('profile_chosen', value => this.profile_chosen(value))
|
this.$watch('profile_chosen', value => this.profile_chosen(value))
|
||||||
},
|
},
|
||||||
update_profile(name) {
|
update_profile(name) {
|
||||||
@ -57,6 +57,9 @@
|
|||||||
this.eta = info.eta;
|
this.eta = info.eta;
|
||||||
this.percent = info.percent + "%";
|
this.percent = info.percent + "%";
|
||||||
this.state = info.state;
|
this.state = info.state;
|
||||||
|
if (this.state != 'choose profile') {
|
||||||
|
this.profile_chosen = true;
|
||||||
|
}
|
||||||
this.finished = info.finished;
|
this.finished = info.finished;
|
||||||
if (info.files && info.files.length > 0) {
|
if (info.files && info.files.length > 0) {
|
||||||
this.filename = info.files[info.files.length - 1];
|
this.filename = info.files[info.files.length - 1];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user