Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow editing push mirrors after creation #26151

Merged
merged 30 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1f5b846
Adding mirror sync time update functionality
puni9869 Jul 24, 2023
99a5fe2
Adding mirror sync time update functionality
puni9869 Jul 24, 2023
d7910e8
Translations and css id fix
puni9869 Jul 25, 2023
feeec6d
Merge branch 'main' into punit/add-mirror-repo-update-time
puni9869 Jul 25, 2023
6112a94
Merge branch 'go-gitea:main' into punit/add-mirror-repo-update-time
puni9869 Jul 25, 2023
f9fe1de
Fix mirror enable check
puni9869 Jul 25, 2023
7940e69
Fixing the translation key.
puni9869 Jul 26, 2023
7e73aed
Merge branch 'main' into punit/add-mirror-repo-update-time
puni9869 Jul 26, 2023
d0ad3cc
Adding translation key to tool tip
puni9869 Jul 26, 2023
4995c00
Merge branch 'main' into punit/add-mirror-repo-update-time
puni9869 Jul 26, 2023
ceeb94c
Merge branch 'main' into punit/add-mirror-repo-update-time
puni9869 Jul 26, 2023
8486cbe
Merge branch 'main' into punit/add-mirror-repo-update-time
puni9869 Jul 26, 2023
00ddf41
Merge branch 'main' into punit/add-mirror-repo-update-time
puni9869 Jul 27, 2023
c0ef7ae
Merge branch 'main' into punit/add-mirror-repo-update-time
puni9869 Jul 27, 2023
d6af331
Merge branch 'main' into punit/add-mirror-repo-update-time
puni9869 Jul 28, 2023
a7d4e7e
Merge branch 'main' into punit/add-mirror-repo-update-time
puni9869 Jul 28, 2023
cc1674a
Merge branch 'main' into punit/add-mirror-repo-update-time
puni9869 Jul 28, 2023
f8f6c48
Merge branch 'main' into punit/add-mirror-repo-update-time
puni9869 Jul 29, 2023
bae2659
fix
wxiaoguang Jul 29, 2023
ec94ec3
Merge branch 'main' into punit/add-mirror-repo-update-time
puni9869 Jul 29, 2023
a0a5409
Merge branch 'main' into punit/add-mirror-repo-update-time
puni9869 Jul 31, 2023
e224fb5
Adding helping comments
puni9869 Jul 31, 2023
62a60b1
Merge branch 'main' into punit/add-mirror-repo-update-time
puni9869 Jul 31, 2023
7440f8e
Merge branch 'main' into punit/add-mirror-repo-update-time
GiteaBot Jul 31, 2023
2683d26
Merge branch 'main' into punit/add-mirror-repo-update-time
GiteaBot Jul 31, 2023
24eb1e5
Merge branch 'main' into punit/add-mirror-repo-update-time
GiteaBot Jul 31, 2023
e1b1639
Merge branch 'main' into punit/add-mirror-repo-update-time
GiteaBot Jul 31, 2023
80f8372
Merge branch 'main' into punit/add-mirror-repo-update-time
GiteaBot Aug 1, 2023
8bf049d
Merge branch 'main' into punit/add-mirror-repo-update-time
GiteaBot Aug 1, 2023
b82fe7d
Merge branch 'main' into punit/add-mirror-repo-update-time
GiteaBot Aug 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions models/repo/pushmirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ func UpdatePushMirror(ctx context.Context, m *PushMirror) error {
return err
}

// UpdatePushMirrorInterval updates the push-mirror
func UpdatePushMirrorInterval(ctx context.Context, m *PushMirror) error {
_, err := db.GetEngine(ctx).ID(m.ID).Cols("interval").Update(m)
return err
}

