ADD 导航栏定位

This commit is contained in:
Jasder 2019-11-15 16:42:25 +08:00
parent 6a692adee7
commit 7d0f8212d6
23 changed files with 148 additions and 28 deletions

View File

@ -994,4 +994,8 @@ class ApplicationController < ActionController::Base
end
true
end
def set_nav_status(active)
@active = active
end
end

View File

@ -21,7 +21,7 @@ class BoardsController < ApplicationController
before_filter :find_project_by_project_id, :find_board_if_available, :except => [:join_to_org_subfields]
before_filter :authorize, :except => [:new, :show, :create, :index, :join_to_org_subfields, :update_position, :update_name]
accept_rss_auth :index, :show
helper :sort
include SortHelper
@ -33,6 +33,7 @@ class BoardsController < ApplicationController
#modify by nwb
@flag = params[:flag] || false
if @project
set_nav_status(NavStatues::PROJECT)
if !@project.is_public? && !User.current.member_of?(@project) && !User.current.admin? && !User.current.allowed_to?(:view_messages, @project)
render_403
else
@ -45,6 +46,7 @@ class BoardsController < ApplicationController
render :layout => false if request.xhr?
end
elsif @course
set_nav_status(NavStatues::COURSE)
if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course)))
@boards = @course.boards.includes(:last_message => :author).all
if @course.boards.empty?
@ -68,6 +70,7 @@ class BoardsController < ApplicationController
render_403
end
elsif @contest
set_nav_status(NavStatues::COMPETION)
if (User.current.admin? || @contest.is_public || (!@contest.is_public && User.current.member_of_contest?(@contest)))
@boards = @contest.boards.includes(:last_message => :author).all
if @contest.boards.empty?

View File

@ -32,6 +32,7 @@ class CalendarsController < ApplicationController
def show
# 控制顶部导航样式
@project_menu_type = 8
set_nav_status(NavStatues::PROJECT)
if params[:year] and params[:year].to_i > 1900
@year = params[:year].to_i

View File

@ -8,13 +8,17 @@ class ContestsController < ApplicationController
helper :files
include AvatarHelper
include ApplicationHelper
before_filter :find_contest, :only => [:show, :settings, :update, :destroy, :contest_activities, :private_or_public, :switch_role, :set_invite_code_halt, :renew,
:member, :export_all_members, :feedback]
before_filter :is_logged, :only => [:index, :new, :create]
before_filter :is_admin?, :only => [:settings, :set_invite_code_halt, :destroy]
before_filter :is_member?, :only => [:show, :contest_activities]
before_filter :only => [:show, :feedback, :member, :new] do
set_nav_status(NavStatues::COMPETION)
end
layout "base_contests"
def show

View File

@ -29,6 +29,9 @@ class CoursesController < ApplicationController
before_filter :authorize_course_global, :only => [:new,:create]
before_filter :toggleCourse, :only => [:finishcourse, :restartcourse]
before_filter :is_deleted, :only => [:show, :settings]
before_filter :only => [:show, :course_statistics, :feedback, :member] do |controller|
set_nav_status(NavStatues::COURSE)
end
before_filter :require_login, :only => [:join, :unjoin]
#before_filter :allow_join, :only => [:join]

View File

@ -1,4 +1,5 @@
class ExerciseController < ApplicationController
include ExerciseHelper
layout "base_courses"
before_filter :find_exercise_and_course, :only => [:create_exercise_question, :edit, :update, :show, :destroy,
@ -6,7 +7,10 @@ class ExerciseController < ApplicationController
:show_student_result,:student_exercise_list, :update_question_num,
:send_to_course, :get_student_uncomplete_question, :edit_question_score]
before_filter :find_course, :only => [:index,:new,:create]
include ExerciseHelper
before_filter :only => [:index] do |controller|
set_nav_status(NavStatues::COURSE)
end
def index
=begin
@ -1020,4 +1024,4 @@ class ExerciseController < ApplicationController
rescue Exception => e
render_404
end
end
end

View File

