package de.kopis.timeclicker.pages;

import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.head.JavaScriptContentHeaderItem;
import org.apache.wicket.request.mapper.parameter.PageParameters;

public class DashboardPage extends SecuredPage {
    public DashboardPage(PageParameters parameters) {
        super("Dashboard", parameters);
    }

    @Override
    protected void onInitialize() {
        super.onInitialize();
    }

    @Override
    public void renderHead(IHeaderResponse response) {
        super.renderHead(response);
        final String highcharts = "$(function () {\n" +
                "            $.getJSON('/startchart.json', callback);\n" +
                "});\n\n" +
                "function round(number, precision) {\n" +
                "    var factor = Math.pow(10, precision);\n" +
                "    var tempNumber = number * factor;\n" +
                "    var roundedTempNumber = Math.round(tempNumber);\n" +
                "    return roundedTempNumber / factor;\n" +
                "};" +
                "function callback(data) {\n" +
                "           Highcharts.chart('container', {\n" +
                "                    chart: {\n" +
                "                        type: 'arearange',\n" +
                "                        zoomType: 'x'\n" +
                "                    },\n" +
                "                    title: {\n" +
                "                        text: 'Work'\n" +
                "                    },\n" +
                "                    xAxis: {\n" +
                "                        type: 'datetime'\n," +
                "                        tickInterval: 24 * 3600 * 1000,\n" +
                "                    },\n" +
                "                    yAxis: {\n" +
                "                        type: 'time'\n," +
                "                        title: 'Working Hours'\n" +
                "                    },\n" +
                "                    legend: {\n" +
                "                        enabled: false\n" +
                "                    },\n" +
                "                    series: [{\n" +
                "                        name: 'Duration',\n" +
                "                        data: data\n" +
                "                    }]\n" +
                "\n" +
                "         });\n" +
                "};\n";
        response.render(JavaScriptContentHeaderItem.forScript(highcharts, "highcharts"));
    }
}

@@ -722,348 +722,8 @@
 %22 +%0A
-                %22function round(number, precision) %7B%5Cn%22 +%0A                %22    var factor = Math.pow(10, precision);%5Cn%22 +%0A                %22    var tempNumber = number * factor;%5Cn%22 +%0A                %22    var roundedTempNumber = Math.round(tempNumber);%5Cn%22 +%0A                %22    return roundedTempNumber / factor;%5Cn%22 +%0A                %22%7D;%22 +%0A
     
@@ -1621,16 +1621,17 @@
 Hours'%5Cn
+,
 %22 +%0A    
@@ -1663,32 +1663,531 @@
         %7D,%5Cn%22 +%0A
+                %22                    tooltip: %7B%5Cn%22 +%0A                %22                        formatter: function () %7B%5Cn%22 +%0A                %22                             var hours = Math.floor(this.y);%5Cn%22 +%0A                %22                             var minutes = ('000' + Math.floor((this.y - hours) * 60)).slice(-2);%5Cn%22 +%0A                %22                             return hours + ':' + minutes;%5Cn%22 +%0A                %22                        %7D%5Cn%22 +%0A                %22                    %7D,%22 +%0A
                 

FIX Display of time as HH:MM on chart tooltip