Browse Source

add tmpl

tags/v1.21.12.1
yuyuanshifu 5 years ago
parent
commit
f8278dbbe1
9 changed files with 200 additions and 60 deletions
  1. +1
    -53
      routers/repo/attachment.go
  2. +0
    -0
      routers/repo/dataset.go
  3. +138
    -0
      routers/repo/dir.go
  4. +4
    -1
      routers/routes/routes.go
  5. +1
    -1
      templates/repo/datasets/dataset_list.tmpl
  6. +20
    -0
      templates/repo/datasets/dirs/dir_list.tmpl
  7. +33
    -0
      templates/repo/datasets/dirs/index.tmpl
  8. +0
    -0
      templates/repo/header.tmpl
  9. +3
    -5
      web_src/js/index.js

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

@@ -13,16 +13,11 @@ import (
"code.gitea.io/gitea/modules/upload"
"code.gitea.io/gitea/modules/worker"
contexExt "context"
"encoding/json"
"fmt"
"io/ioutil"
gouuid "github.com/satori/go.uuid"
"net/http"
"path"
"strconv"
"strings"
"time"

gouuid "github.com/satori/go.uuid"
)

const (
@@ -31,12 +26,6 @@ const (
DecompressFailed = "1"
)

type FileInfo struct {
FileName string
ModTime time.Time
IsDir bool
}

func RenderAttachmentSettings(ctx *context.Context) {
renderAttachmentSettings(ctx)
}
@@ -360,44 +349,3 @@ func HandleUnDecompressAttachment() {

return
}

func GetDir(ctx *context.Context) {
uuid := ctx.Query("uuid")

//todo: 查询解压状态成功之后才能查看文件目录
files, err := ioutil.ReadDir(setting.Attachment.Minio.RealPath + setting.Attachment.Minio.Bucket + "/" + setting.Attachment.Minio.BasePath +
path.Join(uuid[0:1], uuid[1:2], uuid + uuid) + "/" + ctx.Query("parentDir"))
if err != nil {
log.Error("ReadDir failed:", err.Error())
ctx.ServerError("ReadDir failed:", err)
return
}

i := 1
var fileInfos []FileInfo
for _, file := range files {
if i > 100 {
break
}

fileInfos = append(fileInfos, FileInfo{
FileName:file.Name(),
ModTime:file.ModTime(),
IsDir:file.IsDir(),
})
i++
}

tmp, err := json.Marshal(fileInfos)
if err != nil {
ctx.ServerError("json.Marshal failed:", err)
return
}

log.Info(string(tmp))

ctx.JSON(200, map[string]string{
"uuid": uuid,
"fileInfos": string(tmp),
})
}

+ 0
- 0
routers/repo/dataset.go View File


+ 138
- 0
routers/repo/dir.go View File

@@ -0,0 +1,138 @@
package repo

import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"encoding/json"
"errors"
"io/ioutil"
"path"
"strings"
)

const (
tplDirIndex base.TplName = "repo/datasets/dirs/index"
)

type FileInfo struct {
FileName string
ModTime string
IsDir bool
Size int64
}

func DirIndex(ctx *context.Context) {
uuid := ctx.Params("uuid")

attachment, err := models.GetAttachmentByUUID(uuid)
if err != nil {
ctx.ServerError("GetDatasetAttachments", err)
return
}

if !strings.HasSuffix(attachment.Name, ".zip") {
log.Error("The file is not zip file, can not query the dir")
ctx.ServerError("The file is not zip file, can not query the dir", errors.New("The file is not zip file, can not query the dir"))
return
} else {
if attachment.DecompressState != models.DecompressStateDone {
log.Error("The file has not been decompressed completely now")
ctx.ServerError("The file has not been decompressed completely now", errors.New("The file has not been decompressed completely now"))
return
}
}

files, err := ioutil.ReadDir(setting.Attachment.Minio.RealPath + setting.Attachment.Minio.Bucket + "/" + setting.Attachment.Minio.BasePath +
path.Join(uuid[0:1], uuid[1:2], uuid + uuid) + "/" )
if err != nil {
log.Error("ReadDir failed:", err.Error())
ctx.ServerError("ReadDir failed:", err)
return
}

i := 1
var fileInfos []FileInfo
for _, file := range files {
if i > 100 {
break
}

fileInfos = append(fileInfos, FileInfo{
FileName:file.Name(),
ModTime:file.ModTime().Format("2006-01-02 15:04:05"),
IsDir:file.IsDir(),
Size:file.Size(),
})
i++
}

ctx.Data["Dirs"] = fileInfos

ctx.Data["Title"] = attachment.Name

ctx.HTML(200, tplDirIndex)
}

