Changeset 8132


Ignore:
Timestamp:
Mar 24, 2023, 1:31:56 PM (2 months ago)
Author:
Nicklas Nordborg
Message:

Fixes #2297: Improve the "File columns" selection in the "Test with file" function

Location:
branches/3.19-stable/www
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/3.19-stable/www/common/plugin/parse_file.js

    r7663 r8132  
    3030  var columnHeaders;
    3131  var fuzzyMatches;
     32  var currentMappingName;
    3233
    3334  /**
     
    7071      Events.addEventHandler(element, 'click', parse.clearColumnMapping);
    7172    }
    72     else if (autoInit == 'column-mapping-preset')
    73     {
    74       Events.addEventHandler(element, 'change', parse.setPresetColumnMapping);
     73    else if (autoInit == 'column-mapping-preset-menu')
     74    {
     75      Buttons.addClickHandler(element, parse.showColumnMappingPresets);
     76    }
     77    else if (autoInit == 'preset-column-mapping')
     78    {
     79      Events.addEventHandler(element, 'click', parse.setPresetColumnMapping);
    7580    }
    7681    else if (autoInit == 'column-mapping')
     
    173178  }
    174179 
     180  parse.showColumnMappingPresets = function(event)
     181  {
     182    currentMappingName = Data.get(event.currentTarget, 'mapping');
     183    var frm = document.forms['mappings'];
     184    frm['mapping.'+currentMappingName+'.expression'].focus();
     185   
     186    var offsetLeft = event.clientX;
     187    var offsetTop = event.clientY;
     188    var offsetBottom = null;
     189    // Open the menu at the mouse position
     190    Menu.showTopMenu('predefinedColumnMappings', offsetLeft, offsetTop);
     191    event.stopPropagation();
     192
     193    // We may have to adjust depending on size of window
     194    var winPos = App.getWindowPosition();
     195    var pcm = Doc.element('predefinedColumnMappings');
     196    pcm.style.bottom = 'auto'; // To ensure that the height is auto-calculated
     197   
     198    // If the right side overflows we move the menu to the left
     199    if (offsetLeft+pcm.offsetWidth+10 > winPos.width)
     200    {
     201      offsetLeft = winPos.width-pcm.offsetWidth-10;
     202    }
     203    // If the bottom side overflows we move up...
     204    if (offsetTop+pcm.offsetHeight+10 > winPos.height)
     205    {
     206      offsetTop = winPos.height-pcm.offsetHeight-10;
     207      // ... but then we may overflow the top so we need to
     208      // limit the height
     209      if (offsetTop < 5)
     210      {
     211        offsetTop = 5;
     212        offsetBottom = 5;
     213        offsetLeft -= 10; // make room for the scrollbar
     214      }
     215    }
     216    pcm.style.left = (offsetLeft)+'px';
     217    pcm.style.top = (offsetTop)+'px';
     218    if (offsetBottom) pcm.style.bottom = (offsetBottom)+'px';   
     219  }
     220
    175221  parse.setPresetColumnMapping = function(event)
    176222  {
    177223    var target = event.currentTarget;
    178     var mappingName = Data.get(target, 'mapping');
    179  
    180     var columnIndex = target.value;
    181     target.selectedIndex = 0;
     224    var columnIndex = Data.int(target, 'index');
    182225    var expression = parse.getMappingExpressionForHeader(columnIndex);
    183 
    184     parse.setColumnMapping(mappingName, expression, true);
     226    parse.setColumnMapping(currentMappingName, expression, true);
    185227  }
    186228 
  • branches/3.19-stable/www/common/plugin/parse_file.jsp

    r7975 r8132  
    3333  import="net.sf.basedb.core.Path"
    3434  import="net.sf.basedb.core.Location"
     35  import="net.sf.basedb.core.StringUtil"
    3536  import="net.sf.basedb.core.PluginConfigurationRequest"
    3637  import="net.sf.basedb.core.plugin.Plugin"
     
    7879  FlatFileParser parser = null;
    7980  FlatFileParser.LineType lastLine = null;
     81  FlatFileParser.Data firstDataLine = null;
    8082  Pattern splitter = null;
    8183  boolean dataIsFound = false;
     
    231233    {
    232234      color: #0000D0;
     235    }
     236   
     237    #predefinedColumnMappings
     238    {
     239      overflow-x: hidden;
     240      overflow-y: auto;
     241    }
     242   
     243    .file-column
     244    {
     245      display: grid;
     246      grid-template-columns: 1fr 1fr;
     247      width: 32em;
     248      padding: 0 !important;
     249    }
     250   
     251    .file-column > div
     252    {
     253      overflow: hidden;
     254      padding: 3px 4px;
     255    }
     256
     257    .file-column > div.example
     258    {
     259      background-color: #F8F8F8;
     260      border-left-width: 1px;
     261      border-left-style: dotted;
     262      font-style: italic;
     263    }
     264
     265    .interactable.file-column:hover > div:first-child
     266    {
     267      padding: 1px 4px 1px 2px;
     268    }
     269    .interactable.file-column:hover > div.example
     270    {
     271      padding: 1px 2px 1px 4px;
     272    }
     273
     274    .index-only .file-column
     275    {
     276      width: 20em;
     277      grid-template-columns: 5em 1fr;
     278    }
     279   
     280    .index-only .interactable.file-column:hover
     281    {
     282      grid-template-columns: calc(5em - 2px) 1fr;
    233283    }
    234284    </style>
     
    360410        if (currentLine < maxLines)
    361411        {
    362           if (lastLine == FlatFileParser.LineType.DATA) parser.nextData();
     412          if (lastLine == FlatFileParser.LineType.DATA)
     413          {
     414            firstDataLine = parser.nextData();
     415          }
    363416          while (currentLine < maxLines && parser.hasMoreData())
    364417          {
    365418            FlatFileParser.Data data = parser.nextData();
     419            if (firstDataLine == null) firstDataLine = data;
    366420            linePatterns.add(Pattern.quote(data.line()));
    367421            if (parser.getNumSkippedLines() > 0)
     
    439493      >
    440494      <%
    441       StringBuilder sb = new StringBuilder();
    442495      List<String> headers = parser.getColumnHeaders();
     496      //headers = null;
    443497      int index = 0;
    444       if (headers != null)
    445       {
    446         for (String header : headers)
     498      int maxDataColumns = headers != null ? headers.size() : firstDataLine.columns();
     499      %>
     500      <div id="predefinedColumnMappings" class="menu vertical bg-filled-100 <%=headers==null?"index-only":"" %>" style="display: none;">
     501        <div class="menuitem file-column" style="font-weight: bold;">
     502          <div>Column</div>
     503          <div class="example">Example</div>
     504        </div>
     505        <%
     506        while (index < maxDataColumns)
    447507        {
    448           sb.append("<option value=\"" + index + "\">" + HTML.encodeTags(header));
     508          String headerText = headers != null ? HTML.encodeTags(headers.get(index)) : "";
     509          String exampleText = HTML.encodeTags(firstDataLine.getString(index));
     510          %>
     511          <div class="menuitem interactable file-column auto-init"
     512            data-auto-init="preset-column-mapping" data-index="<%=index%>"
     513            title="<%=headerText%> – <%=exampleText%>"
     514            >
     515            <div><%=Integer.toString(index+1)%>: <%=headerText%></div>
     516            <div class="example"><%=exampleText%></div>
     517          </div>
     518          <%
    449519          index++;
    450520        }
    451       }
    452       else
    453       {
    454         int maxDataColumns = Values.getInt(request.getParameter("maxDataColumns"), -1);
    455         while (index < maxDataColumns)
    456         {
    457           sb.append("<option value=\"" + index + "\">" + index);
    458           index++;
    459         }
    460       }
    461       String mappings = sb.toString();
     521        %>
     522      </div>
     523      <%
    462524      String[] mappingParameters = request.getParameter("mappingParameterNames").split(",");
    463525      if (headers != null)
     
    568630               
    569631                <tbl:cell column="columns">
    570                   <select name="list.<%=name%>" class="auto-init"
    571                     data-auto-init="column-mapping-preset" data-mapping="<%=name%>">
    572                   <option value="">
    573                   <%=mappings%>
    574                   </select>
     632                  <base:button
     633                    title="- select -" image="mini_scroll_down.png"
     634                    subclass="icon-to-right auto-init" style="font-style: italic;"
     635                    data-auto-init="column-mapping-preset-menu"
     636                    data-mapping="<%=name%>"
     637                  />
    575638                </tbl:cell>
    576639             
  • branches/3.19-stable/www/include/styles/main.css

    r8065 r8132  
    283283{
    284284  padding-right: 2px;
     285}
     286
     287.basicbutton.icon-to-right > img
     288{
     289  float: right;
     290  padding-left: 2px;
    285291}
    286292
Note: See TracChangeset for help on using the changeset viewer.