Skip to content

Commit

Permalink
Frontend refactor, PascalCase to camelCase, remove unused code (#17365)
Browse files Browse the repository at this point in the history
* Frontend refactor, PascalCase to camelCase, remove unused code

* fix
  • Loading branch information
wxiaoguang committed Oct 21, 2021
1 parent 5879ab8 commit 2add8fe
Show file tree
Hide file tree
Showing 42 changed files with 162 additions and 182 deletions.
9 changes: 1 addition & 8 deletions integrations/branches_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"net/url"
"testing"

"github.com/PuerkitoBio/goquery"
"github.com/stretchr/testify/assert"
"github.com/unknwon/i18n"
)
Expand Down Expand Up @@ -62,7 +61,7 @@ func branchAction(t *testing.T, button string) (*HTMLDoc, string) {
}

req = NewRequestWithValues(t, "POST", link, map[string]string{
"_csrf": getCsrf(t, htmlDoc.doc),
"_csrf": htmlDoc.GetCSRF(),
})
session.MakeRequest(t, req, http.StatusOK)

Expand All @@ -73,9 +72,3 @@ func branchAction(t *testing.T, button string) (*HTMLDoc, string) {

return NewHTMLParser(t, resp.Body), url.Query().Get("name")
}

func getCsrf(t *testing.T, doc *goquery.Document) string {
csrf, exists := doc.Find("meta[name=\"_csrf\"]").Attr("content")
assert.True(t, exists)
return csrf
}
2 changes: 1 addition & 1 deletion integrations/html_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (doc *HTMLDoc) Find(selector string) *goquery.Selection {
return doc.doc.Find(selector)
}

