Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4c611bf

Browse files
Add a button editing action secret (#34348)
Add a button editing action secretCloses#34190---------Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
1 parent2fbc8f9 commit4c611bf

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
iferr!=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+
constelForm=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+
constelInput=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
@@ -102,14 +102,29 @@ function onHidePanelClick(el: HTMLElement, e: MouseEvent) {
102102
thrownewError('no panel to hide');// should never happen, otherwise there is a bug in code
103103
}
104104

105+
exportfunctionassignElementProperty(el:any,name:string,val:string){
106+
name=camelize(name);
107+
constold=el[name];
108+
if(typeofold==='boolean'){
109+
el[name]=val==='true';
110+
}elseif(typeofold==='number'){
111+
el[name]=parseFloat(val);
112+
}elseif(typeofold==='string'){
113+
el[name]=val;
114+
}else{
115+
// in the future, we could introduce a better typing system like `data-modal-form.action:string="..."`
116+
thrownewError(`cannot assign element property${name} by value${val}`);
117+
}
118+
}
119+
105120
functiononShowModalClick(el:HTMLElement,e:MouseEvent){
106121
// A ".show-modal" button will show a modal dialog defined by its "data-modal" attribute.
107122
// Each "data-modal-{target}" attribute will be filled to target element's value or text-content.
108123
// * First, try to query '#target'
109124
// * Then, try to query '[name=target]'
110125
// * Then, try to query '.target'
111126
// * Then, try to query 'target' as HTML tag
112-
// If there is a ".{attr}" part like "data-modal-form.action",thenthe form's "action"attribute will be set.
127+
// 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".
113128
e.preventDefault();
114129
constmodalSelector=el.getAttribute('data-modal');
115130
constelModal=document.querySelector(modalSelector);
@@ -122,7 +137,7 @@ function onShowModalClick(el: HTMLElement, e: MouseEvent) {
122137
}
123138

124139
constattrTargetCombo=attrib.name.substring(modalAttrPrefix.length);
125-
const[attrTargetName,attrTargetAttr]=attrTargetCombo.split('.');
140+
const[attrTargetName,attrTargetProp]=attrTargetCombo.split('.');
126141
// try to find target by: "#target" -> "[name=target]" -> ".target" -> "<target> tag"
127142
constattrTarget=elModal.querySelector(`#${attrTargetName}`)||
128143
elModal.querySelector(`[name=${attrTargetName}]`)||
@@ -133,8 +148,8 @@ function onShowModalClick(el: HTMLElement, e: MouseEvent) {
133148
continue;
134149
}
135150

136-
if(attrTargetAttr){
137-
(attrTargetasany)[camelize(attrTargetAttr)]=attrib.value;
151+
if(attrTargetProp){
152+
assignElementProperty(attrTarget,attrTargetProp,attrib.value);
138153
}elseif(attrTarget.matches('input, textarea')){
139154
(attrTargetasHTMLInputElement|HTMLTextAreaElement).value=attrib.value;// FIXME: add more supports like checkbox
140155
}else{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp