Browse Source

feat: change the set for the url, add upload and add delete

tags/vopendata0.1.2
colorfulberry 5 years ago
parent
commit
cdba7247c0
5 changed files with 38 additions and 5 deletions
  1. +5
    -1
      routers/repo/attachment.go
  2. +1
    -1
      templates/repo/datasets/dataset.tmpl
  3. +2
    -3
      templates/repo/datasets/dataset_list.tmpl
  4. +10
    -0
      templates/repo/datasets/index.tmpl
  5. +20
    -0
      web_src/js/index.js

+ 5
- 1
routers/repo/attachment.go View File

@@ -7,6 +7,7 @@ package repo
import (
"fmt"
"net/http"
"strconv"
"strings"

"code.gitea.io/gitea/models"
@@ -55,9 +56,12 @@ func UploadAttachment(ctx *context.Context) {
return
}

datasetID, _ := strconv.ParseInt(ctx.Req.FormValue("dataset_id"), 10, 64)

attach, err := models.NewAttachment(&models.Attachment{
UploaderID: ctx.User.ID,
Name: header.Filename,
DatasetID: datasetID,
}, buf, file)
if err != nil {
ctx.Error(500, fmt.Sprintf("NewAttachment: %v", err))
@@ -180,7 +184,7 @@ func GetAttachment(ctx *context.Context) {

}

func increaseDownloadCount(attach *models.Attachment, dataSet *models.Dataset) error{
func increaseDownloadCount(attach *models.Attachment, dataSet *models.Dataset) error {
if err := attach.IncreaseDownloadCount(); err != nil {
return err
}


+ 1
- 1
templates/repo/datasets/dataset.tmpl View File

@@ -2,7 +2,7 @@
<div class="field required dataset-files">
<label>{{.i18n.Tr "dataset.file"}}</label>
<div class="files"></div>
<div class="ui dropzone" id="dataset" data-upload-url="{{AppSubUrl}}/attachments" data-accepts="{{.AttachmentAllowedTypes}}" data-max-file="1000" data-max-size="{{.AttachmentMaxSize}}" data-default-message="{{.i18n.Tr "dropzone.default_message"}}" data-invalid-input-type="{{.i18n.Tr "dropzone.invalid_input_type"}}" data-file-too-big="{{.i18n.Tr "dropzone.file_too_big"}}" data-remove-file="{{.i18n.Tr "dropzone.remove_file"}}">
<div class="ui dropzone" id="dataset" data-upload-url="{{AppSubUrl}}/attachments" data-accepts="{{.AttachmentAllowedTypes}}" data-remove-url="{{AppSubUrl}}/attachments/delete" data-csrf="{{.CsrfToken}}" dataset-id={{.dataset.ID}} data-max-file="100" data-dataset-id="{{.dataset.ID}}" data-max-size="{{.AttachmentMaxSize}}" data-default-message="{{.i18n.Tr "dropzone.default_message"}}" data-invalid-input-type="{{.i18n.Tr "dropzone.invalid_input_type"}}" data-file-too-big="{{.i18n.Tr "dropzone.file_too_big"}}" data-remove-file="{{.i18n.Tr "dropzone.remove_file"}}">
</div>
</div>
</div>

+ 2
- 3
templates/repo/datasets/dataset_list.tmpl View File

@@ -1,6 +1,6 @@
{{if .dataset.Attachments}}
{{range .dataset.Attachments}}
<div class="ui grid item">
<div class="ui grid item" id="{{.UUID}}">
<div class="row">
<div class="six wide column">
<a class="title" href="{{.DownloadURL}}">
@@ -27,10 +27,9 @@
</div>

<div class="two wide column right aligned">
<a class="delete-button ui red button mini" href="">删除</a>
<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}}">删除</a>
</div>
</div>
</div>
{{end}}
{{end}}


+ 10
- 0
templates/repo/datasets/index.tmpl View File

@@ -75,4 +75,14 @@
</div>
</form>
</div>
<div class="ui small basic delete modal" id="data-dataset-delete-modal">
<div class="ui icon header">
<i class="trash icon"></i>
删除分支
</div>
<div class="content">
<p>{{.i18n.Tr "repo.branch.delete_desc" | Str2html}}</p>
</div>
{{template "base/delete_modal_actions" .}}
</div>
{{template "base/footer" .}}

+ 20
- 0
web_src/js/index.js View File

@@ -1094,6 +1094,23 @@ async function initRepository() {
$('#dataset-content input').focus();
return false;
};
$('[data-dataset-delete]').on('click', function () {
const $this = $(this);

$('#data-dataset-delete-modal').modal({
closable: false,
onApprove() {
$.post($this.data('remove-url'), {
_csrf: $this.data('csrf'),
file: $this.data('uuid')
}).done((_data) => {
$(`#${$this.data('uuid')}`).hide();
}).fail(() => {
window.location.reload();
});
}
}).modal('show');
});
$('[data-category-id]').on('click', function () {
const category = $(this).data('category-id');
$('#category').val(category);
@@ -2372,6 +2389,9 @@ $(document).ready(async () => {
timeout: 3600000,
previewTemplate,
init() {
this.on('sending', (_file, _xhr, formData) => {
formData.append('dataset_id', $dataset.data('dataset-id'));
});
this.on('success', (file, data) => {
filenameDict[file.name] = data.uuid;
const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid);


Loading…
Cancel
Save