Commit 97161dee938fd00c8f2a0f696a9d0b7791e9ffaa

Authored by Alessandro Palmeira + João M. M. da Silva
Committed by Alessandro Palmeira
1 parent 253ca723

[Mezuro] Draft to show_repository view (javascripts pending)

plugins/mezuro/controllers/profile/mezuro_plugin_repository_controller.rb
... ... @@ -2,7 +2,7 @@ class MezuroPluginRepositoryController < MezuroPluginProfileController
2 2  
3 3 append_view_path File.join(File.dirname(__FILE__) + '/../../views')
4 4  
5   - def new_repository
  5 + def new
6 6 @project_content = profile.articles.find(params[:id])
7 7  
8 8 @repository_types = Kalibro::Repository.repository_types
... ... @@ -18,26 +18,39 @@ class MezuroPluginRepositoryController < MezuroPluginProfileController
18 18 end
19 19 end
20 20  
21   - def create_repository
  21 + def create
22 22 project_content = profile.articles.find(params[:id])
23   - project_content_name = project_content.name
24 23  
25 24 repository = Kalibro::Repository.new( params[:repository] )
26 25 repository.save(project_content.project_id)
27 26  
28 27 if( repository.errors.empty? )
29   - redirect_to "/#{profile.identifier}/#{project_content_name.downcase.gsub(/\s/, '-')}"
  28 + redirect_to "/#{profile.identifier}/#{project_content.name.downcase.gsub(/\s/, '-')}"
30 29 else
31 30 redirect_to_error_page repository.errors[0].message
32 31 end
33 32 end
34 33  
35   - def show_repository
  34 + def show
36 35 project_content = profile.articles.find(params[:id])
37 36 @project_name = project_content.name
38 37 @repository = project_content.repositories.select{ |repository| repository.id == params[:repository_id].to_s }.first
39 38 @configuration_name = Kalibro::Configuration.find(@repository.configuration_id).name
  39 + @processing = processing(@repository.id)
40 40 end
  41 +
  42 + def destroy
  43 + project_content = profile.articles.find(params[:id])
  44 + repository = project_content.repositories.select{ |repository| repository.id == params[:repository_id].to_s }.first
  45 + repository.destroy
  46 + if( repository.errors.empty? )
  47 + redirect_to "/#{profile.identifier}/#{project_content.name.downcase.gsub(/\s/, '-')}"
  48 + else
  49 + redirect_to_error_page repository.errors[0].message
  50 + end
  51 + end
  52 +
  53 + private
41 54  
42 55 def processing(repository_id)
43 56 begin
... ...
plugins/mezuro/lib/kalibro/repository.rb
... ... @@ -25,6 +25,7 @@ class Kalibro::Repository < Kalibro::Model
25 25 def save(project_id)
26 26 begin
27 27 self.id = self.class.request(:save_repository, {:repository => self.to_hash, :project_id => project_id})[:repository_id]
  28 + process_repository
