@@ -46,6 +46,7 @@ type Attachment struct { | |||
CreatedUnix timeutil.TimeStamp `xorm:"created"` | |||
FileChunk *FileChunk `xorm:"-"` | |||
CanDel bool `xorm:"-"` | |||
} | |||
type AttachmentUsername struct { | |||
@@ -437,3 +438,29 @@ func getModelArtsUserAttachments(e Engine, userID int64) ([]*AttachmentUsername, | |||
func GetModelArtsUserAttachments(userID int64) ([]*AttachmentUsername, error) { | |||
return getModelArtsUserAttachments(x, userID) | |||
} | |||
func CanDelAttachment(isSigned bool, user *User, attach *Attachment) bool { | |||
if !isSigned { | |||
return false | |||
} | |||
dataset, err := GetDatasetByID(attach.DatasetID) | |||
if err != nil { | |||
log.Error("GetDatasetByID failed:%v", err.Error()) | |||
return false | |||
} | |||
repo, _ := GetRepositoryByID(dataset.RepoID) | |||
if err != nil { | |||
log.Error("GetRepositoryByID failed:%v", err.Error()) | |||
return false | |||
} | |||
permission, _ := GetUserRepoPermission(repo, user) | |||
if err != nil { | |||
log.Error("GetUserRepoPermission failed:%v", err.Error()) | |||
return false | |||
} | |||
if user.ID == attach.UploaderID || user.IsAdmin || permission.AccessMode >= AccessModeAdmin { | |||
return true | |||
} | |||
return false | |||
} |
@@ -196,11 +196,11 @@ func (s datasetMetaSearch) Less(i, j int) bool { | |||
return s.ID[i] < s.ID[j] | |||
} | |||
func GetDatasetAttachments(typeCloudBrain int, rels ...*Dataset) (err error) { | |||
return getDatasetAttachments(x, typeCloudBrain, rels...) | |||
func GetDatasetAttachments(typeCloudBrain int, isSigned bool, user *User, rels ...*Dataset) (err error) { | |||
return getDatasetAttachments(x, typeCloudBrain, isSigned, user, rels...) | |||
} | |||
func getDatasetAttachments(e Engine, typeCloudBrain int, rels ...*Dataset) (err error) { | |||
func getDatasetAttachments(e Engine, typeCloudBrain int, isSigned bool, user *User, rels ...*Dataset) (err error) { | |||
if len(rels) == 0 { | |||
return | |||
} | |||
@@ -243,6 +243,7 @@ func getDatasetAttachments(e Engine, typeCloudBrain int, rels ...*Dataset) (err | |||
return err | |||
} | |||
attachment.FileChunk = fileChunks[0] | |||
attachment.CanDel = CanDelAttachment(isSigned, user, attachment) | |||
sortedRels.Rel[currentIndex].Attachments = append(sortedRels.Rel[currentIndex].Attachments, attachment) | |||
} | |||
@@ -712,7 +712,17 @@ function loadimg(){ | |||
reset_var(); | |||
var picturePath = labeltastresult[fileindex].pic_image_field; | |||
img.src = ip + "/getgiteaimage?filename=" + picturePath; | |||
var html = picturePath.substring(picturePath.lastIndexOf("/") + 1) + " "+ "(" + (tablePageData.current * pageSize + fileindex + 1) + "/" + tablePageData.total + ")" | |||
var picIndex = picturePath.indexOf("/",70); | |||
if(picIndex != -1){ | |||
float_text_name = picturePath.substring(picIndex + 1); | |||
float_text_name = float_text_name.substring(float_text_name.indexOf('/')+1); | |||
}else{ | |||
float_text_name = picturePath.substring(picturePath.lastIndexOf("/") + 1) | |||
} | |||
var html = float_text_name + " "+ "(" + (tablePageData.current * pageSize + fileindex + 1) + "/" + tablePageData.total + ")" | |||
document.getElementById("float_text").innerHTML = html; | |||
} | |||
function save(){ | |||
@@ -2666,7 +2676,7 @@ function setPage(pageData,pageSize){ | |||
canvas = document.getElementById("myCanvas"); | |||
context = canvas.getContext("2d"); | |||
maxWidth = document.getElementById("showPic").offsetWidth; | |||
maxWidth = document.getElementById("showPic").offsetWidth-56; | |||
maxHeight = document.getElementById("showPic").offsetHeight-100; | |||
canvas.width = maxWidth; | |||
canvas.height = maxHeight; | |||
@@ -2843,14 +2853,20 @@ function isJSON(str) { | |||
img.onload = function(){ | |||
loadFinished = false; | |||
// 初始设置画布大小,最大值宽和高 | |||
canvas.width = maxWidth;//document.getElementById("tool0").offsetWidth; | |||
canvas.height = maxHeight;//document.getElementById("tool0").offsetWidth/1280*720; | |||
canvas.width = img.width;// maxWidth document.getElementById("tool0").offsetWidth; | |||
canvas.height =img.height;//maxHeight document.getElementById("tool0").offsetWidth/1280*720; | |||
//调整画布大小 | |||
if ((img.width/img.height)<(canvas.width/canvas.height)){ | |||
canvas.width=canvas.height * img.width / img.height; | |||
// if ((img.width/img.height)>(maxWidth/maxWidth)){ | |||
// canvas.width=canvas.height * img.width / img.height; | |||
// } | |||
// else{ | |||
// canvas.height=canvas.width * img.height / img.width; | |||
// } | |||
if(canvas.width>maxWidth){ | |||
canvas.width = maxWidth | |||
} | |||
else{ | |||
canvas.height=canvas.width * img.height / img.width; | |||
if(canvas.height>maxHeight){ | |||
canvas.height=maxHeight | |||
} | |||
maxIdNum=0; | |||
@@ -128,7 +128,9 @@ func DeleteAttachment(ctx *context.Context) { | |||
ctx.Error(400, err.Error()) | |||
return | |||
} | |||
if !ctx.IsSigned || (ctx.User.ID != attach.UploaderID) { | |||
//issue 214: mod del-dataset permission | |||
if !models.CanDelAttachment(ctx.IsSigned, ctx.User, attach) { | |||
ctx.Error(403) | |||
return | |||
} | |||
@@ -146,7 +148,7 @@ func DeleteAttachment(ctx *context.Context) { | |||
_, err = models.DeleteFileChunkById(attach.UUID) | |||
if err != nil { | |||
ctx.Error(500, fmt.Sprintf("DeleteAttachment: %v", err)) | |||
ctx.Error(500, fmt.Sprintf("DeleteFileChunkById: %v", err)) | |||
return | |||
} | |||
ctx.JSON(200, map[string]string{ | |||
@@ -76,7 +76,7 @@ func QueryDataSet(ctx *context.Context) []*models.Attachment { | |||
ctx.NotFound("type error", nil) | |||
return nil | |||
} | |||
err = models.GetDatasetAttachments(ctx.QueryInt("type"), dataset) | |||
err = models.GetDatasetAttachments(ctx.QueryInt("type"), ctx.IsSigned, ctx.User, dataset) | |||
if err != nil { | |||
ctx.ServerError("GetDatasetAttachments", err) | |||
return nil | |||
@@ -120,7 +120,7 @@ func DatasetIndex(ctx *context.Context) { | |||
ctx.NotFound("type error", nil) | |||
return | |||
} | |||
err = models.GetDatasetAttachments(ctx.QueryInt("type"), dataset) | |||
err = models.GetDatasetAttachments(ctx.QueryInt("type"), ctx.IsSigned, ctx.User, dataset) | |||
if err != nil { | |||
ctx.ServerError("GetDatasetAttachments", err) | |||
return | |||
@@ -39,6 +39,7 @@ | |||
</style> | |||
<div class="ui secondary pointing tabular top attached borderless menu navbar"> | |||
{{if .PageIsExplore}} | |||
<a class="{{if eq .SortType "hot"}}active{{end}} item" href="{{$.Link}}?sort=hot&q={{$.Keyword}}&tab={{$.TabName}}"> | |||
<svg class="svg octicon-repo" width="16" height="16" aria-hidden="true"> | |||
<use xlink:href="#octicon-repo" /> | |||
@@ -51,7 +52,7 @@ | |||
</svg> | |||
活跃{{.i18n.Tr "explore.repos"}} | |||
</a> | |||
{{end}} | |||
<a class="{{if eq .SortType "recentupdate"}}active{{end}} item" href="{{$.Link}}?sort=recentupdate&q={{$.Keyword}}&tab={{$.TabName}}"> | |||
<svg class="svg octicon-organization" width="16" height="16" aria-hidden="true"> | |||
<use xlink:href="#octicon-organization" /> | |||
@@ -2,6 +2,13 @@ | |||
{{template "base/head" .}} | |||
<style> | |||
.label_after::after{ | |||
margin: -.2em 0 0 .2em; | |||
content: '\00a0'; | |||
} | |||
.selectcloudbrain .active.item{ | |||
color: #0087f5 !important; | |||
border: 1px solid #0087f5; | |||
@@ -232,13 +239,13 @@ | |||
<div class="ui two column stackable grid"> | |||
<div class="column"> | |||
</div> | |||
<div class="column right aligned"> | |||
<!-- <div class="column right aligned"> | |||
<div class="ui right dropdown type jump item"> | |||
<span class="text"> | |||
{{.i18n.Tr "repo.issues.filter_sort"}}<i class="dropdown icon"></i> | |||
</span> | |||
</div> | |||
</div> | |||
</div> --> | |||
</div> | |||
</div> | |||
@@ -320,37 +327,40 @@ | |||
<!-- 镜像列表弹窗 --> | |||
<div id="imageModal" class="modal" style="display: none;"> | |||
<div class="modal-content"> | |||
<span class="close">×</span> | |||
<!-- 表格 --> | |||
<form id="commitImageForm" action="{{$.Link}}/{{.JobID}}/commit_image" method="post" target="iframeContent"> | |||
{{$.CsrfTokenHtml}} | |||
<p>提交任务镜像</p> | |||
<div class="ui divider"></div> | |||
<div class="inline required field dis"> | |||
<label>镜像标签:</label> | |||
<input name="tag" id="image_tag" tabindex="3" autofocus required maxlength="255" style="width:75%"> | |||
</div> | |||
<div class="inline required field" style="position:relative;height:180px;"> | |||
<div style="height:20px;width:75px;"> | |||
<label>镜像描述:</label> | |||
<div class="ui form"> | |||
<form id="commitImageForm" action="{{$.Link}}/{{.JobID}}/commit_image" method="post" target="iframeContent"> | |||
{{$.CsrfTokenHtml}} | |||
<div class="row"> | |||
<p style="display: inline;">提交任务镜像</p> | |||
<span class="close">×</span> | |||
</div> | |||
<div style="position:absolute;left:75px;top:0;width:75%"> | |||
<textarea name="description" rows="10" style="width:100%"></textarea> | |||
<div class="ui divider"></div> | |||
<div class="inline required field dis"> | |||
<label>镜像标签:</label> | |||
<input name="tag" id="image_tag" tabindex="3" autofocus required maxlength="255" style="width:75%"> | |||
</div> | |||
</div> | |||
<div class="ui divider"></div> | |||
<div class="inline field"> | |||
<label></label> | |||
<button class="ui green button" onclick="showmask()"> | |||
{{$.i18n.Tr "repo.cloudbrain.commit_image"}} | |||
</button> | |||
</div> | |||
</form> | |||
<div class="inline field"> | |||
<label class="label_after">镜像描述:</label> | |||
<textarea name="description" rows="8" style="width:75%;margin-left: 0.2em;"></textarea> | |||
</div> | |||
<div class="ui divider"></div> | |||
<div class="inline field"> | |||
<label></label> | |||
<button class="ui green button" onclick="showmask()"> | |||
{{$.i18n.Tr "repo.cloudbrain.commit_image"}} | |||
</button> | |||
</div> | |||
</form> | |||
</div> | |||
</div> | |||
</div> | |||
@@ -487,6 +497,11 @@ | |||
// 显示弹窗,弹出相应的信息 | |||
function showmask() { | |||
var image_tag = !$('#image_tag').val() | |||
console.log("image_tag",image_tag) | |||
if(image_tag){ | |||
return | |||
} | |||
$('#imageModal').css('display', 'none') | |||
$('#mask').css('display', 'block') | |||
@@ -177,8 +177,9 @@ | |||
</div> | |||
<div class="inline required field"> | |||
<label>数据集(只有zip格式的数据集才能发起云脑任务)</label> | |||
<select id="cloudbrain_dataset" class="ui search dropdown" placeholder="选择数据集" style='width:385px' name="attachment"> | |||
<label>数据集</label> | |||
<select id="cloudbrain_dataset" class="ui search dropdown" placeholder="选择数据集" style='width:385px' name="attachment" required> | |||
{{range .attachments}} | |||
<option name="attachment" value="{{.UUID}}">{{.Attachment.Name}}</option> | |||
{{end}} | |||
@@ -241,15 +242,14 @@ | |||
let url_href = window.location.pathname.split('create')[0] | |||
$(".ui.button").attr('href',url_href) | |||
let form = document.getElementById('form_id'); | |||
let value_image = $("input[name='image']").val() | |||
console.log("value_image",$("input[name='image']").val()) | |||
$('#messageInfo').css('display','none') | |||
form.onsubmit = function(e){ | |||
let value_task = $("input[name='job_name']").val() | |||
let value_image = $("input[name='image']").val() | |||
let value_data = $("input[name='attachment']").val() | |||
let re = /^[a-z0-9][a-z0-9-_]{1,36}$/ | |||
let flag = re.test(value_task) | |||
if(!flag){ | |||
@@ -258,13 +258,11 @@ | |||
$('#messageInfo p').text(str) | |||
return false | |||
} | |||
if(!value_image){ | |||
return false | |||
} | |||
// if(!value_image || !value_data){ | |||
// console.log("------------------------") | |||
// return false | |||
// } | |||
let min_value_task = value_task.toLowerCase() | |||
console.log(min_value_task) | |||
$("input[name='job_name']").attr("value",min_value_task) | |||
document.getElementById("mask").style.display = "block" | |||
@@ -24,22 +24,6 @@ | |||
<td class="four wide"> 状态 </td> | |||
<td> {{.State}} </td> | |||
</tr> | |||
<tr> | |||
<td> 开始时间 </td> | |||
<td>{{.StartTime}}</td> | |||
</tr> | |||
<tr> | |||
<td> 结束时间 </td> | |||
<td>{{.FinishedTime}}</td> | |||
</tr> | |||
<tr> | |||
<td> ExitCode </td> | |||
<td>{{.ExitCode}}</td> | |||
</tr> | |||
<tr> | |||
<td> 退出信息 </td> | |||
<td>{{.ExitDiagnostics| nl2br}}</td> | |||
</tr> | |||
</tbody> | |||
</table> | |||
{{end}} | |||
@@ -73,7 +57,7 @@ | |||
</thead> | |||
<tbody> | |||
<tr> | |||
<td class="four wide"> 状态 </td> | |||
<td class="four wide"> 平台 </td> | |||
<td> {{.Platform}} </td> | |||
</tr> | |||
<tr> | |||
@@ -1,5 +1,5 @@ | |||
{{template "base/head" .}} | |||
<div class="repository new repo"> | |||
<div class="repository new repo" style="margin-top: 40px;"> | |||
<div class="ui middle very relaxed page grid"> | |||
<div class="column"> | |||
<form class="ui form" action="{{.Link}}" method="post"> | |||
@@ -31,7 +31,7 @@ | |||
</div> | |||
{{end}} | |||
{{if $.Permission.CanWrite $.UnitTypeDatasets}} | |||
{{if $.Repository.IsPrivate}} | |||
{{if (not .CanDel) or $.Repository.IsPrivate}} | |||
<div class="two wide column"> | |||
<a class="ui button mini" disabled='true' data-tooltip='{{$.i18n.Tr "dataset.how_to_public"}}'>{{$.i18n.Tr "dataset.private"}}</a> | |||
</div> | |||
@@ -45,7 +45,7 @@ | |||
</div> | |||
{{end}} | |||
<div class="two wide column right aligned"> | |||
<div class="two wide column right aligned" style="{{if not .CanDel}}visibility: hidden;{{end}}"> | |||
<a class="ui red button mini" href="javascript:void(0)" data-uuid={{.UUID}} data-dataset-delete data-remove-url="{{AppSubUrl}}/attachments/delete" data-csrf="{{$.CsrfToken}}">{{$.i18n.Tr "dataset.delete"}}</a> | |||
</div> | |||
{{end}} | |||
@@ -232,13 +232,13 @@ | |||
<div class="ui two column stackable grid"> | |||
<div class="column"> | |||
</div> | |||
<div class="column right aligned"> | |||
<!-- <div class="column right aligned"> | |||
<div class="ui right dropdown type jump item"> | |||
<span class="text"> | |||
{{.i18n.Tr "repo.issues.filter_sort"}}<i class="dropdown icon"></i> | |||
</span> | |||
</div> | |||
</div> | |||
</div> --> | |||
</div> | |||
</div> | |||
@@ -100,7 +100,10 @@ | |||
<div class="repository new repo ui middle very relaxed page grid"> | |||
<div class="column"> | |||
{{template "base/alert" .}} | |||
<form class="ui form" action="{{.Link}}" method="post"> | |||
<div class="ui positive message" id="messageInfo"> | |||
<p></p> | |||
</div> | |||
<form class="ui form" id="form_id" action="{{.Link}}" method="post"> | |||
{{.CsrfTokenHtml}} | |||
<h3 class="ui top attached header"> | |||
{{.i18n.Tr "repo.cloudbrain.new"}} | |||
@@ -125,11 +128,11 @@ | |||
<div class="inline required field"> | |||
<label>工作环境</label> | |||
<input name="de" id="cloudbrain_de" value="{{.env}}" tabindex="3" autofocus required maxlength="255" readonly="readonly"> | |||
<input name="de" id="cloudbrain_de" value="{{.env}}" tabindex="3" disabled autofocus required maxlength="255" readonly="readonly"> | |||
</div> | |||
<div class="inline required field"> | |||
<label>类型</label> | |||
<input name="job_type" id="cloudbrain_job_type" value="{{.notebook_type}}" tabindex="3" autofocus required maxlength="255" readonly="readonly"> | |||
<input name="job_type" id="cloudbrain_job_type" value="{{.notebook_type}}" tabindex="3" disabled autofocus required maxlength="255" readonly="readonly"> | |||
</div> | |||
<div class="inline required field"> | |||
<label>规格</label> | |||
@@ -142,7 +145,7 @@ | |||
</div> | |||
<div class="inline required field"> | |||
<label>数据集存放路径</label> | |||
<input name="dataset_path" id="cloudbrain_dataset_path" value="{{.dataset_path}}" tabindex="3" autofocus required maxlength="255" readonly="readonly"> | |||
<input name="dataset_path" id="cloudbrain_dataset_path" value="{{.dataset_path}}" tabindex="3" disabled autofocus required maxlength="255" readonly="readonly"> | |||
</div> | |||
<div class="inline field"> | |||
<label>描述</label> | |||
@@ -150,7 +153,7 @@ | |||
</div> | |||
<div class="inline field"> | |||
<label></label> | |||
<button class="ui green button" onclick="showmask()"> | |||
<button class="ui green button"> | |||
{{.i18n.Tr "repo.cloudbrain.new"}} | |||
</button> | |||
<a class="ui button" href="/">{{.i18n.Tr "repo.cloudbrain.cancel"}}</a> | |||
@@ -163,10 +166,38 @@ | |||
{{template "base/footer" .}} | |||
<script> | |||
// 点击按钮后遮罩层显示 | |||
function showmask() { | |||
// 取消创建跳转 | |||
let url_href = window.location.pathname.split('create')[0] | |||
$(".ui.button").attr('href',url_href) | |||
// 判断必填选项是否填写正确 | |||
let form = document.getElementById('form_id'); | |||
$('#messageInfo').css('display','none') | |||
form.onsubmit = function(e){ | |||
let value_task = $("input[name='job_name']").val() | |||
let re = /^[a-z0-9][a-z0-9-_]{1,36}$/ | |||
let flag = re.test(value_task) | |||
if(!flag){ | |||
$('#messageInfo').css('display','block') | |||
let str = '只能以小写字母或数字开头且只包含小写字母、数字、_和-、最长36个字符。' | |||
$('#messageInfo p').text(str) | |||
return false | |||
} | |||
let min_value_task = value_task.toLowerCase() | |||
$("input[name='job_name']").attr("value",min_value_task) | |||
document.getElementById("mask").style.display = "block" | |||
} | |||
// 点击按钮后遮罩层显示 | |||
// function showmask() { | |||
// document.getElementById("mask").style.display = "block" | |||
// } | |||
// 页面加载完毕后遮罩层隐藏 | |||
document.onreadystatechange = function() { | |||
@@ -79,9 +79,11 @@ | |||
&.profile { | |||
.members { | |||
.ui.avatar { | |||
width: 48px; | |||
height: 48px; | |||
width: 44px; | |||
height: 44px; | |||
margin-right: 5px; | |||
margin-bottom: 5px; | |||
border-radius: 22px; | |||
} | |||
} | |||
} | |||
@@ -2764,6 +2764,8 @@ tbody.commit-list { | |||
.text { | |||
width: 100%; | |||
overflow: hidden; | |||
height: 36px; | |||
line-height: 36px; | |||
} | |||
} | |||