diff --git a/app/controllers/libraries_controller.rb b/app/controllers/libraries_controller.rb index 8f54a0e82..a2e70d95a 100644 --- a/app/controllers/libraries_controller.rb +++ b/app/controllers/libraries_controller.rb @@ -2,7 +2,8 @@ class LibrariesController < ApplicationController include PaginateHelper before_action :require_login, :check_auth, except: %i[index show] - + before_action :check_account, except: %i[index show] + after_action :increment_visit_count, only: [:show, :edit, :update] helper_method :current_library, :library_manageable? def index @@ -80,6 +81,10 @@ class LibrariesController < ApplicationController current_user&.id == library.user_id || admin_or_business? end + def increment_visit_count + current_library.increment_visited_count! if current_library && current_library.id + end + def save_params params.permit(:title, :content, :author_name, :author_school_name, :cover_id, :publish, attachment_ids: [], tag_ids: []) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 07ad71ec1..3145636df 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -5,7 +5,6 @@ class ShixunsController < ApplicationController before_action :require_login, :check_auth, except: [:download_file, :index, :menus] before_action :check_account, only: [:new, :create, :shixun_exec] - before_action :check_auth, except: [:download_file, :index, :menus] before_action :find_shixun, :shixun_access_allowed, except: [:index, :new, :create, :menus, :get_recommend_shixuns, :propaedeutics, :departments, :apply_shixun_mirror, diff --git a/app/models/library.rb b/app/models/library.rb index 13a5c3243..3c7222140 100644 --- a/app/models/library.rb +++ b/app/models/library.rb @@ -34,6 +34,10 @@ class Library < ApplicationRecord end end + def increment_visited_count!(num = 1) + increment_column!(:visited_count, num) + end + def generate_uuid uuid = Util::UUID.time_uuid while Library.exists?(uuid: uuid) @@ -42,4 +46,10 @@ class Library < ApplicationRecord self.uuid = uuid end + + private + + def increment_column!(column, num = 1) + self.class.connection.execute("update #{self.class.table_name} set #{column} = COALESCE(#{column}, 0) + #{num} where id = #{id}") + end end \ No newline at end of file diff --git a/db/migrate/20190805010561_modify_ke_contents_for_markdown.rb b/db/migrate/20190805010562_modify_ke_contents_for_markdown.rb similarity index 58% rename from db/migrate/20190805010561_modify_ke_contents_for_markdown.rb rename to db/migrate/20190805010562_modify_ke_contents_for_markdown.rb index bd8ad915d..958b70448 100644 --- a/db/migrate/20190805010561_modify_ke_contents_for_markdown.rb +++ b/db/migrate/20190805010562_modify_ke_contents_for_markdown.rb @@ -1,13 +1,13 @@ class ModifyKeContentsForMarkdown < ActiveRecord::Migration[5.2] include ActionView::Helpers::SanitizeHelper def change - def ke_transform_to_md content - return content if content.blank? - s_contents = sanitize(content, tags: %w(img a table td tr tbody pre), attributes: %w(src href target style)) - s_contents.gsub(">\n<", "><").gsub(/^\n/, "").gsub(" ", "").gsub(/(\n)+/, "") - .gsub("\t", "").gsub(" ", " ").gsub("\n", "") - .gsub(/()+/, "") - end + # def ke_transform_to_md content + # return content if content.blank? + # s_contents = sanitize(content, tags: %w(img a table td tr tbody pre), attributes: %w(src href target style)) + # s_contents.gsub(">\n<", "><").gsub(/^\n/, "").gsub(" ", "").gsub(/(\n)+/, "") + # .gsub("\t", "").gsub("\n", "").gsub(" ", " ").gsub(/()+/, "") + # s_contents.gsub("\n", "").gsub(/()+/, "") + # end # # # 课程讨论区 # MessageDetail.find_each do |m| @@ -16,12 +16,12 @@ class ModifyKeContentsForMarkdown < ActiveRecord::Migration[5.2] # end #试卷的标题 - ExerciseQuestion.where(:exercise_id => 1890).find_each do |eq| - puts("#eq.question_title: #{eq.question_title}") - question_title = ke_transform_to_md eq.question_title - puts("#question_title: #{question_title}") - eq.update_column(:question_title, question_title) - end + # ExerciseQuestion.where(:exercise_id => 1892).find_each do |eq| + # puts("#eq.question_title: #{eq.question_title}") + # question_title = ke_transform_to_md eq.question_title + # puts("#question_title: #{question_title}") + # eq.update_column(:question_title, question_title) + # end # # 试卷的答案 # ExerciseStandardAnswer.find_each do |esa| diff --git a/public/editormd/lib/marked.min.js b/public/editormd/lib/marked.min.js index 636c21b01..519296797 100644 --- a/public/editormd/lib/marked.min.js +++ b/public/editormd/lib/marked.min.js @@ -2,6 +2,10 @@ * marked v0.3.3 - a markdown parser * Copyright (c) 2011-2014, Christopher Jeffrey. (MIT Licensed) * https://github.com/chjj/marked + + 备注,这个改动没启用,只是做个记录: + br不转成br + 加了个 if (cap[0] != '' && cap[0] != '') { out+=this.options.sanitize?escape(cap[0]):cap[0]; } */ (function(){var block={newline:/^\n+/,code:/^( {4}[^\n]+\n*)+/,fences:noop,hr:/^( *[-*_]){3,} *(?:\n+|$)/,heading:/^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,nptable:noop,lheading:/^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,blockquote:/^( *>[^\n]+(\n(?!def)[^\n]+)*\n*)+/,list:/^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,html:/^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/,def:/^ *\[([^\]]+)\]: *([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,table:noop,paragraph:/^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/,text:/^[^\n]+/};block.bullet=/(?:[*+-]|\d+\.)/;block.item=/^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/;block.item=replace(block.item,"gm")(/bull/g,block.bullet)();block.list=replace(block.list)(/bull/g,block.bullet)("hr","\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))")("def","\\n+(?="+block.def.source+")")();block.blockquote=replace(block.blockquote)("def",block.def)();block._tag="(?!(?:"+"a|em|strong|small|s|cite|q|dfn|abbr|data|time|code"+"|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo"+"|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|[^\\w\\s@]*@)\\b";block.html=replace(block.html)("comment",//)("closed",/<(tag)[\s\S]+?<\/\1>/)("closing",/])*?>/)(/tag/g,block._tag)();block.paragraph=replace(block.paragraph)("hr",block.hr)("heading",block.heading)("lheading",block.lheading)("blockquote",block.blockquote)("tag","<"+block._tag)("def",block.def)();block.normal=merge({},block);block.gfm=merge({},block.normal,{fences:/^ *(`{3,}|~{3,}) *(\S+)? *\n([\s\S]+?)\s*\1 *(?:\n+|$)/,paragraph:/^/});block.gfm.paragraph=replace(block.paragraph)("(?!","(?!"+block.gfm.fences.source.replace("\\1","\\2")+"|"+block.list.source.replace("\\1","\\3")+"|")();block.tables=merge({},block.gfm,{nptable:/^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/,table:/^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/});function Lexer(options){this.tokens=[];this.tokens.links={};this.options=options||marked.defaults;this.rules=block.normal;if(this.options.gfm){if(this.options.tables){this.rules=block.tables}else{this.rules=block.gfm}}}Lexer.rules=block;Lexer.lex=function(src,options){var lexer=new Lexer(options);return lexer.lex(src)};Lexer.prototype.lex=function(src){src=src.replace(/\r\n|\r/g,"\n").replace(/\t/g," ").replace(/\u00a0/g," ").replace(/\u2424/g,"\n");return this.token(src,true)};Lexer.prototype.token=function(src,top,bq){var src=src.replace(/^ +$/gm,""),next,loose,cap,bull,b,item,space,i,l;while(src){if(cap=this.rules.newline.exec(src)){src=src.substring(cap[0].length);if(cap[0].length>1){this.tokens.push({type:"space"})}}if(cap=this.rules.code.exec(src)){src=src.substring(cap[0].length);cap=cap[0].replace(/^ {4}/gm,"");this.tokens.push({type:"code",text:!this.options.pedantic?cap.replace(/\n+$/,""):cap});continue}if(cap=this.rules.fences.exec(src)){src=src.substring(cap[0].length);this.tokens.push({type:"code",lang:cap[2],text:cap[3]});continue}if(cap=this.rules.heading.exec(src)){src=src.substring(cap[0].length);this.tokens.push({type:"heading",depth:cap[1].length,text:cap[2]});continue}if(top&&(cap=this.rules.nptable.exec(src))){src=src.substring(cap[0].length);item={type:"table",header:cap[1].replace(/^ *| *\| *$/g,"").split(/ *\| */),align:cap[2].replace(/^ *|\| *$/g,"").split(/ *\| */),cells:cap[3].replace(/\n$/,"").split("\n")};for(i=0;i ?/gm,"");this.token(cap,top,true);this.tokens.push({type:"blockquote_end"});continue}if(cap=this.rules.list.exec(src)){src=src.substring(cap[0].length);bull=cap[2];this.tokens.push({type:"list_start",ordered:bull.length>1});cap=cap[0].match(this.rules.item);next=false;l=cap.length;i=0;for(;i1&&b.length>1)){src=cap.slice(i+1).join("\n")+src;i=l-1}}loose=next||/\n\n(?!\s*$)/.test(item);if(i!==l-1){next=item.charAt(item.length-1)==="\n";if(!loose){loose=next}}this.tokens.push({type:loose?"loose_item_start":"list_item_start"});this.token(item,false,bq); this.tokens.push({type:"list_item_end"})}this.tokens.push({type:"list_end"});continue}if(cap=this.rules.html.exec(src)){src=src.substring(cap[0].length);this.tokens.push({type:this.options.sanitize?"paragraph":"html",pre:cap[1]==="pre"||cap[1]==="script"||cap[1]==="style",text:cap[0]});continue}if((!bq&&top)&&(cap=this.rules.def.exec(src))){src=src.substring(cap[0].length);this.tokens.links[cap[1].toLowerCase()]={href:cap[2],title:cap[3]};continue}if(top&&(cap=this.rules.table.exec(src))){src=src.substring(cap[0].length);item={type:"table",header:cap[1].replace(/^ *| *\| *$/g,"").split(/ *\| */),align:cap[2].replace(/^ *|\| *$/g,"").split(/ *\| */),cells:cap[3].replace(/(?: *\| *)?\n$/,"").split("\n")};for(i=0;i])/,autolink:/^<([^ >]+(@|:\/)[^ >]+)>/,url:noop,tag:/^|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/,link:/^!?\[(inside)\]\(href\)/,reflink:/^!?\[(inside)\]\s*\[([^\]]*)\]/,nolink:/^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,strong:/^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,em:/^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,code:/^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,br:/^ {2,}\n(?!\s*$)/,del:noop,text:/^[\s\S]+?(?=[\\?(?:\s+['"]([\s\S]*?)['"])?\s*/;inline.link=replace(inline.link)("inside",inline._inside)("href",inline._href)();inline.reflink=replace(inline.reflink)("inside",inline._inside)();inline.normal=merge({},inline);inline.pedantic=merge({},inline.normal,{strong:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,em:/^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/});inline.gfm=merge({},inline.normal,{escape:replace(inline.escape)("])","~|])")(),url:/^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,del:/^~~(?=\S)([\s\S]*?\S)~~/,text:replace(inline.text)("]|","~]|")("|","|https?://|")()});inline.breaks=merge({},inline.gfm,{br:replace(inline.br)("{2,}","*")(),text:replace(inline.gfm.text)("{2,}","*")()});function InlineLexer(links,options){this.options=options||marked.defaults;this.links=links;this.rules=inline.normal;this.renderer=this.options.renderer||new Renderer;this.renderer.options=this.options;if(!this.links){throw new Error("Tokens array requires a `links` property.")}if(this.options.gfm){if(this.options.breaks){this.rules=inline.breaks}else{this.rules=inline.gfm}}else{if(this.options.pedantic){this.rules=inline.pedantic}}}InlineLexer.rules=inline;InlineLexer.output=function(src,links,options){var inline=new InlineLexer(links,options);return inline.output(src)};InlineLexer.prototype.output=function(src){var out="",link,text,href,cap;while(src){if(cap=this.rules.escape.exec(src)){src=src.substring(cap[0].length);out+=cap[1];continue}if(cap=this.rules.autolink.exec(src)){src=src.substring(cap[0].length);if(cap[2]==="@"){text=cap[1].charAt(6)===":"?this.mangle(cap[1].substring(7)):this.mangle(cap[1]);href=this.mangle("mailto:")+text}else{text=escape(cap[1]);href=text}out+=this.renderer.link(href,null,text);continue}if(!this.inLink&&(cap=this.rules.url.exec(src))){src=src.substring(cap[0].length);text=escape(cap[1]);href=text;out+=this.renderer.link(href,null,text);continue}if(cap=this.rules.tag.exec(src)){if(!this.inLink&&/^/i.test(cap[0])){this.inLink=false}}src=src.substring(cap[0].length);out+=this.options.sanitize?escape(cap[0]):cap[0];continue}if(cap=this.rules.link.exec(src)){src=src.substring(cap[0].length);this.inLink=true;out+=this.outputLink(cap,{href:cap[2],title:cap[3]});this.inLink=false;continue}if((cap=this.rules.reflink.exec(src))||(cap=this.rules.nolink.exec(src))){src=src.substring(cap[0].length);link=(cap[2]||cap[1]).replace(/\s+/g," ");link=this.links[link.toLowerCase()];if(!link||!link.href){out+=cap[0].charAt(0);src=cap[0].substring(1)+src;continue}this.inLink=true;out+=this.outputLink(cap,link);this.inLink=false;continue}if(cap=this.rules.strong.exec(src)){src=src.substring(cap[0].length);out+=this.renderer.strong(this.output(cap[2]||cap[1]));continue}if(cap=this.rules.em.exec(src)){src=src.substring(cap[0].length);out+=this.renderer.em(this.output(cap[2]||cap[1]));continue diff --git a/public/react/src/context/TPIContextProvider.js b/public/react/src/context/TPIContextProvider.js index 0f2f68a75..006c0af49 100644 --- a/public/react/src/context/TPIContextProvider.js +++ b/public/react/src/context/TPIContextProvider.js @@ -498,7 +498,7 @@ pop_box_new(htmlvalue, 480, 182); return resData } - fetchAll(stageId) { + fetchAll(stageId, noTimeout) { if (window.__fetchAllFlag == true ) { console.log('TPIContextProvider call fetchAll repeatly!') @@ -544,6 +544,13 @@ pop_box_new(htmlvalue, 480, 182); return; } if (response.data.status == 404) { + // 如果第一次发生404,则隔1s后再调用一次本接口;(因为ucloud主从同步可能有延迟) + if (!noTimeout) { + setTimeout(() => { + this.fetchAll(stageId, true) + }, 1000) + return; + } window.location.href = '/myshixuns/not_found' return; } diff --git a/public/react/src/modules/courses/coursesPublic/Addcourses.js b/public/react/src/modules/courses/coursesPublic/Addcourses.js index a9d30f2b6..8c9709fee 100644 --- a/public/react/src/modules/courses/coursesPublic/Addcourses.js +++ b/public/react/src/modules/courses/coursesPublic/Addcourses.js @@ -248,7 +248,7 @@ class Addcourses extends Component{ }else{ - notification.open({ + response.data.message && notification.open({ message:"提示", description:response.data.message }); diff --git a/public/react/src/modules/tpm/NewHeader.js b/public/react/src/modules/tpm/NewHeader.js index 56b386288..a35d3293a 100644 --- a/public/react/src/modules/tpm/NewHeader.js +++ b/public/react/src/modules/tpm/NewHeader.js @@ -659,8 +659,8 @@ submittojoinclass=(value)=>{ {AccountProfiletype===true?this.hideAccountProfile()} - {...this.state} {...this.props} + {...this.state} />:""} diff --git a/public/react/src/modules/tpm/TPMIndexHOC.js b/public/react/src/modules/tpm/TPMIndexHOC.js index 0361b090f..0b4f312e4 100644 --- a/public/react/src/modules/tpm/TPMIndexHOC.js +++ b/public/react/src/modules/tpm/TPMIndexHOC.js @@ -10,6 +10,8 @@ import axios from 'axios'; import './TPMIndex.css' import LoginDialog from '../login/LoginDialog'; +import AccountProfile from '../user/AccountProfile'; + import Trialapplication from "../login/Trialapplication"; // import "antd/dist/antd.css"; // import '../../css/educoder/edu-common.css' @@ -76,7 +78,8 @@ export function TPMIndexHOC(WrappedComponent) { Footerdown:undefined, coursedata: {}, - isRender: false + isRender: false, + AccountProfiletype: false } } @@ -300,11 +303,26 @@ export function TPMIndexHOC(WrappedComponent) { isRender: true }) } + checkIfLogin = () => { return this.state.current_user && this.state.current_user.login != '' } + + hideAccountProfile = () => { + this.setState({ + hideAccountProfile: false + }) + } + showProfileCompleteDialog = () => { + this.setState({ + hideAccountProfile: true + }) + } + checkIfProfileCompleted = () => { + return this.state.current_user && this.state.current_user.profile_completed + } render() { - let{Headertop,Footerdown, isRender}=this.state; + let{Headertop,Footerdown, isRender, AccountProfiletype}=this.state; const common = { isSuperAdmin:this.isSuperAdmin, isAdminOrCreator:this.isAdminOrCreator, @@ -319,6 +337,8 @@ export function TPMIndexHOC(WrappedComponent) { showLoginDialog: this.showLoginDialog, checkIfLogin: this.checkIfLogin, + showProfileCompleteDialog: this.showProfileCompleteDialog, + checkIfProfileCompleted: this.checkIfProfileCompleted, } return ( @@ -327,6 +347,11 @@ export function TPMIndexHOC(WrappedComponent) { {...this.state} {...this.props} /> : ""} + {AccountProfiletype===true ? this.hideAccountProfile()} + {...this.state} + {...this.props} + />:""} {/* 注释掉了1440 影响到了手机屏幕的展示 */}