28 29 true
29 30 rescue Exception => exception
30 31 add_error exception
... ...
plugins/mezuro/public/javascripts/processing.js 0 → 100644
... ... @@ -0,0 +1,135 @@
  1 +var processingTree = false;
  2 +var metricName;
  3 +jQuery(function (){
  4 + jQuery('.source-tree-link').live("click", reloadModule);
  5 + jQuery('[show-metric-history]').live("click", display_metric_history);
  6 + jQuery('[show-grade-history]').live("click", display_grade_history);
  7 + jQuery('#project_date_submit').live("click", reloadProjectWithDate);
  8 + showLoadingProcess(true);
  9 + showProcessing();
  10 +});
  11 +
  12 +function showProcessing() {
  13 + callAction('processing', 'processing_state', {}, showProcessingFor);
  14 +}
  15 +
  16 +function display_metric_history() {
  17 + var module_name = jQuery(this).attr('data-module-name');
  18 + var metric_name = jQuery(this).attr('show-metric-history');
  19 + toggle_mezuro("." + metric_name);
  20 + metricName = metric_name;
  21 + callAction('module', 'module_metrics_history', {module_id: module_id, module_result_id: module_result_id}, show_metrics);
  22 + return false;
  23 +}
  24 +
  25 +function display_grade_history() {
  26 + var module_name = jQuery(this).attr('data-module-name');
  27 + toggle_mezuro("#historical-grade");
  28 + callAction('module', 'module_grade_history', {module_name: module_name}, show_grades);
  29 + return false;
  30 +}
  31 +
  32 +function show_metrics(content) {
  33 + jQuery('#historical-' + metricName).html(content);
  34 +}
  35 +
  36 +function show_grades(content) {
  37 + jQuery('#historical-grade').html(content);
  38 +}
  39 +
  40 +function toggle_mezuro(element){
  41 + jQuery(element).toggle();
  42 + return false;
  43 +}
  44 +
  45 +function reloadModule(){
  46 + var results_root_id = jQuery(this).attr('results_root_id');
  47 + showLoadingProcess(false);
  48 + processingTree = true;
  49 + callAction('module_result', 'project_tree', {results_root_id: results_root_id }, showProjectTree);
  50 + callAction('module_result', 'module_result', {results_root_id: results_root_id}, showModuleResult);
  51 + return false;
  52 +}
  53 +
  54 +function reloadProjectWithDate(date){
  55 + reloadProject(date + "T00:00:00+00:00");
  56 + return false;
  57 +}
  58 +
  59 +function reloadProject(date){
  60 + showLoadingProcess(true);
  61 +
  62 + callAction('processing', 'processing', {date: date}, showProjectResult);
  63 + callAction('module_result', 'project_tree', {date: date}, showProjectTree);
  64 + callAction('module_result', 'module_result', {date: date}, showModuleResult);
  65 +}
  66 +
  67 +function showProcessingFor(state){
  68 + if (state == 'ERROR') {
  69 + jQuery('#project-state').html('<div style="color:Red">ERROR</div>');
  70 + callAction('processing', 'processing_error', {}, showProcessing);
  71 + }
  72 + else if (state == 'READY') {
  73 + jQuery('#msg-time').html('');
  74 + jQuery('#processing-state').html('<div style="color:Green">READY</div>');
  75 + callAction('processing', 'processing', {}, showProcessing);
  76 + callAction('module_result','project_tree', {}, showProjectTree);
  77 + var module_result_id = jQuery("#processing").attr('results_root_id');
  78 + callAction('module_result', 'module_result', {module_result_id: module_result_id}, showModuleResult);
  79 + }
  80 + else if (state.endsWith("ING")) {
  81 + jQuery('#processing-state').html('<div style="color:DarkGoldenRod">'+ state +'</div>');
  82 + jQuery('#msg-time').html("The project analysis may take long. <br/> You'll receive an e-mail when it's ready!");
  83 + showProjectContentAfter(20);
  84 + }
  85 +}
  86 +
  87 +function showProjectContentAfter(seconds){
  88 + if (seconds > 0){
  89 + setTimeout(function() { showProjectContentAfter(seconds - 10);}, 10000);
  90 + } else {
  91 + showProjectContent();
  92 + }
  93 +}
  94 +
  95 +function showProjectResult(content) {
  96 + jQuery('#processing').html(content);
  97 +}
  98 +
  99 +function showProjectTree(content){
  100 + processingTree = false;
  101 + jQuery('#project-tree').html(content);
  102 + return false;
  103 +}
  104 +
  105 +function showModuleResult(content){
  106 + if (processingTree != true){
  107 + jQuery('#module-result').html(content);
  108 + }
  109 + return false;
  110 +}
  111 +
  112 +function callAction(controller, action, params, callback){
  113 + var profile = projectContentData('profile');
  114 + var content = projectContentData('content');
  115 + var endpoint = '/profile/' + profile + '/plugin/mezuro/' + controller + '/' + action + '/' + content;
  116 + jQuery.get(endpoint, params, callback);
  117 +}
  118 +
  119 +function projectContentData(data){
  120 + return jQuery('#processing').attr('data-' + data);
  121 +}
  122 +
  123 +function showLoadingProcess(firstLoad){
  124 + if(firstLoad)
  125 + showProjectResult("<img src='/images/loading-small.gif'/>");
  126 +
  127 + showProjectTree("<img src='/images/loading-small.gif'/>");
  128 + showModuleResult("<img src='/images/loading-small.gif'/>");
  129 +}
  130 +
  131 +function sourceNodeToggle(id){
  132 + var suffixes = ['_hidden', '_plus', '_minus'];
  133 + for (var i in suffixes)
  134 + jQuery('#' + id + suffixes[i]).toggle();
  135 +}
