Browse Source

fix

tags/v0.1.8
yuyuanshifu 4 years ago
parent
commit
3cef6a47ab
4 changed files with 23 additions and 3 deletions
  1. +6
    -0
      models/repo.go
  2. +16
    -0
      models/repo_unit.go
  3. +1
    -1
      routers/repo/blockchain.go
  4. +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, Type: tp,
Config: &CloudBrainConfig{EnableCloudBrain: true}, Config: &CloudBrainConfig{EnableCloudBrain: true},
}) })
} else if tp == UnitTypeBlockChain {
units = append(units, RepoUnit{
RepoID: repo.ID,
Type: tp,
Config: &BlockChainConfig{EnableBlockChain: true},
})
} else { } else {
units = append(units, RepoUnit{ units = append(units, RepoUnit{
RepoID: repo.ID, 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) 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. // BeforeSet is invoked from XORM before setting the value of a field of this object.
func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) { func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) {
switch colName { switch colName {
@@ -160,6 +174,8 @@ func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) {
r.Config = new(DatasetConfig) r.Config = new(DatasetConfig)
case UnitTypeCloudBrain: case UnitTypeCloudBrain:
r.Config = new(CloudBrainConfig) r.Config = new(CloudBrainConfig)
case UnitTypeBlockChain:
r.Config = new(BlockChainConfig)
default: default:
panic("unrecognized repo unit type: " + com.ToStr(*val)) panic("unrecognized repo unit type: " + com.ToStr(*val))
} }


+ 1
- 1
routers/repo/blockchain.go View File

@@ -33,7 +33,7 @@ func MustEnableBlockChain(ctx *context.Context) {
} }


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


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

@@ -145,11 +145,9 @@
</a> </a>
{{end}} {{end}}


{{if .Permission.CanRead $.UnitTypeBlockChain}}
<a class="activate item" href="{{.RepoLink}}/blockchain"> <a class="activate item" href="{{.RepoLink}}/blockchain">
<i class="balance scale icon"></i> {{.i18n.Tr "repo.balance"}} <i class="balance scale icon"></i> {{.i18n.Tr "repo.balance"}}
</a> </a>
{{end}}


{{template "custom/extra_tabs" .}} {{template "custom/extra_tabs" .}}




Loading…
Cancel
Save