From 36a11d9690224c9fb90b1e3da61ef06e7dea9f96 Mon Sep 17 00:00:00 2001 From: Jasder <2053003901@@qq.com> Date: Tue, 12 Nov 2019 10:20:26 +0800 Subject: [PATCH] ADD trustie home edit --- app/controllers/admin_controller.rb | 21 +++++++++++++++++++ app/helpers/homes_helper.rb | 7 ++++++- app/views/admin/home.html.erb | 32 +++++++++++++++++++++++++++++ config/locales/zh.yml | 1 + config/routes.rb | 1 + lib/redmine.rb | 2 +- 6 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 app/views/admin/home.html.erb diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index c9baa13ba..540cb9431 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -527,6 +527,27 @@ class AdminController < ApplicationController end end + def home + if request.get? + @home = Home.first + elsif request.post? + @home = Home.first || Home.new + @home.name = params[:home][:name] + @home.content = params[:home][:content] + if @home.save + respond_to do |format| + flash[:notice] = l(:notice_successful_update) + format.html { redirect_to admin_home_path } + end + else + respond_to do |format| + flash.now[:error] = "#{l :label_first_page_create_fail}: #{@home.errors.full_messages[0]}" + format.html { render :action => 'home' } + end + end + end + end + def course_page_made if request.get? @course_page = FirstPage.find_by_page_type('course') diff --git a/app/helpers/homes_helper.rb b/app/helpers/homes_helper.rb index a26170f93..5a1a0ec1c 100644 --- a/app/helpers/homes_helper.rb +++ b/app/helpers/homes_helper.rb @@ -1,7 +1,12 @@ module HomesHelper def home_cover_tag(home) - file_path = home&.cover&.file.nil? ? "/images/introduce/activeBanner.jpg": local_path(home.cover.file) + file_path = + if File.exists?(Rails.root.join('/public/images', url_to_avatar(home))) + url_to_avatar(home) + else + "/images/introduce/activeBanner.jpg" + end image_tag(file_path, class: 'mb30', width: '592px') end diff --git a/app/views/admin/home.html.erb b/app/views/admin/home.html.erb new file mode 100644 index 000000000..619f58d32 --- /dev/null +++ b/app/views/admin/home.html.erb @@ -0,0 +1,32 @@ +

trustie首页

+ +
+
+<%= form_tag(:controller => 'admin', :action => 'home') do %> +

首页定制

+

+ +

+
+ <%= render :partial=>"avatar/avatar_form",:style => "display:inline",:locals=> {source: @home} %> +
+ +

+ + <%= text_field_tag 'home[name]', params[:name], :value => @home&.name, :style => "font-size:small;width:490px;margin-left:10px;" %> +

+ +

+ + + <%= text_area 'home', 'content', :value => @home.content,:cols => 80, :rows => 15, :class => 'wiki-edit' %> + <%= wikitoolbar_for 'home_content' %> +

+ + + <%= submit_tag l(:button_save), :class => "small", :name => nil %> +<% end %> diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 513aba59c..758ca7437 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -2204,6 +2204,7 @@ zh: # 动态消息 label_dynamic_new: 新建动态新闻 label_dynamic_new_plural: 首页动态新闻列表 + label_trustie_home: trustie首页 label_dynamic_new_title: 标题 label_dynamic_new_synopsis: 简介 label_new_dynamic_new: '动态新闻' diff --git a/config/routes.rb b/config/routes.rb index 14e130802..94bc5fa48 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1380,6 +1380,7 @@ RedmineApp::Application.routes.draw do post 'admin/select_course_syllabus' post 'admin/create_syllabus' match 'admin/dynamic_news', :via => [:get, :post] + match 'admin/home', :via => [:get, :post] resources :auth_sources do member do diff --git a/lib/redmine.rb b/lib/redmine.rb index ad184368a..9ddb21e7b 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -376,6 +376,7 @@ Redmine::MenuManager.map :homework_menu do |menu| end ########end Redmine::MenuManager.map :admin_menu do |menu| + menu.push :home, {:controller => 'admin',:action => 'home'}, :caption => :label_trustie_home menu.push :organization, {:controller => 'admin', :action => 'organization'}, :caption => :label_organization_list menu.push :projects, {:controller => 'admin', :action => 'projects'}, :caption => :label_project_plural menu.push :syllabuses, {:controller => 'admin', :action => 'syllabuses'}, :caption => :label_course_all @@ -387,7 +388,6 @@ Redmine::MenuManager.map :admin_menu do |menu| menu.push :schools, {:controller => 'admin', :action => 'schools'}, :caption => :label_school_plural menu.push :applied_schools, {:controller => 'admin', :action => 'applied_schools'}, :caption => :label_applied_shcools menu.push :first_page_made, {:controller => 'admin',:action => 'first_page_made'},:caption => :label_first_page_made - menu.push :dynamic_news, {:controller => 'admin',:action => 'dynamic_news'},:caption => :label_dynamic_new_plural menu.push :mobile_version, {:controller => 'admin',:action => 'mobile_version'},:caption => :label_mobile_version menu.push :groups, {:controller => 'groups'}, :caption => :label_group_plural menu.push :roles, {:controller => 'roles'}, :caption => :label_role_and_permissions