diff --git a/codepot/src/codepot/controllers/graph.php b/codepot/src/codepot/controllers/graph.php index dccc4ab6..5ef91409 100644 --- a/codepot/src/codepot/controllers/graph.php +++ b/codepot/src/codepot/controllers/graph.php @@ -164,7 +164,7 @@ class Graph extends CI_Controller if ($path == '.') $path = ''; /* treat a period specially */ $path = $this->_normalize_path ($path); - $cloc = $cloc = $this->subversion->clocRevByFile($projectid, $path, $rev); + $cloc = $this->subversion->clocRevByFile($projectid, $path, $rev); print codepot_json_encode($cloc); } diff --git a/codepot/src/codepot/models/subversionmodel.php b/codepot/src/codepot/models/subversionmodel.php index 9a2bab31..159bce36 100644 --- a/codepot/src/codepot/models/subversionmodel.php +++ b/codepot/src/codepot/models/subversionmodel.php @@ -1486,24 +1486,36 @@ class SubversionModel extends CodeRepoModel if ($info === FALSE || $info === NULL || count($info) != 1) return FALSE; } - if ($info[0]['kind'] == SVN_NODE_FILE) return FALSE; - - // pass __FILE__ as the first argument so that tempnam creates a name - // in the system directory. __FILE__ can never be a valid directory. - $tfname = @tempnam(__FILE__, 'codepot-cloc-rev-'); - if ($tfname === FALSE) return FALSE; - - $actual_tfname = $tfname . '.d'; - codepot_delete_files ($actual_tfname, TRUE); // delete the directory in case it exists - - if (@svn_checkout ($workurl, $actual_tfname, $rev, 0) === FALSE) + if ($info[0]['kind'] == SVN_NODE_FILE) { - codepot_delete_files ($actual_tfname, TRUE); - @unlink ($tfname); - return FALSE; + $file = $this->getFile($projectid, $path, $rev); + if ($file === FALSE) return FALSE; + + $tfname = @tempnam(__FILE__, 'codepot-cloc-rev-'); + if ($tfname === FALSE) return FALSE; + + $actual_tfname = $tfname . '.' . pathinfo ($file['name'], PATHINFO_EXTENSION); + @file_put_contents ($actual_tfname, $file['content']); + } + else + { + // pass __FILE__ as the first argument so that tempnam creates a name + // in the system directory. __FILE__ can never be a valid directory. + $tfname = @tempnam(__FILE__, 'codepot-cloc-rev-'); + if ($tfname === FALSE) return FALSE; + + $actual_tfname = $tfname . '.d'; + codepot_delete_files ($actual_tfname, TRUE); // delete the directory in case it exists + + if (@svn_checkout ($workurl, $actual_tfname, $rev, 0) === FALSE) + { + codepot_delete_files ($actual_tfname, TRUE); + @unlink ($tfname); + return FALSE; + } } - $cloc_cmd = sprintf ('%s --quiet --csv --csv-delimiter=":" %s', CODEPOT_CLOC_COMMAND_PATH, $actual_tfname); + $cloc_cmd = sprintf('%s --quiet --csv --csv-delimiter=":" %s', CODEPOT_CLOC_COMMAND_PATH, $actual_tfname); $cloc = @popen ($cloc_cmd, 'r'); if ($cloc === FALSE) { diff --git a/codepot/src/codepot/views/code_file.php b/codepot/src/codepot/views/code_file.php index f6773ee8..461cd245 100644 --- a/codepot/src/codepot/views/code_file.php +++ b/codepot/src/codepot/views/code_file.php @@ -102,6 +102,13 @@ + + + + + + + @@ -479,9 +486,9 @@ var RevGraphApp = (function () edges: { smooth: { - //type: 'cubicBezier', - //forceDirection: 'horizontal', // 'vertical', - roundness: 0.4 + //type: 'cubicBezier', + //forceDirection: 'horizontal', // 'vertical', + roundness: 0.4 } }, physics: { @@ -550,6 +557,81 @@ var RevGraphApp = (function () })(); +var LocGraphApp = (function () +{ + function App (top_container, graph_container, graph_msgdiv, graph_canvas, graph_button, graph_spin, graph_url, graph_title) + { + GraphApp.call (this, top_container, graph_container, graph_msgdiv, graph_canvas, graph_button, graph_spin, graph_url, graph_title); + this.plot_dataset = null; + this.plot_options = null; + return this; + } + App.prototype = Object.create(GraphApp.prototype); + App.prototype.constructor = App; + App.prototype.renderGraph = function (data) + { + if (!data.hasOwnProperty('SUM')) + { + this.showMessage ('No data to show'); + return; + } + if (data.SUM.length != 4) + { + this.showMessage ('Invalid data to show'); + return; + } + + this.clearMessage (); + + var pd = []; + // files, blank, comment, code + // files is always 1. + for (var i = 1; i < data.SUM.length ; i++) + { + pd[i - 1] = [ i - 1, data.SUM[i] ]; + } + this.plot_dataset = [ + { label: 'LOC', data: pd } + ] + + var ticks = [ + [0, "lang->line('Blank')?>(" + data.SUM[1] + ")"], + [1, "lang->line('Comment')?>(" + data.SUM[2] + "])"], + [2, "lang->line('Code')?>(" + data.SUM[3] + ")"] + ]; + + this.plot_options = { + series: { + bars: { show: true } + }, + bars: { + align: "center", + barWidth: 0.8 + }, + xaxis: { + axisLabel: "", + axisLabelUseCanvas: true, + ticks: ticks + }, + yaxis: { + } + }; + } + + App.prototype.resizeGraph = function () + { + if (this.plot_dataset != null) + { + this.graph_canvas.width (this.graph_container.width() - 5); + this.graph_canvas.height (this.graph_container.height() - 10); + $.plot(this.graph_canvas, this.plot_dataset, this.plot_options); + } + } + + return App; +})(); + + $(function () { $('#code_file_metadata').accordion({ @@ -558,24 +640,20 @@ $(function () { }); - $("#code_file_loc_info").hide(); - btn = $("#code_file_loc_button").button().click (function () { - if ($("#code_file_loc_info").is(":visible")) - { - $("#code_file_loc_info").hide("blind",{},200); - } - else - { - $("#code_file_loc_info").show("blind",{},200); - } - - return false; // prevent the default behavior - }); - - $("#code_file_edit_button").button(); - + var loc_graph_app = new LocGraphApp ( + $(window), + $("#code_file_loc_graph_container"), + $("#code_file_loc_graph_error"), + $("#code_file_loc_graph"), + $("#code_file_loc_graph_button"), + $("#code_file_loc_graph_spin"), + codepot_merge_path ("", "/graph/enjson_loc_by_lang/id; ?>/"), + "LOC" + ); + loc_graph_app.initWidgets (); + var rev_graph_app = new RevGraphApp ( $(window), @@ -815,9 +893,11 @@ $this->load->view ( if ((isset($login['id']) && $login['id'] != '') ) { print ' '; - print anchor ("code/edit/{$project->id}/{$hex_headpath}{$revreq}", $this->lang->line('Edit'), 'id="code_file_edit_button"'); + print anchor("code/edit/{$project->id}/{$hex_headpath}{$revreq}", $this->lang->line('Edit'), 'id="code_file_edit_button"'); } - print anchor ("#", "LOC", "id=code_file_loc_button"); + /*print anchor ("#", "LOC", "id=code_file_loc_button");*/ + print ''; + print 'LOC'; } ?> @@ -905,6 +985,11 @@ $this->load->view (
+ +
+
+
+
@@ -989,16 +1074,6 @@ if ($login['settings'] != NULL && } print ''; - - if (!$is_special_stream) - { - print '
'; - print '
LOC
'; - /* TODO: show this if it's enabled in the user settings */ - $graph_url = codepot_merge_path (site_url(), "/code/graph/cloc-file/{$project->id}/{$hex_headpath}{$revreq}"); - print ""; - print '
'; - } } if ($is_wiki_file) diff --git a/codepot/src/codepot/views/code_folder.php b/codepot/src/codepot/views/code_folder.php index 47c554ed..5b0da6f7 100644 --- a/codepot/src/codepot/views/code_folder.php +++ b/codepot/src/codepot/views/code_folder.php @@ -490,7 +490,7 @@ var LocFileApp = (function () function App (top_container, graph_container, graph_msgdiv, graph_canvas, graph_button, graph_spin, graph_url, graph_title) { GraphApp.call (this, top_container, graph_container, graph_msgdiv, graph_canvas, graph_button, graph_spin, graph_url, graph_title); - this.cf = null; + this.fc = null; this.loc_data = null; var self = this;