Skip to content

Commit 24f912d

Browse files
authored
Merge branch 'main' into fix-autofocus
2 parents 26d4c59 + 4c611bf commit 24f912d

File tree

5 files changed

+62
-14
lines changed

5 files changed

+62
-14
lines changed

options/locale/locale_en-US.ini

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3722,13 +3722,18 @@ owner.settings.chef.keypair.description = A key pair is necessary to authenticat
37223722
secrets = Secrets
37233723
description = Secrets will be passed to certain actions and cannot be read otherwise.
37243724
none = There are no secrets yet.
3725-
creation = Add Secret
3725+
3726+
; These keys are also for "edit secret", the keys are kept as-is to avoid unnecessary re-translation
37263727
creation.description = Description
37273728
creation.name_placeholder = case-insensitive, alphanumeric characters or underscores only, cannot start with GITEA_ or GITHUB_
37283729
creation.value_placeholder = Input any content. Whitespace at the start and end will be omitted.
37293730
creation.description_placeholder = Enter short description (optional).
3730-
creation.success = The secret "%s" has been added.
3731-
creation.failed = Failed to add secret.
3731+
3732+
save_success = The secret "%s" has been saved.
3733+
save_failed = Failed to save secret.
3734+
3735+
add_secret = Add secret
3736+
edit_secret = Edit secret
37323737
deletion = Remove secret
37333738
deletion.description = Removing a secret is permanent and cannot be undone. Continue?
37343739
deletion.success = The secret has been removed.

routers/web/shared/secrets/secrets.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ func PerformSecretsPost(ctx *context.Context, ownerID, repoID int64, redirectURL
3232
s, _, err := secret_service.CreateOrUpdateSecret(ctx, ownerID, repoID, form.Name, util.ReserveLineBreakForTextarea(form.Data), form.Description)
3333
if err != nil {
3434
log.Error("CreateOrUpdateSecret failed: %v", err)
35-
ctx.JSONError(ctx.Tr("secrets.creation.failed"))
35+
ctx.JSONError(ctx.Tr("secrets.save_failed"))
3636
return
3737
}
3838

39-
ctx.Flash.Success(ctx.Tr("secrets.creation.success", s.Name))
39+
ctx.Flash.Success(ctx.Tr("secrets.save_success", s.Name))
4040
ctx.JSONRedirect(redirectURL)
4141
}
4242

templates/shared/secrets/add_list.tmpl

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44
<button class="ui primary tiny button show-modal"
55
data-modal="#add-secret-modal"
66
data-modal-form.action="{{.Link}}"
7-
data-modal-header="{{ctx.Locale.Tr "secrets.creation"}}"
7+
data-modal-header="{{ctx.Locale.Tr "secrets.add_secret"}}"
8+
data-modal-secret-name.value=""
9+
data-modal-secret-name.read-only="false"
10+
data-modal-secret-data=""
11+
data-modal-secret-description=""
812
>
9-
{{ctx.Locale.Tr "secrets.creation"}}
13+
{{ctx.Locale.Tr "secrets.add_secret"}}
1014
</button>
1115
</div>
1216
</h4>
@@ -33,6 +37,18 @@
3337
<span class="color-text-light-2">
3438
{{ctx.Locale.Tr "settings.added_on" (DateUtils.AbsoluteShort .CreatedUnix)}}
3539
</span>
40+
<button class="ui btn interact-bg show-modal tw-p-2"
41+
data-modal="#add-secret-modal"
42+
data-modal-form.action="{{$.Link}}"
43+
data-modal-header="{{ctx.Locale.Tr "secrets.edit_secret"}}"
44+
data-tooltip-content="{{ctx.Locale.Tr "secrets.edit_secret"}}"
45+
data-modal-secret-name.value="{{.Name}}"
46+
data-modal-secret-name.read-only="true"
47+
data-modal-secret-data=""
48+
data-modal-secret-description="{{if .Description}}{{.Description}}{{end}}"
49+
>
50+
{{svg "octicon-pencil"}}
51+
</button>
3652
<button class="ui btn interact-bg link-action tw-p-2"
3753
data-url="{{$.Link}}/delete?id={{.ID}}"
3854
data-modal-confirm="{{ctx.Locale.Tr "secrets.deletion.description"}}"
@@ -51,9 +67,7 @@
5167

