OSDN Git Service

project tile view
authorgitlabhq <m@gitlabhq.com>
Tue, 11 Oct 2011 20:00:00 +0000 (23:00 +0300)
committergitlabhq <m@gitlabhq.com>
Wed, 12 Oct 2011 13:19:14 +0000 (16:19 +0300)
13 files changed:
app/assets/images/list_view_icon.jpg [new file with mode: 0644]
app/assets/javascripts/jquery.cookie.js [new file with mode: 0644]
app/assets/stylesheets/projects.css.scss
app/controllers/dashboard_controller.rb
app/helpers/projects_helper.rb
app/models/user.rb
app/views/dashboard/index.html.haml
app/views/layouts/application.html.haml
app/views/projects/_list.html.haml [new file with mode: 0644]
app/views/projects/_projects_top_menu.html.haml [new file with mode: 0644]
app/views/projects/_tile.html.haml [new file with mode: 0644]
app/views/projects/_tree_item.html.haml
app/views/projects/index.html.haml

diff --git a/app/assets/images/list_view_icon.jpg b/app/assets/images/list_view_icon.jpg
new file mode 100644 (file)
index 0000000..45a34cb
Binary files /dev/null and b/app/assets/images/list_view_icon.jpg differ
diff --git a/app/assets/javascripts/jquery.cookie.js b/app/assets/javascripts/jquery.cookie.js
new file mode 100644 (file)
index 0000000..6a3e394
--- /dev/null
@@ -0,0 +1,41 @@
+/**
+ * jQuery Cookie plugin
+ *
+ * Copyright (c) 2010 Klaus Hartl (stilbuero.de)
+ * Dual licensed under the MIT and GPL licenses:
+ * http://www.opensource.org/licenses/mit-license.php
+ * http://www.gnu.org/licenses/gpl.html
+ *
+ */
+jQuery.cookie = function (key, value, options) {
+
+    // key and at least value given, set cookie...
+    if (arguments.length > 1 && String(value) !== "[object Object]") {
+        options = jQuery.extend({}, options);
+
+        if (value === null || value === undefined) {
+            options.expires = -1;
+        }
+
+        if (typeof options.expires === 'number') {
+            var days = options.expires, t = options.expires = new Date();
+            t.setDate(t.getDate() + days);
+        }
+
+        value = String(value);
+
+        return (document.cookie = [
+            encodeURIComponent(key), '=',
+            options.raw ? value : encodeURIComponent(value),
+            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
+            options.path ? '; path=' + options.path : '',
+            options.domain ? '; domain=' + options.domain : '',
+            options.secure ? '; secure' : ''
+        ].join(''));
+    }
+
+    // key and possibly options given, get cookie...
+    options = value || {};
+    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
+    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
+};
index c87751d..0ee40f5 100644 (file)
@@ -525,3 +525,17 @@ tbody tr:nth-child(2n) td, tbody tr.even td {
 #user_projects_limit{
   width: 60px;  
 }
+
+.project_thumb { 
+  margin:20px 0;
+  width: 250px;
+  float:left;
+  padding:20px;
+  text-align:center;
+  p, h4 { 
+    text-align:left;
+  }
+  .lbutton { 
+    float:left;
+  }
+}
index e1192e4..2476b17 100644 (file)
@@ -1,2 +1,5 @@
 class DashboardController < ApplicationController
+  def index
+    @projects = current_user.projects.all
+  end
 end
index db5c5ce..d570dff 100644 (file)
@@ -1,2 +1,6 @@
 module ProjectsHelper
+  def view_mode_style(type)
+    cookies["project_view"] ||= "tile"
+    cookies["project_view"] == type ? nil : "display:none"
+  end
 end
index 104843a..0972f00 100644 (file)
@@ -33,6 +33,10 @@ class User < ActiveRecord::Base
   def can_create_project?
     projects_limit >= my_own_projects.count
   end
+
+  def last_activity_project
+    projects.first
+  end
 end
 # == Schema Information
 #
index 8ac413a..3eb99da 100644 (file)
@@ -21,6 +21,7 @@
       = render :partial => "layouts/head_panel"
       .top_bar.container
         = render :partial => "projects/top_menu" if @project && !@project.new_record?
+        = render :partial => "projects/projects_top_menu" if (controller.controller_name == "projects" && ["index", "new", "create"].include?(controller.action_name)) && !admin_namespace?
         = render :partial => "profile/top_menu" if ["keys", "profile"].include?(controller.controller_name)
         = render :partial => "admin/top_menu" if admin_namespace?
     #content-container.container
