Skip to content

Commit 11de118

Browse files
committed
Removed the old upload form from the TraceSwitcher.
Also added a separate button for "Import trace", next to the "New Trace" button.
1 parent 2e2ff6f commit 11de118

File tree

5 files changed

+21
-338
lines changed

5 files changed

+21
-338
lines changed

codepulse/src/main/resources/toserve/pages/TraceInputForm/TraceInputForm.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919

2020
$(document).ready(function(){
2121

22+
switch(window.location.hash){
23+
case '#import':
24+
$('a[href=#new-import-form]').tab('show')
25+
}
26+
2227
// wire up the new analysis form to submit to the trace creation url, with a mandatory name
2328
setupUploadForm($('#new-analysis-form'), '/trace-api/trace/create', false)
2429

codepulse/src/main/resources/toserve/pages/TraceSwitcher/TraceSwitcher.css

Lines changed: 9 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -23,126 +23,37 @@
2323
bottom: calc(100% - 60px);
2424
}
2525

26-
.traceSwitcher .slideOutForm {
27-
position: fixed;
28-
bottom: 25px;
29-
right: 285px;
30-
width: 35%;
31-
padding: 5px;
32-
33-
transition: right .3s ease;
34-
35-
background-color: #BBB;
36-
box-shadow: 0 0 5px black;
37-
}
38-
39-
.traceSwitcher .slideOutForm.collapsed {
40-
/* slide off screen to the right, enough that the full width is hidden */
41-
right: calc(-35% - 5px);
42-
}
43-
4426
.traceSwitcher .full-container {
4527
width: 100%;
4628
height: 100%;
4729
position: relative;
4830
}
4931

50-
.traceSwitcher .addTraceButton {
32+
.traceSwitcher .traceInputLinks {
5133
position: absolute;
5234
bottom: 0;
5335
width: 100%;
36+
}
37+
38+
.traceSwitcher .traceInputLink {
39+
display: block;
5440
padding: 5px;
5541
box-sizing: border-box;
5642

5743
background-color: silver;
5844
color: black;
59-
cursor: pointer;
45+
text-decoration: none;
6046
}
6147

62-
.traceSwitcher .addTraceButton:hover {
48+
.traceSwitcher .traceInputLink:hover {
6349
background-color: gray;
6450
}
6551

6652
.traceSwitcher .traceList {
67-
max-height: calc(100% - 30px);
53+
max-height: calc(100% - 60px);
6854
overflow-y: auto;
6955
}
7056

71-
.traceSwitcher .feedback {
72-
min-height: 150px;
73-
max-height: 150px;
74-
margin: 5px;
75-
border-radius: 10px;
76-
padding: 10px;
77-
box-sizing: border-box;
78-
background-color: #DDD;
79-
overflow-y: scroll;
80-
overflow-x: hidden;
81-
}
82-
83-
.traceSwitcher .feedback .message-box {
84-
border-bottom: 1px solid silver;
85-
margin-bottom: 3px;
86-
overflow: hidden;
87-
}
88-
89-
.traceSwitcher .feedback .message-box.error { color: #BD0000; }
90-
.traceSwitcher .feedback .message-box.success { color: dodgerblue; }
91-
92-
.traceSwitcher .feedback .message-box .message {
93-
font-size: .8em;
94-
position: relative;
95-
transition: left .3s ease;
96-
left: 0;
97-
}
98-
99-
.traceSwitcher .feedback .message-box .message.out {
100-
left: 100%;
101-
}
102-
103-
.traceSwitcher .uploadProgressBar {
104-
height: 3px;
105-
border-bottom: 1px solid;
106-
margin-top: 5px;
107-
}
108-
109-
.traceSwitcher .uploadProgressBar .fill {
110-
height: 100%;
111-
background-color: dodgerblue;
112-
box-shadow: 0 0 3px dodgerblue;
113-
transition: width .3s ease;
114-
}
115-
116-
.traceSwitcher .formlabel {
117-
font-size: 14px;
118-
}
119-
120-
.traceSwitcher .formfield {
121-
margin-bottom: 3px;
122-
}
123-
124-
.traceSwitcher [name=filebutton] {
125-
position: relative;
126-
overflow: hidden;
127-
}
128-
129-
.traceSwitcher input[type=file] {
130-
position: absolute;
131-
opacity: 0;
132-
right: 0;
133-
top: 0;
134-
font-size: 200px;
135-
direction: ltr;
136-
cursor: pointer;
137-
}
138-
139-
.traceSwitcher input[type=text] {
140-
/* mostly overriding unwanted styles coming from bootstrap */
141-
margin: 0;
142-
border-radius: 0;
143-
height: 24px;
144-
}
145-
14657
[data-toggle=TraceSwitcher].active {
14758
background-color: #FFA500;
14859
}
@@ -226,46 +137,4 @@
226137
.stripedBackground.animated {
227138
animation: stripe-animation 2s linear infinite;
228139
-webkit-animation: stripe-animation 2s linear infinite;
229-
}
230-
231-
/*********************\
232-
| File Drag/Drop Zone |
233-
\*********************/
234-
235-
.traceSwitcher .dropzone {
236-
position: absolute;
237-
top: 0;
238-
left: 0;
239-
width: 100%;
240-
height: 100%;
241-
background-color: lightgray;
242-
243-
display: none;
244-
}
245-
246-
.traceSwitcher .dropzone.in {
247-
display: block;
248-
}
249-
250-
.traceSwitcher .dropzone.hover {
251-
background-color: lightgreen;
252-
}
253-
254-
.traceSwitcher .dropzone-msg {
255-
font-size: xx-large;
256-
color: gray;
257-
text-align: center;
258-
height: calc(100% - 1em);
259-
margin: .5em;
260-
padding-top: 70px; /* to vertically center the text */
261-
border: 3px dashed;
262-
border-radius: .5em;
263-
}
264-
265-
.traceSwitcher .dropzone.in .dropzone-msg:after {
266-
content: 'Drag here to import!';
267-
}
268-
269-
.traceSwitcher .dropzone.hover .dropzone-msg:after {
270-
content: 'Drop it here!';
271-
}
140+
}

codepulse/src/main/resources/toserve/pages/TraceSwitcher/TraceSwitcher.js

Lines changed: 2 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,14 @@ template html.
3333
;(function(exports){
3434

3535
// predefinition of jQuery vars that will be assigned when the document is ready
36-
var slideOutForm, slideDownSidebar, formOpener
37-
38-
var feedbackZone
36+
var slideDownSidebar
3937

4038
// the main exported variable, defined later
4139
var TraceSwitcher
4240

4341
$(document).ready(function(){
4442
// get references to the moving parts
45-
slideOutForm = $('.traceSwitcher .slideOutForm')
4643
slideDownSidebar = $('.traceSwitcher .slideDownSidebar')
47-
formOpener = slideDownSidebar.find('.addTraceButton')
48-
feedbackZone = $('.traceSwitcher .feedback')
49-
50-
feedbackZone.click(function(){
51-
sendFeedback("you clicked the feedback zone")
52-
})
53-
54-
// wire up a file upload process to the fileChooser
55-
setupFileUpload()
56-
57-
setupDropZone()
58-
59-
// clicking the "Add a new trace target" button opens and closes the form
60-
formOpener.click(function(){ showForm('toggle') })
6144

6245
// auto-setup a master button control to toggle the TraceSwitcher view
6346
$('[data-toggle=TraceSwitcher]').each(function(){
@@ -77,22 +60,6 @@ template html.
7760
return !shouldBeCollapsed
7861
}
7962

80-
// showForm('toggle'|true|false) to show/hide the slideOutForm
81-
function showForm(arg){
82-
if(!slideOutForm) return
83-
84-
var isCollapsed = slideOutForm.hasClass('collapsed'),
85-
shouldBeCollapsed = (arg == 'toggle') ? !isCollapsed : !arg
86-
87-
slideOutForm.toggleClass('collapsed', shouldBeCollapsed)
88-
89-
formOpener.text(shouldBeCollapsed ? '+ New Trace' : 'Cancel')
90-
91-
return !shouldBeCollapsed
92-
}
93-
94-
95-
9663
function wireUpController($button){
9764
var switcherOpen = false
9865
$button.click(function(){
@@ -102,141 +69,9 @@ template html.
10269
})
10370
}
10471

105-
function sendFeedback(message, style){
106-
var msgDiv = $("<div class='message out'>").text(message).hide(),
107-
msgBox = $("<div class='message-box'>")
108-
109-
style && msgBox.addClass(style)
110-
111-
msgBox.append(msgDiv).prependTo(feedbackZone)
112-
113-
msgDiv.slideDown(function(){
114-
msgDiv.removeClass('out')
115-
})
116-
}
117-
118-
function setupFileUpload(){
119-
var fileChooser = slideOutForm.find('input[type=file]'),
120-
progressFill = slideOutForm.find('.uploadProgressBar .fill'),
121-
filenameSpan = slideOutForm.find('[name=filename]'),
122-
uploadUrl = '/trace-api/file-upload'
123-
124-
fileChooser.fileupload({
125-
url: uploadUrl,
126-
dropZone: slideOutForm,
127-
add: function(e, data){
128-
129-
var file = data.files[0],
130-
filename = file.name,
131-
filepath = file.path
132-
133-
filenameSpan.text(filename)
134-
135-
// Reset the progress bar
136-
updateProgress(0)
137-
138-
if(CodePulse.isEmbedded && filepath) doNativeUpload(filepath)
139-
else {
140-
console.log('using browser upload behavior on ', filename)
141-
data.submit()
142-
}
143-
},
144-
done: function(e, data){
145-
onUploadDone(data.result)
146-
},
147-
error: function(e, data){
148-
onUploadError(e.responseText)
149-
},
150-
progress: function(e, data){
151-
updateProgress(+data.loaded / +data.total)
152-
}
153-
})
154-
155-
function onUploadError(err){
156-
sendFeedback('Error: ' + (err || '(unknown error)'), 'error')
157-
updateProgress(0)
158-
}
159-
160-
function onUploadDone(result){
161-
updateProgress(1)
162-
163-
var there = result.href,
164-
here = window.location.pathname,
165-
href = window.location.href.replace(new RegExp(here + '$'), there)
166-
console.log('there: ' + there, 'here: ' + here, 'href: ' + href)
167-
window.location.href = href
168-
}
169-
170-
function doNativeUpload(path){
171-
console.log('using native upload behavior on ', path)
172-
updateProgress(0.9)
173-
$.ajax(uploadUrl, {
174-
data: {'path': path},
175-
type: 'POST',
176-
error: function(xhr, status){ onUploadError(xhr.responseText) },
177-
success: function(data){ onUploadDone(data) }
178-
})
179-
}
180-
181-
function updateProgress(ratio){
182-
if(!isNaN(ratio) && isFinite(ratio)){
183-
var fillWidth = parseInt(ratio * 100) + '%'
184-
progressFill.css('width', fillWidth)
185-
}
186-
}
187-
188-
}
189-
190-
function setupDropZone(){
191-
var $zone = slideOutForm.find('.dropzone'),
192-
timeout = undefined
193-
194-
$(document).bind('dragover', function(e){
195-
if(!timeout) $zone.addClass('in')
196-
else clearTimeout(timeout)
197-
198-
// figure out if we're dragging over the dropzone
199-
var found = false, node = e.target
200-
do {
201-
if(node === $zone[0]){
202-
found = true
203-
break
204-
}
205-
node = node.parentNode
206-
} while(node != null)
207-
208-
// set the 'hover' class depending on `found`
209-
$zone.toggleClass('hover', found)
210-
211-
timeout = setTimeout(function(){
212-
timeout = null
213-
$zone.removeClass('in hover')
214-
}, 300)
215-
})
216-
}
217-
218-
/* Drag and Drop is useless if they don't have files */
219-
function isFileDrag(event) {
220-
if(event.originalEvent) return isFileDrag(event.originalEvent)
221-
222-
var dt = event.dataTransfer
223-
224-
// can't use forEach or $.inArray because IE10 uses a DomStringList
225-
var foundFiles = false, idx
226-
for(idx = 0; idx < dt.types.length; idx++){
227-
var s = dt.types[idx]
228-
if(s == 'Files') foundFiles = true
229-
}
230-
231-
return dt && foundFiles
232-
}
233-
23472
TraceSwitcher = exports['TraceSwitcher'] = {
23573
'open': function(){ showSidebar(true) },
236-
'close': function(){
237-
showForm(false)
238-
showSidebar(false)
239-
}
74+
'close': function(){ showSidebar(false) }
24075
}
24176

24277
})(this);

0 commit comments

Comments
 (0)