-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathscript.iced
108 lines (104 loc) · 3.83 KB
/
script.iced
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
await $ defer()
$modal = $("form.vcode-template").modal(show: false)
img = $modal.find("img")[0]
$modal.on "submit", (ev) ->
ev.preventDefault()
$.post "vcode", $modal.serialize()
return
fmt_size = (size)->
k = 1000
m = 1000 * k
g = 1000 * m
return "#{(size / g).toFixed(2)}GB" if size > g
return "#{(size / m).toFixed(2)}MB" if size > m
return "#{Math.floor size / k}KB" if size > k
"#{Math.floor size}B"
fmt_time = (time)->
m = 60
h = 60 * m
d = h * 24
return "#{Math.floor time / d}天#{fmt_time time % d}" if time > d
return "#{Math.floor time / h}小时#{fmt_time time % h}" if time > h
return "#{Math.floor time / m}分#{fmt_time time % m}" if time > m
"#{Math.floor time}秒"
$.fn.text_update = (text)->
return @ unless text !=$(@).text()
return @text(text)
while true
await $.get("stats.json").done defer data
if data.vcode?.length
$modal.modal "show" unless $modal.is(":visible")
unless img.src is data.vcode
img.src = data.vcode
$modal.find("input").val ""
else
$modal.modal "hide" if $modal.is(":visible")
if $('#accordion-log').length
$("#queue").html $("#queue", data).html()
$("#log").html $("#log", data).html()
if $('#tasks').length
task_template = $('#task_template').html()
file_template = $('#file_template').html()
tasks = d3.select('#tasks')
.selectAll('.task')
.data data.tasks, (task)-> task.id
tasks.enter()
.append('div')
.classed('task', true)
.html task_template
tasks.exit().each -> $(@).fadeOut -> $(@).remove()
tasks.each (task, i)->
$(@).find('.task-name').text_update task.name
$(@).find('.task-delete').attr href: "/tasks/#{task.id}"
$(@).find('.task-toggler').attr href: "#task#{task.id}"
$(@).find('.task-togglee').attr id: "task#{task.id}"
$(@).find('.task-progressbar')
.css('width': "#{task.progress}%")
.removeClass('active progress-bar-striped')
files = d3.select($(@).find('.task-files')[0])
.selectAll('.file')
.data task.files, (file)-> file.name
files.enter()
.append('div')
.classed('file', true)
.html file_template
files.exit().each -> $(@).remove()
files.each (file, i)->
$(@).find('.file-name').text_update file.name
$(@).find('.file-size').text_update fmt_size file.size
if file.retrieving && data.progress?
$(@).find('.file-status').text_update "已取回#{fmt_size data.progress.fetched};预计剩余#{fmt_time data.progress.eta}"
$(@).find('.file-progressbar')
.css(width: "#{100 * data.progress.progress}%")
.addClass('active progress-bar-striped')
.text_update("#{Math.floor 100 * data.progress.progress}%")
.parent()
.removeClass('notready')
$(@).closest('.task').find('.task-progressbar').addClass('active progress-bar-striped')
else if file.finished
$(@).find('.file-status').text_update '已取回本地'
$(@).find('.file-progressbar')
.css(width: '100%')
.text_update('')
.removeClass('active progress-bar-striped')
.parent()
.removeClass('notready')
else if file.url
$(@).find('.file-progressbar')
.text_update('')
$(@).find('.file-status').text_update "等待取回"
else
$(@).find('.file-status').text_update "未就绪"
$(@).find('.file-progressbar')
.parent()
.addClass('notready')
$('.executings').empty()
for executing in data.executings
$(document.createElement 'li')
.text(executing)
.appendTo('.executings')
if data?.progress
$('#stats .speed').stop().fadeIn().text("#{fmt_size data.progress.speed}/s")
else
$('#stats .speed').stop().fadeOut()
await setTimeout defer(), 500