diff --git a/app/views/projects/_list.html.haml b/app/views/projects/_list.html.haml
new file mode 100644 (file)
index 0000000..82e1948
--- /dev/null
@@ -0,0 +1,26 @@
+-#- if current_user.can_create_project?
+  = link_to 'New Project', new_project_path, :class => "lbutton vm"
+
+%table.round-borders#projects-list
+  %tr
+    %th Name
+    %th Path
+    %th Code
+    %th Web
+    %th Git
+    %th Admin
+    %th Actions
+
+  - @projects.each do |project|
+    %tr{ :class => "project", :url => project_path(project) }
+      %td= project.name
+      %td= truncate project.url_to_repo
+      %td= project.code
+      %td= check_box_tag "read",   1, project.readers.include?(current_user), :disabled => :disabled
+      %td= check_box_tag "commit", 1, project.writers.include?(current_user), :disabled => :disabled
+      %td= check_box_tag "admin",  1, project.admins.include?(current_user), :disabled => :disabled
+      %td 
+        -if can? current_user, :admin_project, project
+          = link_to 'Edit', edit_project_path(project), :class => "lbutton positive"
+%br
+
diff --git a/app/views/projects/_projects_top_menu.html.haml b/app/views/projects/_projects_top_menu.html.haml
new file mode 100644 (file)
index 0000000..be04c57
--- /dev/null
@@ -0,0 +1,16 @@
+%div.top_project_menu
+  %span= link_to 'All', projects_path, :class => current_page?(projects_path) ? "current" : nil
+  %span= link_to "New Project", new_project_path, :class => current_page?(:controller => "projects", :action => "new") ? "current" : nil
+  %span.right
+    = link_to_function(image_tag("list_view_icon.jpg"), "switchProjectView()", :style => "border:none;box-shadow:none;")
+
+:javascript
+  function switchProjectView(){
+    $(".tile").toggle();
+    $(".list").toggle();
+    if($(".tile").is(":visible")){
+      $.cookie('project_view', 'tile', { expires: 14 });
+    } else { 
+      $.cookie('project_view', 'list', { expires: 14 });
+    }
+  }
diff --git a/app/views/projects/_tile.html.haml b/app/views/projects/_tile.html.haml
new file mode 100644 (file)
index 0000000..037aecc
--- /dev/null
@@ -0,0 +1,16 @@
+- @projects.in_groups_of(3, false) do |projects|
+  - projects.each_with_index do |project, i|
+    %div{ :class => "project_thumb round-borders", :style => i == 2 ? "" : "margin-right:30px;" }
+      %div{ :class => "project", :url => project_path(project) }
+        %h2
+          = image_tag gravatar_icon(project.name), :class => "left", :width => 40, :style => "padding-right:5px;"
+          = "/" + project.code
+        %p= project.name
+        %p= project.url_to_repo
+        -#%p
+          Commit &ndash;
+          = last_commit(project)
+        %hr
+        = link_to "Browse Code", tree_project_path(project), :class => "lbutton"
+        = link_to "Commits", project_commits_path(project), :class => "lbutton", :style => "float:right;width:80px;"
+        .clear
index 2557528..7179368 100644 (file)
@@ -1,5 +1,5 @@
 - file = params[:path] ? File.join(params[:path], content.name) : content.name
-- content_commit = @repo.log(@branch, file, :max_count => 1).last
+- content_commit = @project.repo.log(@branch, file, :max_count => 1).last
 - return unless content_commit
 %tr{ :class => "tree-item", :url => tree_file_project_path(@project, @commit.id, file) }
   %td.tree-item-file-name
index a33b4f5..22af6b7 100644 (file)
@@ -1,26 +1,4 @@
-- if current_user.can_create_project?
-  = link_to 'New Project', new_project_path, :class => "lbutton vm"
-
-%table.round-borders#projects-list
-  %tr
-    %th Name
-    %th Path
-    %th Code
-    %th Web
-    %th Git
-    %th Admin
-    %th Actions
-
-  - @projects.each do |project|
-    %tr{ :class => "project", :url => project_path(project) }
-      %td= project.name
-      %td= truncate project.url_to_repo
-      %td= project.code
-      %td= check_box_tag "read",   1, project.readers.include?(current_user), :disabled => :disabled
-      %td= check_box_tag "commit", 1, project.writers.include?(current_user), :disabled => :disabled
-      %td= check_box_tag "admin",  1, project.admins.include?(current_user), :disabled => :disabled
-      %td 
-        -if can? current_user, :admin_project, project
-          = link_to 'Edit', edit_project_path(project), :class => "lbutton positive"
-%br
-
+%div{:class => "tile", :style => view_mode_style("tile")}
+  = render "tile"
+%div{:class => "list", :style => view_mode_style("list")}
+  = render "list"