Merge branch 'dev_jupyter' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_jupyter

chromesetting
杨树林 5 years ago
commit e222538b9b

@ -365,12 +365,7 @@ class ShixunsController < ApplicationController
end
def create
begin
@shixun = CreateShixunService.call(current_user, shixun_params, params)
rescue Exception => e
logger_error("shixun_create_error: #{e.message}")
tip_exception("创建实训失败!")
end
@shixun = CreateShixunService.call(current_user, shixun_params, params)
end
# 保存jupyter到版本库

@ -1,8 +1,6 @@
class ShixunInfo < ApplicationRecord
belongs_to :shixun
validates_uniqueness_of :shixun_id
validates_presence_of :shixun_id, :description
after_commit :create_diff_record
private

@ -14,34 +14,39 @@ class CreateShixunService < ApplicationService
shixun.user_id = user.id
main_mirror = MirrorRepository.find params[:main_type]
sub_mirrors = MirrorRepository.where(id: params[:sub_type])
ActiveRecord::Base.transaction do
shixun.save!
# 获取脚本内容
shixun_script = get_shixun_script(shixun, main_mirror, sub_mirrors)
# 创建额外信息
ShixunInfo.create!(shixun_id: shixun.id, evaluate_script: shixun_script, description: params[:description])
# 创建合作者
shixun.shixun_members.create!(user_id: user.id, role: 1)
# 创建镜像
ShixunMirrorRepository.create!(:shixun_id => shixun.id, :mirror_repository_id => main_mirror.id)
# 创建主服务配置
ShixunServiceConfig.create!(:shixun_id => shixun.id, :mirror_repository_id => main_mirror.id)
# 创建子镜像相关数据(实训镜像关联表,子镜像服务配置)
sub_mirrors.each do |sub|
ShixunMirrorRepository.create!(:shixun_id => shixun.id, :mirror_repository_id => sub.id)
# 实训子镜像服务配置
name = sub.name #查看镜像是否有名称,如果没有名称就不用服务配置
ShixunServiceConfig.create!(:shixun_id => shixun.id, :mirror_repository_id => sub.id) if name.present?
end
# 创建版本库
repo_path = repo_namespace(user.login, shixun.identifier)
GitService.add_repository(repo_path: repo_path)
shixun.update_column(:repo_name, repo_path.split(".")[0])
# 如果是云上实验室,创建相关记录
if !Laboratory.current.main_site?
Laboratory.current.laboratory_shixuns.create!(shixun: shixun, ownership: true)
begin
ActiveRecord::Base.transaction do
shixun.save!
# 获取脚本内容
shixun_script = get_shixun_script(shixun, main_mirror, sub_mirrors)
# 创建额外信息
ShixunInfo.create!(shixun_id: shixun.id, evaluate_script: shixun_script, description: params[:description])
# 创建合作者
shixun.shixun_members.create!(user_id: user.id, role: 1)
# 创建镜像
ShixunMirrorRepository.create!(:shixun_id => shixun.id, :mirror_repository_id => main_mirror.id)
# 创建主服务配置
ShixunServiceConfig.create!(:shixun_id => shixun.id, :mirror_repository_id => main_mirror.id)
# 创建子镜像相关数据(实训镜像关联表,子镜像服务配置)
sub_mirrors.each do |sub|
ShixunMirrorRepository.create!(:shixun_id => shixun.id, :mirror_repository_id => sub.id)
# 实训子镜像服务配置
name = sub.name #查看镜像是否有名称,如果没有名称就不用服务配置
ShixunServiceConfig.create!(:shixun_id => shixun.id, :mirror_repository_id => sub.id) if name.present?
end
# 创建版本库
repo_path = repo_namespace(user.login, shixun.identifier)
GitService.add_repository(repo_path: repo_path)
shixun.update_column(:repo_name, repo_path.split(".")[0])
# 如果是云上实验室,创建相关记录
if !Laboratory.current.main_site?
Laboratory.current.laboratory_shixuns.create!(shixun: shixun, ownership: true)
end
return shixun
end
return shixun
rescue => e
Rails.logger.error("shixun_create_error: #{e.message}")
raise("创建实训失败!")
end
end

