Skip to content

Commit b7c4274

Browse files
committed
Frontend refactor, PascalCase to camelCase, remove unused code
1 parent 0208ea0 commit b7c4274

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+162
-182
lines changed

integrations/branches_test.go

+1-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"net/url"
1010
"testing"
1111

12-
"github.com/PuerkitoBio/goquery"
1312
"github.com/stretchr/testify/assert"
1413
"github.com/unknwon/i18n"
1514
)
@@ -62,7 +61,7 @@ func branchAction(t *testing.T, button string) (*HTMLDoc, string) {
6261
}
6362

6463
req = NewRequestWithValues(t, "POST", link, map[string]string{
65-
"_csrf": getCsrf(t, htmlDoc.doc),
64+
"_csrf": htmlDoc.GetCSRF(),
6665
})
6766
session.MakeRequest(t, req, http.StatusOK)
6867

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

7473
return NewHTMLParser(t, resp.Body), url.Query().Get("name")
7574
}
76-
77-
func getCsrf(t *testing.T, doc *goquery.Document) string {
78-
csrf, exists := doc.Find("meta[name=\"_csrf\"]").Attr("content")
79-
assert.True(t, exists)
80-
return csrf
81-
}

integrations/html_helper.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (doc *HTMLDoc) Find(selector string) *goquery.Selection {
4444
return doc.doc.Find(selector)
4545
}
4646

47-
// GetCSRF for get CSRC token value from input
47+
// GetCSRF for getting CSRF token value from input
4848
func (doc *HTMLDoc) GetCSRF() string {
4949
return doc.GetInputValueByName("_csrf")
5050
}

integrations/pull_create_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func testUIDeleteBranch(t *testing.T, session *TestSession, ownerName, repoName,
114114
htmlDoc := NewHTMLParser(t, resp.Body)
115115

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

129129
req = NewRequestWithValues(t, "POST", relURL+"?action=delete", map[string]string{
130-
"_csrf": getCsrf(t, htmlDoc.doc),
130+
"_csrf": htmlDoc.GetCSRF(),
131131
"repo_name": repoName,
132132
})
133133
session.MakeRequest(t, req, http.StatusFound)

modules/context/context.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ func Contexter() func(next http.Handler) http.Handler {
645645
"CurrentURL": setting.AppSubURL + req.URL.RequestURI(),
646646
"PageStartTime": startTime,
647647
"Link": link,
648-
"IsProd": setting.IsProd(),
648+
"RunModeIsProd": setting.IsProd(),
649649
},
650650
}
651651
// PageData is passed by reference, and it will be rendered to `window.config.pageData` in `head.tmpl` for JavaScript modules

routers/web/repo/projects.go

