7604 |
25 Feb 19 |
nicklas |
/* $Id $ |
7604 |
25 Feb 19 |
nicklas |
2 |
------------------------------------------------------------------ |
7604 |
25 Feb 19 |
nicklas |
Copyright (C) 2012 Nicklas Nordborg |
7604 |
25 Feb 19 |
nicklas |
4 |
|
7604 |
25 Feb 19 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
7604 |
25 Feb 19 |
nicklas |
Available at http://base.thep.lu.se/ |
7604 |
25 Feb 19 |
nicklas |
7 |
|
7604 |
25 Feb 19 |
nicklas |
BASE is free software; you can redistribute it and/or |
7604 |
25 Feb 19 |
nicklas |
modify it under the terms of the GNU General Public License |
7604 |
25 Feb 19 |
nicklas |
as published by the Free Software Foundation; either version 3 |
7604 |
25 Feb 19 |
nicklas |
of the License, or (at your option) any later version. |
7604 |
25 Feb 19 |
nicklas |
12 |
|
7604 |
25 Feb 19 |
nicklas |
BASE is distributed in the hope that it will be useful, |
7604 |
25 Feb 19 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
7604 |
25 Feb 19 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7604 |
25 Feb 19 |
nicklas |
GNU General Public License for more details. |
7604 |
25 Feb 19 |
nicklas |
17 |
|
7604 |
25 Feb 19 |
nicklas |
You should have received a copy of the GNU General Public License |
7604 |
25 Feb 19 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
7604 |
25 Feb 19 |
nicklas |
20 |
------------------------------------------------------------------ |
7604 |
25 Feb 19 |
nicklas |
21 |
|
7604 |
25 Feb 19 |
nicklas |
@author Nicklas |
7604 |
25 Feb 19 |
nicklas |
23 |
*/ |
7604 |
25 Feb 19 |
nicklas |
'use strict'; |
7604 |
25 Feb 19 |
nicklas |
25 |
|
7604 |
25 Feb 19 |
nicklas |
var ParseFile = function() |
7604 |
25 Feb 19 |
nicklas |
27 |
{ |
7604 |
25 Feb 19 |
nicklas |
var parse = {}; |
7604 |
25 Feb 19 |
nicklas |
var linePatterns; |
7604 |
25 Feb 19 |
nicklas |
var columnHeaders; |
7604 |
25 Feb 19 |
nicklas |
var fuzzyMatches; |
8144 |
21 Apr 23 |
nicklas |
var currentMappingName; |
7604 |
25 Feb 19 |
nicklas |
33 |
|
7604 |
25 Feb 19 |
nicklas |
34 |
/** |
7604 |
25 Feb 19 |
nicklas |
Initialize the page. |
7604 |
25 Feb 19 |
nicklas |
36 |
*/ |
7604 |
25 Feb 19 |
nicklas |
parse.initPage = function() |
7604 |
25 Feb 19 |
nicklas |
38 |
{ |
7604 |
25 Feb 19 |
nicklas |
linePatterns = Data.json('page-data', 'line-patterns'); |
7604 |
25 Feb 19 |
nicklas |
columnHeaders = Data.json('page-data', 'column-headers'); |
7604 |
25 Feb 19 |
nicklas |
fuzzyMatches = Data.json('page-data', 'fuzzy-matches'); |
7604 |
25 Feb 19 |
nicklas |
42 |
|
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnFuzzyMatches', parse.setFuzzyMatches); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('similarityScore', 'keypress', Events.numberOnly); |
7663 |
20 Mar 19 |
nicklas |
45 |
|
7663 |
20 Mar 19 |
nicklas |
var mappingHeader = Doc.element('col-mappings.expression'); |
7663 |
20 Mar 19 |
nicklas |
if (mappingHeader != null) |
7663 |
20 Mar 19 |
nicklas |
48 |
{ |
7663 |
20 Mar 19 |
nicklas |
var html = mappingHeader.innerHTML; |
7663 |
20 Mar 19 |
nicklas |
html += '<img class="link" id="clearAllMappings" src="../../images/clear_down.png" title="Clear all mappings" style="margin-left: 2em;">'; |
7663 |
20 Mar 19 |
nicklas |
mappingHeader.innerHTML = html; |
7663 |
20 Mar 19 |
nicklas |
Buttons.addClickHandler('clearAllMappings', parse.clearAllColumnMappings); |
7663 |
20 Mar 19 |
nicklas |
53 |
} |
7604 |
25 Feb 19 |
nicklas |
54 |
} |
7604 |
25 Feb 19 |
nicklas |
55 |
|
7654 |
15 Mar 19 |
nicklas |
parse.pleaseWaitWhileParsing = function() |
7654 |
15 Mar 19 |
nicklas |
57 |
{ |
7654 |
15 Mar 19 |
nicklas |
TabControl.setActiveTab('parsedFile.filedata'); |
7654 |
15 Mar 19 |
nicklas |
Doc.hide('myContent'); |
7654 |
15 Mar 19 |
nicklas |
Doc.show('waitWhileParsing'); |
7654 |
15 Mar 19 |
nicklas |
61 |
} |
7654 |
15 Mar 19 |
nicklas |
62 |
|
7604 |
25 Feb 19 |
nicklas |
parse.initColumnMapping = function(element, autoInit) |
7604 |
25 Feb 19 |
nicklas |
64 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (autoInit == 'line-pattern') |
7604 |
25 Feb 19 |
nicklas |
66 |
{ |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler(element, 'change', parse.setLinePattern) |
7604 |
25 Feb 19 |
nicklas |
68 |
} |
7604 |
25 Feb 19 |
nicklas |
else if (autoInit == 'column-mapping-clear') |
7604 |
25 Feb 19 |
nicklas |
70 |
{ |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler(element, 'click', parse.clearColumnMapping); |
7604 |
25 Feb 19 |
nicklas |
72 |
} |
8144 |
21 Apr 23 |
nicklas |
else if (autoInit == 'column-mapping-preset-menu') |
7604 |
25 Feb 19 |
nicklas |
74 |
{ |
8144 |
21 Apr 23 |
nicklas |
Buttons.addClickHandler(element, parse.showColumnMappingPresets); |
7604 |
25 Feb 19 |
nicklas |
76 |
} |
8144 |
21 Apr 23 |
nicklas |
else if (autoInit == 'preset-column-mapping') |
8144 |
21 Apr 23 |
nicklas |
78 |
{ |
8144 |
21 Apr 23 |
nicklas |
Events.addEventHandler(element, 'click', parse.setPresetColumnMapping); |
8144 |
21 Apr 23 |
nicklas |
80 |
} |
7604 |
25 Feb 19 |
nicklas |
else if (autoInit == 'column-mapping') |
7604 |
25 Feb 19 |
nicklas |
82 |
{ |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler(element, 'blur', parse.columnMappingOnBlur); |
7604 |
25 Feb 19 |
nicklas |
84 |
} |
7604 |
25 Feb 19 |
nicklas |
85 |
} |
7604 |
25 Feb 19 |
nicklas |
Doc.addElementInitializer(parse.initColumnMapping); |
7604 |
25 Feb 19 |
nicklas |
87 |
|
7604 |
25 Feb 19 |
nicklas |
parse.setLinePattern = function(event) |
7604 |
25 Feb 19 |
nicklas |
89 |
{ |
7604 |
25 Feb 19 |
nicklas |
var target = event.currentTarget; |
7604 |
25 Feb 19 |
nicklas |
var lineNo = Data.int(target, 'line-no'); |
7604 |
25 Feb 19 |
nicklas |
92 |
|
7604 |
25 Feb 19 |
nicklas |
var whichPattern = target.value; |
7604 |
25 Feb 19 |
nicklas |
target.selectedIndex = 0; |
7604 |
25 Feb 19 |
nicklas |
var frm = window.parent.document.forms['testwithfile']; |
7604 |
25 Feb 19 |
nicklas |
96 |
|
7604 |
25 Feb 19 |
nicklas |
if (frm[whichPattern]) |
7604 |
25 Feb 19 |
nicklas |
98 |
{ |
7604 |
25 Feb 19 |
nicklas |
frm[whichPattern].value = linePatterns[lineNo]; |
7660 |
20 Mar 19 |
nicklas |
if (window.parent.TestWithFile) |
7660 |
20 Mar 19 |
nicklas |
101 |
{ |
7660 |
20 Mar 19 |
nicklas |
window.parent.TestWithFile.autoParse(); |
7660 |
20 Mar 19 |
nicklas |
103 |
} |
7604 |
25 Feb 19 |
nicklas |
104 |
} |
7604 |
25 Feb 19 |
nicklas |
105 |
} |
7604 |
25 Feb 19 |
nicklas |
106 |
|
7604 |
25 Feb 19 |
nicklas |
parse.columnMappingOnBlur = function(event) |
7604 |
25 Feb 19 |
nicklas |
108 |
{ |
7604 |
25 Feb 19 |
nicklas |
var target = event.currentTarget; |
7604 |
25 Feb 19 |
nicklas |
window.parent.TestWithFile.setFormValue(target.name, target.value); |
7604 |
25 Feb 19 |
nicklas |
111 |
} |
7604 |
25 Feb 19 |
nicklas |
112 |
|
7662 |
20 Mar 19 |
nicklas |
parse.setColumnMapping = function(mappingName, expression, overwrite) |
7604 |
25 Feb 19 |
nicklas |
114 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['mappings']; |
7663 |
20 Mar 19 |
nicklas |
var extendName = (mappingName.indexOf('mapping.') == -1); |
7663 |
20 Mar 19 |
nicklas |
var field = extendName ? 'mapping.'+mappingName+'.expression' : mappingName; |
7662 |
20 Mar 19 |
nicklas |
if (overwrite || frm[field].value == '') |
7662 |
20 Mar 19 |
nicklas |
119 |
{ |
7662 |
20 Mar 19 |
nicklas |
frm[field].value = expression; |
7662 |
20 Mar 19 |
nicklas |
window.parent.TestWithFile.setFormValue(field, expression); |
7662 |
20 Mar 19 |
nicklas |
122 |
} |
7604 |
25 Feb 19 |
nicklas |
123 |
} |
7604 |
25 Feb 19 |
nicklas |
124 |
|
7604 |
25 Feb 19 |
nicklas |
parse.getMappingExpressionForHeader = function(columnIndex) |
7604 |
25 Feb 19 |
nicklas |
126 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['mappings']; |
7604 |
25 Feb 19 |
nicklas |
var style = Forms.getCheckedRadio(frm.expressionStyle); |
7604 |
25 Feb 19 |
nicklas |
var header = columnHeaders[columnIndex]; |
7604 |
25 Feb 19 |
nicklas |
130 |
|
7604 |
25 Feb 19 |
nicklas |
var expression = ''; |
7604 |
25 Feb 19 |
nicklas |
if (style && style.value == 1) |
7604 |
25 Feb 19 |
nicklas |
133 |
{ |
7604 |
25 Feb 19 |
nicklas |
// 'simple' style with backslashes |
7604 |
25 Feb 19 |
nicklas |
// use index of the header already has a backslash |
7604 |
25 Feb 19 |
nicklas |
if (header.indexOf('\\') >= 0) |
7604 |
25 Feb 19 |
nicklas |
137 |
{ |
7604 |
25 Feb 19 |
nicklas |
expression = '\\'+columnIndex+'\\'; |
7604 |
25 Feb 19 |
nicklas |
139 |
} |
7604 |
25 Feb 19 |
nicklas |
else |
7604 |
25 Feb 19 |
nicklas |
141 |
{ |
7604 |
25 Feb 19 |
nicklas |
expression = '\\'+header+'\\'; |
7604 |
25 Feb 19 |
nicklas |
143 |
} |
7604 |
25 Feb 19 |
nicklas |
144 |
} |
7604 |
25 Feb 19 |
nicklas |
else |
7604 |
25 Feb 19 |
nicklas |
146 |
{ |
7604 |
25 Feb 19 |
nicklas |
// use 'expression' style |
7604 |
25 Feb 19 |
nicklas |
if (header.indexOf('\\') >= 0) |
7604 |
25 Feb 19 |
nicklas |
149 |
{ |
7659 |
20 Mar 19 |
nicklas |
expression = '=col('+columnIndex+')'; |
7604 |
25 Feb 19 |
nicklas |
151 |
} |
7604 |
25 Feb 19 |
nicklas |
else |
7604 |
25 Feb 19 |
nicklas |
153 |
{ |
7659 |
20 Mar 19 |
nicklas |
expression = '=col(\''+header+'\')'; |
7604 |
25 Feb 19 |
nicklas |
155 |
} |
7604 |
25 Feb 19 |
nicklas |
156 |
} |
7604 |
25 Feb 19 |
nicklas |
return expression; |
7604 |
25 Feb 19 |
nicklas |
158 |
} |
7604 |
25 Feb 19 |
nicklas |
159 |
|
7663 |
20 Mar 19 |
nicklas |
parse.clearAllColumnMappings = function(event) |
7663 |
20 Mar 19 |
nicklas |
161 |
{ |
7663 |
20 Mar 19 |
nicklas |
var frm = document.forms['mappings']; |
7663 |
20 Mar 19 |
nicklas |
for (var i = 0; i < frm.elements.length; i++) |
7663 |
20 Mar 19 |
nicklas |
164 |
{ |
7663 |
20 Mar 19 |
nicklas |
var e = frm.elements[i]; |
7663 |
20 Mar 19 |
nicklas |
if (e.name.indexOf('mapping.') == 0) |
7663 |
20 Mar 19 |
nicklas |
167 |
{ |
7663 |
20 Mar 19 |
nicklas |
parse.setColumnMapping(e.name, '', true); |
7663 |
20 Mar 19 |
nicklas |
169 |
} |
7663 |
20 Mar 19 |
nicklas |
170 |
} |
7663 |
20 Mar 19 |
nicklas |
171 |
} |
7663 |
20 Mar 19 |
nicklas |
172 |
|
7604 |
25 Feb 19 |
nicklas |
parse.clearColumnMapping = function(event) |
7604 |
25 Feb 19 |
nicklas |
174 |
{ |
7604 |
25 Feb 19 |
nicklas |
var target = event.currentTarget; |
7604 |
25 Feb 19 |
nicklas |
var mappingName = Data.get(target, 'mapping'); |
7662 |
20 Mar 19 |
nicklas |
parse.setColumnMapping(mappingName, '', true); |
7604 |
25 Feb 19 |
nicklas |
178 |
} |
7604 |
25 Feb 19 |
nicklas |
179 |
|
8144 |
21 Apr 23 |
nicklas |
parse.showColumnMappingPresets = function(event) |
8144 |
21 Apr 23 |
nicklas |
181 |
{ |
8144 |
21 Apr 23 |
nicklas |
currentMappingName = Data.get(event.currentTarget, 'mapping'); |
8144 |
21 Apr 23 |
nicklas |
var frm = document.forms['mappings']; |
8144 |
21 Apr 23 |
nicklas |
frm['mapping.'+currentMappingName+'.expression'].focus(); |
8144 |
21 Apr 23 |
nicklas |
185 |
|
8144 |
21 Apr 23 |
nicklas |
var offsetLeft = event.clientX; |
8144 |
21 Apr 23 |
nicklas |
var offsetTop = event.clientY; |
8144 |
21 Apr 23 |
nicklas |
var offsetBottom = null; |
8144 |
21 Apr 23 |
nicklas |
// Open the menu at the mouse position |
8144 |
21 Apr 23 |
nicklas |
Menu.showTopMenu('predefinedColumnMappings', offsetLeft, offsetTop); |
8144 |
21 Apr 23 |
nicklas |
event.stopPropagation(); |
8144 |
21 Apr 23 |
nicklas |
192 |
|
8144 |
21 Apr 23 |
nicklas |
// We may have to adjust depending on size of window |
8144 |
21 Apr 23 |
nicklas |
var winPos = App.getWindowPosition(); |
8144 |
21 Apr 23 |
nicklas |
var pcm = Doc.element('predefinedColumnMappings'); |
8144 |
21 Apr 23 |
nicklas |
pcm.style.bottom = 'auto'; // To ensure that the height is auto-calculated |
8144 |
21 Apr 23 |
nicklas |
197 |
|
8144 |
21 Apr 23 |
nicklas |
// If the right side overflows we move the menu to the left |
8144 |
21 Apr 23 |
nicklas |
if (offsetLeft+pcm.offsetWidth+10 > winPos.width) |
8144 |
21 Apr 23 |
nicklas |
200 |
{ |
8144 |
21 Apr 23 |
nicklas |
offsetLeft = winPos.width-pcm.offsetWidth-10; |
8144 |
21 Apr 23 |
nicklas |
202 |
} |
8144 |
21 Apr 23 |
nicklas |
// If the bottom side overflows we move up... |
8144 |
21 Apr 23 |
nicklas |
if (offsetTop+pcm.offsetHeight+10 > winPos.height) |
8144 |
21 Apr 23 |
nicklas |
205 |
{ |
8144 |
21 Apr 23 |
nicklas |
offsetTop = winPos.height-pcm.offsetHeight-10; |
8144 |
21 Apr 23 |
nicklas |
// ... but then we may overflow the top so we need to |
8144 |
21 Apr 23 |
nicklas |
// limit the height |
8144 |
21 Apr 23 |
nicklas |
if (offsetTop < 5) |
8144 |
21 Apr 23 |
nicklas |
210 |
{ |
8144 |
21 Apr 23 |
nicklas |
offsetTop = 5; |
8144 |
21 Apr 23 |
nicklas |
offsetBottom = 5; |
8144 |
21 Apr 23 |
nicklas |
offsetLeft -= 10; // make room for the scrollbar |
8144 |
21 Apr 23 |
nicklas |
214 |
} |
8144 |
21 Apr 23 |
nicklas |
215 |
} |
8144 |
21 Apr 23 |
nicklas |
pcm.style.left = (offsetLeft)+'px'; |
8144 |
21 Apr 23 |
nicklas |
pcm.style.top = (offsetTop)+'px'; |
8144 |
21 Apr 23 |
nicklas |
if (offsetBottom) pcm.style.bottom = (offsetBottom)+'px'; |
8144 |
21 Apr 23 |
nicklas |
219 |
} |
8144 |
21 Apr 23 |
nicklas |
220 |
|
7604 |
25 Feb 19 |
nicklas |
parse.setPresetColumnMapping = function(event) |
7604 |
25 Feb 19 |
nicklas |
222 |
{ |
7604 |
25 Feb 19 |
nicklas |
var target = event.currentTarget; |
8144 |
21 Apr 23 |
nicklas |
var columnIndex = Data.int(target, 'index'); |
7604 |
25 Feb 19 |
nicklas |
var expression = parse.getMappingExpressionForHeader(columnIndex); |
8144 |
21 Apr 23 |
nicklas |
parse.setColumnMapping(currentMappingName, expression, true); |
7604 |
25 Feb 19 |
nicklas |
227 |
} |
7604 |
25 Feb 19 |
nicklas |
228 |
|
7604 |
25 Feb 19 |
nicklas |
parse.setFuzzyMatches = function() |
7604 |
25 Feb 19 |
nicklas |
230 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['mappings']; |
7604 |
25 Feb 19 |
nicklas |
var minScore = parseFloat(frm.similarity.value); |
7662 |
20 Mar 19 |
nicklas |
var overwrite = frm.overwrite.checked; |
7604 |
25 Feb 19 |
nicklas |
for (var i = 0; i < fuzzyMatches.length; i++) |
7604 |
25 Feb 19 |
nicklas |
235 |
{ |
7604 |
25 Feb 19 |
nicklas |
var match = fuzzyMatches[i]; |
7604 |
25 Feb 19 |
nicklas |
if (match) |
7604 |
25 Feb 19 |
nicklas |
238 |
{ |
7604 |
25 Feb 19 |
nicklas |
var expression; |
7604 |
25 Feb 19 |
nicklas |
if (match.score >= minScore) |
7604 |
25 Feb 19 |
nicklas |
241 |
{ |
7604 |
25 Feb 19 |
nicklas |
expression = parse.getMappingExpressionForHeader(match.columnIndex); |
7604 |
25 Feb 19 |
nicklas |
243 |
} |
7604 |
25 Feb 19 |
nicklas |
else |
7604 |
25 Feb 19 |
nicklas |
245 |
{ |
7604 |
25 Feb 19 |
nicklas |
expression = ''; |
7604 |
25 Feb 19 |
nicklas |
247 |
} |
7662 |
20 Mar 19 |
nicklas |
parse.setColumnMapping(match.name, expression, overwrite); |
7604 |
25 Feb 19 |
nicklas |
249 |
} |
7604 |
25 Feb 19 |
nicklas |
250 |
} |
7604 |
25 Feb 19 |
nicklas |
251 |
} |
7604 |
25 Feb 19 |
nicklas |
252 |
|
7604 |
25 Feb 19 |
nicklas |
return parse; |
7604 |
25 Feb 19 |
nicklas |
254 |
}(); |
7604 |
25 Feb 19 |
nicklas |
255 |
|
6200 |
05 Nov 12 |
nicklas |
Doc.onLoad(ParseFile.initPage); |