2021-09-21 17:13:30 +09:30
{{ define "content" }}
2021-09-30 23:48:56 +09:30
< div id = "layout" class = "pure-g pure-u-1" x-data = "popup()" x-init = "fetch_data()" >
2021-09-21 19:20:48 +09:30
< h2 > Download started< / h2 >
2021-09-30 23:48:56 +09:30
< p > Fetching < tt > {{ .dl.Url }}< / tt > < / p >
2021-09-21 19:20:48 +09:30
< table class = "pure-table" >
2021-09-30 23:48:56 +09:30
< tr >
< th > profile< / th >
< td >
< select x-bind:disabled = "profile_chosen" x-on:change = "update_profile()" class = "pure-input-1-2" x-model = "profile_chosen" >
< option value = "" > choose a profile to start< / option >
{{ range $i := .config.DownloadProfiles }}
< option > {{ $i.Name }}< / option >
{{ end }}
< / select >
< / td >
< / tr >
2021-09-21 08:33:24 +09:30
< tr > < th > current filename< / th > < td x-text = "filename" > < / td > < / tr >
2022-07-05 20:43:32 +09:30
< tr >
< th > destination< / th >
< td >
< select x-on:change = "update_destination()" class = "pure-input-1-2" x-model = "destination_chosen" >
< option value = "-" > leave in {{ .config.Server.DownloadPath }}< / option >
{{ range $i := .config.Destinations }}
< option > {{ $i.Name }}< / option >
{{ end }}
< / select >
< / td >
< / tr >
2021-09-21 08:33:24 +09:30
< tr > < th > state< / th > < td x-text = "state" > < / td > < / tr >
2022-04-09 15:13:22 +09:30
< tr x-show = "playlist_total > 0" > < th > playlist progress< / th > < td x-text = "playlist_current + '/' + playlist_total" > < / td > < / tr >
2021-09-21 08:33:24 +09:30
< tr > < th > progress< / th > < td x-text = "percent" > < / td > < / tr >
< tr > < th > ETA< / th > < td x-text = "eta" > < / td > < / tr >
2022-01-05 23:56:12 +10:30
2021-09-21 08:33:24 +09:30
< / table >
2021-09-21 19:20:48 +09:30
< p > You can close this window and your download will continue. Check the < a href = "/" target = "_gropple_status" > Status page< / a > to see all downloads in progress.< / p >
2022-01-06 21:37:30 +10:30
{{ if .canStop }}
2022-01-05 23:56:12 +10:30
< button x-show = "state=='downloading'" class = "pure-button" @ click = "stop()" > stop< / button >
2022-01-06 21:37:30 +10:30
{{ end }}
2021-09-21 19:20:48 +09:30
< div >
< h4 > Logs< / h4 >
2023-03-13 11:43:08 +10:30
< pre x-text = "log" style = "height: auto;" >
2021-09-21 19:20:48 +09:30
< / pre >
< / div >
2021-09-21 08:33:24 +09:30
< / div >
2021-09-21 17:13:30 +09:30
{{ end }}
{{ define "js" }}
2021-09-21 08:33:24 +09:30
< script >
function popup() {
2021-10-25 22:45:56 +10:30
history.replaceState(null, '', ['/fetch/{{ .dl.Id }}'])
2021-09-21 08:33:24 +09:30
return {
2021-09-21 19:20:48 +09:30
eta: '', percent: 0.0, state: '??', filename: '', finished: false, log :'',
2022-04-09 15:13:22 +09:30
playlist_current: 0, playlist_total: 0,
2021-09-30 23:48:56 +09:30
profile_chosen: null,
2022-07-05 20:43:32 +09:30
destination_chosen: null,
2021-09-30 23:48:56 +09:30
watch_profile() {
this.$watch('profile_chosen', value => this.profile_chosen(value))
},
update_profile(name) {
console.log('you chose name', this.profile_chosen);
let op = {
method: 'POST',
body: JSON.stringify({action: 'start', profile: this.profile_chosen}),
headers: { 'Content-Type': 'application/json' }
};
fetch('/rest/fetch/{{ .dl.Id }}', op)
.then(response => response.json())
.then(info => {
console.log(info)
})
},
2022-07-05 20:43:32 +09:30
update_destination(name) {
let op = {
method: 'POST',
body: JSON.stringify({action: 'change_destination', destination: this.destination_chosen}),
headers: { 'Content-Type': 'application/json' }
};
fetch('/rest/fetch/{{ .dl.Id }}', op)
.then(response => response.json())
.then(info => {
console.log(info)
})
},
2022-01-05 23:56:12 +10:30
stop() {
let op = {
method: 'POST',
body: JSON.stringify({action: 'stop'}),
headers: { 'Content-Type': 'application/json' }
};
fetch('/rest/fetch/{{ .dl.Id }}', op)
.then(response => response.json())
.then(info => {
console.log(info)
})
},
2021-09-21 08:33:24 +09:30
fetch_data() {
2021-09-30 23:48:56 +09:30
fetch('/rest/fetch/{{ .dl.Id }}')
2021-09-21 08:33:24 +09:30
.then(response => response.json())
.then(info => {
this.eta = info.eta;
this.percent = info.percent + "%";
this.state = info.state;
2022-04-09 15:13:22 +09:30
this.playlist_current = info.playlist_current;
this.playlist_total = info.playlist_total;
2023-03-13 10:32:20 +10:30
this.destination_chosen = null;
if (info.destination) {
this.destination_chosen = info.destination.name;
}
2023-03-13 10:48:38 +10:30
if (this.state != 'Choose Profile') {
2021-10-25 22:45:56 +10:30
this.profile_chosen = true;
}
2021-09-21 17:13:30 +09:30
this.finished = info.finished;
2021-09-21 08:33:24 +09:30
if (info.files & & info.files.length > 0) {
this.filename = info.files[info.files.length - 1];
}
2021-09-21 19:20:48 +09:30
if (info.log & & info.log.length > 0) {
this.log = info.log.join("\n");
}
2021-09-21 17:13:30 +09:30
console.log('finish?', this.finished);
if (! this.finished) {
2021-09-21 19:20:48 +09:30
setTimeout(() => { this.fetch_data() }, 1000);
2021-09-21 08:33:24 +09:30
}
2021-09-21 19:20:48 +09:30
console.log('log', this.log);
2021-09-21 08:33:24 +09:30
});
},
}
}
< / script >
2021-09-21 17:13:30 +09:30
{{ end }}
2021-09-21 08:33:24 +09:30