... ...
plugins/mezuro/public/javascripts/project_content.js
... ... @@ -1,135 +0,0 @@
1   -var processingTree = false;
2   -var metricName;
3   -jQuery(function (){
4   - jQuery('.source-tree-link').live("click", reloadModule);
5   - jQuery('[show-metric-history]').live("click", display_metric_history);
6   - jQuery('[show-grade-history]').live("click", display_grade_history);
7   - jQuery('#project_date_submit').live("click", reloadProjectWithDate);
8   - showLoadingProcess(true);
9   - showProjectContent();
10   -});
11   -
12   -function showProjectContent() {
13   - callAction('project', 'project_state', {}, showProjectContentFor);
14   -}
15   -
16   -function display_metric_history() {
17   - var module_name = jQuery(this).attr('data-module-name');
18   - var metric_name = jQuery(this).attr('show-metric-history');
19   - toggle_mezuro("." + metric_name);
20   - metricName = metric_name;
21   - callAction('module', 'module_metrics_history', {module_id: module_id, module_result_id: module_result_id}, show_metrics);
22   - return false;
23   -}
24   -
25   -function display_grade_history() {
26   - var module_name = jQuery(this).attr('data-module-name');
27   - toggle_mezuro("#historical-grade");
28   - callAction('module', 'module_grade_history', {module_name: module_name}, show_grades);
29   - return false;
30   -}
31   -
32   -function show_metrics(content) {
33   - jQuery('#historical-' + metricName).html(content);
34   -}
35   -
36   -function show_grades(content) {
37   - jQuery('#historical-grade').html(content);
38   -}
39   -
40   -function toggle_mezuro(element){
41   - jQuery(element).toggle();
42   - return false;
43   -}
44   -
45   -function reloadModule(){
46   - var module_name = jQuery(this).attr('data-module-name');
47   - showLoadingProcess(false);
48   - processingTree = true;
49   - callAction('project', 'project_tree', {module_name: module_name }, showProjectTree);
50   - callAction('module', 'module_result', {module_name: module_name}, showModuleResult);
51   - return false;
52   -}
53   -
54   -function reloadProjectWithDate(date){
55   - reloadProject(date + "T00:00:00+00:00");
56   - return false;
57   -}
58   -
59   -function reloadProject(date){
60   - showLoadingProcess(true);
61   -
62   - callAction('project', 'project_result', {date: date}, showProjectResult);
63   - callAction('project', 'project_tree', {date: date}, showProjectTree);
64   - callAction('module', 'module_result', {date: date}, showModuleResult);
65   -}
66   -
67   -function showProjectContentFor(state){
68   - if (state == 'ERROR') {
69   - jQuery('#project-state').html('<div style="color:Red">ERROR</div>');
70   - callAction('project', 'project_error', {}, showProjectResult);
71   - }
72   - else if (state == 'READY') {
73   - jQuery('#msg-time').html('');
74   - jQuery('#project-state').html('<div style="color:Green">READY</div>');
75   - callAction('project', 'project_result', {}, showProjectResult);
76   - callAction('project','project_tree', {}, showProjectTree);
77   - var project_name = jQuery("#project-result").attr('data-project-name');
78   - callAction('module', 'module_result', {module_name: project_name}, showModuleResult);
79   - }
80   - else if (state.endsWith("ING")) {
81   - jQuery('#project-state').html('<div style="color:DarkGoldenRod">'+ state +'</div>');
82   - jQuery('#msg-time').html("The project analysis may take long. <br/> You'll receive an e-mail when it's ready!");
83   - showProjectContentAfter(20);
84   - }
85   -}
86   -
87   -function showProjectContentAfter(seconds){
88   - if (seconds > 0){
89   - setTimeout(function() { showProjectContentAfter(seconds - 10);}, 10000);
90   - } else {
91   - showProjectContent();
92   - }
93   -}
94   -
95   -function showProjectResult(content) {
96   - jQuery('#project-result').html(content);
97   -}
98   -
99   -function showProjectTree(content){
100   - processingTree = false;
101   - jQuery('#project-tree').html(content);
102   - return false;
103   -}
104   -
105   -function showModuleResult(content){
106   - if (processingTree != true){
107   - jQuery('#module-result').html(content);
108   - }
109   - return false;
110   -}
111   -
112   -function callAction(controller, action, params, callback){
113   - var profile = projectContentData('profile');
114   - var content = projectContentData('content');
115   - var endpoint = '/profile/' + profile + '/plugin/mezuro/' + controller + '/' + action + '/' + content;
116   - jQuery.get(endpoint, params, callback);
117   -}
118   -
119   -function projectContentData(data){
120   - return jQuery('#project-result').attr('data-' + data);
121   -}
122   -
123   -function showLoadingProcess(firstLoad){
124   - if(firstLoad)
125   - showProjectResult("<img src='/images/loading-small.gif'/>");
126   -
127   - showProjectTree("<img src='/images/loading-small.gif'/>");
128   - showModuleResult("<img src='/images/loading-small.gif'/>");
129   -}
130   -
131   -function sourceNodeToggle(id){
132   - var suffixes = ['_hidden', '_plus', '_minus'];
133   - for (var i in suffixes)
134   - jQuery('#' + id + suffixes[i]).toggle();
135   -}
plugins/mezuro/views/content_viewer/show_project.rhtml
... ... @@ -18,21 +18,29 @@
18 18 <td><%= @project.description %></td>
19 19 </tr>
20 20 </table>
21   -
22   - <%= _('Repositories') %>
  21 + <br/>
  22 + <h5><%= _('Repositories') %></h5>
  23 + <table>