func DeletePushMirrors(ctx context.Context, opts PushMirrorOptions) error {
if opts.RepoID > 0 {
_, err := db.GetEngine(ctx).Where(opts.toConds()).Delete(&PushMirror{})
Expand Down
2 changes: 2 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1954,6 +1954,8 @@ settings.mirror_settings.last_update = Last update
settings.mirror_settings.push_mirror.none = No push mirrors configured
settings.mirror_settings.push_mirror.remote_url = Git Remote Repository URL
settings.mirror_settings.push_mirror.add = Add Push Mirror
settings.mirror_settings.push_mirror.edit_sync_time = Edit mirror sync interval

settings.sync_mirror = Synchronize Now
settings.mirror_sync_in_progress = Mirror synchronization is in progress. Check back in a minute.
settings.site = Website
Expand Down
33 changes: 33 additions & 0 deletions routers/web/repo/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,39 @@ func SettingsPost(ctx *context.Context) {
ctx.Flash.Info(ctx.Tr("repo.settings.mirror_sync_in_progress"))
ctx.Redirect(repo.Link() + "/settings")

case "push-mirror-update":
if !setting.Mirror.Enabled {
ctx.NotFound("", nil)
return
}

// This section doesn't require repo_name/RepoName to be set in the form, don't show it
// as an error on the UI for this action
ctx.Data["Err_RepoName"] = nil

interval, err := time.ParseDuration(form.PushMirrorInterval)
if err != nil || (interval != 0 && interval < setting.Mirror.MinInterval) {
ctx.RenderWithErr(ctx.Tr("repo.mirror_interval_invalid"), tplSettingsOptions, &forms.RepoSettingForm{})
return
}

id, err := strconv.ParseInt(form.PushMirrorID, 10, 64)
if err != nil {
ctx.ServerError("UpdatePushMirrorIntervalPushMirrorID", err)
return
}
m := &repo_model.PushMirror{
ID: id,
Interval: interval,
}
if err := repo_model.UpdatePushMirrorInterval(ctx, m); err != nil {
ctx.ServerError("UpdatePushMirrorInterval", err)
return
}
mirror_module.AddPushMirrorToQueue(m.ID)
puni9869 marked this conversation as resolved.
Show resolved Hide resolved
ctx.Flash.Success(ctx.Tr("repo.settings.update_settings_success"))
ctx.Redirect(repo.Link() + "/settings")

case "push-mirror-remove":
if !setting.Mirror.Enabled {
ctx.NotFound("", nil)
Expand Down
32 changes: 32 additions & 0 deletions templates/repo/settings/mirror_sync_modal.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<div class="ui small modal" id="mirror-sync-update">
<div class="header">
{{$.locale.Tr "repo.settings.mirror_settings.push_mirror.edit_sync_time"}}
</div>
<div class="content">
<form class="ui form ignore-dirty" method="post">
{{.CsrfTokenHtml}}
<input type="hidden" name="action" value="push-mirror-update">
<input type="hidden" name="push_mirror_id" id="push_mirror_id">
<div class="field">
<label for="name">{{$.locale.Tr "repo.settings.mirror_settings.mirrored_repository"}}</label>
<div class="ui small input">
<input name="mirror-address" id="mirror-address" readonly>
</div>
</div>
<div class="inline field">
<label for="push_mirror_interval">{{.locale.Tr "repo.mirror_interval" .MinimumMirrorInterval}}</label>
<input id="push_mirror_interval" name="push_mirror_interval" autofocus>
</div>
</div>
<div class="actions">
<button class="ui small basic cancel button">
{{svg "octicon-x"}}
{{.locale.Tr "cancel"}}
</button>
<button class="ui primary small approve button">
{{svg "fontawesome-save"}}
{{.locale.Tr "save"}}
</button>
</div>
</form>
</div>
20 changes: 16 additions & 4 deletions templates/repo/settings/options.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -203,17 +203,27 @@
<td>{{$.locale.Tr "repo.settings.mirror_settings.direction.push"}}</td>
<td>{{if .LastUpdateUnix}}{{DateTime "full" .LastUpdateUnix}}{{else}}{{$.locale.Tr "never"}}{{end}} {{if .LastError}}<div class="ui red label" data-tooltip-content="{{.LastError}}">{{$.locale.Tr "error"}}</div>{{end}}</td>
<td class="right aligned">
<button
data-modal="#mirror-sync-update"
data-id={{.ID}}
data-interval="{{.Interval}}"
data-mirror-address="{{$address.Address}}"
class="ui tiny button show-modal inline text-thin mirror-sync-update-button"
data-tooltip-content="{{$.locale.Tr "repo.settings.mirror_settings.push_mirror.edit_sync_time"}}"
>
{{svg "octicon-pencil" 14}}
</button>
<form method="post" class="gt-dib">
{{$.CsrfTokenHtml}}
<input type="hidden" name="action" value="push-mirror-remove">
<input type="hidden" name="action" value="push-mirror-sync">
<input type="hidden" name="push_mirror_id" value="{{.ID}}">
<button class="ui basic red tiny button inline text-thin">{{$.locale.Tr "remove"}}</button>
<button class="ui primary tiny button inline text-thin" data-tooltip-content="{{$.locale.Tr "repo.settings.sync_mirror"}}">{{svg "octicon-sync" 14}}</button>
</form>
<form method="post" class="gt-dib">
{{$.CsrfTokenHtml}}
<input type="hidden" name="action" value="push-mirror-sync">
<input type="hidden" name="action" value="push-mirror-remove">
<input type="hidden" name="push_mirror_id" value="{{.ID}}">
<button class="ui primary tiny button inline text-thin">{{$.locale.Tr "repo.settings.sync_mirror"}}</button>
<button class="ui basic red tiny button inline text-thin"data-tooltip-content="{{$.locale.Tr "remove"}}">{{svg "octicon-trash" 14}}</button>
</form>
</td>
</tr>
Expand Down Expand Up @@ -987,3 +997,5 @@
</div>
{{end}}
{{end}}

{{template "repo/settings/mirror_sync_modal" .}}
15 changes: 15 additions & 0 deletions web_src/js/features/repo-mirror.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import $ from 'jquery';

export function initMirrorRepoSyncUpdate() {
puni9869 marked this conversation as resolved.
Show resolved Hide resolved
$('.mirror-sync-update-button').on('click', (event) => {
const mirrorAddress = $(event.currentTarget).data('mirror-address');
const mirrorId = $(event.currentTarget).data('id');
const syncTime = $(event.currentTarget).data('interval');
$('#mirror-sync-update #mirror-address').val(mirrorAddress);
$('#mirror-sync-update #push_mirror_id').val(mirrorId);
$('#mirror-sync-update #push_mirror_interval').val(syncTime);
$('#mirror-sync-update .cancel').on('click', (event) => {
event.preventDefault();
});
});
}
3 changes: 3 additions & 0 deletions web_src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import {initGiteaFomantic} from './modules/fomantic.js';
import {onDomReady} from './utils/dom.js';
import {initRepoIssueList} from './features/repo-issue-list.js';
import {initCommonIssueListQuickGoto} from './features/common-issue-list.js';
import {initMirrorRepoSyncUpdate} from './features/repo-mirror.js';

// Init Gitea's Fomantic settings
initGiteaFomantic();
Expand Down Expand Up @@ -179,4 +180,6 @@ onDomReady(() => {
initRepoDiffView();
initPdfViewer();
initScopedAccessTokenCategories();

initMirrorRepoSyncUpdate();
});