Changeset 1491


Ignore:
Timestamp:
Dec 2, 2011, 8:30:26 AM (10 years ago)
Author:
Martin Svensson
Message:

References #339 The generation of Week-view is now available.
The report needs to have some kind of limitation on the number of column so it not causes an overflow of the GUI.

Location:
extensions/net.sf.basedb.reggie/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/trunk/resources/reggie.js

    r1389 r1491  
    177177  return fullTimeString;
    178178}
     179
     180function getWeekByDate(currentDate)
     181{
     182  var weeknum; 
     183  var newYear = new Date(currentDate.getFullYear(),0,1);
     184  var numdays = Math.ceil((currentDate.getTime() - newYear.getTime()) / (1000 * 60 * 60 * 24));
     185  var day = newYear.getDay()-1;
     186  day = day>=0 ? day : day+7;
     187  var offset = day < 3 ? day : day-7;
     188 
     189  if ( (numdays+offset) > 0 )
     190  {
     191    weeknum = Math.ceil((numdays + offset) / 7);
     192  }
     193  else
     194  {
     195    // Current week belongs to the year before.
     196    weeknum = getWeekByDate(new Date(currentDate.getFullYear()-1, 11, 31));
     197  }
     198     
     199  // If the last day of the year is on a monday or thuesday.
     200  if (weeknum > 52)
     201  {
     202    var nYear = new Date(newYear.getFullYear()+1, 0, 1);
     203    var nday = nYear.getDay()-1;
     204    nday = nday >=0 ? nday : nday+7;
     205    weeknum = nday < 4 ? 1 : 53;
     206  }
     207 
     208   
     209 
     210  return weeknum;
     211}
  • extensions/net.sf.basedb.reggie/trunk/resources/samplereportgenerator.jsp

    r1472 r1491  
    2727  <script language="JavaScript">
    2828  var currentStep = 1;
    29   var debug = false;
     29  var debug = true;
     30  var maxCols = 30;
    3031  var sitesCombined;
    3132  var numCols;
     
    9899      {
    99100        var numYears = latestDate.getFullYear() - firstDate.getFullYear();
    100         numCols = (12*(numYears-1)) + (12-parseInt(fdString.substr(4,2)) + 1) + parseInt(ldString.substr(4,2));
     101        numCols = (12*(numYears-1)) + (12-parseInt(firstDate.getMonth())) + parseInt(ldString.substr(4,2));               
    101102      }
    102103      else
    103       {
    104        
     104      {       
     105        var diffTime = latestDate.getTime() - firstDate.getTime();
     106        var milliSecPerWeek = 1000*60*60*24*7;
     107        numCols = Math.ceil(diffTime/milliSecPerWeek)+1;       
    105108      }
    106109      sitesCombined = Array(numCols);
     
    131134      columnHeaderRow.appendChild(startDateHeader);     
    132135      if (columnView == 'MONTH') addMonthColumnHeaders(columnHeaderRow, firstDate, latestDate);
    133 //      else addWeekColumnHeaders(columnHeaderRow, firstDate,latestDate);
     136      else addWeekColumnHeaders(columnHeaderRow, firstDate,latestDate);
    134137      columnHeaderRow.appendChild(getTableCellElement('Grand\ntotal', 'reportsubheader'));
    135138
     
    148151      var gt = 0;
    149152      for (key in sitesCombined)
    150       {       
     153      {
    151154        sitesCombinedRow.appendChild(getTableCellElement(sitesCombined[key],'colsummary'));
    152155        gt += sitesCombined[key];
     
    162165  }
    163166 
    164   function addWeekcolumnHeaders(columnHeaderRow, firstDate, latestDate)
    165   {
    166     var currentDate = firstDate;
     167  function addWeekColumnHeaders(columnHeaderRow, firstDate, latestDate)
     168  {
     169    var currentDate = firstDate;   
     170    for (var i=0;i<numCols;i++)
     171    {
     172      var weekNum = getWeekByDate(currentDate);
     173      var columnText = weekNum;
     174      if (weekNum < 10) columnText = '0'+columnText;
     175      columnHeaderRow.appendChild(getTableCellElement(columnText, 'reportsubheader'));
     176      currentDate.setDate(currentDate.getDate()+7);
     177    }
    167178  }
    168179 
     
    217228          colspan = parseInt(latestDate.getMonth()+1);
    218229        else
    219           colspan = 12;
    220         subHeaderRowYear.appendChild(getTableCellElement(currentYear, 'reportsubheader', colspan));
     230          colspan = 12;       
    221231      }
    222232      else
    223       {
    224        
     233      {       
     234        if (currentYear == firstDate.getFullYear())
     235        {
     236          var startWeek = getWeekByDate(firstDate);
     237          var lastDay = new Date(firstDate.getFullYear(), 11, 31);
     238          var endWeek = getWeekByDate(lastDay);
     239          if (endWeek == 1) endWeek = getWeekByDate(lastDay.setDate(lastDay.getDate()-7));
     240          colspan = endWeek - startWeek +1;
     241        }
     242        else if (currentYear == latestDate.getFullYear())
     243        {
     244          var endWeek = getWeekByDate(latestDate);
     245          colspan = endWeek;
     246        }
     247        else
     248        {
     249          var dateInLastWeek = new Date(currentYear, 11, 31);
     250          var endWeek = getWeekByDate(dateInLastWeek);
     251          if (endWeek == 1) endWeek = getWeekByDate(dateInLastWeek.setDate(dateInLastWeek.getDate()-7));
     252          colspan = endWeek;
     253        }
    225254      }
     255      subHeaderRowYear.appendChild(getTableCellElement(currentYear, 'reportsubheader', colspan));
    226256    }while(!(++currentYear>latestDate.getFullYear()));
    227257  }
     
    246276      var site = sites[namePrefix];
    247277      var siteName = site.name;       
    248       var siteStartDate = site.startdate;
     278      var year = site.startdate.substr(0,4);
     279      var month = site.startdate.substr(5,2);
     280      var date = site.startdate.substr(8,2);     
     281      var siteStartDate = new Date(year, month-1, date);
    249282     
    250283      var siteData = report[namePrefix];
     
    252285      var tableCol = getTableCellElement(siteName, 'rowtitle');
    253286      tableRow.appendChild(tableCol);
    254       tableRow.appendChild(getTableCellElement(siteStartDate, 'reportdata'));
    255      
    256       var yearIndex = firstDate.getFullYear();
    257       var monthIndex = firstDate.getMonth()+1;
     287      tableRow.appendChild(getTableCellElement(year+'-'+(month)+'-'+date, 'reportdata'));
     288     
     289      var cDate = new Date(firstDate.getFullYear(), firstDate.getMonth(), firstDate.getDate());     
    258290      var grandTotal = 0;
    259       for (var i=0;i<numCols;i++)
    260       {         
    261         var dataCol = getTableCellElement('0', 'reportdata');       
     291      do
     292      {
     293        var dataCol = getTableCellElement('', 'reportdata');
     294        if (!(cDate < siteStartDate)) dataCol = getTableCellElement('0','reportdata');
     295        var yearIndex = cDate.getFullYear();       
     296        var keyIndex;       
    262297        if (siteData != null)
    263         {
    264           var rowfill = monthIndex < 10 ? '0' : '';
    265           var keyIndex = null;
    266           if (viewType == 'MONTH') keyIndex = yearIndex + rowfill + monthIndex;           
     298        {                   
     299          if (viewType == 'MONTH')
     300          {
     301            var monthIndex = cDate.getMonth()+1;
     302            var rowfill = monthIndex < 10 ? '0' : '';
     303            keyIndex = yearIndex + rowfill + monthIndex;           
     304          }
     305          else
     306          {
     307            var weekIndex = getWeekByDate(cDate);
     308            var rowfill = weekIndex < 10 ? '0' : '';
     309            keyIndex = yearIndex + rowfill + weekIndex;
     310          }
    267311          var data = siteData[keyIndex];
    268           if (data == null) data = 0;
    269           dataCol = getTableCellElement(data, 'reportdata');
     312          if (data != null)
     313          {
     314            dataCol = getTableCellElement(data, 'reportdata');           
     315          }         
     316          else
     317            data = 0;
    270318          if (sitesCombined[keyIndex] != null)
    271319            sitesCombined[keyIndex] += parseInt(data);
     
    273321            sitesCombined[keyIndex] = parseInt(data);
    274322          grandTotal += data;
    275           monthIndex++;
    276           if (monthIndex > 12)
    277           {
    278             yearIndex++;
    279             monthIndex = 1;
    280           }
    281323        }
    282324        tableRow.appendChild(dataCol);
    283       }
     325       
     326        var isLastCol;
     327        if (viewType == 'MONTH')
     328        {
     329          cDate.setMonth(cDate.getMonth()+1);         
     330          isLastCol = cDate > latestDate;
     331        }
     332        else
     333        {
     334          cDate.setDate(cDate.getDate()+7);
     335          isLastCol = getWeekByDate(cDate) > getWeekByDate(latestDate);
     336          isLastCol = isLastCol && (cDate > latestDate);
     337         
     338        }       
     339      }while (!isLastCol)     
    284340      tableRow.appendChild(getTableCellElement(grandTotal, 'rowsummary'));
    285341      reportTable.appendChild(tableRow);
     
    382438              <td class="prompt">View</td>
    383439              <td class="input">
    384                 per Month<input type="radio" value="MONTH" checked onChange="viewOnChange()" name="view"/>&nbsp;
    385                 per Week<input type="radio" value="WEEK" onChange="viewOnChange()" name="view" />
     440                per Month<input type="radio" value="MONTH" checked name="view"/>&nbsp;
     441                per Week<input type="radio" value="WEEK" name="view" />
    386442              </td>
    387443              <td class="status" id="displayInterval.status"></td>
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/SampleReportServlet.java

    r1472 r1491  
    33import java.io.IOException;
    44import java.text.SimpleDateFormat;
     5import java.util.Calendar;
    56import java.util.Date;
    67import java.util.HashMap;
     
    9293            else
    9394            {
    94               DateToStringConverter date2WeekStringConverter = new DateToStringConverter(new SimpleDateFormat("yyyyw"));
     95              SimpleDateFormat sdf = new SimpleDateFormat("yyyyw");
     96              Calendar c = Calendar.getInstance();
     97              c.setFirstDayOfWeek(Calendar.MONDAY);
     98              c.setMinimalDaysInFirstWeek(5);
     99              sdf.setCalendar(c);
     100              DateToStringConverter date2WeekStringConverter = new DateToStringConverter(sdf);
    95101              currentPeriod = date2WeekStringConverter.convert(creationDate).substring(0,6);           
    96102            }         
     
    118124          }         
    119125        }
    120         jsonReport.put("sitesCombined", jsonSitesCombined);
    121126        jsonReport.put("firstDate", date2StringConverter.convert(firstDate));
    122127        jsonReport.put("latestDate", date2StringConverter.convert(latestDate));
Note: See TracChangeset for help on using the changeset viewer.