23 24 <% @page.repositories.each do |repository| %>
24   - <%= repository.name %>
25   - <%= link_to repository.name, :controller => "mezuro_plugin_repository",
  25 + <tr>
  26 + <td><%= link_to repository.name, :controller => "mezuro_plugin_repository",
26 27 :profile => @page.profile.identifier,
27   - :action => "show_repository",
  28 + :action => "show",
28 29 :id => @page.id,
29   - :repository_id => repository.id %><br/>
  30 + :repository_id => repository.id %></td>
  31 + <td><%= link_to "#{image_tag ('/plugins/mezuro/images/minus.png')}", :controller => "mezuro_plugin_repository",
  32 + :profile => @page.profile.identifier,
  33 + :action => "destroy",
  34 + :id => @page.id,
  35 + :repository_id => repository.id %></td>
  36 + </tr>
30 37 <% end %>
  38 + </table>
31 39  
32 40 <br>
33 41 <%= link_to "#{image_tag ('/plugins/mezuro/images/plus.png')}Add Repository", :controller => "mezuro_plugin_repository",
34 42 :profile => @page.profile.identifier,
35   - :action => "new_repository",
  43 + :action => "new",
36 44 :id => @page.id %><br/>
37 45  
38 46 <% end %>
... ...
plugins/mezuro/views/mezuro_plugin_repository/show_repository.html.erb
1   - <p>
2   - <%= "Project Name: " + @project_name %>
3   - </p>
4   - <p>
5   - <%= "Name: " + @repository.name %>
6   - </p>
7   - <p>
8   - <%= "Description: " + @repository.description %>
9   - </p>
10   - <p>
11   - <%= "License: " + @repository.license %>
12   - </p>
13   - <p>
14   - <%= "Process Period: " + @repository.process_period %>
15   - </p>
16   - <p>
17   - <%= "Type: " + @repository.type %>
18   - </p>
19   - <p>
20   - <%= "Address: " + @repository.address %>
21   - </p>
22   - <p>
23   - <%= "Configuration: " + @configuration_name %>
24   - </p>
  1 +<script src="/plugins/mezuro/javascripts/processing.js" type="text/javascript"></script>
  2 +<h3><%= @project_name %></h3>
  3 +
  4 +<table>
  5 + <tr>
  6 + <td><%= _('Name') %></td>
  7 + <td><%= @repository.name %></td>
  8 + </tr>
  9 + <tr>
  10 + <td><%= _('Description') %></td>
  11 + <td><%= @repository.description %></td>
  12 + </tr>
  13 + <tr>
  14 + <td><%= _('License') %></td>
  15 + <td><%= @repository.license %></td>
  16 + </tr>
  17 + <tr>
  18 + <td><%= _('Process Period') %></td>
  19 + <td><%= MezuroPlugin::Helpers::ContentViewerHelper.get_periodicity_option(@repository.process_period) %></td>
  20 + </tr>
  21 + <tr>
  22 + <td><%= _('Type') %></td>
  23 + <td><%= @repository.type %></td>
  24 + </tr>
  25 + <tr>
  26 + <td><%= _('Address') %></td>
  27 + <td><%= @repository.address %></td>
  28 + </tr>
  29 + <tr>
  30 + <td><%= _('Configuration') %></td>
  31 + <td><%= @configuration_name %></td>
  32 + </tr>
  33 + <tr>
  34 + <td><%= _('Status')%></td>
  35 + <td>
  36 + <div id="processing-state" style="color:DarkGoldenRod"><%= @processing.state %></div>
  37 + <div id="msg-time"></div>
  38 + </td>
  39 + </tr>
  40 +</table>
  41 +
  42 +
  43 +<br />
  44 +
  45 +<div id="processing" data-profile="<%= @page.profile.identifier %>" data-content="<%= @page.id %>"
  46 + data-repository-id="<%= @repository.id %>"></div>
  47 +<div id="project-tree"></div>
  48 +<div id="module-result"></div>
... ...