@ -280,6 +280,7 @@ class FilesController < ApplicationController
@is_remote = false
@curr_page = params[:page] ? params[:page].to_i : 1
if params[:project_id]
set_nav_status(NavStatues::PROJECT)
# 更新资源申请消息为已读
# ar_ids = ApplyResource.where("user_id =? and container_id =? and container_type =?", User.current.id, params[:project_id].to_i, "Project").map{|ar| ar.id}
# cms = CourseMessage.where("course_message_type =? and user_id =? and course_message_id in (#{ar_ids.empty? ? '0': ar_ids.join(',')})", "ApplyResource", User.current.id)
@ -341,6 +342,7 @@ class FilesController < ApplicationController
render :layout => 'base_projects'
elsif params[:course_id]
set_nav_status(NavStatues::COURSE)
@container_type = 1
@page = params[:page] ? params[:page].to_i + 1 : 2
if params[:sort]

View File

@ -8,6 +8,14 @@ class ForumsController < ApplicationController
before_filter :authenticate_user_edit, :only => [:edit, :update]
before_filter :authenticate_user_destroy, :only => [:destroy]
before_filter :require_login, :only => [:new, :create,:destroy,:update,:edit]
before_filter do
set_nav_status(NavStatues::FORNUM)
end
before_filter :only => :show do |controller|
controller.instance_eval do
end
end
helper :sort
include SortHelper
@ -413,4 +421,4 @@ class ForumsController < ApplicationController
find_forum_if_available
render_403 unless @forum.destroyable_by? User.current
end
end
end

View File

@ -34,6 +34,7 @@ class GanttsController < ApplicationController
def show
# 控制顶部导航样式
@project_menu_type = 9
set_nav_status(NavStatues::PROJECT)
@gantt = Redmine::Helpers::Gantt.new(params)
@gantt.project = @project

View File

@ -13,6 +13,9 @@ class HomeworkCommonController < ApplicationController
:start_evaluation_set,:set_evaluation_attr,:score_rule_set,:alert_forbidden_anonymous_comment,:alert_open_student_works,
:open_student_works,:add_to_homework_bank,:publish_homework]
before_filter :member_of_course, :only => [:index]
before_filter :only => [:index] do |controller|
set_nav_status(NavStatues::COURSE)
end
def index
#unless params[:page]

View File

@ -32,6 +32,9 @@ class IssuesController < ApplicationController
before_filter :build_new_issue_from_params, :only => [:new, :create, :update_form]
accept_rss_auth :index, :show
accept_api_auth :index, :show, :create, :update, :destroy
before_filter :only => [:index, :show, :new, :edit] do |controller|
set_nav_status(NavStatues::PROJECT)
end
rescue_from Query::StatementInvalid, :with => :query_statement_invalid

View File

@ -6,7 +6,10 @@ class MemosController < ApplicationController
before_filter :authenticate_user_edit, :only => [:edit, :update]
before_filter :authenticate_user_destroy, :only => [:destroy]
before_filter :require_login, :only => [:new, :create]
before_filter :only => [:new, :show, :edit] do
set_nav_status(NavStatues::FORNUM)
end
helper :attachments
include AttachmentsHelper
include ApplicationHelper
@ -39,7 +42,7 @@ class MemosController < ApplicationController
format.json { render json: @memo }
end
end
def create
if params[:quote].nil?
@quote = ""
@ -85,7 +88,7 @@ class MemosController < ApplicationController
end
end
end
REPLIES_PER_PAGE = 20 unless const_defined?(:REPLIES_PER_PAGE)
def show
# 更新贴吧帖子留言对应的memo_messages的viewed字段
@ -137,7 +140,7 @@ class MemosController < ApplicationController
@my_topic_count = 0
@my_replies_count = Memo.where(:parent_id => @memo.id).count
respond_to do |format|
format.js
format.html {render :layout => 'base_new_forum'}

View File

@ -29,6 +29,9 @@ class NewsController < ApplicationController
before_filter :find_optional_project, :only => :index
accept_rss_auth :index
accept_api_auth :index
before_filter :only => [:index] do |controller|
set_nav_status(NavStatues::COURSE)
end
helper :watchers
helper :attachments

View File