@ -35,7 +35,7 @@ class Bottomsubmit extends Component {
<span> </span></button>
<Button type="button" className="ant-btn newshixunmode mr40 ant-btn-primary" type="primary"
htmlType="submit" onClick={() => this.props.onSubmits()}
loading={this.props.loadings}><span> </span></Button>
loading={this.props.loadings}><span>{this.props.bottomvalue===undefined?"确 定":this.props.bottomvalue}</span></Button>
</div>
</div>
</div>

@ -69,14 +69,14 @@ export default class Shixuninformation extends Component {
}
componentDidMount() {
if (this.props.data) {
if (this.props.data.shixun) {
this.setState({
can_copy: this.props.data && this.props.data.shixun.can_copy === undefined ? false : this.props.data.shixun.can_copy,
use_scope: this.props.data && this.props.data.shixun.use_scope,
opening_time: this.props.data && this.props.data.shixun.opening_time,
opentime: !this.props.data && this.props.data.shixun.opening_time ? false : true,
oldscope_partment: this.props.data && this.props.data.shixun.scope_partment,
can_copy:this.props.data.shixun && this.props.data.shixun.can_copy === undefined ? false : this.props.data.shixun&&this.props.data.shixun.can_copy,
use_scope: this.props.data.shixun && this.props.data.shixun.use_scope,
opening_time: this.props.data.shixun && this.props.data.shixun.opening_time,
opentime: !this.props.data.shixun && this.props.data.shixun.opening_time ? false : true,
oldscope_partment:this.props.data.shixun && this.props.data.shixun.scope_partment,
})
}
@ -100,11 +100,11 @@ export default class Shixuninformation extends Component {
if (this.props.data) {
this.setState({
can_copy: this.props.data && this.props.data.shixun.can_copy === undefined ? false : this.props.data.shixun.can_copy,
use_scope: this.props.data && this.props.data.shixun.use_scope,
opening_time: this.props.data && this.props.data.shixun.opening_time,
opentime: !this.props.data && this.props.data.shixun.opening_time ? false : true,
oldscope_partment: this.props.data && this.props.data.shixun.scope_partment,
can_copy: this.props.data.shixun && this.props.data.shixun.can_copy === undefined ? false : this.props.data.shixun&&this.props.data.shixun.can_copy,
use_scope: this.props.data.shixun&& this.props.data.shixun.use_scope,
opening_time: this.props.data.shixun && this.props.data.shixun.opening_time,
opentime: !this.props.data.shixun && this.props.data.shixun.opening_time ? false : true,
oldscope_partment: this.props.data.shixun && this.props.data.shixun.scope_partment,
})
}
@ -138,7 +138,7 @@ export default class Shixuninformation extends Component {
if (response.data.status === -1) {
} else {
this.props.getdatas()
this.props.getdatas("3")
this.props.showNotification("权限配置保存成功!")
this.setState({
loading: false
@ -249,7 +249,7 @@ export default class Shixuninformation extends Component {
return (
<div>
<div className="educontent mb200 edu-back-white padding10-20 pdb30">
<div className="educontent mb200 edu-back-white padding10-20 pdb30 mb50">
<div className="clearfix ml40">
<span className="color-grey-6 mt5 fl font-16 ml20" style={{minWidth: '45px'}}>复制:</span>
<span className="fl mt8 ml13">
@ -261,7 +261,7 @@ export default class Shixuninformation extends Component {
</div>
<div className="edu-back-white mb10 ml30 mt20">
{this.props.data && this.props.data.shixun.use_scope === 0 && this.props.data && this.props.data.shixun.status === 2 ? "" :
{this.props.data.shixun && this.props.data.shixun.use_scope === 0 && this.props.data.shixun && this.props.data.shixun.status === 2 ? "" :
<div>
<span className="color-grey-6 mt5 fl font-16" style={{minWidth: '45px'}}>公开程度:</span>
<span className="fl mt8 ml20">
@ -375,7 +375,7 @@ export default class Shixuninformation extends Component {
</div>
{this.props.identity < 5 ?
<Bottomsubmit {...this.props} {...this.state} url={`/shixuns/${this.props.match.params.shixunId}/challenges`}
onSubmits={this.onSubmits} loadings={this.state.loading}/> : ""}
onSubmits={this.onSubmits} loadings={this.state.loading} bottomvalue={ this.props.shixunsDetails&&this.props.shixunsDetails.is_jupyter === true?"确 定":"下一步"} /> : ""}
</div>
);
}

@ -34,7 +34,7 @@ export default class Shixuninformation extends Component {
componentDidMount() {
if (this.props.data) {
if (this.props.data.shixun) {
this.setState({
vnc: this.props.data && this.props.data.shixun.vnc,
@ -225,7 +225,7 @@ export default class Shixuninformation extends Component {
console.log(this.props)
return (
<div>
<div className="educontent mb200 edu-back-white padding10-20 pdb30">
<div className="educontent mb200 edu-back-white padding10-20 pdb30 mb50">
{this.state.websshshow === true ? "" : <div className="clearfix mb20">
<span className="color-grey-6 mt5 fl font-16" style={{minWidth: '45px'}}>开启图形化界面</span>

@ -45,7 +45,7 @@ class Shixuninformation extends Component {
Compilecommandvalue: "",
shixun_service_configs: undefined,
fileList:[],
loading:false
loading:false,
}
}
@ -57,35 +57,35 @@ class Shixuninformation extends Component {
if (prevProps.data != this.props.data) {
if (this.props.data) {
this.setState({
shixunName: this.props.data.shixun.name,
trainee: this.props.data.shixun.trainee,
choice_main_type: this.props.data.shixun.choice_main_type,
choice_small_type: this.props.data.shixun.choice_small_type,
choice_standard_scripts: this.props.data.shixun.choice_standard_scripts,
shixunmemoMDvalue: this.props.data.shixun.evaluate_script,
simichecked: this.props.data.shixun.is_secret_repository,
shixun_service_configs: this.props.data.shixun.shixun_service_configs,
standard_scripts:this.props.data.shixun.standard_scripts,
shixun_service_configlist:this.props.data.shixun.shixun_service_configs,
shixunName: this.props.data.shixun&&this.props.data.shixun.name,
trainee:this.props.data.shixun&&this.props.data.shixun.trainee,
choice_main_type: this.props.data.shixun&&this.props.data.shixun.choice_main_type,
choice_small_type: this.props.data.shixun&&this.props.data.shixun.choice_small_type,
choice_standard_scripts:this.props.data.shixun&&this.props.data.shixun.choice_standard_scripts,
shixunmemoMDvalue: this.props.data.shixun&&this.props.data.shixun.evaluate_script,
simichecked: this.props.data.shixun&&this.props.data.shixun.is_secret_repository,
shixun_service_configs: this.props.data.shixun&&this.props.data.shixun.shixun_service_configs,
standard_scripts:this.props.data.shixun&&this.props.data.shixun.standard_scripts,
shixun_service_configlist:this.props.data.shixun&&this.props.data.shixun.shixun_service_configs,
})
if(this.props.data.shixun.choice_standard_scripts===null){
if(this.props.data.shixun&&this.props.data.shixun.choice_standard_scripts===null){
this.setState({
choice_standard_scripts:{id: this.props.data.shixun.standard_scripts[0].id, value: ""},
choice_standard_scriptssum:this.props.data.shixun.standard_scripts[0].id
choice_standard_scripts:{id: this.props.data.shixun&&this.props.data.shixun.standard_scripts[0].id, value: ""},
choice_standard_scriptssum:this.props.data.shixun&&this.props.data.shixun.standard_scripts[0].id
})
this.props.form.setFieldsValue({
selectscripts:this.props.data.shixun.standard_scripts[0].id
selectscripts:this.props.data.shixun&&this.props.data.shixun.standard_scripts[0].id
})
this.get_mirror_script(this.props.data.shixun.standard_scripts[0].id)
this.get_mirror_script(this.props.data.shixun&&this.props.data.shixun.standard_scripts[0].id)
}else{
this.props.form.setFieldsValue({
selectscripts:this.props.data.shixun.choice_standard_scripts
selectscripts:this.props.data.shixun&&this.props.data.shixun.choice_standard_scripts
})
}
let newlist = ""
this.props.data.shixun.choice_small_type.map((item, key) => {
this.props.data.shixun&&this.props.data.shixun.choice_small_type.map((item, key) => {
this.props.data.shixun.small_type.map((i,k)=>{
if (item===i.id) {
newlist = newlist + `${i.description}`
@ -96,8 +96,8 @@ class Shixuninformation extends Component {
subvalues: newlist
})
this.props.data.shixun.main_type.map((item,key)=>{
if(item.id===this.props.data.shixun.choice_main_type){
this.props.data.shixun&&this.props.data.shixun.main_type.map((item,key)=>{
if(item.id===this.props.data.shixun&&this.props.data.shixun.choice_main_type){
this.setState({
mainvalues:item.description,
})
@ -105,12 +105,12 @@ class Shixuninformation extends Component {
})
this.props.form.setFieldsValue({
name: this.props.data.shixun.name,
trainee: this.props.data.shixun.trainee,
selectleft: this.props.data.shixun.choice_main_type,
selectright:this.props.data.shixun.choice_small_type,
name:this.props.data.shixun&&this.props.data.shixun.name,
trainee: this.props.data.shixun&&this.props.data.shixun.trainee,
selectleft: this.props.data.shixun&&this.props.data.shixun.choice_main_type,
selectright:this.props.data.shixun&&this.props.data.shixun.choice_small_type,
})
this.contentMdRef.current.setValue(this.props.data.shixun.description);
this.contentMdRef.current.setValue(this.props.data.shixun&&this.props.data.shixun.description);
}
}
}
@ -681,7 +681,7 @@ class Shixuninformation extends Component {
axios.put(url, data).then((result) => {
if (result) {
if (result.data) {
this.props.getdatas()
this.props.getdatas("2")
if(result.data.shixun_identifier){
this.props.showNotification("基本信息更新成功!")
this.setState({
@ -838,7 +838,7 @@ class Shixuninformation extends Component {
>
{
this.props.data === undefined ? "" : this.props.data.shixun.main_type.map((item, key) => {
this.props.data === undefined ? "" : this.props.data.shixun&&this.props.data.shixun.main_type.map((item, key) => {
return (
<Option value={item.id} key={key} name={item.description}>
<Tooltip placement="right" title={item.description === "" ? "无描述" : item.description}>
@ -867,7 +867,7 @@ class Shixuninformation extends Component {
<div className=" fl pr mr20">
<Select placeholder="请选择小类别"
mode="multiple"
value={this.state.choice_small_type.length === 0 || this.state.choice_small_type[0] === "" || this.state.choice_small_type === [] ? undefined : this.state.choice_small_type}
value={!this.state.choice_small_type?undefined:this.state.choice_small_type.length === 0 || this.state.choice_small_type[0] === "" || this.state.choice_small_type === [] ? undefined : this.state.choice_small_type}
style={{width: 200}}
disabled={operateauthority ? false : true}
onDeselect={operateauthority ? this.Deselectlittle : ""}
@ -876,7 +876,7 @@ class Shixuninformation extends Component {
defaultOpen={false}
>
{
this.props.data === undefined ? "" : this.props.data.shixun.small_type.map((item, key) => {
this.props.data === undefined ? "" : this.props.data.shixun&&this.props.data.shixun.small_type.map((item, key) => {
return (
<Option value={item.id} key={key} name={item.description}>
<Tooltip placement="right" title={item.description === "" ? "无描述" : item.description}>
@ -1251,7 +1251,7 @@ class Shixuninformation extends Component {
</div>
{this.props.identity < 5 ?
<Bottomsubmit {...this.props} {...this.state} url={`/shixuns/${this.props.match.params.shixunId}/challenges`}
onSubmits={this.onSubmits} loadings={this.state.loading} /> : ""}
onSubmits={this.onSubmits} loadings={this.state.loading} bottomvalue={"下一步"} /> : ""}
</div>
);

@ -24,42 +24,51 @@ const {TabPane} = Tabs;
export default class TPMsettings extends Component {
constructor(props) {
super(props)
this.state = {}
this.state = {
activeKeys:"1"
}
}
componentDidMount() {
this.getdatas()
this.getdatas("1")
}
getdatas = () => {
getdatas = (key) => {
let id = this.props.match.params.shixunId;
let Url = `/shixuns/` + id + `/settings.json`;
axios.get(Url).then((response) => {
// alert(response.data.shixun.choice_standard_scripts)
if (response.status === 200) {
this.setState({
data: response.data
})
if (response.data.shixun.multi_webssh === true) {
this.setState({
SelectTheCommandtype: true
})
} else {
this.setState({
SelectTheCommandtype: false
})
}
if (response.data.shixun.scope_partment.length > 0) {
this.setState({
scopetype: true
})
}
}
});
if(key==="3"&&this.props.shixunsDetails&&this.props.shixunsDetails.is_jupyter === true){
this.props.history.replace(`/shixuns/${this.props.match.params.shixunId}/challenges`);
}else{
if(key){
this.setState({
activeKeys:key
})
}else{
this.props.history.replace(`/shixuns/${this.props.match.params.shixunId}/challenges`);
}
}
}
operateshixuns = (value) => {
@ -111,6 +120,12 @@ export default class TPMsettings extends Component {
})
}
callback = (key) => {
this.setState({
activeKeys:key
})
}
render() {
let showtabs = this.props.shixunsDetails === undefined ? "" : this.props.shixunsDetails.is_jupyter === true ? "" : "学习页面设置"
@ -120,7 +135,7 @@ export default class TPMsettings extends Component {
// console.log(a.indexOf("vnc"))
// console.log(b.indexOf("vnc"))
console.log( this.props.shixunsDetails === undefined ? "" : this.props.shixunsDetails.is_jupyter === false ? "学习页面设置" : "")
// console.log( this.props.shixunsDetails === undefined ? "" : this.props.shixunsDetails.is_jupyter === false ? "学习页面设置" : "")
return (
<div>
@ -143,7 +158,8 @@ export default class TPMsettings extends Component {
`
}
</style>
<Tabs animated={false} tabBarExtraContent={
<Tabs activeKey={this.state.activeKeys} onChange={this.callback} animated={false} tabBarExtraContent={
<div className={"mb20 mr20"}>
{
@ -171,14 +187,14 @@ export default class TPMsettings extends Component {
<TopShixuninformation
{...this.state}
{...this.props}
getdatas={() => this.getdatas()}
getdatas={(key) => this.getdatas(key)}
/>
</TabPane>
<TabPane tab="权限配置" key="2">
<Configuration
{...this.state}
{...this.props}
getdatas={() => this.getdatas()}
getdatas={(key) => this.getdatas(key)}
/>
</TabPane>
{this.props.shixunsDetails === undefined ? "" : this.props.shixunsDetails.is_jupyter === false ?
@ -186,7 +202,7 @@ export default class TPMsettings extends Component {
<LearningSettings
{...this.state}
{...this.props}
getdatas={() => this.getdatas()}
getdatas={(key) => this.getdatas(key)}
/>
</TabPane>:"" }
</Tabs>

Loading…
Cancel
Save