Commit 9550bbbc authored by Laura Schlimmer's avatar Laura Schlimmer
Browse files

render single metric view

parent 104158c1
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ build:
	      fnordmetric-webui-sqleditorview.js \
	      fnordmetric-webui-visualeditorview.js \
	      fnordmetric-webui-queryresultview.js \
	      fnordmetric-webui-singlemetricview.js \
	      codemirror.js \
	) > fnordmetric-webui.js

+23 −26
Original line number Diff line number Diff line
@@ -18,38 +18,38 @@ if (FnordMetric.views === undefined) {

FnordMetric.views.MetricList = function() {
  var actions = {
    "search" : FnordMetric.util.searchMetricList,
    "metric" : FnordMetric.util.getSingleMetric
    "search" : {
      "render" : loadMetricList,
      "data" :FnordMetric.util.searchMetricList
    },
    "metric" : {
      "render" : FnordMetric.util.singleMetricView().render
    }
  }



  function render(viewport, url, query_params) {
    if (query_params != undefined) {
      actions[query_params.name].render(viewport, query_params);
      return;
    }
    loadMetricList(viewport, query_params);
  };


  function onRowClick(e) {
    e.preventDefault();
    var metric = this.firstChild.id;
  function onRowClick() {
    //FIXME
    FnordMetric.util.setURLQueryString(
      "metric", metric, false);
    location.reload();
    console.log("on row click");
    var viewport = document.body.querySelector(".viewport");
    var params = {
      "name" : "metric",
      "value" : this.firstChild.id
    };
    FnordMetric.util.singleMetricView().render(
      viewport, params);
  };

  function renderMetricButton(elem, metric) {
    var button = FnordMetric.createButton(
      "#", undefined, "Open in Query Editor");
    elem.appendChild(button);

    button.onclick = function(e) {
      e.preventDefault();
      var query = 
        "SELECT * FROM " + metric[0].key;
      FnordMetric.util.setFragmentURL(
        "query_playground", "sql_query", query, true);
      location.reload();
    }
  }
  
  function renderMetricList(viewport, metrics, action) {
    viewport.innerHTML = "";
@@ -65,9 +65,6 @@ FnordMetric.views.MetricList = function() {
      return;
    }

    if (action == "metric") {
      renderMetricButton(viewport, metrics);
    }

    var table_view = FnordMetric.util.TableView([
        "Metric",
+50 −0
Original line number Diff line number Diff line
/**
 * This file is part of the "FnordMetric" project
 *   Copyright (c) 2014 Laura Schlimmer
 *   Copyright (c) 2014 Paul Asmuth, Google Inc.
 *
 * FnordMetric is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License v3.0. You should have received a
 * copy of the GNU General Public License along with this program. If not, see
 * <http://www.gnu.org/licenses/>.
 */
if (FnordMetric === undefined) {
  FnordMetric = {};
}

if (FnordMetric.views === undefined) {
  FnordMetric.views = {};
}


FnordMetric.util.singleMetricView = function() {
  function render(elem, query_params) {
    FnordMetric.util.setURLQueryString(
      query_params.name, query_params.value, false, true);
   
    elem.innerHTML = "";
    var header = document.createElement("h1");
    header.className = "metric";
    header.innerHTML = query_params.value;

    var button = FnordMetric.createButton(
      "#", undefined, "Open in Query Editor");

    elem.appendChild(header);
    elem.appendChild(button);

    button.onclick = function(e) {
      e.preventDefault();
      var query = 
        "SELECT * FROM " + query_params.value;
      FnordMetric.util.setFragmentURL(
        "query_playground", "sql_query", query, true);
      location.reload();
    }

  }

  return {
    "render" : render
  }
}
+7 −4
Original line number Diff line number Diff line
@@ -125,16 +125,19 @@ FnordMetric.util.setURLQueryString = function(name, value, encode) {
  window.location.hash = hash;
}

FnordMetric.util.setFragmentURL = function(hash, name, value, encode) {
  console.log(window.location.pathname);
FnordMetric.util.setFragmentURL = function(hash, name, value, encode, push_state) {
  var path = window.location.pathname;
  var value = value;
  if (encode) {
  if (encode == true) {
    value = encodeURIComponent(value);
  }
  var hash = 
    path + "#" + hash + "?" + name + "=" + value;
  window.location = hash;
  console.log("push state: " + push_state);
  if (push_state == true) {
    window.history.pushState({url: hash}, "#", hash);
  }
}

FnordMetric.util.openPopup = function(elem, text) {
+3 −0
Original line number Diff line number Diff line
@@ -571,6 +571,9 @@ ul.dropdown li:hover {
  background-color: #d7e4f2;
}

h1.metric {
  margin-top: 80px;
}

table.metric_list {
  width: 100%;