-4
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ func DeleteProject(ctx *context.Context) {
205205
// EditProject allows a project to be edited
206206
func EditProject(ctx *context.Context) {
207207
ctx.Data["Title"] = ctx.Tr("repo.projects.edit")
208-
ctx.Data["PageIsProjects"] = true
209208
ctx.Data["PageIsEditProjects"] = true
210209
ctx.Data["CanWriteProjects"] = ctx.Repo.Permission.CanWrite(models.UnitTypeProjects)
211210

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

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

341337
ctx.HTML(http.StatusOK, tplProjectsView)
342338
}

templates/base/head.tmpl

+13-22
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,32 @@
33
<head>
44
<meta charset="utf-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1">
6-
<title>{{if .Title}}{{.Title | RenderEmojiPlain}} - {{end}} {{if .Repository.Name}}{{.Repository.Name}} - {{end}}{{AppName}} </title>
6+
<title>{{if .Title}}{{.Title | RenderEmojiPlain}} - {{end}} {{if .Repository.Name}}{{.Repository.Name}} - {{end}}{{AppName}}</title>
77
<link rel="manifest" href="data:{{.ManifestData}}"/>
88
<meta name="theme-color" content="{{ThemeColorMetaTag}}">
99
<meta name="default-theme" content="{{DefaultTheme}}" />
1010
<meta name="author" content="{{if .Repository}}{{.Owner.Name}}{{else}}{{MetaAuthor}}{{end}}" />
1111
<meta name="description" content="{{if .Repository}}{{.Repository.Name}}{{if .Repository.Description}} - {{.Repository.Description}}{{end}}{{else}}{{MetaDescription}}{{end}}" />
1212
<meta name="keywords" content="{{MetaKeywords}}">
1313
<meta name="referrer" content="no-referrer" />
14-
<meta name="_csrf" content="{{.CsrfToken}}" />
1514
{{if .GoGetImport}}
1615
<meta name="go-import" content="{{.GoGetImport}} git {{.CloneLink.HTTPS}}">
1716
<meta name="go-source" content="{{.GoGetImport}} _ {{.GoDocDirectory}} {{.GoDocFile}}">
1817
{{end}}
1918
<script>
2019
<!-- /* eslint-disable */ -->
2120
window.config = {
22-
AppVer: '{{AppVer}}',
23-
AppSubUrl: '{{AppSubUrl}}',
24-
AssetUrlPrefix: '{{AssetUrlPrefix}}',
25-
IsProd: {{.IsProd}},
26-
CustomEmojis: {{CustomEmojis}},
27-
UseServiceWorker: {{UseServiceWorker}},
28-
csrf: '{{.CsrfToken}}',
29-
pageData: {{ .PageData }},
30-
HighlightJS: {{if .RequireHighlightJS}}true{{else}}false{{end}},
31-
SimpleMDE: {{if .RequireSimpleMDE}}true{{else}}false{{end}},
32-
Tribute: {{if .RequireTribute}}true{{else}}false{{end}},
33-
NotificationSettings: {
34-
MinTimeout: {{NotificationSettings.MinTimeout}},
35-
TimeoutStep: {{NotificationSettings.TimeoutStep}},
36-
MaxTimeout: {{NotificationSettings.MaxTimeout}},
37-
EventSourceUpdateTime: {{NotificationSettings.EventSourceUpdateTime}},
38-
},
39-
EnableTimetracking: {{if EnableTimetracking}}true{{else}}false{{end}},
40-
PageIsProjects: {{if .PageIsProjects }}true{{else}}false{{end}},
21+
appVer: '{{AppVer}}',
22+
appSubUrl: '{{AppSubUrl}}',
23+
assetUrlPrefix: '{{AssetUrlPrefix}}',
24+
runModeIsProd: {{.RunModeIsProd}},
25+
customEmojis: {{CustomEmojis}},
26+
useServiceWorker: {{UseServiceWorker}},
27+
csrfToken: '{{.CsrfToken}}',
28+
pageData: {{.PageData}},
29+
requireTribute: {{.RequireTribute}},
30+
notificationSettings: {{NotificationSettings}}, {{/*a map provided by NewFuncMap in helper.go*/}}
31+
enableTimeTracking: {{EnableTimetracking}},
4132
{{if .RequireTribute}}
4233
tributeValues: Array.from(new Map([
4334
{{ range .Participants }}
@@ -54,7 +45,7 @@
5445
{{ end }}
5546
]).values()),
5647
{{end}}
57-
MermaidMaxSourceCharacters: {{MermaidMaxSourceCharacters}},
48+
mermaidMaxSourceCharacters: {{MermaidMaxSourceCharacters}},
5849
};
5950
</script>
6051
<link rel="icon" href="{{AssetUrlPrefix}}/img/logo.svg" type="image/svg+xml">

templates/repo/projects/list.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{template "base/head" .}}
2-
<div class="page-content repository milestones">
2+
<div class="page-content repository projects milestones">
33
{{template "repo/header" .}}
44
<div class="ui container">
55
<div class="navbar">

templates/repo/projects/new.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{template "base/head" .}}
2-
<div class="page-content repository new milestone">
2+
<div class="page-content repository projects edit-project new milestone">
33
{{template "repo/header" .}}
44
<div class="ui container">
55
<div class="navbar">

templates/repo/projects/view.tmpl

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{{template "base/head" .}}
2-
<div class="page-content repository">
2+
<div class="page-content repository projects view-project">
33
{{template "repo/header" .}}
44
<div class="ui container">
55
<div class="ui two column stackable grid">
66
<div class="column">
77
{{template "repo/issue/navbar" .}}
88
</div>
99
<div class="column right aligned">
10-
{{if and .CanWriteProjects (not .Repository.IsArchived) .PageIsProjects}}
10+
{{if and .CanWriteProjects (not .Repository.IsArchived)}}
1111
<a class="ui green button show-modal item" href="{{$.RepoLink}}/issues/new?project={{$.Project.ID}}">{{.i18n.Tr "repo.issues.new"}}</a>
1212
<a class="ui green button show-modal item" data-modal="#new-board-item">{{.i18n.Tr "new_project_board"}}</a>
1313
{{end}}
@@ -80,10 +80,10 @@
8080
<div class="board">
8181
{{ range $board := .Boards }}
8282

