Browse Source

add balance

master
Gitea 4 years ago
parent
commit
e453ffe714
6 changed files with 26 additions and 107 deletions
  1. +6
    -0
      models/repo.go
  2. +16
    -0
      models/repo_unit.go
  3. +0
    -9
      routers/repo/blockchain.go
  4. +2
    -2
      routers/routes/routes.go
  5. +2
    -94
      templates/repo/blockchain/index.tmpl
  6. +0
    -2
      templates/repo/header.tmpl

+ 6
- 0
models/repo.go View File

@@ -1105,6 +1105,12 @@ func CreateRepository(ctx DBContext, doer, u *User, repo *Repository) (err error
Type: tp,
Config: &CloudBrainConfig{EnableCloudBrain: true},
})
} else if tp == UnitTypeBlockChain {
units = append(units, RepoUnit{
RepoID: repo.ID,
Type: tp,
Config: &BlockChainConfig{EnableBlockChain: true},
})
} else {
units = append(units, RepoUnit{
RepoID: repo.ID,


+ 16
- 0
models/repo_unit.go View File

@@ -141,6 +141,20 @@ func (cfg *CloudBrainConfig) ToDB() ([]byte, error) {
return json.Marshal(cfg)
}

type BlockChainConfig struct {
EnableBlockChain bool
}

// FromDB fills up a CloudBrainConfig from serialized format.
func (cfg *BlockChainConfig) FromDB(bs []byte) error {
return json.Unmarshal(bs, &cfg)
}

// ToDB exports a CloudBrainConfig to a serialized format.
func (cfg *BlockChainConfig) ToDB() ([]byte, error) {
return json.Marshal(cfg)
}

// BeforeSet is invoked from XORM before setting the value of a field of this object.
func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) {
switch colName {
@@ -160,6 +174,8 @@ func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) {
r.Config = new(DatasetConfig)
case UnitTypeCloudBrain:
r.Config = new(CloudBrainConfig)
case UnitTypeBlockChain:
r.Config = new(BlockChainConfig)
default:
panic("unrecognized repo unit type: " + com.ToStr(*val))
}


+ 0
- 9
routers/repo/blockchain.go View File

@@ -24,16 +24,7 @@ const (
tplBlockChainIndex base.TplName = "repo/blockchain/index"
)

// MustEnableDataset check if repository enable internal cb
func MustEnableBlockChain(ctx *context.Context) {
if !ctx.Repo.CanRead(models.UnitTypeBlockChain) {
ctx.NotFound("MustEnableBlockChain", nil)
return
}
}

func BlockChainIndex(ctx *context.Context) {
MustEnableBlockChain(ctx)
repo := ctx.Repo.Repository
if repo.ContractAddress == "" || ctx.User.PublicKey == ""{
log.Error("the repo(%d) or the user(%d) has not been initialized in block_chain", repo.RepoID, ctx.User.ID)


+ 2
- 2
routers/routes/routes.go View File

@@ -568,7 +568,7 @@ func RegisterRoutes(m *macaron.Macaron) {
reqRepoDatasetWriter := context.RequireRepoWriter(models.UnitTypeDatasets)
reqRepoCloudBrainReader := context.RequireRepoReader(models.UnitTypeCloudBrain)
reqRepoCloudBrainWriter := context.RequireRepoWriter(models.UnitTypeCloudBrain)
reqRepoBlockChainReader := context.RequireRepoReader(models.UnitTypeBlockChain)
//reqRepoBlockChainReader := context.RequireRepoReader(models.UnitTypeBlockChain)
//reqRepoBlockChainWriter := context.RequireRepoWriter(models.UnitTypeBlockChain)

// ***** START: Organization *****
@@ -914,7 +914,7 @@ func RegisterRoutes(m *macaron.Macaron) {
}, context.RepoRef())

m.Group("/blockchain", func() {
m.Get("", reqRepoBlockChainReader, repo.BlockChainIndex)
m.Get("", repo.BlockChainIndex)
}, context.RepoRef())

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


+ 2
- 94
templates/repo/blockchain/index.tmpl View File

@@ -12,101 +12,9 @@
</div>

<div class="column right aligned">
212
{{.balance}}
</div>
</div>

<!-- 中间分割线 -->
<div class="ui divider"></div>

<!-- 中下列表展示区 -->
<div class="ui grid">
<div class="row">
<div class="ui sixteen wide column">

<!-- 排序区 -->
<div class="ui sixteen wide column">
<div class="ui two column stackable grid">
<div class="column">
</div>
<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 class="balance list">
{{range .Tasks}}
<div class="ui grid stackable item">
<div class="row">

<!-- 项目名字 -->
<div class="four wide column">
<span class="fitted">{{svg "octicon-tasklist" 16}}</span>
<span class="fitted">项目名字《待补充》</span>
</a>
</div>

<!--余额状态 -->
<div class="three wide column job-status" id="{{.JobID}}" data-repopath="{{$.RepoRelPath}}" data-jobid="{{.JobID}}">
余额:待补充
</div>

<!-- 任务创建时间 -->
<div class="three wide column">
<span class="ui text center">{{svg "octicon-flame" 16}} {{TimeSinceUnix .CreatedUnix $.Lang}}</span>
</div>

<!-- 查看 -->
<div class="one wide column">
<span class="ui text clipboard">
<a class="title" href="{{$.Link}}/{{.JobID}}">
<span class="fitted">查看</span>
</a>
</span>
</div>

<!-- 评分 -->
<div class="one wide column">
<div class="ui text center clipboard">
<a class="title" onclick="stop(this)" href="{{if and (ne .Status "WAITING") (eq .JobType "BENCHMARK")}}{{$.Link}}/{{.JobID}}/benchmark{{else}}javascript:void(0);{{end}}" style="{{if and (ne .Status "WAITING") (eq .JobType "BENCHMARK")}}{{else}}color:#CCCCCC{{end}}">
<span class="fitted">评分</span>
</a>
</div>
</div>

<!-- 删除镜像 -->
<div class="one wide column">
<div class="ui text center clipboard">
<form id="delForm-{{.JobID}}" action="{{if ne .Status "STOPPED"}}javascript:void(0){{else}}{{$.Link}}/{{.JobID}}/del{{end}}" method="post">
{{$.CsrfTokenHtml}}
<a class="fitted" onclick="assertDelete(this)" style="{{if ne .Status "STOPPED"}}color:#CCCCCC{{end}}; font-size:16px; font-weight:bold">删除</a>
</form>
</div>
</div>

<!-- 调试 -->
<div class="one wide column">
<div class="ui text center clipboard">
<a class="title" onclick="stop(this)" href="{{if not .CanDebug}}javascript:void(0){{else}}{{$.Link}}/{{.JobID}}/debug{{end}}" style="{{if not .CanDebug}}color:#CCCCCC{{end}}">
<span class="fitted">调试</span>
</a>
</div>
</div>

</div>
</div>
<!-- {{end}} {{template "base/paginate" .}} -->
</div>

</div>
</div>
</div>
</div>
</div>
{{template "base/footer" .}}

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

@@ -148,8 +148,6 @@
<a class="{{if .PageIsCloudBrain}}active{{end}} item" href="{{.RepoLink}}/blockchain">
{{svg "octicon-balance" 16}}
{{.i18n.Tr "repo.balance"}}
</svg>

</a>

{{template "custom/extra_tabs" .}}


Loading…
Cancel
Save