5268
{{/* Add secret dialog */}}
5369
<div class="ui small modal" id="add-secret-modal">
54-
<div class="header">
55-
<span id="actions-modal-header"></span>
56-
</div>
70+
<div class="header"></div>
5771
<form class="ui form form-fetch-action" method="post">
5872
<div class="content">
5973
{{.CsrfTokenHtml}}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {assignElementProperty} from './common-button.ts';
2+
3+
test('assignElementProperty', () => {
4+
const elForm = document.createElement('form');
5+
assignElementProperty(elForm, 'action', '/test-link');
6+
expect(elForm.action).contains('/test-link'); // the DOM always returns absolute URL
7+
assignElementProperty(elForm, 'text-content', 'dummy');
8+
expect(elForm.textContent).toBe('dummy');
9+
10+
const elInput = document.createElement('input');
11+
expect(elInput.readOnly).toBe(false);
12+
assignElementProperty(elInput, 'read-only', 'true');
13+
expect(elInput.readOnly).toBe(true);
14+
});

web_src/js/features/common-button.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,29 @@ function onHidePanelClick(el: HTMLElement, e: MouseEvent) {
103103
throw new Error('no panel to hide'); // should never happen, otherwise there is a bug in code
104104
}
105105

106+
export function assignElementProperty(el: any, name: string, val: string) {
107+
name = camelize(name);
108+
const old = el[name];
109+
if (typeof old === 'boolean') {
110+
el[name] = val === 'true';
111+
} else if (typeof old === 'number') {
112+
el[name] = parseFloat(val);
113+
} else if (typeof old === 'string') {
114+
el[name] = val;
115+
} else {
116+
// in the future, we could introduce a better typing system like `data-modal-form.action:string="..."`
117+
throw new Error(`cannot assign element property ${name} by value ${val}`);
118+
}
119+
}
120+
106121
function onShowModalClick(el: HTMLElement, e: MouseEvent) {
107122
// A ".show-modal" button will show a modal dialog defined by its "data-modal" attribute.
108123
// Each "data-modal-{target}" attribute will be filled to target element's value or text-content.
109124
// * First, try to query '#target'
110125
// * Then, try to query '[name=target]'
111126
// * Then, try to query '.target'
112127
// * Then, try to query 'target' as HTML tag
113-
// If there is a ".{attr}" part like "data-modal-form.action", then the form's "action" attribute will be set.
128+
// If there is a ".{prop-name}" part like "data-modal-form.action", the "form" element's "action" property will be set, the "prop-name" will be camel-cased to "propName".
114129
e.preventDefault();
115130
const modalSelector = el.getAttribute('data-modal');
116131
const elModal = document.querySelector(modalSelector);
@@ -123,7 +138,7 @@ function onShowModalClick(el: HTMLElement, e: MouseEvent) {
123138
}
124139

125140
const attrTargetCombo = attrib.name.substring(modalAttrPrefix.length);
126-
const [attrTargetName, attrTargetAttr] = attrTargetCombo.split('.');
141+
const [attrTargetName, attrTargetProp] = attrTargetCombo.split('.');
127142
// try to find target by: "#target" -> "[name=target]" -> ".target" -> "<target> tag"
128143
const attrTarget = elModal.querySelector(`#${attrTargetName}`) ||
129144
elModal.querySelector(`[name=${attrTargetName}]`) ||
@@ -134,8 +149,8 @@ function onShowModalClick(el: HTMLElement, e: MouseEvent) {
134149
continue;
135150
}
136151

137-
if (attrTargetAttr) {
138-
(attrTarget as any)[camelize(attrTargetAttr)] = attrib.value;
152+
if (attrTargetProp) {
153+
assignElementProperty(attrTarget, attrTargetProp, attrib.value);
139154
} else if (attrTarget.matches('input, textarea')) {
140155
(attrTarget as HTMLInputElement | HTMLTextAreaElement).value = attrib.value; // FIXME: add more supports like checkbox
141156
} else {

0 commit comments

Comments
 (0)