Compare commits
11 commits
forgejo
...
playground
| Author | SHA1 | Date | |
|---|---|---|---|
| 438cb54f2b | |||
| 68bb649c32 | |||
| ce0ae467f2 | |||
| 536ab31de3 | |||
| d9ea2e1b00 | |||
| 2bb6f391db | |||
| 7a09e9ca7e | |||
| 38d4eca60a | |||
| 48c9630647 | |||
| ebee7185a3 | |||
| b3743e1f9d |
18 changed files with 581 additions and 0 deletions
108
Dockerfile.custom
Normal file
108
Dockerfile.custom
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
FROM --platform=$BUILDPLATFORM code.forgejo.org/oci/xx AS xx
|
||||
|
||||
FROM --platform=$BUILDPLATFORM code.forgejo.org/oci/golang:1.23-alpine3.20 as build-env
|
||||
|
||||
ARG GOPROXY
|
||||
ENV GOPROXY=${GOPROXY:-direct}
|
||||
|
||||
ARG RELEASE_VERSION
|
||||
ARG TAGS="sqlite sqlite_unlock_notify"
|
||||
ENV TAGS="bindata timetzdata $TAGS"
|
||||
ARG CGO_EXTRA_CFLAGS
|
||||
|
||||
#
|
||||
# Transparently cross compile for the target platform
|
||||
#
|
||||
COPY --from=xx / /
|
||||
ARG TARGETPLATFORM
|
||||
RUN apk add clang lld
|
||||
RUN xx-apk add gcc musl-dev
|
||||
ENV CGO_ENABLED=1
|
||||
RUN xx-go --wrap
|
||||
#
|
||||
# for go generate and binfmt to find
|
||||
# without it the generate phase will fail with
|
||||
# #19 25.04 modules/public/public_bindata.go:8: running "go": exit status 1
|
||||
# #19 25.39 aarch64-binfmt-P: Could not open '/lib/ld-musl-aarch64.so.1': No such file or directory
|
||||
# why exactly is it needed? where is binfmt involved?
|
||||
#
|
||||
RUN cp /*-alpine-linux-musl*/lib/ld-musl-*.so.1 /lib || true
|
||||
|
||||
RUN apk add build-base git nodejs npm
|
||||
|
||||
COPY . ${GOPATH}/src/code.gitea.io/gitea
|
||||
WORKDIR ${GOPATH}/src/code.gitea.io/gitea
|
||||
|
||||
#RUN make clean
|
||||
RUN make frontend
|
||||
RUN go build contrib/environment-to-ini/environment-to-ini.go && xx-verify environment-to-ini
|
||||
RUN LDFLAGS="-buildid=" make RELEASE_VERSION=$RELEASE_VERSION GOFLAGS="-trimpath" go-check generate-backend static-executable && xx-verify gitea
|
||||
|
||||
# Copy local files
|
||||
COPY docker/root /tmp/local
|
||||
|
||||
# Set permissions
|
||||
RUN chmod 755 /tmp/local/usr/bin/entrypoint \
|
||||
/tmp/local/usr/local/bin/gitea \
|
||||
/tmp/local/etc/s6/gitea/* \
|
||||
/tmp/local/etc/s6/openssh/* \
|
||||
/tmp/local/etc/s6/.s6-svscan/* \
|
||||
/go/src/code.gitea.io/gitea/gitea \
|
||||
/go/src/code.gitea.io/gitea/environment-to-ini
|
||||
RUN chmod 644 /go/src/code.gitea.io/gitea/contrib/autocompletion/bash_autocomplete
|
||||
|
||||
FROM code.forgejo.org/oci/alpine:3.20
|
||||
ARG RELEASE_VERSION
|
||||
LABEL maintainer="contact@forgejo.org" \
|
||||
org.opencontainers.image.authors="Forgejo" \
|
||||
org.opencontainers.image.url="https://forgejo.org" \
|
||||
org.opencontainers.image.documentation="https://forgejo.org/download/#container-image" \
|
||||
org.opencontainers.image.source="https://codeberg.org/forgejo/forgejo" \
|
||||
org.opencontainers.image.version="${RELEASE_VERSION}" \
|
||||
org.opencontainers.image.vendor="Forgejo" \
|
||||
org.opencontainers.image.licenses="GPL-3.0-or-later" \
|
||||
org.opencontainers.image.title="Forgejo. Beyond coding. We forge." \
|
||||
org.opencontainers.image.description="Forgejo is a self-hosted lightweight software forge. Easy to install and low maintenance, it just does the job."
|
||||
|
||||
EXPOSE 22 3000
|
||||
|
||||
RUN apk add \
|
||||
bash \
|
||||
ca-certificates \
|
||||
curl \
|
||||
gettext \
|
||||
git \
|
||||
linux-pam \
|
||||
openssh \
|
||||
s6 \
|
||||
sqlite \
|
||||
su-exec \
|
||||
gnupg \
|
||||
&& rm -rf /var/cache/apk/*
|
||||
|
||||
RUN addgroup \
|
||||
-S -g 1000 \
|
||||
git && \
|
||||
adduser \
|
||||
-S -H -D \
|
||||
-h /data/git \
|
||||
-s /bin/bash \
|
||||
-u 1000 \
|
||||
-G git \
|
||||
git && \
|
||||
echo "git:*" | chpasswd -e
|
||||
|
||||
ENV USER=git
|
||||
ENV GITEA_CUSTOM=/data/gitea
|
||||
|
||||
VOLUME ["/data"]
|
||||
|
||||
ENTRYPOINT ["/usr/bin/entrypoint"]
|
||||
CMD ["/bin/s6-svscan", "/etc/s6"]
|
||||
|
||||
COPY --from=build-env /tmp/local /
|
||||
RUN cd /usr/local/bin ; ln -s gitea forgejo
|
||||
COPY --from=build-env /go/src/code.gitea.io/gitea/gitea /app/gitea/gitea
|
||||
RUN ln -s /app/gitea/gitea /app/gitea/forgejo-cli
|
||||
COPY --from=build-env /go/src/code.gitea.io/gitea/environment-to-ini /usr/local/bin/environment-to-ini
|
||||
COPY --from=build-env /go/src/code.gitea.io/gitea/contrib/autocompletion/bash_autocomplete /etc/profile.d/gitea_bash_autocomplete.sh
|
||||
1
Makefile
1
Makefile
|
|
@ -111,6 +111,7 @@ STRIP ?= 1
|
|||
ifeq ($(STRIP),1)
|
||||
LDFLAGS := $(LDFLAGS) -s -w
|
||||
endif
|
||||
|
||||
LDFLAGS := $(LDFLAGS) -X "main.ReleaseVersion=$(RELEASE_VERSION)" -X "main.MakeVersion=$(MAKE_VERSION)" -X "main.Version=$(FORGEJO_VERSION)" -X "main.Tags=$(TAGS)" -X "main.ForgejoVersion=$(FORGEJO_VERSION_API)"
|
||||
|
||||
LINUX_ARCHS ?= linux/amd64,linux/386,linux/arm-5,linux/arm-6,linux/arm64
|
||||
|
|
|
|||
1
STORED_VERSION_FILE
Normal file
1
STORED_VERSION_FILE
Normal file
|
|
@ -0,0 +1 @@
|
|||
0.1
|
||||
19
models/playground/player.go
Normal file
19
models/playground/player.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package playground
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
)
|
||||
|
||||
type Player struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
}
|
||||
|
||||
func createPlayer(ctx context.Context, p *Player) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func init() {
|
||||
db.RegisterModel(new(Player))
|
||||
}
|
||||
|
|
@ -40,6 +40,7 @@ var (
|
|||
svgComment = regexp.MustCompile(`(?s)<!--.*?-->`)
|
||||
svgTagRegex = regexp.MustCompile(`(?si)\A\s*(?:(<!DOCTYPE\s+svg([\s:]+.*?>|>))\s*)*<svg\b`)
|
||||
svgTagInXMLRegex = regexp.MustCompile(`(?si)\A<\?xml\b.*?\?>\s*(?:(<!DOCTYPE\s+svg([\s:]+.*?>|>))\s*)*<svg\b`)
|
||||
ifcRegex = regexp.MustCompile(`(?si)ISO\-10303\-21\;`)
|
||||
)
|
||||
|
||||
// SniffedType contains information about a blobs type.
|
||||
|
|
@ -67,6 +68,11 @@ func (ct SniffedType) IsPDF() bool {
|
|||
return strings.Contains(ct.contentType, "application/pdf")
|
||||
}
|
||||
|
||||
// IsIFC detects if data is a IFC format
|
||||
func (ct SniffedType) IsIFC() bool {
|
||||
return strings.Contains(ct.contentType, "ifc/")
|
||||
}
|
||||
|
||||
// IsVideo detects if data is an video format
|
||||
func (ct SniffedType) IsVideo() bool {
|
||||
return strings.Contains(ct.contentType, "video/")
|
||||
|
|
@ -123,6 +129,14 @@ func (ct SniffedType) GetMimeType() string {
|
|||
return strings.SplitN(ct.contentType, ";", 2)[0]
|
||||
}
|
||||
|
||||
func DetectContentFromData(ct string, data []byte) string {
|
||||
if ifcRegex.Match(data) {
|
||||
return "ifc/"
|
||||
} else {
|
||||
return ct
|
||||
}
|
||||
}
|
||||
|
||||
// DetectContentType extends http.DetectContentType with more content types. Defaults to text/unknown if input is empty.
|
||||
func DetectContentType(data []byte, filename string) SniffedType {
|
||||
if len(data) == 0 {
|
||||
|
|
@ -189,6 +203,8 @@ func DetectContentType(data []byte, filename string) SniffedType {
|
|||
ct = GLBMimeType
|
||||
}
|
||||
|
||||
ct = DetectContentFromData(ct, data)
|
||||
|
||||
return SniffedType{ct}
|
||||
}
|
||||
|
||||
|
|
|
|||
37
routers/web/playground.go
Normal file
37
routers/web/playground.go
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
// Copyright 2024 Milovann Yanatchkov
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package web
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/services/context"
|
||||
)
|
||||
|
||||
const (
|
||||
tplPlayground base.TplName = "playground/playground"
|
||||
tplPlaygroundReplIframe base.TplName = "playground/repl-iframe"
|
||||
tplPlaygroundPyScript base.TplName = "playground/pyscript"
|
||||
)
|
||||
|
||||
func PlaygroundReplIframe(ctx *context.Context) {
|
||||
ctx.Data["PageIsPlayground"] = true
|
||||
ctx.HTML(http.StatusOK, tplPlaygroundReplIframe)
|
||||
}
|
||||
|
||||
func PlaygroundPyScript(ctx *context.Context) {
|
||||
|
||||
ctx.Data["PageIsPlayground"] = true
|
||||
ctx.HTML(http.StatusOK, tplPlaygroundPyScript)
|
||||
}
|
||||
|
||||
func Playground(ctx *context.Context) {
|
||||
if ctx.IsSigned {
|
||||
ctx.Data["UserName"] = ctx.Doer.DisplayName()
|
||||
}
|
||||
|
||||
ctx.Data["PageIsPlayground"] = true
|
||||
ctx.HTML(http.StatusOK, tplPlayground)
|
||||
}
|
||||
119
routers/web/repo/run.go
Normal file
119
routers/web/repo/run.go
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
package repo
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/charset"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/markup"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/typesniffer"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
"code.gitea.io/gitea/services/context"
|
||||
)
|
||||
|
||||
const (
|
||||
tplRunFile base.TplName = "repo/editor/run"
|
||||
)
|
||||
|
||||
func RunFile(ctx *context.Context) {
|
||||
runFile(ctx, false)
|
||||
}
|
||||
|
||||
func runFile(ctx *context.Context, isNewFile bool) {
|
||||
ctx.Data["PageIsEdit"] = true
|
||||
ctx.Data["IsNewFile"] = isNewFile
|
||||
canCommit := renderCommitRights(ctx)
|
||||
|
||||
treePath := cleanUploadFileName(ctx.Repo.TreePath)
|
||||
if treePath != ctx.Repo.TreePath {
|
||||
if isNewFile {
|
||||
ctx.Redirect(path.Join(ctx.Repo.RepoLink, "_new", util.PathEscapeSegments(ctx.Repo.BranchName), util.PathEscapeSegments(treePath)))
|
||||
} else {
|
||||
ctx.Redirect(path.Join(ctx.Repo.RepoLink, "_edit", util.PathEscapeSegments(ctx.Repo.BranchName), util.PathEscapeSegments(treePath)))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Check if the filename (and additional path) is specified in the querystring
|
||||
// (filename is a misnomer, but kept for compatibility with GitHub)
|
||||
filePath, fileName := path.Split(ctx.Req.URL.Query().Get("filename"))
|
||||
filePath = strings.Trim(filePath, "/")
|
||||
treeNames, treePaths := getParentTreeFields(path.Join(ctx.Repo.TreePath, filePath))
|
||||
|
||||
if !isNewFile {
|
||||
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath)
|
||||
if err != nil {
|
||||
HandleGitError(ctx, "Repo.Commit.GetTreeEntryByPath", err)
|
||||
return
|
||||
}
|
||||
|
||||
// No way to edit a directory online.
|
||||
if entry.IsDir() {
|
||||
ctx.NotFound("entry.IsDir", nil)
|
||||
return
|
||||
}
|
||||
|
||||
blob := entry.Blob()
|
||||
if blob.Size() >= setting.UI.MaxDisplayFileSize {
|
||||
ctx.NotFound("blob.Size", err)
|
||||
return
|
||||
}
|
||||
|
||||
dataRc, err := blob.DataAsync()
|
||||
if err != nil {
|
||||
ctx.NotFound("blob.Data", err)
|
||||
return
|
||||
}
|
||||
|
||||
defer dataRc.Close()
|
||||
|
||||
ctx.Data["FileSize"] = blob.Size()
|
||||
ctx.Data["FileName"] = blob.Name()
|
||||
|
||||
buf := make([]byte, 1024)
|
||||
n, _ := util.ReadAtMost(dataRc, buf)
|
||||
buf = buf[:n]
|
||||
|
||||
// Only some file types are editable online as text.
|
||||
if !typesniffer.DetectContentType(buf).IsRepresentableAsText() {
|
||||
ctx.NotFound("typesniffer.IsRepresentableAsText", nil)
|
||||
return
|
||||
}
|
||||
|
||||
d, _ := io.ReadAll(dataRc)
|
||||
|
||||
buf = append(buf, d...)
|
||||
if content, err := charset.ToUTF8(buf, charset.ConvertOpts{KeepBOM: true}); err != nil {
|
||||
log.Error("ToUTF8: %v", err)
|
||||
ctx.Data["FileContent"] = string(buf)
|
||||
} else {
|
||||
ctx.Data["FileContent"] = content
|
||||
}
|
||||
} else {
|
||||
// Append filename from query, or empty string to allow user name the new file.
|
||||
treeNames = append(treeNames, fileName)
|
||||
}
|
||||
|
||||
ctx.Data["TreeNames"] = treeNames
|
||||
ctx.Data["TreePaths"] = treePaths
|
||||
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
|
||||
ctx.Data["commit_summary"] = ""
|
||||
ctx.Data["commit_message"] = ""
|
||||
if canCommit {
|
||||
ctx.Data["commit_choice"] = frmCommitChoiceDirect
|
||||
} else {
|
||||
ctx.Data["commit_choice"] = frmCommitChoiceNewBranch
|
||||
}
|
||||
ctx.Data["new_branch_name"] = GetUniquePatchBranchName(ctx)
|
||||
ctx.Data["last_commit"] = ctx.Repo.CommitID
|
||||
ctx.Data["PreviewableExtensions"] = strings.Join(markup.PreviewableExtensions(), ",")
|
||||
ctx.Data["LineWrapExtensions"] = strings.Join(setting.Repository.Editor.LineWrapExtensions, ",")
|
||||
ctx.Data["EditorconfigJson"] = GetEditorConfig(ctx, treePath)
|
||||
|
||||
ctx.HTML(http.StatusOK, tplRunFile)
|
||||
}
|
||||
|
|
@ -620,6 +620,8 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry) {
|
|||
|
||||
case fInfo.st.IsPDF():
|
||||
ctx.Data["IsPDFFile"] = true
|
||||
case fInfo.st.IsIFC():
|
||||
ctx.Data["IsIFC"] = true
|
||||
case fInfo.st.IsVideo():
|
||||
ctx.Data["IsVideoFile"] = true
|
||||
case fInfo.st.IsAudio():
|
||||
|
|
|
|||
|
|
@ -470,6 +470,9 @@ func registerRoutes(m *web.Route) {
|
|||
// Especially some AJAX requests, we can reduce middleware number to improve performance.
|
||||
|
||||
m.Get("/", Home)
|
||||
m.Get("/playground", Playground)
|
||||
m.Get("/playground/repl-iframe", PlaygroundReplIframe)
|
||||
m.Get("/playground/pyscript", PlaygroundPyScript)
|
||||
m.Get("/sitemap.xml", sitemapEnabled, ignExploreSignIn, HomeSitemap)
|
||||
m.Group("/.well-known", func() {
|
||||
m.Get("/openid-configuration", auth.OIDCWellKnown)
|
||||
|
|
@ -1291,6 +1294,8 @@ func registerRoutes(m *web.Route) {
|
|||
m.Group("", func() {
|
||||
m.Combo("/_edit/*").Get(repo.EditFile).
|
||||
Post(web.Bind(forms.EditRepoFileForm{}), repo.EditFilePost)
|
||||
m.Combo("/_run/*").Get(repo.RunFile).
|
||||
Post(web.Bind(forms.EditRepoFileForm{}), repo.EditFilePost)
|
||||
m.Combo("/_new/*").Get(repo.NewFile).
|
||||
Post(web.Bind(forms.EditRepoFileForm{}), repo.NewFilePost)
|
||||
m.Post("/_preview/*", web.Bind(forms.EditPreviewDiffForm{}), repo.DiffPreviewPost)
|
||||
|
|
|
|||
1
templates/playground/footer.tmpl
Normal file
1
templates/playground/footer.tmpl
Normal file
|
|
@ -0,0 +1 @@
|
|||
|
||||
16
templates/playground/header.tmpl
Normal file
16
templates/playground/header.tmpl
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<div class="secondary-nav">
|
||||
<overflow-menu class="ui container secondary pointing tabular top attached borderless menu tw-pt-0 tw-my-0">
|
||||
<div class="overflow-menu-items">
|
||||
<a class="{{if .IsRepoFlagsPage}}active {{end}}item" href="{{AppSubUrl}}/playground">
|
||||
{{svg "octicon-stack"}} Playground
|
||||
</a>
|
||||
<a class="{{if .IsRepoFlagsPage}}active {{end}}item" href="{{AppSubUrl}}/playground/repl-iframe">
|
||||
{{svg "octicon-terminal"}} Repl
|
||||
</a>
|
||||
<a class="{{if .IsRepoFlagsPage}}active {{end}}item" href="{{AppSubUrl}}/playground/pyscript">
|
||||
{{svg "octicon-paper-airplane"}} PyScript
|
||||
</a>
|
||||
</div>
|
||||
|
||||
</overflow-menu>
|
||||
</div>
|
||||
10
templates/playground/playground.tmpl
Normal file
10
templates/playground/playground.tmpl
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
{{template "base/head" .}}
|
||||
|
||||
{{template "playground/header" .}}
|
||||
|
||||
{{if .IsSigned}}
|
||||
User : {{.UserName}}
|
||||
{{else}}
|
||||
User : None
|
||||
{{end}}
|
||||
{{template "base/footer" .}}
|
||||
11
templates/playground/pyscript.tmpl
Normal file
11
templates/playground/pyscript.tmpl
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
{{template "base/head" .}}
|
||||
|
||||
{{template "playground/header" .}}
|
||||
|
||||
<input type="text" id="english" placeholder="Type English here..." />
|
||||
<button py-click="translate_english">Translate</button>
|
||||
<div id="output"></div>
|
||||
<script type="py" src="{{AssetUrlPrefix}}/pyscript/main.py" config="{{AssetUrlPrefix}}/pyscript/pyscript.json"></script>
|
||||
|
||||
{{template "base/footer" .}}
|
||||
13
templates/playground/repl-iframe.tmpl
Normal file
13
templates/playground/repl-iframe.tmpl
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
{{template "base/head" .}}
|
||||
|
||||
{{template "playground/header" .}}
|
||||
|
||||
<iframe
|
||||
src="https://jupyterlite.github.io/demo/repl/index.html?kernel=python"
|
||||
width="100%"
|
||||
height="97%"
|
||||
></iframe>
|
||||
|
||||
|
||||
{{template "base/footer" .}}
|
||||
|
|
@ -29,6 +29,9 @@
|
|||
<div class="ui top attached tabular menu" data-write="write" data-preview="preview" data-diff="diff">
|
||||
<a class="active item" data-tab="write">{{svg "octicon-code"}} {{if .IsNewFile}}{{ctx.Locale.Tr "repo.editor.new_file"}}{{else}}{{ctx.Locale.Tr "repo.editor.edit_file"}}{{end}}</a>
|
||||
<a class="item" data-tab="preview" data-url="{{.Repository.Link}}/markup" data-context="{{.RepoLink}}" data-branch-path="{{.BranchNameSubURL}}" data-markup-mode="file">{{svg "octicon-eye"}} {{ctx.Locale.Tr "preview"}}</a>
|
||||
<a class="item" data-tab="run" data-url="{{.Repository.Link}}/markup" data-context="{{.RepoLink}}/src/{{.BranchNameSubURL}}" data-markup-mode="file">{{svg "octicon-paper-airplane"}} {{ctx.Locale.Tr "Run"}}</a>
|
||||
<a class="item" data-tab="run" >{{svg "octicon-paper-airplane"}} {{ctx.Locale.Tr "Run"}}</a>
|
||||
<a class="item" data-tab="preview" data-url="{{.Repository.Link}}/markup" data-context="{{.RepoLink}}/src/{{.BranchNameSubURL}}" data-markup-mode="file">{{svg "octicon-eye"}} {{ctx.Locale.Tr "preview"}}</a>
|
||||
{{if not .IsNewFile}}
|
||||
<a class="item" data-tab="diff" hx-params="context,content" hx-vals='{"context":"{{.BranchLink}}"}' hx-include="#edit_area" hx-swap="innerHTML" hx-target=".tab[data-tab='diff']" hx-indicator=".tab[data-tab='diff']" hx-post="{{.RepoLink}}/_preview/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}">{{svg "octicon-diff"}} {{ctx.Locale.Tr "repo.editor.preview_changes"}}</a>
|
||||
{{end}}
|
||||
|
|
@ -41,6 +44,14 @@
|
|||
data-line-wrap-extensions="{{.LineWrapExtensions}}">{{.FileContent}}</textarea>
|
||||
<div class="editor-loading is-loading"></div>
|
||||
</div>
|
||||
<!-- <div class="ui bottom attached tab segment markup" data-tab="run"> -->
|
||||
<div class="ui tab" data-tab="run">
|
||||
<button>click me</button>
|
||||
<input type="text" id="english" placeholder="Type English here..." />
|
||||
<button py-click="translate_english">Translate</button>
|
||||
<div id="output"></div>
|
||||
<script type="py" src="{{AssetUrlPrefix}}/pyscript/main.py" config="{{AssetUrlPrefix}}/pyscript/pyscript.json"></script>
|
||||
</div>
|
||||
<div class="ui bottom attached tab segment markup" data-tab="preview">
|
||||
{{ctx.Locale.Tr "loading"}}
|
||||
</div>
|
||||
|
|
|
|||
83
templates/repo/editor/run.tmpl
Normal file
83
templates/repo/editor/run.tmpl
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
{{template "base/head" .}}
|
||||
<div role="main" aria-label="{{.Title}}" class="page-content repository file editor edit">
|
||||
{{template "repo/header" .}}
|
||||
<div class="ui container">
|
||||
{{template "base/alert" .}}
|
||||
<form class="ui edit form" method="post">
|
||||
{{.CsrfTokenHtml}}
|
||||
<input type="hidden" name="last_commit" value="{{.last_commit}}">
|
||||
<input type="hidden" name="page_has_posted" value="{{.PageHasPosted}}">
|
||||
<div class="repo-editor-header">
|
||||
<div class="ui breadcrumb field{{if .Err_TreePath}} error{{end}}">
|
||||
<a class="section" href="{{$.BranchLink}}">{{.Repository.Name}}</a>
|
||||
{{$n := len .TreeNames}}
|
||||
{{$l := Eval $n "-" 1}}
|
||||
{{range $i, $v := .TreeNames}}
|
||||
<div class="breadcrumb-divider">/</div>
|
||||
{{if eq $i $l}}
|
||||
<input id="file-name" maxlength="500" value="{{$v}}" placeholder="{{ctx.Locale.Tr "repo.editor.name_your_file"}}" data-editorconfig="{{$.EditorconfigJson}}" required autofocus>
|
||||
<span data-tooltip-content="{{ctx.Locale.Tr "repo.editor.filename_help"}}">{{svg "octicon-info"}}</span>
|
||||
{{else}}
|
||||
<span class="section"><a href="{{$.BranchLink}}/{{index $.TreePaths $i | PathEscapeSegments}}">{{$v}}</a></span>
|
||||
{{end}}
|
||||
{{end}}
|
||||
<span>{{ctx.Locale.Tr "repo.editor.or"}} <a href="{{$.BranchLink}}{{if not .IsNewFile}}/{{PathEscapeSegments .TreePath}}{{end}}">{{ctx.Locale.Tr "repo.editor.cancel_lower"}}</a></span>
|
||||
<input type="hidden" id="tree_path" name="tree_path" value="{{.TreePath}}" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="ui top attached tabular menu" data-write="write" data-preview="preview" data-diff="diff">
|
||||
<a class="active item" data-tab="write">{{svg "octicon-code"}} {{if .IsNewFile}}{{ctx.Locale.Tr "repo.editor.new_file"}}{{else}}{{ctx.Locale.Tr "repo.editor.edit_file"}}{{end}}</a>
|
||||
<a class="item" data-tab="run" data-url="{{.Repository.Link}}/markup" data-context="{{.RepoLink}}/src/{{.BranchNameSubURL}}" data-markup-mode="file">{{svg "octicon-paper-airplane"}} {{ctx.Locale.Tr "Run"}}</a>
|
||||
<a class="item" data-tab="preview" data-url="{{.Repository.Link}}/markup" data-context="{{.RepoLink}}/src/{{.BranchNameSubURL}}" data-markup-mode="file">{{svg "octicon-eye"}} {{ctx.Locale.Tr "preview"}}</a>
|
||||
{{if not .IsNewFile}}
|
||||
<a class="item" data-tab="diff" hx-params="context,content" hx-vals='{"context":"{{.BranchLink}}"}' hx-include="#edit_area" hx-swap="innerHTML" hx-target=".tab[data-tab='diff']" hx-indicator=".tab[data-tab='diff']" hx-post="{{.RepoLink}}/_preview/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}">{{svg "octicon-diff"}} {{ctx.Locale.Tr "repo.editor.preview_changes"}}</a>
|
||||
{{end}}
|
||||
</div>
|
||||
<div class="ui bottom attached active tab segment" data-tab="write">
|
||||
<textarea id="edit_area" name="content" class="tw-hidden" data-id="repo-{{.Repository.Name}}-{{.TreePath}}"
|
||||
data-url="{{.Repository.Link}}/markup"
|
||||
data-context="{{.RepoLink}}"
|
||||
data-previewable-extensions="{{.PreviewableExtensions}}"
|
||||
data-line-wrap-extensions="{{.LineWrapExtensions}}">{{.FileContent}}</textarea>
|
||||
<div class="editor-loading is-loading"></div>
|
||||
</div>
|
||||
<!-- <div class="ui bottom attached tab segment markup" data-tab="run"> -->
|
||||
<div class="ui bottom attached tab segment markup" data-tab="run">
|
||||
<button>click me</button>
|
||||
<input type="text" id="english" placeholder="Type English here..." />
|
||||
<button py-click="translate_english">Translate</button>
|
||||
<div id="output"></div>
|
||||
<script type="py" src="{{AssetUrlPrefix}}/pyscript/main.py" config="{{AssetUrlPrefix}}/pyscript/pyscript.json"></script>
|
||||
</div>
|
||||
<div class="ui bottom attached tab segment markup" data-tab="preview">
|
||||
{{ctx.Locale.Tr "loading"}}
|
||||
</div>
|
||||
<div class="ui bottom attached tab segment diff edit-diff" data-tab="diff">
|
||||
<div class="tw-p-16"></div>
|
||||
</div>
|
||||
</div>
|
||||
{{template "repo/editor/commit_form" .}}
|
||||
</form>
|
||||
</div>
|
||||
<div class="ui g-modal-confirm modal" id="edit-empty-content-modal">
|
||||
<div class="header">
|
||||
{{svg "octicon-file"}}
|
||||
{{ctx.Locale.Tr "repo.editor.commit_empty_file_header"}}
|
||||
</div>
|
||||
<div class="center content">
|
||||
<p>{{ctx.Locale.Tr "repo.editor.commit_empty_file_text"}}</p>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button class="ui cancel button">
|
||||
{{svg "octicon-x"}}
|
||||
{{ctx.Locale.Tr "repo.editor.cancel"}}
|
||||
</button>
|
||||
<button class="ui primary ok button">
|
||||
{{svg "fontawesome-save"}}
|
||||
{{ctx.Locale.Tr "repo.editor.commit_changes"}}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{template "base/footer" .}}
|
||||
|
|
@ -103,6 +103,7 @@
|
|||
{{if and .ReadmeInList .CanEditReadmeFile}}
|
||||
<a class="btn-octicon" data-tooltip-content="{{ctx.Locale.Tr "repo.editor.edit_this_file"}}" href="{{.RepoLink}}/_edit/{{PathEscapeSegments .BranchName}}/{{PathEscapeSegments .TreePath}}/{{PathEscapeSegments .FileName}}">{{svg "octicon-pencil"}}</a>
|
||||
{{end}}
|
||||
<a class="btn-octicon" data-tooltip-content="{{ctx.Locale.Tr "repo.editor.edit_this_file"}}" href="{{.RepoLink}}/_run/{{PathEscapeSegments .BranchName}}/{{PathEscapeSegments .TreePath}}/{{PathEscapeSegments .FileName}}">{{svg "octicon-paper-airplane"}}</a>
|
||||
</div>
|
||||
</h4>
|
||||
<div class="ui bottom attached table unstackable segment">
|
||||
|
|
@ -136,6 +137,129 @@
|
|||
{{else}}
|
||||
<a href="{{$.RawFileLink}}" rel="nofollow">{{ctx.Locale.Tr "repo.file_view_raw"}}</a>
|
||||
{{end}}
|
||||
<div class="pdf-content is-loading" data-src="{{$.RawFileLink}}" data-fallback-button-text="{{ctx.Locale.Tr "repo.diff.view_file"}}"></div>
|
||||
{{else if .IsIFC}}
|
||||
|
||||
|
||||
<div class="full-screen" id="container" style="width: 100%;height:500px;"></div>
|
||||
<script type="module">
|
||||
|
||||
import * as THREE from "https://unpkg.com/three@0.152.2/build/three.module.js";
|
||||
import * as OBC from "/assets/js/openbim-components.js";
|
||||
import * as WEBIFC from "https://unpkg.com/web-ifc@0.0.50/web-ifc-api.js";
|
||||
import Stats from "https://unpkg.com/stats-js@1.0.1/src/Stats.js";
|
||||
import * as dat from "https://unpkg.com/three@0.152.2/examples/jsm/libs/lil-gui.module.min.js";
|
||||
import {downloadZip} from "https://unpkg.com/client-zip@2.3.0/index.js";
|
||||
|
||||
const container = document.getElementById('container');
|
||||
const components = new OBC.Components();
|
||||
|
||||
components.scene = new OBC.SimpleScene(components);
|
||||
components.renderer = new OBC.PostproductionRenderer(components, container);
|
||||
components.camera = new OBC.SimpleCamera(components);
|
||||
components.raycaster = new OBC.SimpleRaycaster(components);
|
||||
|
||||
components.init();
|
||||
|
||||
components.renderer.postproduction.enabled = true;
|
||||
const scene = components.scene.get();
|
||||
components.camera.controls.setLookAt(12, 6, 8, 0, 0, -10);
|
||||
components.scene.setup();
|
||||
|
||||
const grid = new OBC.SimpleGrid(components, new THREE.Color(0x666666));
|
||||
const customEffects = components.renderer.postproduction.customEffects;
|
||||
customEffects.excludedMeshes.push(grid.get());
|
||||
|
||||
let fragments = new OBC.FragmentManager(components);
|
||||
let fragmentIfcLoader = new OBC.FragmentIfcLoader(components);
|
||||
|
||||
const mainToolbar = new OBC.Toolbar(components, { name: 'Main Toolbar', position: 'bottom' });
|
||||
components.ui.addToolbar(mainToolbar);
|
||||
const ifcButton = fragmentIfcLoader.uiElement.get("main");
|
||||
mainToolbar.addChild(ifcButton);
|
||||
|
||||
await fragmentIfcLoader.setup()
|
||||
|
||||
const excludedCats = [
|
||||
WEBIFC.IFCTENDONANCHOR,
|
||||
WEBIFC.IFCREINFORCINGBAR,
|
||||
WEBIFC.IFCREINFORCINGELEMENT,
|
||||
];
|
||||
|
||||
for(const cat of excludedCats) {
|
||||
fragmentIfcLoader.settings.excludedCategories.add(cat);
|
||||
}
|
||||
|
||||
fragmentIfcLoader.settings.webIfc.COORDINATE_TO_ORIGIN = true;
|
||||
fragmentIfcLoader.settings.webIfc.OPTIMIZE_PROFILES = true;
|
||||
|
||||
async function loadIfcAsFragments() {
|
||||
//const testpath="http://localhost:3014/rvba/test/src/branch/main/1019-column.ifc"
|
||||
//const testpath="/rvba/test/src/branch/main/1019-column.ifc"
|
||||
//const testpath="http://localhost:3014/rvba/test/raw/branch/main/1019-column.ifc"
|
||||
const testpath="{{$.RawFileLink}}"
|
||||
//const testpath="http://localhost:3014/rvba/test/src/branch/main/example.ifc"
|
||||
//const file = await fetch('./small.ifc');
|
||||
const file = await fetch(testpath);
|
||||
const data = await file.arrayBuffer();
|
||||
const buffer = new Uint8Array(data);
|
||||
const model = await fragmentIfcLoader.load(buffer, "example");
|
||||
scene.add(model);
|
||||
}
|
||||
|
||||
async function exportFragments() {
|
||||
if (!fragments.groups.length) return;
|
||||
const group = fragments.groups[0];
|
||||
const data = fragments.export(group);
|
||||
const blob = new Blob([data]);
|
||||
const fragmentFile = new File([blob], 'small.frag');
|
||||
|
||||
const files = [];
|
||||
files.push(fragmentFile);
|
||||
files.push(new File([JSON.stringify(group.properties)], 'small.json'));
|
||||
const result = await downloadZip(files).blob();
|
||||
result.name = 'example';
|
||||
download(result);
|
||||
}
|
||||
|
||||
function download(file) {
|
||||
const link = document.createElement('a');
|
||||
link.href = URL.createObjectURL(file);
|
||||
link.download = file.name;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
link.remove();
|
||||
}
|
||||
|
||||
function disposeFragments() {
|
||||
fragments.dispose();
|
||||
}
|
||||
|
||||
const stats = new Stats();
|
||||
stats.showPanel(2);
|
||||
document.body.append(stats.dom);
|
||||
stats.dom.style.left = '0px';
|
||||
const renderer = components.renderer;
|
||||
renderer.onBeforeUpdate.add(() => stats.begin());
|
||||
renderer.onAfterUpdate.add(() => stats.end());
|
||||
|
||||
window.dispatchEvent(new Event('resize'));
|
||||
|
||||
const settings = {
|
||||
loadFragments: () => loadIfcAsFragments(),
|
||||
exportFragments: () => exportFragments(),
|
||||
disposeFragments: () => disposeFragments(),
|
||||
};
|
||||
|
||||
const gui = new dat.GUI();
|
||||
|
||||
//gui.add(settings, 'loadFragments').name('Import fragments');
|
||||
//gui.add(settings, 'exportFragments').name('Export fragments');
|
||||
//gui.add(settings, 'disposeFragments').name('Dispose fragments');
|
||||
|
||||
loadIfcAsFragments();
|
||||
|
||||
</script>
|
||||
{{else}}
|
||||
<a href="{{$.RawFileLink}}" rel="nofollow">{{ctx.Locale.Tr "repo.file_view_raw"}}</a>
|
||||
{{end}}
|
||||
|
|
|
|||
|
|
@ -48,10 +48,14 @@ function initEditPreviewTab($form) {
|
|||
}
|
||||
}
|
||||
|
||||
function initEditRunTab($form) {
|
||||
}
|
||||
|
||||
function initEditorForm() {
|
||||
const $form = $('.repository .edit.form');
|
||||
if (!$form) return;
|
||||
initEditPreviewTab($form);
|
||||
//initEditRunTab($form);
|
||||
}
|
||||
|
||||
function getCursorPosition($e) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue