[Xfce4-commits] <moka:master> Add project and related fixes.

Nick Schermer noreply at xfce.org
Sun Nov 20 14:30:42 CET 2011


Updating branch refs/heads/master
         to 00e971302eec4b298a740095bc5d95bb56aaea18 (commit)
       from 89d33affbbf285a5838a0c2f5c2f7626d21d81ff (commit)

commit 00e971302eec4b298a740095bc5d95bb56aaea18
Author: Nick Schermer <nick at xfce.org>
Date:   Sat Oct 15 19:44:26 2011 +0200

    Add project and related fixes.

 lib/controllers/projects.rb |   18 ++++++++++++++++++
 lib/helpers/general.rb      |    7 ++++++-
 lib/models/archive.rb       |   30 +++++++++++++++++-------------
 lib/views/project.haml      |    2 +-
 lib/views/project_list.haml |   41 ++++++++++++++++++++++++++++-------------
 lib/views/stylesheet.sass   |   20 +++++++++++---------
 6 files changed, 81 insertions(+), 37 deletions(-)

diff --git a/lib/controllers/projects.rb b/lib/controllers/projects.rb
index a2a0e24..cb8eeba 100755
--- a/lib/controllers/projects.rb
+++ b/lib/controllers/projects.rb
@@ -11,6 +11,24 @@ module Moka
           view :project_list
         end
 
+        app.post '/project' do
+
+          authentication_required
+
+          if params[:name] and not params[:name].empty?
+            project = Moka::Models::Project.first_or_create(:name => params[:name].strip)
+
+            classification = Classification.find_by_name(params[:classification])
+            project.classify_as(classification) if classification
+
+            project.save
+
+            redirect "/project/#{params[:name]}"
+          else
+            view :project_list
+          end
+        end
+
         app.get '/project/:name' do
           @project = Project.get(params[:name])
 
diff --git a/lib/helpers/general.rb b/lib/helpers/general.rb
index 6bf867c..d012e93 100755
--- a/lib/helpers/general.rb
+++ b/lib/helpers/general.rb
@@ -68,9 +68,14 @@ module Moka
         end
 
         def cycle
-          %w{even odd}[@_cycle = ((@_cycle || -1) + 1) % 2]
+          @_cycle ||= reset_cycle
+          @_cycle = [@_cycle.pop] + @_cycle
+          @_cycle.first
         end
 
+        def reset_cycle
+          @_cycle = %w(even odd)
+        end
       end
     end
   end
diff --git a/lib/models/archive.rb b/lib/models/archive.rb
index b4a1e0c..21cc048 100755
--- a/lib/models/archive.rb
+++ b/lib/models/archive.rb
@@ -388,23 +388,27 @@ module Moka
       end
 
       def project_change_classification(project, new_classification)
-        old_classification = project.classification
-        old_dir = project_dir(project)
+        new_dir = File.join(classification_dir(new_classification), project.name)
 
-        project.classification = new_classification
-        new_dir = project_dir(project)
+        if project.classification
+          old_classification = project.classification
+          old_dir = project_dir(project)
 
-        path = Pathname.new(new_dir)
-        parent = path.parent
+          path = Pathname.new(new_dir)
+          parent = path.parent
+          File.makedirs(parent) unless File.directory?(parent)
 
-        File.makedirs(parent) unless File.directory?(parent)
-
-        project.classification = old_classifcation unless File.move(old_dir, new_dir)
-
-        begin
-          Dir.delete(old_dir)
-        rescue SystemCallError
+          project.classification = old_classifcation unless File.move(old_dir, new_dir)
+          begin
+            Dir.delete(old_dir)
+          rescue SystemCallError
+          end
+        else
+          File.makedirs(new_dir) unless File.directory?(new_dir)
         end
+
+        # destroy and reload the classification
+        @classifications = nil
       end
     end
   end
diff --git a/lib/views/project.haml b/lib/views/project.haml
index 9e2573b..7379dff 100755
--- a/lib/views/project.haml
+++ b/lib/views/project.haml
@@ -17,7 +17,7 @@
   %p
     %select{:name => "classification"}
       - for classification in Classification.find_all
-        %option{:name => classification.name, :selected => @project.classification.name == classification.name} #{classification.name}
+        %option{:name => classification.name, :selected => (@project.classification.eql? classification)} #{classification.name}
     %input{:type => "submit", :value => "Change"}
 
 %h2 Releases
diff --git a/lib/views/project_list.haml b/lib/views/project_list.haml
index c085e3b..ffd8326 100644
--- a/lib/views/project_list.haml
+++ b/lib/views/project_list.haml
@@ -1,15 +1,30 @@
-%h2 Projects
+%h2 Create Project
+%form{:method => "post" }
+  %p
+    %label{:for => "name"} Name:
+    %input{:type => "text", :name => "name" }
+  %p
+    %label{:for => "classification"} Classification:
+    %select{:name => "classification"}
+      - for classification in Classification.find_all
+        %option{:name => classification.name} #{classification.name}
+  %p
+    %input{:type => "submit", :value => "Create" }
 
+%h2 Projects
+- projects = Project.all.sort
 %table
-  %tr
-    %th Name
-    %th Description
-    %th Maintainers
-  - for project in Project.all.sort
-    %tr{:class => cycle}
-      %td
-        %a{:href => "/project/#{project.name}"} #{project.name}
-      %td
-        #{project.description}
-      %td
-        #{maintainer_names(project)}
+  - for classification in Classification.find_all.sort
+    %tr{:class => 'head'}
+      %th{:colspan => 2} #{classification.name.capitalize}
+    %tr
+      %th Name
+      %th Maintainers
+    - reset_cycle
+    - for project in projects
+      - if project.classification.eql? classification
+        %tr{:class => cycle}
+          %td
+            %a{:href => "/project/#{project.name}"} #{project.name}
+          %td
+            #{maintainer_names(project)}
diff --git a/lib/views/stylesheet.sass b/lib/views/stylesheet.sass
index ebe5f5d..a06d24f 100755
--- a/lib/views/stylesheet.sass
+++ b/lib/views/stylesheet.sass
@@ -44,7 +44,7 @@ a
 
   a
     color: rgb(255,255,255)
-    padding: 
+    padding:
       top: 0.25em
       bottom: 0.25em
       left: 1em
@@ -72,18 +72,20 @@ table
 
   th
     text-align: left
-    padding: 
-      top: 0.25em
-      bottom: 0.25em
-      left: 0.25em
-      right: 2em
-      
+
   tr.admin
     font-weight: bold
 
   tr.odd
     background-color: #eee
-  
+
+  tr.head th
+    padding-top: 1em
+    font-size: 1.2em
+
+  tr.head:first-child th
+    padding-top: 0
+
   td
     padding: 0.25em
 
@@ -105,7 +107,7 @@ fieldset
   padding: 0em
   margin: 0em
 
-  p 
+  p
     padding: 0em
 
   label


More information about the Xfce4-commits mailing list