-
Notifications
You must be signed in to change notification settings - Fork 211
/
_sidebar_exports.html.erb
196 lines (179 loc) · 8.39 KB
/
_sidebar_exports.html.erb
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<p>
Export maps to generate downloadable, printable, high-resolution files.
</p>
<p>
If you only need one or two images, consider using the new <a href="https://publiclab.org/wiki/mapknitter-exporting-your-map#Per-image+exporting">per-image download</a> in the Images pane; to download a single full-resolution distorted image, click the <code><i class='fa fa-download'></i></code> button next to the image.
</p>
<p>
<img style="width:100%;" src="/images/download-btn.png" />
</p>
<p>
<a href="#" onClick="$('#exporting-info').toggle();">Learn more about exporting »</a>
</p>
<div style="display:none;" id="exporting-info">
<p>From this panel you can export this map in a variety of formats. If you've changed the map at all since last exporting, you can re-run the export, but be aware that this will <b>delete and replace previously exported files</b>, so download them first if you want them. All formats are generated sequentially, so if you're waiting for a JPG you will have to let all the other formats complete first.</p>
<p>This may take some time - a large map could take as long as <b>an hour or more</b>. Closing this panel will not stop the export.</p>
<p><a href="//publiclab.org/wiki/mapknitter-exporting">Learn even more »</a></p>
</div>
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" href="#map-export-subtab" role="tab" data-toggle="tab">Export</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#map-export-options-subtab" role="tab" data-toggle="tab">Advanced option</a>
</li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="map-export-subtab">
<div class="progress"<% unless @map.exporting? %> style="display:none;"<% end %>>
<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%">
<span class="" id="export_progress"><%= @map.export ? @map.export.status : "Loading..." %></span>
</div>
</div>
<% if Rails.env.production? && !logged_in? && @map.anonymous? %>
<div class="recaptcha"<% if @map.exporting? %> style="display:none;"<% end %>>
<p><%= recaptcha_tags :display => {:theme => "white"} %></p>
<p>Prove that you're a person, then click EXPORT to begin:</p>
</div>
<% end %>
<% if logged_in? || @map.anonymous? %>
<p>
<button id="begin-export" class="btn btn-lg btn-primary"<% if @map.export && @map.exporting? %> style="display:none;"<% end %>>Start export</button>
<button <% unless @map.export && @map.exporting? %>style="display:none;"<% end %> id="cancel-export" class="btn btn-lg btn-outline-secondary"><i class="fa fa-remove"></i> Cancel export</button>
</p>
<% if @map.exporting? && ((@map.export.updated_at-DateTime.now)/1.hours).abs > 4 %>
<p class="alert alert-warning alert-toolong">
This export is taking a while; consider cancelling it and following the tips linked to below.
</p>
<% else %>
<p>
Closing this window will not interrupt the export.
</p>
<% end %>
<p>
<i class="fa fa-question-circle"></i> Having trouble? Taking too long? <a href="//publiclab.org/wiki/mapknitter-exporting">Click here</a> to learn more about exporting and get help.
</p>
<% else %>
<p>You must be <a href="/login?back_to=/maps/<%= @map.slug %>">logged in</a> to run exports, except on anonymous maps.</p>
<% end %>
<p style="color:#888;">
<% if @map.export %>Export last run <%= time_ago_in_words @map.export.updated_at %> ago<% if @map.export.user %> by <a href="//publiclab.org/profile/<%= @map.export.user.login %>"><%= @map.export.user.login %></a>.<% end %><% end %>
<a href="/exports">View all running exports</a>
</p>
</div>
<div class="tab-pane" id="map-export-options-subtab">
<p>Tweak your export resolution; too high a resolution may stall the export (if the resulting file is too big!), while too low a resolution causes lots of processing to resize the images.</p>
<p>Graph coming soon.</p><!-- Sparklines graph will go here -->
<p><b>Resolution:</b> <span id="resolution-label"><%= @resolution %></span> cm/px</p>
<p><input style="width:100%" id="export-resolution" data-slider-id='exResSlider' type="text" data-slider-min="1" data-slider-max="100" data-slider-step="1" data-slider-value="<%= @resolution %>"/></p>
</div>
</div>
<script>
var exporting, exportResolutionSlider
(function(){
exportResolutionSlider = new Slider('#export-resolution',{
min: 1,
formatter: function(value) {
return value + ' cm/px';
}
}).on('change',function() {
$('#resolution-label').html(exportResolutionSlider.getValue())
});
updateExports = function() {
$.ajax({
url: '/maps/exports/<%= @map.id %>?authenticity_token=<%= form_authenticity_token %>'
}).done(function(data) {
$('.map-exports').html(data)
})
}
// 'complete', 'failed', ''
exportProgress = function() {
$.ajax({
url: '/export/status/<%= @map.id %>?authenticity_token=<%= form_authenticity_token %>',
dataType: "json"
}).done(function(data) {
$('.progress').show()
$('#export_progress').html(data['status'])
// change progress indicator appearance accordingly
// -- maybe have a handler which assigns prog indicator state based on status?
})
}
<% if @map.exporting? %>
exporting = true
setInterval(exportProgress,5000)
<% end %>
$('#cancel-export').click(function() {
$.ajax({
url: '/export/cancel/<%= @map.id %>?authenticity_token=<%= form_authenticity_token %>',
beforeSend: function() {
$('.progress-bar').addClass('progress-bar-warning')
$('.progress-bar').removeClass('progress-bar-danger')
$('.progress-bar').removeClass('progress-bar-success')
$('#export_progress').html('cancelling...')
}
}).done(function(data){
$('.alert-toolong').hide()
$('.progress-bar').removeClass('progress-bar-warning')
$('.progress-bar').removeClass('progress-bar-danger')
$('.progress-bar').removeClass('active')
$('.progress-bar').removeClass('progress-bar-striped')
$('#begin-export').html('Re-run export')
$('#begin-export').show()
$('#cancel-export').hide()
$('.recaptcha').show()
$('.progress').hide()
updateExports()
})
})
$('#begin-export').click(function() {
if (images.length < 30 || confirm('This map has over 30 images; this is a lot! Please read the tips on exporting maps listed below the Export button.')) {
$('.alert-toolong').hide()
$('.progress').show()
$('.progress-bar').addClass('active')
$('.progress-bar').addClass('progress-bar-striped')
$('.progress-bar').removeClass('progress-bar-danger')
$('.progress-bar').removeClass('progress-bar-success')
if (exporting != true) {
exporting = true
setInterval(exportProgress,5000)
}
$('#begin-export').hide()
$('.recaptcha').hide()
$('#cancel-export').show()
$('#export_progress').html("starting export")
$('.map-exports').html('')
$.ajax({
url: '/maps/export/<%= @map.id %>?authenticity_token=<%= form_authenticity_token %>',
method: 'POST',
data: {
<% if Rails.env.production? && !logged_in? && @map.anonymous? %>
recaptcha_response_field: Recaptcha.get_response(),
recaptcha_challenge_field: Recaptcha.get_challenge(),
<% end %>
resolution: exportResolutionSlider.getValue()
}
}).done(function(data){
$('.progress-bar').addClass('progress-bar-success')
$('.progress-bar').removeClass('active')
$('.progress-bar').removeClass('progress-bar-striped')
$('#export_progress').html(data)
$('#begin-export').show()
$('#begin-export').html('Re-run export')
$('.recaptcha').show()
$('#cancel-export').hide()
updateExports()
}).fail(function(data){
console.log(data)
$('.progress-bar').addClass('progress-bar-danger')
$('.progress-bar').removeClass('active')
$('.progress-bar').removeClass('progress-bar-striped')
$('#export_progress').html('There was an error.')
$('#begin-export').show()
$('.recaptcha').show()
$('#begin-export').html('Retry export')
$('#cancel-export').hide()
})
}
})
})()
</script>