83-
<div class="ui segment board-column" style="background: {{.Color}}!important;" data-id="{{.ID}}" data-sorting="{{.Sorting}}" data-url="{{$.RepoLink}}/projects/{{$.Project.ID}}/{{.ID}}">
83+
<div class="ui segment board-column" style="background: {{.Color}} !important;" data-id="{{.ID}}" data-sorting="{{.Sorting}}" data-url="{{$.RepoLink}}/projects/{{$.Project.ID}}/{{.ID}}">
8484
<div class="board-column-header df ac sb">
8585
<div class="ui large label board-label py-2">{{.Title}}</div>
86-
{{if and $.CanWriteProjects (not $.Repository.IsArchived) $.PageIsProjects (ne .ID 0)}}
86+
{{if and $.CanWriteProjects (not $.Repository.IsArchived) (ne .ID 0)}}
8787
<div class="ui dropdown jump item poping up" data-variation="tiny inverted">
8888
<div class="not-mobile px-3" tabindex="-1">
8989
{{svg "octicon-kebab-horizontal"}}
@@ -232,7 +232,7 @@
232232
{{if .Labels}}
233233
<div class="extra content labels-list p-0 pt-2">
234234
{{ range .Labels }}
235-
<a class="ui label" href="{{$.RepoLink}}/issues?labels={{.ID}}" style="color: {{.ForegroundColor}}; background-color: {{.Color}}" title="{{.Description | RenderEmojiPlain}}">{{.Name | RenderEmoji}}</a>
235+
<a class="ui label" href="{{$.RepoLink}}/issues?labels={{.ID}}" style="color: {{.ForegroundColor}}; background-color: {{.Color}};" title="{{.Description | RenderEmojiPlain}}">{{.Name | RenderEmoji}}</a>
236236
{{ end }}
237237
</div>
238238
{{end}}

