diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/assets/javascripts/behaviors/toggle_diff_line_wrap_behavior.coffee | 14 | ||||
| -rw-r--r-- | app/assets/javascripts/calendar.js.coffee | 17 | ||||
| -rw-r--r-- | app/assets/stylesheets/generic/calendar.scss | 62 | ||||
| -rw-r--r-- | app/controllers/users_controller.rb | 19 | ||||
| -rw-r--r-- | app/helpers/events_helper.rb | 2 | ||||
| -rw-r--r-- | app/helpers/projects_helper.rb | 37 | ||||
| -rw-r--r-- | app/models/event.rb | 2 | ||||
| -rw-r--r-- | app/models/project_contributions.rb | 9 | ||||
| -rw-r--r-- | app/models/repository.rb | 38 | ||||
| -rw-r--r-- | app/models/tree.rb | 54 | ||||
| -rw-r--r-- | app/views/admin/application_settings/_form.html.haml | 4 | ||||
| -rw-r--r-- | app/views/events/event/_push.html.haml | 10 | ||||
| -rw-r--r-- | app/views/projects/_issuable_form.html.haml | 4 | ||||
| -rw-r--r-- | app/views/projects/diffs/_file.html.haml | 7 | ||||
| -rw-r--r-- | app/views/projects/merge_requests/_new_submit.html.haml | 4 | ||||
| -rw-r--r-- | app/views/projects/show.html.haml | 23 | ||||
| -rw-r--r-- | app/views/users/calendar.html.haml | 3 | ||||
| -rw-r--r-- | app/views/users/calendar_activities.html.haml | 33 | ||||
| -rw-r--r-- | app/views/users/show.html.haml | 1 |
19 files changed, 249 insertions, 94 deletions
diff --git a/app/assets/javascripts/behaviors/toggle_diff_line_wrap_behavior.coffee b/app/assets/javascripts/behaviors/toggle_diff_line_wrap_behavior.coffee deleted file mode 100644 index 691ed4f98ae..00000000000 --- a/app/assets/javascripts/behaviors/toggle_diff_line_wrap_behavior.coffee +++ /dev/null @@ -1,14 +0,0 @@ -$ -> - # Toggle line wrapping in diff. - # - # %div.diff-file - # %input.js-toggle-diff-line-wrap - # %td.line_content - # - $("body").on "click", ".js-toggle-diff-line-wrap", (e) -> - diffFile = $(@).closest(".diff-file") - if $(@).is(":checked") - diffFile.addClass("diff-wrap-lines") - else - diffFile.removeClass("diff-wrap-lines") - diff --git a/app/assets/javascripts/calendar.js.coffee b/app/assets/javascripts/calendar.js.coffee index 19ea4ccc4cf..2891a48e249 100644 --- a/app/assets/javascripts/calendar.js.coffee +++ b/app/assets/javascripts/calendar.js.coffee @@ -4,7 +4,7 @@ class @calendar day: "numeric" year: "numeric" - constructor: (timestamps, starting_year, starting_month) -> + constructor: (timestamps, starting_year, starting_month, calendar_activities_path) -> cal = new CalHeatMap() cal.init itemName: ["commit"] @@ -26,5 +26,16 @@ class @calendar ] legendCellPadding: 3 onClick: (date, count) -> - return - return + formated_date = date.getFullYear() + "-" + (date.getMonth()+1) + "-" + date.getDate() + $(".calendar_commit_activity").fadeOut 400 + $.ajax + url: calendar_activities_path + data: + date: formated_date + cache: false + dataType: "html" + success: (data) -> + $(".user-calendar-activities").html data + $(".calendar_commit_activity").find(".js-toggle-content").hide() + $(".calendar_commit_activity").fadeIn 400 + diff --git a/app/assets/stylesheets/generic/calendar.scss b/app/assets/stylesheets/generic/calendar.scss index 9483b26164e..e2ab7fc51a5 100644 --- a/app/assets/stylesheets/generic/calendar.scss +++ b/app/assets/stylesheets/generic/calendar.scss @@ -1,29 +1,45 @@ -.calendar_onclick_placeholder { - padding: 0 0 2px 0; -} - -.calendar_commit_activity { - padding: 5px 0 0; -} - -.calendar_onclick_second { - font-size: 14px; - display: block; -} - -.calendar_onclick_hr { - padding: 0; - margin: 10px 0; -} +.user-calendar-activities { + + .calendar_commit_activity { + padding: 5px 0 0; + } + + .calendar_onclick_hr { + padding: 0; + margin: 10px 0; + } + + .calendar_commit_date { + color: #999; + } + + .calendar_activity_summary { + font-size: 14px; + } -.calendar_commit_date { - color: #999; -} + .str-truncated { + max-width: 70%; + } -.calendar_activity_summary { - font-size: 14px; + .text-expander { + background: #eee; + color: #555; + padding: 0 5px; + cursor: pointer; + margin-left: 4px; + &:hover { + background-color: #ddd; + } + } + + .commit-row-message { + color: #333; + &:hover { + color: #444; + text-decoration: underline; + } + } } - /** * This overwrites the default values of the cal-heatmap gem */ diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 8a13394dbac..68130eb128c 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -32,6 +32,7 @@ class UsersController < ApplicationController def calendar projects = Project.where(id: authorized_projects_ids & @user.contributed_projects_ids) + calendar = Gitlab::CommitsCalendar.new(projects, @user) @timestamps = calendar.timestamps @starting_year = calendar.starting_year @@ -40,6 +41,24 @@ class UsersController < ApplicationController render 'calendar', layout: false end + def calendar_activities + projects = Project.where(id: authorized_projects_ids & @user.contributed_projects_ids) + + date = Date.parse(params[:date]) rescue nil + if date + @calendar_activities = Gitlab::CommitsCalendar.get_commits_for_date(projects, @user, date) + else + @calendar_activities = {} + end + + # get the total number of unique commits + @commit_count = @calendar_activities.values.flatten.map(&:id).uniq.count + + @calendar_date = date + + render 'calendar_activities', layout: false + end + def determine_layout if current_user 'navless' diff --git a/app/helpers/events_helper.rb b/app/helpers/events_helper.rb index 779cebc0136..c9fd0f0362b 100644 --- a/app/helpers/events_helper.rb +++ b/app/helpers/events_helper.rb @@ -96,7 +96,7 @@ module EventsHelper end end elsif event.push? - if event.push_with_commits? + if event.push_with_commits? && event.md_ref? if event.commits_count > 1 namespace_project_compare_url(event.project.namespace, event.project, from: event.commit_from, to: diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 2225b110651..a14277180c7 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -232,12 +232,45 @@ module ProjectsHelper end def contribution_guide_url(project) - if project && project.repository.contribution_guide + if project && contribution_guide = project.repository.contribution_guide namespace_project_blob_path( project.namespace, project, tree_join(project.default_branch, - project.repository.contribution_guide.name) + contribution_guide.name) + ) + end + end + + def changelog_url(project) + if project && changelog = project.repository.changelog + namespace_project_blob_path( + project.namespace, + project, + tree_join(project.default_branch, + changelog.name) + ) + end + end + + def license_url(project) + if project && license = project.repository.license + namespace_project_blob_path( + project.namespace, + project, + tree_join(project.default_branch, + license.name) + ) + end + end + + def version_url(project) + if project && version = project.repository.version + namespace_project_blob_path( + project.namespace, + project, + tree_join(project.default_branch, + version.name) ) end end diff --git a/app/models/event.rb b/app/models/event.rb index 8d20d7ef252..2103a48a71b 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -247,7 +247,7 @@ class Event < ActiveRecord::Base end def push_with_commits? - md_ref? && commits.any? && commit_from && commit_to + !commits.empty? && commit_from && commit_to end def last_push_to_non_root? diff --git a/app/models/project_contributions.rb b/app/models/project_contributions.rb index 8ab2d814a94..bfe9928b158 100644 --- a/app/models/project_contributions.rb +++ b/app/models/project_contributions.rb @@ -17,6 +17,15 @@ class ProjectContributions end end + def user_commits_on_date(date) + repository = @project.repository + + if !repository.exists? || repository.empty? + return [] + end + commits = repository.commits_by_user_on_date_log(@user, date) + end + def cache_key "#{Date.today.to_s}-commits-log-#{project.id}-#{user.email}" end diff --git a/app/models/repository.rb b/app/models/repository.rb index 47758b8ad68..c6eaa485b8a 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -122,7 +122,7 @@ class Repository def expire_cache %i(size branch_names tag_names commit_count graph_log - readme version contribution_guide).each do |key| + readme version contribution_guide changelog license).each do |key| cache.expire(key) end end @@ -157,6 +157,20 @@ class Repository end end + def commits_by_user_on_date_log(user, date) + # format the date string for git + start_date = date.strftime("%Y-%m-%d 00:00:00") + end_date = date.strftime("%Y-%m-%d 23:59:59") + + author_emails = '(' + user.all_emails.map{ |e| Regexp.escape(e) }.join('|') + ')' + args = %W(git log -E --author=#{author_emails} --after=#{start_date.to_s} --until=#{end_date.to_s} --branches --pretty=format:%h) + commits = Gitlab::Popen.popen(args, path_to_repo).first.split("\n") + + commits.map! do |commit_id| + commit(commit_id) + end + end + def commits_per_day_for_user(user) timestamps_by_user_log(user). group_by { |commit_date| commit_date }. @@ -197,7 +211,27 @@ class Repository end def contribution_guide - cache.fetch(:contribution_guide) { tree(:head).contribution_guide } + cache.fetch(:contribution_guide) do + tree(:head).blobs.find do |file| + file.contributing? + end + end + end + + def changelog + cache.fetch(:changelog) do + tree(:head).blobs.find do |file| + file.name =~ /^(changelog|history)/i + end + end + end + + def license + cache.fetch(:license) do + tree(:head).blobs.find do |file| + file.name =~ /^license/i + end + end end def head_commit diff --git a/app/models/tree.rb b/app/models/tree.rb index 4f5d81f0a5e..f279e896cda 100644 --- a/app/models/tree.rb +++ b/app/models/tree.rb @@ -1,38 +1,38 @@ class Tree include Gitlab::MarkdownHelper - attr_accessor :entries, :readme, :contribution_guide + attr_accessor :repository, :sha, :path, :entries def initialize(repository, sha, path = '/') path = '/' if path.blank? - git_repo = repository.raw_repository - @entries = Gitlab::Git::Tree.where(git_repo, sha, path) - - available_readmes = @entries.select(&:readme?) - - if available_readmes.count > 0 - # If there is more than 1 readme in tree, find readme which is supported - # by markup renderer. - if available_readmes.length > 1 - supported_readmes = available_readmes.select do |readme| - previewable?(readme.name) - end - - # Take the first supported readme, or the first available readme, if we - # don't support any of them - readme_tree = supported_readmes.first || available_readmes.first - else - readme_tree = available_readmes.first - end - - readme_path = path == '/' ? readme_tree.name : File.join(path, readme_tree.name) - @readme = Gitlab::Git::Blob.find(git_repo, sha, readme_path) - end + + @repository = repository + @sha = sha + @path = path + + git_repo = @repository.raw_repository + @entries = Gitlab::Git::Tree.where(git_repo, @sha, @path) + end + + def readme + return @readme if defined?(@readme) - if contribution_tree = @entries.find(&:contributing?) - contribution_path = path == '/' ? contribution_tree.name : File.join(path, contribution_tree.name) - @contribution_guide = Gitlab::Git::Blob.find(git_repo, sha, contribution_path) + available_readmes = blobs.select(&:readme?) + + if available_readmes.count == 0 + return @readme = nil end + + # Take the first previewable readme, or the first available readme, if we + # can't preview any of them + readme_tree = available_readmes.find do |readme| + previewable?(readme.name) + end || available_readmes.first + + readme_path = path == '/' ? readme_tree.name : File.join(path, readme_tree.name) + + git_repo = repository.raw_repository + @readme = Gitlab::Git::Blob.find(git_repo, sha, readme_path) end def trees diff --git a/app/views/admin/application_settings/_form.html.haml b/app/views/admin/application_settings/_form.html.haml index 781600a3766..edfcccfcf4c 100644 --- a/app/views/admin/application_settings/_form.html.haml +++ b/app/views/admin/application_settings/_form.html.haml @@ -12,13 +12,13 @@ .checkbox = f.label :signup_enabled do = f.check_box :signup_enabled - Signin enabled + Signup enabled .form-group .col-sm-offset-2.col-sm-10 .checkbox = f.label :signin_enabled do = f.check_box :signin_enabled - Signup enabled + Signin enabled .form-group .col-sm-offset-2.col-sm-10 .checkbox diff --git a/app/views/events/event/_push.html.haml b/app/views/events/event/_push.html.haml index 489138887ae..60d7978b13f 100644 --- a/app/views/events/event/_push.html.haml +++ b/app/views/events/event/_push.html.haml @@ -21,5 +21,11 @@ %li.commits-stat - if event.commits_count > 2 %span ... and #{event.commits_count - 2} more commits. - = link_to namespace_project_compare_path(event.project.namespace, event.project, from: event.commit_from, to: event.commit_to) do - %strong Compare → #{truncate_sha(event.commit_from)}...#{truncate_sha(event.commit_to)} + - if event.md_ref? + - from = event.commit_from + - from_label = truncate_sha(from) + - else + - from = event.project.default_branch + - from_label = from + = link_to namespace_project_compare_path(event.project.namespace, event.project, from: from, to: event.commit_to) do + %strong Compare → #{from_label}...#{truncate_sha(event.commit_to)} diff --git a/app/views/projects/_issuable_form.html.haml b/app/views/projects/_issuable_form.html.haml index a7cd129b631..7fd5fe8a6e1 100644 --- a/app/views/projects/_issuable_form.html.haml +++ b/app/views/projects/_issuable_form.html.haml @@ -71,10 +71,10 @@ = link_to 'Create new label', new_namespace_project_label_path(issuable.project.namespace, issuable.project), target: :blank .form-actions - - if !issuable.project.empty_repo? && contribution_guide_url(issuable.project) && !issuable.persisted? + - if !issuable.project.empty_repo? && (guide_url = contribution_guide_url(issuable.project)) && !issuable.persisted? %p Please review the - %strong #{link_to 'guidelines for contribution', contribution_guide_url(issuable.project)} + %strong #{link_to 'guidelines for contribution', guide_url} to this repository. - if issuable.new_record? = f.submit "Submit new #{issuable.class.model_name.human.downcase}", class: 'btn btn-create' diff --git a/app/views/projects/diffs/_file.html.haml b/app/views/projects/diffs/_file.html.haml index 36d98b26712..a9e4d63cd98 100644 --- a/app/views/projects/diffs/_file.html.haml +++ b/app/views/projects/diffs/_file.html.haml @@ -22,11 +22,6 @@ .diff-btn-group - if blob.text? - - unless params[:view] == 'parallel' - %label - = check_box_tag nil, 1, false, class: 'js-toggle-diff-line-wrap' - Wrap text - = link_to '#', class: 'js-toggle-diff-comments btn btn-sm' do %i.fa.fa-chevron-down Show/Hide comments @@ -39,7 +34,7 @@ = view_file_btn(@commit.id, diff_file, project) - .diff-content + .diff-content.diff-wrap-lines -# Skipp all non non-supported blobs - return unless blob.respond_to?('text?') - if blob.text? diff --git a/app/views/projects/merge_requests/_new_submit.html.haml b/app/views/projects/merge_requests/_new_submit.html.haml index bf80afe8785..1d8eef4e8ce 100644 --- a/app/views/projects/merge_requests/_new_submit.html.haml +++ b/app/views/projects/merge_requests/_new_submit.html.haml @@ -69,10 +69,10 @@ = link_to 'Create new label', new_namespace_project_label_path(@merge_request.target_project.namespace, @merge_request.target_project), target: :blank .form-actions - - if contribution_guide_url(@target_project) + - if guide_url = contribution_guide_url(@target_project) %p Please review the - %strong #{link_to 'guidelines for contribution', contribution_guide_url(@target_project)} + %strong #{link_to 'guidelines for contribution', guide_url} to this repository. = f.hidden_field :source_project_id = f.hidden_field :source_branch diff --git a/app/views/projects/show.html.haml b/app/views/projects/show.html.haml index 74b07395650..822e67c5616 100644 --- a/app/views/projects/show.html.haml +++ b/app/views/projects/show.html.haml @@ -47,15 +47,26 @@ = link_to @project.forked_from_project.name_with_namespace, namespace_project_path(@project.namespace, @project.forked_from_project) - unless @project.empty_repo? - = link_to namespace_project_compare_index_path(@project.namespace, @project, from: @repository.root_ref, to: @ref || @repository.root_ref), class: 'btn btn-block' do - Compare code - - - if @repository.version - - version = @repository.version - = link_to namespace_project_blob_path(@project.namespace, @project, tree_join(@repository.root_ref, version.name)), class: 'btn btn-block' do + - if version = @repository.version + - detail_url = changelog_url(@project) || version_url(@project) + = link_to detail_url, class: 'btn btn-block' do Version: %span.count = @repository.blob_by_oid(version.id).data + - elsif @repository.changelog + = link_to changelog_url(@project), class: 'btn btn-block' do + View changelog + + - if @repository.contribution_guide + = link_to contribution_guide_url(@project), class: 'btn btn-block' do + View contribution guide + + - if @repository.license + = link_to license_url(@project), class: 'btn btn-block' do + View license + + = link_to namespace_project_compare_index_path(@project.namespace, @project, from: @repository.root_ref, to: @ref || @repository.root_ref), class: 'btn btn-block' do + Compare code .prepend-top-10 %p diff --git a/app/views/users/calendar.html.haml b/app/views/users/calendar.html.haml index 1d1c974da24..d113ceeb753 100644 --- a/app/views/users/calendar.html.haml +++ b/app/views/users/calendar.html.haml @@ -4,5 +4,6 @@ new calendar( #{@timestamps.to_json}, #{@starting_year}, - #{@starting_month} + #{@starting_month}, + '#{user_calendar_activities_path}' ); diff --git a/app/views/users/calendar_activities.html.haml b/app/views/users/calendar_activities.html.haml new file mode 100644 index 00000000000..7c0cecfadb5 --- /dev/null +++ b/app/views/users/calendar_activities.html.haml @@ -0,0 +1,33 @@ +.calendar_commit_activity + %hr + %h4 + Commit Activity + %strong + - if @commit_count == 0 + no + - else + = @commit_count + %span.calendar_commit_date + unique + = 'commit'.pluralize(@commit_count) + on + = @calendar_date.strftime("%b %d, %Y") rescue '' + -unless @commit_count == 0 + %hr + - @calendar_activities.each do |project, commits| + - next if commits.empty? + %div.js-toggle-container + %strong + = pluralize(commits.count, 'commit') + in project + = link_to project.name_with_namespace, project_path(project) + %a.text-expander.js-toggle-button … + %hr + %div.js-toggle-content + - commits.each do |commit| + %span.monospace + = commit.committed_date.strftime("%H:%M") + = link_to commit.short_id, namespace_project_commit_path(project.namespace, project, commit), class: "commit_short_id" + = link_to commit.message, namespace_project_commit_path(project.namespace, project, commit), class: "commit-row-message str-truncated" + %br + %hr diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index abd6b229782..6d6beb58711 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -25,6 +25,7 @@ .user-calendar %h4.center.light %i.fa.fa-spinner.fa-spin + .user-calendar-activities %hr %h4 User Activity |