@ -8,6 +8,7 @@ class PollController < ApplicationController
include PollHelper
def index
if @course
set_nav_status(NavStatues::COURSE)
@is_teacher = User.current.allowed_to?(:as_teacher,@course)
if @is_teacher
remove_invalid_poll(@course)
@ -113,18 +114,18 @@ class PollController < ApplicationController
def statistics_result
@poll = Poll.find(params[:id])
poll_questions = @poll.poll_questions
poll_questions = @poll.poll_questions
@poll_questions = paginateHelper poll_questions, 5
@left_nav_type = 7
respond_to do |format|
format.html{render :layout => 'base_courses'}
end
end
def get_poll_totalcount poll_question
@total_questions_count = poll_question.poll_votes.count
end
def get_poll_everycount poll_answer
@every_answer_count = poll_answer.poll_votes.count
end
@ -818,4 +819,4 @@ class PollController < ApplicationController
book.write xls_report
xls_report.string
end
end
end

View File

@ -36,6 +36,9 @@ class ProjectsController < ApplicationController
before_filter :require_admin, :only => [ :copy, :unarchive, :calendar]
before_filter :require_admin_or_manager, :only => [ :destroy]
before_filter :file
before_filter :only => [:new, :show, :settings] do |controller|
set_nav_status(NavStatues::PROJECT)
end
# 除非项目内人员,不可查看成员, TODO: 完了写报表里去

View File

@ -22,6 +22,7 @@ class PullRequestsController < ApplicationController
def index
# project_menu_type 为了控制base顶部导航
@project_menu_type = 6
set_nav_status(NavStatues::PROJECT)
# 不符合pullrequest条件的给出提示
@allow_to_pull_request = allow_pull_request(@project) > 0

View File

@ -528,6 +528,7 @@ update
def show
# 顶部导航
@project_menu_type = 5
set_nav_status(NavStatues::PROJECT)
# TODO: the below will move to filter, done.
# 获取版本库目录结构

View File

@ -10,6 +10,10 @@ class StatisticsController < ApplicationController
before_filter :require_login
before_filter :find_statistic, :only => [:show, :edit, :update, :destroy]
before_filter :require_manager, :only =>[:edit, :update, :destroy]
before_filter :only => [:index, :new, :show, :edit] do
set_nav_status(NavStatues::STATISTIC)
end
if RUBY_PLATFORM =~ /linux/
require 'simple_xlsx_reader'
end
@ -181,7 +185,7 @@ class StatisticsController < ApplicationController
if @statistic.file_size.nil? && @statistic.attachments.count > 0
@statistic.update_attribute('file_size', format("%0.3f", @statistic.attachments.map{|c| c.filesize}.sum.to_f/(1024*1024)))
end
format.html { redirect_to @statistic, notice: '更新成功' }
format.json { head :no_content }
else

View File

@ -57,6 +57,18 @@ class UsersController < ApplicationController
#visitor
before_filter :recorded_visitor, :only => [:show,:user_fanslist,:user_watchlist,:user_visitorlist]
before_filter :only => [:user_contestlist, :contest_community] do
set_nav_status(NavStatues::COMPETION)
end
before_filter :only => [:projects_list, :new, :user_receive_issues, :user_manage_issues] do
set_nav_status(NavStatues::PROJECT)
end
before_filter :only => [:course_community] do
set_nav_status(NavStatues::COURSE)
end
helper :sort
helper :attachments
include SortHelper
@ -2035,6 +2047,7 @@ class UsersController < ApplicationController
end
def show
set_nav_status(NavStatues::HOME)
# @user_projects = @user.projects.order("updated_on desc")
messages_all = @user.project_relate_messages
@limit = 20

View File

@ -34,6 +34,7 @@ class VersionsController < ApplicationController
def index
# 顶部导航
@project_menu_type = 7
set_nav_status(NavStatues::PROJECT)
type = params[:type]
case type
when nil,"1"

View File

@ -6,6 +6,9 @@ class WorksController < ApplicationController
:set_score_rule]
before_filter :admin_of_contest, :only => [:new, :create, :edit, :update, :destroy,:score_rule_set,:open_contestant_works]
before_filter :member_of_contest, :only => [:index]
before_filter :only => [:index] do
set_nav_status(NavStatues::COMPETION)
end
def index
search = "%#{params[:search].to_s.strip.downcase}%"

View File