func GetDir(ctx *context.Context) {
uuid := ctx.Query("uuid")
parentDir := ctx.Query("parentDir")

if parentDir == "" {
attachment, err := models.GetAttachmentByUUID(uuid)
if err != nil {
ctx.ServerError("GetAttachmentByUUID failed:", err)
return
}

if !strings.HasSuffix(attachment.Name, ".zip") {
log.Error("The file is not zip file, can not query the dir")
ctx.ServerError("The file is not zip file, can not query the dir", errors.New("The file is not zip file, can not query the dir"))
return
} else {
if attachment.DecompressState != models.DecompressStateDone {
log.Error("The file has not been decompressed completely now")
ctx.ServerError("The file has not been decompressed completely now", errors.New("The file has not been decompressed completely now"))
return
}
}
}

files, err := ioutil.ReadDir(setting.Attachment.Minio.RealPath + setting.Attachment.Minio.Bucket + "/" + setting.Attachment.Minio.BasePath +
path.Join(uuid[0:1], uuid[1:2], uuid + uuid) + "/" + parentDir)
if err != nil {
log.Error("ReadDir failed:", err.Error())
ctx.ServerError("ReadDir failed:", err)
return
}

i := 1
var fileInfos []FileInfo
for _, file := range files {
if i > 100 {
break
}

fileInfos = append(fileInfos, FileInfo{
FileName:file.Name(),
ModTime:file.ModTime().Format("2006-01-02 15:04:05"),
IsDir:file.IsDir(),
})
i++
}

tmp, err := json.Marshal(fileInfos)
if err != nil {
ctx.ServerError("json.Marshal failed:", err)
return
}

ctx.Data["Dirs"] = fileInfos

ctx.JSON(200, map[string]string{
"uuid": uuid,
"fileInfos": string(tmp),
})
}

+ 4
- 1
routers/routes/routes.go View File

@@ -521,7 +521,6 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/get_pre_url", repo.GetPresignedPutObjectURL)
m.Post("/add", repo.AddAttachment)
m.Post("/private", repo.UpdatePublicAttachment)
m.Get("/dir", repo.GetDir)
}, reqSignIn)

m.Group("/attachments", func() {
@@ -874,6 +873,10 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Group("/datasets", func() {
m.Get("", reqRepoDatasetReader, repo.DatasetIndex)
m.Post("", reqRepoDatasetWriter, bindIgnErr(auth.EditDatasetForm{}), repo.EditDatasetPost)

m.Group("/dirs/:uuid", func() {
m.Get("", reqRepoDatasetReader, repo.DirIndex)
})
}, context.RepoRef())

m.Group("/cloudbrain", func() {


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

@@ -19,7 +19,7 @@
</div>

<div class="two wide column">
<a class="ui button mini" href="javascript:void(0)" data-uuid={{.UUID}} data-dataset-dir data-dir-url="{{AppSubUrl}}/attachments/dir" data-csrf="{{$.CsrfToken}}">{{$.i18n.Tr "dataset.dir"}}</a>
<a class="ui button mini" href="datasets/dirs/{{.UUID}}" data-uuid={{.UUID}} data-dataset-dir data-dir-url="{{AppSubUrl}}/attachments/dir" data-csrf="{{$.CsrfToken}}">{{$.i18n.Tr "dataset.dir"}}</a>
</div>

{{if $.Permission.CanWrite $.UnitTypeDatasets}}


+ 20
- 0
templates/repo/datasets/dirs/dir_list.tmpl View File

@@ -0,0 +1,20 @@
{{if .Dirs}}
{{range .Dirs}}
<div class="ui grid item">
<div class="row">
<div class="six wide column">
<a class="title" href="{{if .IsDir}}{{AppSubUrl}}/attachments/dir{{end}}">
<span class="fitted">{{if .IsDir}} {{svg "octicon-file-directory" 16}}{{else}}{{svg "octicon-file" 16}}{{end}}</span> {{.FileName}}
</a>
</div>
<div class="two wide column">
{{.Size | FileSize}}
</div>
<div class="six wide column">
<span>{{.ModTime}}</span>
</div>

</div>
</div>
{{end}}
{{end}}

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

@@ -0,0 +1,33 @@
{{template "base/head" .}}

<div class="repository dataset dir-list view">
<form class="ui container">
<div class="ui stackable grid {{if .Error}}hide{{end}}" id="dir-content">
<div class="row">
<div class="column sixteen wide">
<h2>{{.Title}}</h2>
</div>
</div>
</div>
</form>
</div>

<div class="ui divider"></div>

<div class="ui grid">
<div class="row">
<div class="ui twelve wide column">
<div class="ui sixteen wide column">
<div class="ui two column stackable grid">
<div class="column">
<h2>{{.i18n.Tr "dataset.dir"}}</h2>
</div>
</div>
</div>
<div class="dir list">
{{template "repo/datasets/dirs/dir_list" .}}
</div>
</div>
</div>

{{template "base/footer" .}}

+ 0
- 0
templates/repo/header.tmpl View File


+ 3
- 5
web_src/js/index.js View File

@@ -1130,19 +1130,17 @@ async function initRepository() {
}
}).modal('show');
});
$('[data-dataset-dir]').on('click', function () {
/*$('[data-dataset-dir]').on('click', function () {
const $this = $(this);
$.get($this.data('dir-url'), {
_csrf: $this.data('csrf'),
uuid: $this.data('uuid'),
//parentDir: $this.data('parentDir')
parentDir: "test"
uuid: $this.data('uuid')
}).done((_data) => {
$(`#${$this.data('uuid')}`).hide();
}).fail(() => {
//window.location.reload();
});
});
});*/
$('[data-category-id]').on('click', function () {
const category = $(this).data('category-id');
$('#category').val(category);


Loading…
Cancel
Save