// GetCSRF for get CSRC token value from input
// GetCSRF for getting CSRF token value from input
func (doc *HTMLDoc) GetCSRF() string {
return doc.GetInputValueByName("_csrf")
}
Expand Down
4 changes: 2 additions & 2 deletions integrations/pull_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func testUIDeleteBranch(t *testing.T, session *TestSession, ownerName, repoName,
htmlDoc := NewHTMLParser(t, resp.Body)

req = NewRequestWithValues(t, "POST", relURL+"/delete", map[string]string{
"_csrf": getCsrf(t, htmlDoc.doc),
"_csrf": htmlDoc.GetCSRF(),
"name": branchName,
})
session.MakeRequest(t, req, http.StatusOK)
Expand All @@ -127,7 +127,7 @@ func testDeleteRepository(t *testing.T, session *TestSession, ownerName, repoNam
htmlDoc := NewHTMLParser(t, resp.Body)

req = NewRequestWithValues(t, "POST", relURL+"?action=delete", map[string]string{
"_csrf": getCsrf(t, htmlDoc.doc),
"_csrf": htmlDoc.GetCSRF(),
"repo_name": repoName,
})
session.MakeRequest(t, req, http.StatusFound)
Expand Down
2 changes: 1 addition & 1 deletion modules/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ func Contexter() func(next http.Handler) http.Handler {
"CurrentURL": setting.AppSubURL + req.URL.RequestURI(),
"PageStartTime": startTime,
"Link": link,
"IsProd": setting.IsProd,
"RunModeIsProd": setting.IsProd,
},
}
// PageData is passed by reference, and it will be rendered to `window.config.pageData` in `head.tmpl` for JavaScript modules
Expand Down
4 changes: 0 additions & 4 deletions routers/web/repo/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ func DeleteProject(ctx *context.Context) {
// EditProject allows a project to be edited
func EditProject(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.projects.edit")
ctx.Data["PageIsProjects"] = true
ctx.Data["PageIsEditProjects"] = true
ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(models.UnitTypeProjects)

Expand Down Expand Up @@ -233,7 +232,6 @@ func EditProject(ctx *context.Context) {
func EditProjectPost(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.CreateProjectForm)
ctx.Data["Title"] = ctx.Tr("repo.projects.edit")
ctx.Data["PageIsProjects"] = true
ctx.Data["PageIsEditProjects"] = true
ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(models.UnitTypeProjects)

Expand Down Expand Up @@ -335,8 +333,6 @@ func ViewProject(ctx *context.Context) {
ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(models.UnitTypeProjects)
ctx.Data["Project"] = project
ctx.Data["Boards"] = boards
ctx.Data["PageIsProjects"] = true
ctx.Data["RequiresDraggable"] = true

ctx.HTML(http.StatusOK, tplProjectsView)
}
Expand Down
35 changes: 13 additions & 22 deletions templates/base/head.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,32 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{if .Title}}{{.Title | RenderEmojiPlain}} - {{end}} {{if .Repository.Name}}{{.Repository.Name}} - {{end}}{{AppName}} </title>
<title>{{if .Title}}{{.Title | RenderEmojiPlain}} - {{end}} {{if .Repository.Name}}{{.Repository.Name}} - {{end}}{{AppName}}</title>
<link rel="manifest" href="data:{{.ManifestData}}"/>
<meta name="theme-color" content="{{ThemeColorMetaTag}}">
<meta name="default-theme" content="{{DefaultTheme}}" />
<meta name="author" content="{{if .Repository}}{{.Owner.Name}}{{else}}{{MetaAuthor}}{{end}}" />
<meta name="description" content="{{if .Repository}}{{.Repository.Name}}{{if .Repository.Description}} - {{.Repository.Description}}{{end}}{{else}}{{MetaDescription}}{{end}}" />
<meta name="keywords" content="{{MetaKeywords}}">
<meta name="referrer" content="no-referrer" />
<meta name="_csrf" content="{{.CsrfToken}}" />
{{if .GoGetImport}}
<meta name="go-import" content="{{.GoGetImport}} git {{.CloneLink.HTTPS}}">
<meta name="go-source" content="{{.GoGetImport}} _ {{.GoDocDirectory}} {{.GoDocFile}}">
{{end}}
<script>
<!-- /* eslint-disable */ -->
window.config = {
AppVer: '{{AppVer}}',
AppSubUrl: '{{AppSubUrl}}',
AssetUrlPrefix: '{{AssetUrlPrefix}}',
IsProd: {{.IsProd}},
CustomEmojis: {{CustomEmojis}},
UseServiceWorker: {{UseServiceWorker}},
csrf: '{{.CsrfToken}}',
pageData: {{ .PageData }},
HighlightJS: {{if .RequireHighlightJS}}true{{else}}false{{end}},
SimpleMDE: {{if .RequireSimpleMDE}}true{{else}}false{{end}},
Tribute: {{if .RequireTribute}}true{{else}}false{{end}},
NotificationSettings: {
MinTimeout: {{NotificationSettings.MinTimeout}},
TimeoutStep: {{NotificationSettings.TimeoutStep}},
MaxTimeout: {{NotificationSettings.MaxTimeout}},
EventSourceUpdateTime: {{NotificationSettings.EventSourceUpdateTime}},
},
EnableTimetracking: {{if EnableTimetracking}}true{{else}}false{{end}},
PageIsProjects: {{if .PageIsProjects }}true{{else}}false{{end}},
appVer: '{{AppVer}}',
appSubUrl: '{{AppSubUrl}}',
assetUrlPrefix: '{{AssetUrlPrefix}}',
runModeIsProd: {{.RunModeIsProd}},
customEmojis: {{CustomEmojis}},
useServiceWorker: {{UseServiceWorker}},
csrfToken: '{{.CsrfToken}}',
pageData: {{.PageData}},
requireTribute: {{.RequireTribute}},
notificationSettings: {{NotificationSettings}}, {{/*a map provided by NewFuncMap in helper.go*/}}
enableTimeTracking: {{EnableTimetracking}},
{{if .RequireTribute}}
tributeValues: Array.from(new Map([
{{ range .Participants }}
Expand All @@ -54,7 +45,7 @@
{{ end }}
]).values()),
{{end}}
MermaidMaxSourceCharacters: {{MermaidMaxSourceCharacters}},
mermaidMaxSourceCharacters: {{MermaidMaxSourceCharacters}},
};
</script>
<link rel="icon" href="{{AssetUrlPrefix}}/img/logo.svg" type="image/svg+xml">
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/projects/list.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{template "base/head" .}}
<div class="page-content repository milestones">
<div class="page-content repository projects milestones">
{{template "repo/header" .}}
<div class="ui container">
<div class="navbar">
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/projects/new.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{template "base/head" .}}
<div class="page-content repository new milestone">
<div class="page-content repository projects edit-project new milestone">
{{template "repo/header" .}}
<div class="ui container">
<div class="navbar">
Expand Down
10 changes: 5 additions & 5 deletions templates/repo/projects/view.tmpl
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{{template "base/head" .}}
<div class="page-content repository">
<div class="page-content repository projects view-project">
{{template "repo/header" .}}
<div class="ui container">
<div class="ui two column stackable grid">
<div class="column">
{{template "repo/issue/navbar" .}}
</div>
<div class="column right aligned">
{{if and .CanWriteProjects (not .Repository.IsArchived) .PageIsProjects}}
{{if and .CanWriteProjects (not .Repository.IsArchived)}}
<a class="ui green button show-modal item" href="{{$.RepoLink}}/issues/new?project={{$.Project.ID}}">{{.i18n.Tr "repo.issues.new"}}</a>
<a class="ui green button show-modal item" data-modal="#new-board-item">{{.i18n.Tr "new_project_board"}}</a>
{{end}}
Expand Down Expand Up @@ -80,10 +80,10 @@
<div class="board">
{{ range $board := .Boards }}

<div class="ui segment board-column" style="background: {{.Color}}!important;" data-id="{{.ID}}" data-sorting="{{.Sorting}}" data-url="{{$.RepoLink}}/projects/{{$.Project.ID}}/{{.ID}}">
<div class="ui segment board-column" style="background: {{.Color}} !important;" data-id="{{.ID}}" data-sorting="{{.Sorting}}" data-url="{{$.RepoLink}}/projects/{{$.Project.ID}}/{{.ID}}">
<div class="board-column-header df ac sb">
<div class="ui large label board-label py-2">{{.Title}}</div>
{{if and $.CanWriteProjects (not $.Repository.IsArchived) $.PageIsProjects (ne .ID 0)}}
{{if and $.CanWriteProjects (not $.Repository.IsArchived) (ne .ID 0)}}
<div class="ui dropdown jump item poping up" data-variation="tiny inverted">
<div class="not-mobile px-3" tabindex="-1">
{{svg "octicon-kebab-horizontal"}}
Expand Down Expand Up @@ -232,7 +232,7 @@
{{if .Labels}}
<div class="extra content labels-list p-0 pt-2">
{{ range .Labels }}
<a class="ui label" href="{{$.RepoLink}}/issues?labels={{.ID}}" style="color: {{.ForegroundColor}}; background-color: {{.Color}}" title="{{.Description | RenderEmojiPlain}}">{{.Name | RenderEmoji}}</a>
<a class="ui label" href="{{$.RepoLink}}/issues?labels={{.ID}}" style="color: {{.ForegroundColor}}; background-color: {{.Color}};" title="{{.Description | RenderEmojiPlain}}">{{.Name | RenderEmoji}}</a>
{{ end }}
</div>
{{end}}
Expand Down
4 changes: 2 additions & 2 deletions web_src/js/components/ContextPopup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<script>
import {SvgIcon} from '../svg.js';
const {AppSubUrl} = window.config;
const {appSubUrl} = window.config;
// NOTE: see models/issue_label.go for similar implementation
const srgbToLinear = (color) => {
Expand Down Expand Up @@ -112,7 +112,7 @@ export default {
methods: {
load(data, callback) {
this.loading = true;
$.get(`${AppSubUrl}/api/v1/repos/${data.owner}/${data.repo}/issues/${data.index}`, (issue) => {
$.get(`${appSubUrl}/api/v1/repos/${data.owner}/${data.repo}/issues/${data.index}`, (issue) => {
this.issue = issue;
this.loading = false;
this.$nextTick(() => {
Expand Down
6 changes: 3 additions & 3 deletions web_src/js/components/DashboardRepoList.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Vue from 'vue';
import {initVueSvg, vueDelimiters} from './VueComponentLoader.js';

const {AppSubUrl, AssetUrlPrefix, pageData} = window.config;
const {appSubUrl, assetUrlPrefix, pageData} = window.config;

function initVueComponents() {
Vue.component('repo-search', {
Expand Down Expand Up @@ -95,7 +95,7 @@ function initVueComponents() {
finalPage: 1,
searchQuery,
isLoading: false,
staticPrefix: AssetUrlPrefix,
staticPrefix: assetUrlPrefix,
counts: {},
repoTypes: {
all: {
Expand Down Expand Up @@ -361,7 +361,7 @@ export function initDashboardRepoList() {
data: () => {
return {
searchLimit: dashboardRepoListData.searchLimit || 0,
subUrl: AppSubUrl,
subUrl: appSubUrl,
uid: dashboardRepoListData.uid || 0,
};
},
Expand Down
2 changes: 1 addition & 1 deletion web_src/js/components/VueComponentLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function initVueEnv() {
if (vueEnvInited) return;
vueEnvInited = true;

const isProd = window.config.IsProd;
const isProd = window.config.runModeIsProd;
Vue.config.productionTip = false;
Vue.config.devtools = !isProd;
}
Expand Down
4 changes: 2 additions & 2 deletions web_src/js/features/admin-common.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {csrf} = window.config;
const {csrfToken} = window.config;

export function initAdminCommon() {
if ($('.admin').length === 0) {
Expand Down Expand Up @@ -204,7 +204,7 @@ export function initAdminCommon() {
}
});
$.post($this.data('link'), {
_csrf: csrf,
_csrf: csrfToken,
ids
}).done(() => {
window.location.href = $this.data('redirect');
Expand Down
16 changes: 8 additions & 8 deletions web_src/js/features/common-global.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {initCompColorPicker} from './comp/ColorPicker.js';

import 'jquery.are-you-sure';

const {csrf} = window.config;
const {csrfToken} = window.config;

export function initGlobalFormDirtyLeaveConfirm() {
// Warn users that try to leave a page after entering data into a form.
Expand Down Expand Up @@ -136,7 +136,7 @@ export async function initGlobalDropzone() {
const $dropzone = $(el);
await createDropzone(el, {
url: $dropzone.data('upload-url'),
headers: {'X-Csrf-Token': csrf},
headers: {'X-Csrf-Token': csrfToken},
maxFiles: $dropzone.data('max-file'),
maxFilesize: $dropzone.data('max-size'),
acceptedFiles: (['*/*', ''].includes($dropzone.data('accepts'))) ? null : $dropzone.data('accepts'),
Expand All @@ -159,7 +159,7 @@ export async function initGlobalDropzone() {
if ($dropzone.data('remove-url')) {
$.post($dropzone.data('remove-url'), {
file: file.uuid,
_csrf: csrf,
_csrf: csrfToken,
});
}
});
Expand Down Expand Up @@ -194,7 +194,7 @@ export function initGlobalLinkActions() {
}

const postData = {
_csrf: csrf,
_csrf: csrfToken,
};
for (const [key, value] of Object.entries(dataArray)) {
if (key && key.startsWith('data')) {
Expand Down Expand Up @@ -232,7 +232,7 @@ export function initGlobalLinkActions() {
}

$.post($this.data('url'), {
_csrf: csrf,
_csrf: csrfToken,
id: $this.data('id')
}).done((data) => {
window.location.href = data.redirect;
Expand All @@ -247,7 +247,7 @@ export function initGlobalLinkActions() {
const $this = $(this);
const redirect = $this.data('redirect');
$.post($this.data('url'), {
_csrf: csrf
_csrf: csrfToken
}).done((data) => {
if (data.redirect) {
window.location.href = data.redirect;
Expand All @@ -270,7 +270,7 @@ export function initGlobalLinkActions() {
$('.undo-button').on('click', function () {
const $this = $(this);
$.post($this.data('url'), {
_csrf: csrf,
_csrf: csrfToken,
id: $this.data('id')
}).done((data) => {
window.location.href = data.redirect;
Expand Down Expand Up @@ -298,7 +298,7 @@ export function initGlobalButtons() {
$('.delete-post.button').on('click', function () {
const $this = $(this);
$.post($this.data('request-url'), {
_csrf: csrf
_csrf: csrfToken
}).done(() => {
window.location.href = $this.data('done-url');
});
Expand Down
8 changes: 4 additions & 4 deletions web_src/js/features/comp/ImagePaste.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const {AppSubUrl, csrf} = window.config;
const {appSubUrl, csrfToken} = window.config;

async function uploadFile(file, uploadUrl) {
const formData = new FormData();
formData.append('file', file, file.name);

const res = await fetch(uploadUrl, {
method: 'POST',
headers: {'X-Csrf-Token': csrf},
headers: {'X-Csrf-Token': csrfToken},
body: formData,
});
return await res.json();
Expand Down Expand Up @@ -67,7 +67,7 @@ export function initCompImagePaste($target) {
const name = img.name.substr(0, img.name.lastIndexOf('.'));
insertAtCursor(textarea, `![${name}]()`);
const data = await uploadFile(img, uploadUrl);
replaceAndKeepCursor(textarea, `![${name}]()`, `![${name}](${AppSubUrl}/attachments/${data.uuid})`);
replaceAndKeepCursor(textarea, `![${name}]()`, `![${name}](${appSubUrl}/attachments/${data.uuid})`);
const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid);
dropzoneFiles.appendChild(input[0]);
}
Expand All @@ -83,7 +83,7 @@ export function initSimpleMDEImagePaste(simplemde, dropzone, files) {
const name = img.name.substr(0, img.name.lastIndexOf('.'));
const data = await uploadFile(img, uploadUrl);
const pos = simplemde.codemirror.getCursor();
simplemde.codemirror.replaceRange(`![${name}](${AppSubUrl}/attachments/${data.uuid})`, pos);
simplemde.codemirror.replaceRange(`![${name}](${appSubUrl}/attachments/${data.uuid})`, pos);
const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid);
files.append(input);
}
Expand Down
4 changes: 2 additions & 2 deletions web_src/js/features/comp/MarkupContentPreview.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {initMarkupContent} from '../../markup/content.js';

const {csrf} = window.config;
const {csrfToken} = window.config;

export function initCompMarkupContentPreviewTab($form) {
const $tabMenu = $form.find('.tabular.menu');
$tabMenu.find('.item').tab();
$tabMenu.find(`.item[data-tab="${$tabMenu.data('preview')}"]`).on('click', function () {
const $this = $(this);
$.post($this.data('url'), {
_csrf: csrf,
_csrf: csrfToken,
mode: 'comment',
context: $this.data('context'),
text: $form.find(`.tab[data-tab="${$tabMenu.data('write')}"] textarea`).val()
Expand Down
Loading

0 comments on commit 2add8fe

Please sign in to comment.