@ -3,36 +3,36 @@
<%=link_to image_tag("../images/logo_blue.png", width:"51px", height: "45px",class: "mt3"), homes_path %>
</div>
<div class="fl">
<ul>
<li class="navHomepageMenu fl">
<ul id="nav_top">
<li class="navHomepageMenu fl <%= 'active' if @active == NavStatues::HOME %>">
<%= link_to "首页", user_activities_path(User.current), :class => "color-grey3 f16 db p10", :title => "回到个人首页" %>
</li>
<% if !hidden_unproject_infos %>
<li class="navHomepageMenu fl">
<%= link_to "资源库", user_resource_user_path(User.current, :type => 1), :class => "color-grey3 f16 db p10", :target => "_blank" %>
<li class="navHomepageMenu fl <%= 'active' if @active == NavStatues::FORNUM %>">
<%= link_to "资源库", user_resource_user_path(User.current, :type => 1), :class => "color-grey3 f16 db p10" %>
</li>
<% end %>
<% if hidden_unproject_infos %>
<li class="navHomepageMenu fl">
<%= link_to "课程", user_course_community_path(User.current), :class => "color-grey3 f16 db p10", :target => "_blank" %>
<li class="navHomepageMenu fl <%= 'active' if @active == NavStatues::COURSE %>">
<%= link_to "课程", user_course_community_path(User.current), :class => "color-grey3 f16 db p10" %>
</li>
<% end %>
<li class="navHomepageMenu fl">
<%= link_to "项目", user_project_community_path(User.current), :class => "color-grey3 f16 db p10", :target => "_blank" %>
<li class="navHomepageMenu fl <%= 'active' if @active == NavStatues::PROJECT %>">
<%= link_to "项目", user_project_community_path(User.current), :class => "color-grey3 f16 db p10" %>
</li>
<li class="navHomepageMenu fl">
<%= link_to "数据", statistics_path, :class => "color-grey3 f16 db p10", :target => "_blank" %>
<li class="navHomepageMenu fl <%= 'active' if @active == NavStatues::STATISTIC %>">
<%= link_to "数据", statistics_path, :class => "color-grey3 f16 db p10" %>
</li>
<% if hidden_unproject_infos %>
<li class="navHomepageMenu fl">
<%= link_to "竞赛", user_contest_community_path(User.current), :class => "color-grey3 f16 db p10", :target => "_blank" %>
<li class="navHomepageMenu fl <%= 'active' if @active == NavStatues::COMPETION %>">
<%= link_to "竞赛", user_contest_community_path(User.current), :class => "color-grey3 f16 db p10" %>
</li>
<% end %>
<li class="navHomepageMenu fl mr20">
<%= link_to "问吧", forums_path, :class =>"color-grey3 f16 db p10", :target => "_blank" %>
<li class="navHomepageMenu fl mr20 <%= 'active' if @active == NavStatues::FORNUM %>">
<%= link_to "问吧", forums_path, :class =>"color-grey3 f16 db p10" %>
</li>
</ul>
@ -165,4 +165,47 @@
{}
);
}
var list = document.querySelector('ul');
list.addEventListener('click', function(ev) {
if( ev.target.tagName === 'LI') {
console.log(ev.target.tagName)
ev.target.classList.add('active');
}
}, false);
$(function(){
var list = document.querySelector('ul');
list.addEventListener('click', function(ev) {
if( ev.target.tagName === 'LI') {
console.log(ev.target.tagName)
ev.target.classList.add('active');
}
}, false);
alert("pp")
})
$(document).ready(function(){
alert("f")
console.log("------")
}
function js(id) {
return document.getElementById(id).getElementsByTagName("li");
}
for(var i=0;i<js("nav_top").length;i++) {
alert(i)
js("nav_top")[i].οnclick=function(){
alert(i)
delBackgroundColor();
this.classList.add("active");
}
}
function delBackgroundColor() {
for(var i=0;i<js("nav_top").length;i++) {
js("nav_top")[i].classList.remove("active");
}
}
</script>

View File

@ -0,0 +1,8 @@
module NavStatues
FORNUM = 'fornum' # 问吧
HOME = 'home' # 首页
COURSE = 'course' # 课程
PROJECT = 'project' # 项目
STATISTIC = 'statistic' # 数据
COMPETION = 'competion' #竞赛
end