web_src/js/components/ContextPopup.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<script>
2323
import {SvgIcon} from '../svg.js';
2424
25-
const {AppSubUrl} = window.config;
25+
const {appSubUrl} = window.config;
2626
2727
// NOTE: see models/issue_label.go for similar implementation
2828
const srgbToLinear = (color) => {
@@ -112,7 +112,7 @@ export default {
112112
methods: {
113113
load(data, callback) {
114114
this.loading = true;
115-
$.get(`${AppSubUrl}/api/v1/repos/${data.owner}/${data.repo}/issues/${data.index}`, (issue) => {
115+
$.get(`${appSubUrl}/api/v1/repos/${data.owner}/${data.repo}/issues/${data.index}`, (issue) => {
116116
this.issue = issue;
117117
this.loading = false;
118118
this.$nextTick(() => {

web_src/js/components/DashboardRepoList.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Vue from 'vue';
22
import {initVueSvg, vueDelimiters} from './VueComponentLoader.js';
33

4-
const {AppSubUrl, AssetUrlPrefix, pageData} = window.config;
4+
const {appSubUrl, assetUrlPrefix, pageData} = window.config;
55

66
function initVueComponents() {
77
Vue.component('repo-search', {
@@ -95,7 +95,7 @@ function initVueComponents() {
9595
finalPage: 1,
9696
searchQuery,
9797
isLoading: false,
98-
staticPrefix: AssetUrlPrefix,
98+
staticPrefix: assetUrlPrefix,
9999
counts: {},
100100
repoTypes: {
101101
all: {
@@ -361,7 +361,7 @@ export function initDashboardRepoList() {
361361
data: () => {
362362
return {
363363
searchLimit: dashboardRepoListData.searchLimit || 0,
364-
subUrl: AppSubUrl,
364+
subUrl: appSubUrl,
365365
uid: dashboardRepoListData.uid || 0,
366366
};
367367
},

web_src/js/components/VueComponentLoader.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function initVueEnv() {
88
if (vueEnvInited) return;
99
vueEnvInited = true;
1010

11-
const isProd = window.config.IsProd;
11+
const isProd = window.config.runModeIsProd;
1212
Vue.config.productionTip = false;
1313
Vue.config.devtools = !isProd;
1414
}

web_src/js/features/admin-common.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const {csrf} = window.config;
1+
const {csrfToken} = window.config;
22

33
export function initAdminCommon() {
44
if ($('.admin').length === 0) {
@@ -204,7 +204,7 @@ export function initAdminCommon() {
204204
}
205205
});
206206
$.post($this.data('link'), {
207-
_csrf: csrf,
207+
_csrf: csrfToken,
208208
ids
209209
}).done(() => {
210210
window.location.href = $this.data('redirect');

web_src/js/features/common-global.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {initCompColorPicker} from './comp/ColorPicker.js';
44

55
import 'jquery.are-you-sure';
66

7-
const {csrf} = window.config;
7+
const {csrfToken} = window.config;
88

99
export function initGlobalFormDirtyLeaveConfirm() {
1010
// Warn users that try to leave a page after entering data into a form.
@@ -136,7 +136,7 @@ export async function initGlobalDropzone() {
136136
const $dropzone = $(el);
137137
await createDropzone(el, {
138138
url: $dropzone.data('upload-url'),
139-
headers: {'X-Csrf-Token': csrf},
139+
headers: {'X-Csrf-Token': csrfToken},
140140
maxFiles: $dropzone.data('max-file'),
141141
maxFilesize: $dropzone.data('max-size'),
142142
acceptedFiles: (['*/*', ''].includes($dropzone.data('accepts'))) ? null : $dropzone.data('accepts'),
@@ -159,7 +159,7 @@ export async function initGlobalDropzone() {
159159
if ($dropzone.data('remove-url')) {
160160
$.post($dropzone.data('remove-url'), {
161161
file: file.uuid,
162-
_csrf: csrf,
162+
_csrf: csrfToken,
163163
});
164164
}
165165
});
@@ -194,7 +194,7 @@ export function initGlobalLinkActions() {
194194
}
195195

196196
const postData = {
197-
_csrf: csrf,
197+
_csrf: csrfToken,
198198
};
199199
for (const [key, value] of Object.entries(dataArray)) {
200200
if (key && key.startsWith('data')) {
@@ -232,7 +232,7 @@ export function initGlobalLinkActions() {
232232
}
233233

234234
$.post($this.data('url'), {
235-
_csrf: csrf,
235+
_csrf: csrfToken,
236236
id: $this.data('id')
237237
}).done((data) => {
238238
window.location.href = data.redirect;
@@ -247,7 +247,7 @@ export function initGlobalLinkActions() {
247247
const $this = $(this);
248248
const redirect = $this.data('redirect');
249249
$.post($this.data('url'), {
250-
_csrf: csrf
250+
_csrf: csrfToken
251251
}).done((data) => {
252252
if (data.redirect) {
253253
window.location.href = data.redirect;
@@ -270,7 +270,7 @@ export function initGlobalLinkActions() {
270270
$('.undo-button').on('click', function () {
271271
const $this = $(this);
272272
$.post($this.data('url'), {
273-
_csrf: csrf,
273+
_csrf: csrfToken,
274274
id: $this.data('id')
275275
}).done((data) => {
276276
window.location.href = data.redirect;
@@ -298,7 +298,7 @@ export function initGlobalButtons() {
298298
$('.delete-post.button').on('click', function () {
299299
const $this = $(this);
300300
$.post($this.data('request-url'), {
301-
_csrf: csrf
301+
_csrf: csrfToken
302302
}).done(() => {
303303
window.location.href = $this.data('done-url');
304304
});

web_src/js/features/comp/ImagePaste.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
const {AppSubUrl, csrf} = window.config;
1+
const {appSubUrl, csrfToken} = window.config;
22

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

77
const res = await fetch(uploadUrl, {
88
method: 'POST',
9-
headers: {'X-Csrf-Token': csrf},
9+
headers: {'X-Csrf-Token': csrfToken},
1010
body: formData,
1111
});
1212
return await res.json();
@@ -67,7 +67,7 @@ export function initCompImagePaste($target) {
6767
const name = img.name.substr(0, img.name.lastIndexOf('.'));
6868
insertAtCursor(textarea, `![${name}]()`);
6969
const data = await uploadFile(img, uploadUrl);
70-
replaceAndKeepCursor(textarea, `![${name}]()`, `![${name}](${AppSubUrl}/attachments/${data.uuid})`);
70+
replaceAndKeepCursor(textarea, `![${name}]()`, `![${name}](${appSubUrl}/attachments/${data.uuid})`);
7171
const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid);
7272
dropzoneFiles.appendChild(input[0]);
7373
}
@@ -83,7 +83,7 @@ export function initSimpleMDEImagePaste(simplemde, dropzone, files) {
8383
const name = img.name.substr(0, img.name.lastIndexOf('.'));
8484
const data = await uploadFile(img, uploadUrl);
8585
const pos = simplemde.codemirror.getCursor();
86-
simplemde.codemirror.replaceRange(`![${name}](${AppSubUrl}/attachments/${data.uuid})`, pos);
86+
simplemde.codemirror.replaceRange(`![${name}](${appSubUrl}/attachments/${data.uuid})`, pos);
8787
const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid);
8888
files.append(input);
8989
}

web_src/js/features/comp/MarkupContentPreview.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import {initMarkupContent} from '../../markup/content.js';
22

3-
const {csrf} = window.config;
3+
const {csrfToken} = window.config;
44

55
export function initCompMarkupContentPreviewTab($form) {
66
const $tabMenu = $form.find('.tabular.menu');
77
$tabMenu.find('.item').tab();
88
$tabMenu.find(`.item[data-tab="${$tabMenu.data('preview')}"]`).on('click', function () {
99
const $this = $(this);
1010
$.post($this.data('url'), {
11-
_csrf: csrf,
11+
_csrf: csrfToken,
1212
mode: 'comment',
1313
context: $this.data('context'),
1414
text: $form.find(`.tab[data-tab="${$tabMenu.data('write')}"] textarea`).val()

0 commit comments

Comments
 (0)