From 6e376bb85c7a154c7567fd4be8cabc9627c8c6e7 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 28 Mar 2014 18:40:31 -0400 Subject: Working on install page --- web.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'web.go') diff --git a/web.go b/web.go index 4ed273ea..35695f0b 100644 --- a/web.go +++ b/web.go @@ -90,7 +90,7 @@ func runWeb(*cli.Context) { // Routers. m.Get("/", ignSignIn, routers.Home) - m.Get("/install", routers.Install) + m.Any("/install", routers.Install) m.Get("/issues", reqSignIn, user.Issues) m.Get("/pulls", reqSignIn, user.Pulls) m.Get("/stars", reqSignIn, user.Stars) -- cgit v1.2.3 From ecce694d77756264864b03e6b06077592ed1676a Mon Sep 17 00:00:00 2001 From: FuXiaoHei Date: Sat, 29 Mar 2014 21:16:06 +0800 Subject: issue content ajax preview --- public/js/app.js | 61 ++++++++++++++++++++++++++++++--------------- routers/preview.go | 17 +++++++++++++ templates/issue/create.tmpl | 8 +++--- templates/issue/view.tmpl | 8 +++--- web.go | 1 + 5 files changed, 67 insertions(+), 28 deletions(-) create mode 100644 routers/preview.go (limited to 'web.go') diff --git a/public/js/app.js b/public/js/app.js index b03d9070..58bda989 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -399,21 +399,24 @@ function initRepository() { function initInstall() { // database type change - $('#install-database').on("change", function () { - var val = $(this).val(); - if (val != "sqlite") { - $('.server-sql').show(); - $('.sqlite-setting').addClass("hide"); - if (val == "pgsql") { - $('.pgsql-setting').removeClass("hide"); + (function () { + $('#install-database').on("change", function () { + var val = $(this).val(); + if (val != "sqlite") { + $('.server-sql').show(); + $('.sqlite-setting').addClass("hide"); + if (val == "pgsql") { + $('.pgsql-setting').removeClass("hide"); + } else { + $('.pgsql-setting').addClass("hide"); + } } else { - $('.pgsql-setting').addClass("hide"); + $('.server-sql').hide(); + $('.sqlite-setting').removeClass("hide"); } - } else { - $('.server-sql').hide(); - $('.sqlite-setting').removeClass("hide"); - } - }); + }); + }()); + } function initIssue() { @@ -445,14 +448,32 @@ function initIssue() { }()); // issue ajax update - $('.issue-edit-save').on("click", function () { - $(this).toggleAjax(function(json){ - if(json.ok){ - $('.issue-head h1.title').text(json.title); - $('.issue-main > .issue-content .content').html(json.content); - } + (function () { + $('.issue-edit-save').on("click", function () { + $(this).toggleAjax(function (json) { + if (json.ok) { + $('.issue-head h1.title').text(json.title); + $('.issue-main > .issue-content .content').html(json.content); + } + }); }); - }); + }()); + + // issue ajax preview + (function () { + $('[data-ajax-name=issue-preview]').on("click", function () { + var $this = $(this); + $this.toggleAjax(function (json) { + if (json.ok) { + $($this.data("preview")).html(json.content); + } + }) + }); + $('.issue-write a[data-toggle]').on("click", function () { + $('.issue-preview-content').html("loading..."); + }); + }()) + } (function ($) { diff --git a/routers/preview.go b/routers/preview.go new file mode 100644 index 00000000..cc34c8fa --- /dev/null +++ b/routers/preview.go @@ -0,0 +1,17 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package routers + +import "github.com/gogits/gogs/modules/middleware" + +func Preview(ctx *middleware.Context) { + content := ctx.Query("content") + // todo : gfm render content + // content = Markdown(content) + ctx.Render.JSON(200, map[string]interface{}{ + "ok": true, + "content": "preview : " + content, + }) +} diff --git a/templates/issue/create.tmpl b/templates/issue/create.tmpl index cbc21f6c..b8a533a1 100644 --- a/templates/issue/create.tmpl +++ b/templates/issue/create.tmpl @@ -18,16 +18,16 @@ Content with Markdown
- +
-
preview
+
loading...
diff --git a/templates/issue/view.tmpl b/templates/issue/view.tmpl index 4266bcbf..431b1d10 100644 --- a/templates/issue/view.tmpl +++ b/templates/issue/view.tmpl @@ -72,17 +72,17 @@ Content with Markdown
- +
-
preview
+
loading...
diff --git a/web.go b/web.go index 35695f0b..451e52ff 100644 --- a/web.go +++ b/web.go @@ -95,6 +95,7 @@ func runWeb(*cli.Context) { m.Get("/pulls", reqSignIn, user.Pulls) m.Get("/stars", reqSignIn, user.Stars) m.Get("/help", routers.Help) + m.Post("/preview", routers.Preview) avt := avatar.CacheServer("public/img/avatar/", "public/img/avatar_default.jpg") m.Get("/avatar/:hash", avt.ServeHTTP) -- cgit v1.2.3 From 2c073afbec4b9845e8ddd10a4d3f469874fdcd37 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 29 Mar 2014 10:01:52 -0400 Subject: Mirror fix and update --- README.md | 2 ++ models/repo.go | 13 ++++++++++--- routers/api/v1/miscellaneous.go | 18 ++++++++++++++++++ routers/preview.go | 17 ----------------- templates/issue/create.tmpl | 4 ++-- templates/issue/view.tmpl | 4 ++-- templates/user/signin.tmpl | 2 +- web.go | 7 ++++++- 8 files changed, 41 insertions(+), 26 deletions(-) create mode 100644 routers/api/v1/miscellaneous.go delete mode 100644 routers/preview.go (limited to 'web.go') diff --git a/README.md b/README.md index 7d688506..e88a2477 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,8 @@ Gogs(Go Git Service) is a Self Hosted Git Service in the Go Programming Language ##### Current version: 0.1.9 Alpha +#### Due to testing purpose, data of [try.gogits.org](http://try.gogits.org) has been reset in March 29, 2014 and will reset multiple times after. Please do NOT put your important data on the site. + #### Other language version - [简体中文](README_ZH.md) diff --git a/models/repo.go b/models/repo.go index 4be655d2..a848694d 100644 --- a/models/repo.go +++ b/models/repo.go @@ -198,12 +198,19 @@ func CreateRepository(user *User, repoName, desc, repoLang, license string, priv c := exec.Command("git", "update-server-info") c.Dir = repoPath - err = c.Run() - if err != nil { + if err = c.Run(); err != nil { log.Error("repo.CreateRepository(exec update-server-info): %v", err) } - return repo, NewRepoAction(user, repo) + if err = NewRepoAction(user, repo); err != nil { + log.Error("repo.CreateRepository(NewRepoAction): %v", err) + } + + if err = WatchRepo(user.Id, repo.Id, true); err != nil { + log.Error("repo.CreateRepository(WatchRepo): %v", err) + } + + return repo, nil } // extractGitBareZip extracts git-bare.zip to repository path. diff --git a/routers/api/v1/miscellaneous.go b/routers/api/v1/miscellaneous.go new file mode 100644 index 00000000..0ff1eb04 --- /dev/null +++ b/routers/api/v1/miscellaneous.go @@ -0,0 +1,18 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package v1 + +import ( + "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/modules/middleware" +) + +func Markdown(ctx *middleware.Context) { + content := ctx.Query("content") + ctx.Render.JSON(200, map[string]interface{}{ + "ok": true, + "content": string(base.RenderMarkdown([]byte(content), "")), + }) +} diff --git a/routers/preview.go b/routers/preview.go deleted file mode 100644 index cc34c8fa..00000000 --- a/routers/preview.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2014 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package routers - -import "github.com/gogits/gogs/modules/middleware" - -func Preview(ctx *middleware.Context) { - content := ctx.Query("content") - // todo : gfm render content - // content = Markdown(content) - ctx.Render.JSON(200, map[string]interface{}{ - "ok": true, - "content": "preview : " + content, - }) -} diff --git a/templates/issue/create.tmpl b/templates/issue/create.tmpl index b8a533a1..f5cec0c0 100644 --- a/templates/issue/create.tmpl +++ b/templates/issue/create.tmpl @@ -15,11 +15,11 @@
- Content with Markdown + Content with Markdown
diff --git a/templates/issue/view.tmpl b/templates/issue/view.tmpl index 431b1d10..c357f535 100644 --- a/templates/issue/view.tmpl +++ b/templates/issue/view.tmpl @@ -69,11 +69,11 @@
- Content with Markdown + Content with Markdown
diff --git a/templates/user/signin.tmpl b/templates/user/signin.tmpl index 49a22626..b6c39af1 100644 --- a/templates/user/signin.tmpl +++ b/templates/user/signin.tmpl @@ -44,7 +44,7 @@
diff --git a/web.go b/web.go index 451e52ff..7725791e 100644 --- a/web.go +++ b/web.go @@ -24,6 +24,7 @@ import ( "github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/routers" "github.com/gogits/gogs/routers/admin" + "github.com/gogits/gogs/routers/api/v1" "github.com/gogits/gogs/routers/dev" "github.com/gogits/gogs/routers/repo" "github.com/gogits/gogs/routers/user" @@ -72,6 +73,7 @@ func newMartini() *martini.ClassicMartini { } func runWeb(*cli.Context) { + fmt.Println("Server is running...") globalInit() base.NewServices() checkRunMode() @@ -95,7 +97,10 @@ func runWeb(*cli.Context) { m.Get("/pulls", reqSignIn, user.Pulls) m.Get("/stars", reqSignIn, user.Stars) m.Get("/help", routers.Help) - m.Post("/preview", routers.Preview) + + m.Group("/api/v1", func(r martini.Router) { + r.Post("/markdown", v1.Markdown) + }) avt := avatar.CacheServer("public/img/avatar/", "public/img/avatar_default.jpg") m.Get("/avatar/:hash", avt.ServeHTTP) -- cgit v1.2.3 From cad2ced3945401243d7b644cb613432e1712ab41 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 29 Mar 2014 11:56:00 -0400 Subject: Bug fix --- routers/repo/issue.go | 8 ++++---- templates/install.tmpl | 2 +- templates/issue/view.tmpl | 8 ++++---- web.go | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) (limited to 'web.go') diff --git a/routers/repo/issue.go b/routers/repo/issue.go index b38967f7..337bd4bf 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -175,6 +175,7 @@ func ViewIssue(ctx *middleware.Context, params martini.Params) { ctx.Data["Title"] = issue.Name ctx.Data["Issue"] = issue ctx.Data["Comments"] = comments + ctx.Data["IsIssueOwner"] = issue.PosterId == ctx.User.Id ctx.Data["IsRepoToolbarIssues"] = true ctx.Data["IsRepoToolbarIssuesList"] = false ctx.HTML(200, "issue/view") @@ -217,10 +218,9 @@ func UpdateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat } ctx.JSON(200, map[string]interface{}{ - "ok": true, - "title": issue.Name, - "content": string(base.RenderMarkdown([]byte(issue.Content), "")), - "raw_content": issue.Content, + "ok": true, + "title": issue.Name, + "content": string(base.RenderMarkdown([]byte(issue.Content), "")), }) } diff --git a/templates/install.tmpl b/templates/install.tmpl index d8f05fca..a456ac5f 100644 --- a/templates/install.tmpl +++ b/templates/install.tmpl @@ -133,7 +133,7 @@
- +
-->
-
+ {{if .SignedUser}}
{{.CsrfTokenHtml}} @@ -95,7 +95,7 @@
-
+
{{else}}
Sign up for free to join this conversation. Already have an account? Sign in to comment
{{end}}
- +
- +

@@ -175,7 +180,7 @@
@@ -186,7 +191,7 @@
diff --git a/templates/issue/view.tmpl b/templates/issue/view.tmpl index 0481a33b..91e5250c 100644 --- a/templates/issue/view.tmpl +++ b/templates/issue/view.tmpl @@ -30,37 +30,37 @@
{{range .Comments}} -
- -
-
- {{.Poster.Name}} commented {{TimeSince .Created}} - - Owner -
-
- {{str2html .Content}} -
-
-
- {{end}} - + Owner + +
+ {{str2html .Content}} +
+ + + {{else if eq .Type 1}} +
+ +
+ {{.Poster.Name}} Reopened this issue {{TimeSince .Created}} +
+
+ {{else if eq .Type 2}} +
+
- {user.name} - Closed this - {close.time} + {{.Poster.Name}} Closed this issue {{TimeSince .Created}}
-
-
- -
- {user.name} - Reopened this - {close.time} -
-
--> + + {{end}} + {{end}}
{{if .SignedUser}}
@@ -68,8 +68,7 @@ {{.CsrfTokenHtml}}
-
- Content with Markdown +
Content with Markdown
-
loading...
+
Loading...
{{if .Issue.IsClosed}} - {{else}} + {{else}} {{end}}  
diff --git a/web.go b/web.go index 7098717a..6aabc0e9 100644 --- a/web.go +++ b/web.go @@ -8,19 +8,16 @@ import ( "fmt" "html/template" "net/http" - "strings" "github.com/codegangsta/cli" "github.com/codegangsta/martini" "github.com/gogits/binding" - "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/avatar" "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/log" - "github.com/gogits/gogs/modules/mailer" "github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/routers" "github.com/gogits/gogs/routers/admin" @@ -40,27 +37,6 @@ and it takes care of all the other things for you`, Flags: []cli.Flag{}, } -// globalInit is for global configuration reload-able. -func globalInit() { - base.NewConfigContext() - mailer.NewMailerContext() - models.LoadModelsConfig() - models.LoadRepoConfig() - models.NewRepoContext() - models.NewEngine() -} - -// Check run mode(Default of martini is Dev). -func checkRunMode() { - switch base.Cfg.MustValue("", "RUN_MODE") { - case "prod": - martini.Env = martini.Prod - case "test": - martini.Env = martini.Test - } - log.Info("Run Mode: %s", strings.Title(martini.Env)) -} - func newMartini() *martini.ClassicMartini { r := martini.NewRouter() m := martini.New() @@ -74,9 +50,7 @@ func newMartini() *martini.ClassicMartini { func runWeb(*cli.Context) { fmt.Println("Server is running...") - globalInit() - base.NewServices() - checkRunMode() + routers.GlobalInit() log.Info("%s %s", base.AppName, base.AppVer) m := newMartini() -- cgit v1.2.3 From e60676aec607471ebfff3a463a7cd7050d645672 Mon Sep 17 00:00:00 2001 From: slene Date: Sun, 30 Mar 2014 10:06:53 +0800 Subject: remove repeat routers & change commitd to branchname --- web.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'web.go') diff --git a/web.go b/web.go index 6aabc0e9..465d7da7 100644 --- a/web.go +++ b/web.go @@ -130,8 +130,8 @@ func runWeb(*cli.Context) { r.Post("/issues/:index", binding.BindIgnErr(auth.CreateIssueForm{}), repo.UpdateIssue) r.Post("/comment/:action", repo.Comment) }, reqSignIn, middleware.RepoAssignment(true)) + m.Group("/:username/:reponame", func(r martini.Router) { - r.Get("/commits/:branchname", repo.Commits) r.Get("/issues", repo.Issues) r.Get("/issues/:index", repo.ViewIssue) r.Get("/pulls", repo.Pulls) @@ -140,11 +140,10 @@ func runWeb(*cli.Context) { r.Get("/src/:branchname/**", repo.Single) r.Get("/raw/:branchname/**", repo.SingleDownload) r.Get("/commits/:branchname", repo.Commits) - r.Get("/commits/:branchname", repo.Commits) }, ignSignIn, middleware.RepoAssignment(true)) - m.Get("/:username/:reponame/commit/:commitid/**", ignSignIn, middleware.RepoAssignment(true), repo.Diff) - m.Get("/:username/:reponame/commit/:commitid", ignSignIn, middleware.RepoAssignment(true), repo.Diff) + m.Get("/:username/:reponame/commit/:branchname/**", ignSignIn, middleware.RepoAssignment(true), repo.Diff) + m.Get("/:username/:reponame/commit/:branchname", ignSignIn, middleware.RepoAssignment(true), repo.Diff) m.Group("/:username", func(r martini.Router) { r.Get("/:reponame", middleware.RepoAssignment(true), repo.Single) -- cgit v1.2.3 From d6c9e3413a982fd64a74e774d4a2b8157f39f299 Mon Sep 17 00:00:00 2001 From: slene Date: Sun, 30 Mar 2014 13:30:17 +0800 Subject: fix display bare repo --- modules/middleware/repo.go | 88 ++++++++++++++++++++++++----------------- routers/repo/repo.go | 1 + templates/repo/single_bare.tmpl | 13 +++--- templates/repo/toolbar.tmpl | 2 +- web.go | 13 +++--- 5 files changed, 68 insertions(+), 49 deletions(-) (limited to 'web.go') diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index deb28286..559e90c0 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -17,10 +17,20 @@ import ( "github.com/gogits/gogs/modules/base" ) -func RepoAssignment(redirect bool) martini.Handler { +func RepoAssignment(redirect bool, args ...bool) martini.Handler { return func(ctx *Context, params martini.Params) { - // assign false first - ctx.Data["IsRepositoryValid"] = false + // valid brachname + var validBranch bool + // display bare quick start if it is a bare repo + var displayBare bool + + if len(args) >= 1 { + validBranch = args[0] + } + + if len(args) >= 2 { + displayBare = args[1] + } var ( user *models.User @@ -71,6 +81,8 @@ func RepoAssignment(redirect bool) martini.Handler { } ctx.Repo.Repository = repo + ctx.Data["IsBareRepo"] = ctx.Repo.Repository.IsBare + gitRepo, err := git.OpenRepository(models.RepoPath(userName, repoName)) if err != nil { ctx.Handle(404, "RepoAssignment Invalid repo "+models.RepoPath(userName, repoName), err) @@ -86,50 +98,54 @@ func RepoAssignment(redirect bool) martini.Handler { ctx.Data["Owner"] = user ctx.Data["RepoLink"] = ctx.Repo.RepoLink ctx.Data["IsRepositoryOwner"] = ctx.Repo.IsOwner + ctx.Data["BranchName"] = "" ctx.Repo.CloneLink.SSH = fmt.Sprintf("%s@%s:%s/%s.git", base.RunUser, base.Domain, user.LowerName, repo.LowerName) ctx.Repo.CloneLink.HTTPS = fmt.Sprintf("%s%s/%s.git", base.AppUrl, user.LowerName, repo.LowerName) ctx.Data["CloneLink"] = ctx.Repo.CloneLink - if repo.IsBare { - ctx.Data["IsBareRepo"] = true - ctx.HTML(200, "repo/single_bare") - return - } - - detect: - if len(branchName) > 0 { - // TODO check tag - if models.IsBranchExist(user.Name, repoName, branchName) { - ctx.Repo.IsBranch = true - ctx.Repo.BranchName = branchName - - ctx.Repo.Commit, err = gitRepo.GetCommitOfBranch(branchName) - if err != nil { - ctx.Handle(404, "RepoAssignment invalid branch", nil) + // when repo is bare, not valid branch + if !ctx.Repo.Repository.IsBare && validBranch { + detect: + if len(branchName) > 0 { + // TODO check tag + if models.IsBranchExist(user.Name, repoName, branchName) { + ctx.Repo.IsBranch = true + ctx.Repo.BranchName = branchName + + ctx.Repo.Commit, err = gitRepo.GetCommitOfBranch(branchName) + if err != nil { + ctx.Handle(404, "RepoAssignment invalid branch", nil) + return + } + + ctx.Repo.CommitId = ctx.Repo.Commit.Oid.String() + + } else if len(branchName) == 40 { + ctx.Repo.IsCommit = true + ctx.Repo.CommitId = branchName + ctx.Repo.BranchName = branchName + + ctx.Repo.Commit, err = gitRepo.GetCommit(branchName) + if err != nil { + ctx.Handle(404, "RepoAssignment invalid commit", nil) + return + } + } else { + ctx.Handle(404, "RepoAssignment invalid repo", nil) return } - ctx.Repo.CommitId = ctx.Repo.Commit.Oid.String() - - } else if len(branchName) == 40 { - ctx.Repo.IsCommit = true - ctx.Repo.CommitId = branchName - ctx.Repo.BranchName = branchName - - ctx.Repo.Commit, err = gitRepo.GetCommit(branchName) - if err != nil { - ctx.Handle(404, "RepoAssignment invalid commit", nil) - return - } } else { - ctx.Handle(404, "RepoAssignment invalid repo", nil) - return + branchName = "master" + goto detect } + } - } else { - branchName = "master" - goto detect + // repo is bare and display enable + if displayBare && ctx.Repo.Repository.IsBare { + ctx.HTML(200, "repo/single_bare") + return } if ctx.IsSigned { diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 27c806a3..5b0a165d 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -78,6 +78,7 @@ func Single(ctx *middleware.Context, params martini.Params) { ctx.Handle(404, "repo.Single(GetBranches)", err) return } + ctx.Data["Branches"] = brs isViewBranch := ctx.Repo.IsBranch diff --git a/templates/repo/single_bare.tmpl b/templates/repo/single_bare.tmpl index fe0e3aa3..035e78e8 100644 --- a/templates/repo/single_bare.tmpl +++ b/templates/repo/single_bare.tmpl @@ -1,6 +1,7 @@ {{template "base/head" .}} {{template "base/navbar" .}} {{template "repo/nav" .}} +{{template "repo/toolbar" .}}
@@ -23,15 +24,15 @@

Create a new repository on the command line

touch README.md
-        git init
-        git add README.md
-        git commit -m "first commit"
-        git remote add origin 
-        git push -u origin master
+git init +git add README.md +git commit -m "first commit" +git remote add origin +git push -u origin master

Push an existing repository from the command line

git remote add origin 
-        git push -u origin master
+git push -u origin master
diff --git a/templates/repo/toolbar.tmpl b/templates/repo/toolbar.tmpl index 3c7c8a50..542f8fd8 100644 --- a/templates/repo/toolbar.tmpl +++ b/templates/repo/toolbar.tmpl @@ -3,7 +3,7 @@