Permalink
Browse files

Added requirejs. Split main.js to separated requirejs modules

  • Loading branch information...
1 parent 3629030 commit 7f6c16ef879f76ca0928136929130badba1a1a47 @Lispython Lispython committed Apr 1, 2013
View
@@ -28,3 +28,4 @@ dist/*
_build/*
build/*
docs/build/*
+nodeenv.py
Submodule buildenv updated 1 files
+4 −2 buildenv.sh

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -0,0 +1,102 @@
+// Main index file
+
+
+require.config({
+ waitSeconds: 15,
+ "baseUrl": "/static/",
+ "paths": {
+ "app": "./app",
+ "jquery": 'js/jquery',
+ "domReady": 'js/domReady',
+ "underscore": 'js/underscore-min',
+ "swig": 'js/swig.pack.min',
+ "bootstrap": "vendor/bootstrap/js/bootstrap",
+ "d3": "js/d3.v2",
+ "rickshaw": "js/rickshaw",
+ "bootstrap-datepicker": "js/bootstrap-datepicker",
+ "bootstrap-datepicker.ru": "js/locales/bootstrap-datepicker.ru",
+ "jquery.tablesorter": "js/jquery.tablesorter",
+ "jquery.tablesorter.widgets": "js/jquery.tablesorter.widgets",
+ "select2": "vendor/select2/select2.min"
+ },
+ "shim": {
+ "jquery": {
+ "exports": '$'
+ },
+ "underscore":{
+ "exports": '_'
+ },
+ 'bootstrap': {
+ "deps": 'jquery',
+ "exports": "jquery"
+ },
+ "d3": {
+ "exports": 'd3'
+ },
+ "jquery.bootstrap": {
+ "deps": ['jquery'],
+ "exports": 'jquery'
+ },
+ "swig": {
+ "deps": ['underscore'],
+ "exports": 'swig'
+ },
+ "select2": {
+ "exports" : 'jquery',
+ "exports": "jquery"
+ },
+ "rickshaw": {
+ "deps": ["d3"],
+ "exports": "rickshaw"
+ },
+ "bootstrap-datepicker": {
+ "deps": ["jquery", "bootstrap"],
+ "exports": "jQuery.fn.datepicker"
+ },
+ "bootstrap-datepicker.ru": {
+ "deps": ["jquery", "bootstrap-datepicker", "bootstrap"],
+ "exports": "jQuery.fn.datepicker"
+ },
+ "jquery.tablesorter": {
+ "deps": ["jquery"],
+ "exports": "jQuery.tablesorter"
+ },
+ "jquery.tablesorter.widgets": {
+ "deps": ["jquery", "jquery.tablesorter"],
+ "exports": "jQuery.tablesorter.widgets"
+ }
+ },
+
+});
+
+require(["jquery", "js/gottwall", "js/inits/tablesorter", "domReady"], function($, GottWall) {
+ (function($) {
+ $.log = function (obj, params) {
+ if ((typeof(console) != 'undefined') && (typeof(console.log) == 'function'))
+ {
+ console.log(obj, (params)?params:'');
+ };
+ return this;
+ };
+ $.fn.debug = function () {
+ return this.each(function(){
+ $.log(this);
+ });
+ };
+ })(jQuery);
+
+
+ console.log("Application entry point");
+
+
+ var self = this;
+ $(function() {
+ var global_metrics = {};
+ var activate_metrics = {};
+ var chart = null;
+
+ console.log();
+
+ self.gottwall = new GottWall(true);
+ });
+});
@@ -0,0 +1,93 @@
+define(["jquery", "underscore", "js/bars/base"], function($, _, BaseBar){
+ var Bar = BaseBar.extend({
+
+ init: function(gottwall, chart, id, metric_name, filter_name, filter_value){
+ this._super(gottwall, chart, id, metric_name, filter_name, filter_value);
+
+ //this.bar = this.chart.node.find("#bar-"+this.id);
+
+ this.metric = null;
+ //this.render_selectors();
+ },
+ setup: function(){
+ //this.node = this.chart.node.find("#bar-"+this.id);
+ this.add_bindings();
+ },
+ get_metric: function(){
+ if(this.metric_name){
+ var metric = new Metric(this.gottwall, this.metric_name,
+ this.filter_name, this.filter_value);
+ return metric;
+ }
+ return null;
+ },
+ add_bindings: function(){
+ var self = this;
+ this.node.on('click', '.delete-bar', function(){
+ self.remove();
+ return false;
+ });
+ },
+ remove: function(){
+ this.chart.remove_bar(this);
+ this.chart.render_chart_graph();
+ },
+ setup_current_filter: function(){
+ var self = this;
+
+ var filter_current = "Фильтр";
+ if(self.filter_name && self.filter_value){
+ filter_current = self.filter_name+":"+self.filter_value;
+ }
+
+ this.node.find('.filters-selector .current').text(filter_current);
+ },
+ setup_current_metric: function(){
+ console.log("Setup current metric");
+ var self = this;
+ var metric_current = "Показатель";
+
+ if(self.metric_name) {
+ metric_current = self.metric_name;
+ }
+
+ this.node.find('.metrics-selector .current').text(metric_current);
+ self.render_filters(self.metric_name,
+ this.gottwall.metrics[this.gottwall.current_project][self.metric_name]);
+ self.setup_current_filter();
+ },
+ render_filters: function(metric_name, filters){
+ console.log("Render filters");
+ var self = this;
+ var template = swig.compile($("#filters-selector-template").text());
+
+ if(!this.node){
+ this.render();
+ }
+ this.node.find('.filters-selector .dropdown-menu').html($(template({
+ "filters": _.map(filters, function(value, key){
+ return [key, value];
+ })
+ })));
+
+ $(this.node.find('.filters-selector li select')).select2({
+ placeholder: "Select a State",
+ allowClear: true
+ });
+
+ this.node.on("change", ".filters-selector select", function(e){
+ var selected = $(this);
+ self.filter_value = selected.val();
+ self.filter_name = selected.attr("placeholder");
+
+ self.node.find('.filters-selector .current').text(self.filter_name+":"+self.filter_value);
+ self.node.find('.filters-selector').removeClass('open');
+ self.chart.render_chart_graph();
+ self.gottwall.save_to_storage();
+ return false;
+ });
+ },
+ });
+
+ return Bar;
+});
@@ -0,0 +1,67 @@
+define(["jquery", "underscore", "js/class"], function($, _, Class){
+
+ var BaseBar = Class.extend({
+ init: function(gottwall, chart, id, metric_name, filter_name, filter_value){
+ this.id = id || GUID();
+ this.gottwall = gottwall;
+ this.chart = chart;
+ this.metric_name = metric_name;
+ this.filter_name = filter_name;
+ this.filter_value = filter_value;
+
+ // DOM object node
+ this.node = null;
+ },
+ add_bindings: function(){
+ console.log("Add bindings to BaseBar");
+ },
+ render: function(){
+ var template = swig.compile($("#selectors-bar-template").text());
+ this.node = $(template({"id": this.id}));
+ return this.node;
+ },
+ to_dict: function(){
+ return {
+ "metric_name": this.metric_name,
+ "filter_name": this.filter_name,
+ "filter_value": this.filter_value,
+ "id": this.id};
+ },
+ render_selectors: function(){
+ this.render_metrics(this.gottwall.metrics[this.gottwall.current_project]);
+ },
+ render_metrics: function(metrics){
+ $.log("Render metrics selectors");
+
+ var self = this;
+ var template = swig.compile($("#metrics-selector-template").text());
+
+ if(!this.node ){
+ this.render();
+ }
+ this.node.find('.metrics-selector .dropdown-menu').html(
+ $(template({
+ "metrics": _.map(metrics, function(value, key){
+ return key;})
+ })));
+
+ self.setup_current_metric();
+
+ this.node.on('click', '.metrics-selector .dropdown-menu li a', function(){
+ var metric = $(this);
+ self.metric_name = metric.data('name');
+
+ self.filter_name = null;
+ self.filter_value = null;
+ self.render_filters(this.metric_name, metrics[self.metric_name]);
+ metric.parent().parent().parent().removeClass('open');
+ metric.parent().parent().parent().find('.current').text(self.metric_name);
+ self.setup_current_filter();
+ self.chart.render_chart_graph();
+ self.gottwall.save_to_storage();
+ return false;
+ });
+ },
+ });
+ return BaseBar;
+});
@@ -0,0 +1,77 @@
+define(["jquery", "underscore", "js/bars/base"], function($, _, BaseBar){
+
+ var TableBar = BaseBar.extend({
+ init: function(gottwall, chart, id, metric_name, filter_name){
+ this._super(gottwall, chart, id, metric_name, filter_name);
+
+ //this.bar = this.chart.node.find("#bar-"+this.id);
+
+ this.metric = null; //this.render_selectors();
+ },
+ render: function(){
+ var template = swig.compile($("#selectors-table-bar-template").text());
+ this.node = $(template({"id": this.id}));
+ return this.node;
+ },
+ setup_current_metric: function(){
+ console.log("Setup current metric for table");
+ var self = this;
+ var metric_current = "Показатель";
+
+ if(self.metric_name) {
+ metric_current = self.metric_name;
+ }
+ self.render_filters(self.metric_name,
+ this.gottwall.metrics[this.gottwall.current_project][self.metric_name]);
+
+ this.node.find('.metrics-selector .current').text(metric_current);
+
+ self.setup_current_filter();
+ },
+ setup_current_filter: function(){
+ console.log("Setup current filter");
+ var self = this;
+
+ var filter_current = "Фильтр";
+ if(self.filter_name){
+ filter_current = self.filter_name;
+ }
+
+ this.node.find('.filters-selector .current').text(filter_current);
+ },
+ get_metric: function(){
+ if(this.metric_name){
+ var metric = new MetricSet(this.gottwall, this.metric_name,
+ this.filter_name, null);
+ return metric;
+ }
+ return null;
+ },
+ render_filters: function(metric_name, filters){
+ var self = this;
+ var template = swig.compile($("#table-filters-selector-template").text());
+
+ if(!this.node){
+ this.render();
+ }
+
+ this.node.find('.filters-selector .dropdown-menu').html(
+ $(template({
+ "filters": _.map(filters, function(value, key){
+ return key;
+ })})));
+
+ this.node.on('click', '.filters-selector li a', function(){
+ var button = $(this);
+ self.filter_name = button.attr('data-name');
+ self.node.find('.filters-selector .current').text(self.filter_name);
+ self.node.find('.filters-selector').removeClass('open');
+ self.chart.render_chart_graph();
+ self.gottwall.save_to_storage();
+ return false;
+ });
+ }
+ });
+
+ return TableBar;
+});
Oops, something went wrong.

0 comments on commit 7f6c16e

Please sign in to comment.