From 1f5b84626cf05a4b28d9ce9ce3ccc31954bfa21b Mon Sep 17 00:00:00 2001 From: puni9869 Date: Mon, 24 Jul 2023 18:27:47 +0530 Subject: [PATCH 1/8] Adding mirror sync time update functionality --- routers/web/repo/setting/setting.go | 17 ++++++++++ .../repo/settings/mirror_sync_modal.tmpl | 31 +++++++++++++++++++ templates/repo/settings/options.tmpl | 11 ++++--- web_src/js/features/repo-mirror.js | 15 +++++++++ web_src/js/index.js | 3 ++ 5 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 templates/repo/settings/mirror_sync_modal.tmpl create mode 100644 web_src/js/features/repo-mirror.js diff --git a/routers/web/repo/setting/setting.go b/routers/web/repo/setting/setting.go index b33660ffc9cc6..d6ee7ef191852 100644 --- a/routers/web/repo/setting/setting.go +++ b/routers/web/repo/setting/setting.go @@ -299,6 +299,23 @@ 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 + } + + m, err := selectPushMirrorByForm(ctx, form, repo) + if err != nil { + ctx.NotFound("", nil) + return + } + + mirror_module.AddPushMirrorToQueue(m.ID) + + ctx.Flash.Info("Mirror sync updated") + ctx.Redirect(repo.Link() + "/settings") + case "push-mirror-remove": if !setting.Mirror.Enabled { ctx.NotFound("", nil) diff --git a/templates/repo/settings/mirror_sync_modal.tmpl b/templates/repo/settings/mirror_sync_modal.tmpl new file mode 100644 index 0000000000000..2d81cd783f122 --- /dev/null +++ b/templates/repo/settings/mirror_sync_modal.tmpl @@ -0,0 +1,31 @@ + diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index ef72c0eadc5f9..18d09683a704e 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -203,17 +203,18 @@ {{$.locale.Tr "repo.settings.mirror_settings.direction.push"}} {{if .LastUpdateUnix}}{{DateTime "full" .LastUpdateUnix}}{{else}}{{$.locale.Tr "never"}}{{end}} {{if .LastError}}
{{$.locale.Tr "error"}}
{{end}} +
{{$.CsrfTokenHtml}} - + - +
{{$.CsrfTokenHtml}} - + - +
@@ -987,3 +988,5 @@ {{end}} {{end}} + +{{template "repo/settings/mirror_sync_modal" .}} diff --git a/web_src/js/features/repo-mirror.js b/web_src/js/features/repo-mirror.js new file mode 100644 index 0000000000000..653ea7c439ba2 --- /dev/null +++ b/web_src/js/features/repo-mirror.js @@ -0,0 +1,15 @@ +import $ from 'jquery'; + +const {csrfToken} = window.config; + +export function initMirrorRepoSyncUpdate() { + $('.mirror-sync-update-button').on('click', () => { + const mirrorSync = $('.mirror-sync-update-button'); + const mirrorAddress = mirrorSync.attr('data-mirror-address'); + const mirrorId = mirrorSync.attr('data-mirror-push-id'); + const syncTime = mirrorSync.attr('data-sync-time'); + $('#mirror-sync-update #mirror-address').val(mirrorAddress); + $('#mirror-sync-update #mirror-id').val(mirrorId); + $('#mirror-sync-update #push_mirror_interval').val(syncTime); + }); +} diff --git a/web_src/js/index.js b/web_src/js/index.js index 0c786f96fbef2..2dd61da423d5d 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -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(); @@ -179,4 +180,6 @@ onDomReady(() => { initRepoDiffView(); initPdfViewer(); initScopedAccessTokenCategories(); + + initMirrorRepoSyncUpdate(); }); From 99a5fe2a73529e2c77e659a27e56b388bca6cbb3 Mon Sep 17 00:00:00 2001 From: puni9869 Date: Tue, 25 Jul 2023 01:57:12 +0530 Subject: [PATCH 2/8] Adding mirror sync time update functionality --- models/repo/pushmirror.go | 6 ++++ routers/web/repo/setting/setting.go | 29 +++++++++++++---- .../repo/settings/mirror_sync_modal.tmpl | 31 ++++++++++--------- templates/repo/settings/options.tmpl | 11 ++++++- web_src/js/features/repo-mirror.js | 16 +++++----- 5 files changed, 63 insertions(+), 30 deletions(-) diff --git a/models/repo/pushmirror.go b/models/repo/pushmirror.go index f34484f638788..dad9a9d388517 100644 --- a/models/repo/pushmirror.go +++ b/models/repo/pushmirror.go @@ -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{}) diff --git a/routers/web/repo/setting/setting.go b/routers/web/repo/setting/setting.go index d6ee7ef191852..da48c6b5c240d 100644 --- a/routers/web/repo/setting/setting.go +++ b/routers/web/repo/setting/setting.go @@ -300,20 +300,37 @@ func SettingsPost(ctx *context.Context) { ctx.Redirect(repo.Link() + "/settings") case "push-mirror-update": - if !setting.Mirror.Enabled { + if setting.Mirror.DisableNewPush { ctx.NotFound("", nil) return } - m, err := selectPushMirrorByForm(ctx, form, repo) - if err != nil { - ctx.NotFound("", nil) + // 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.Data["Err_PushMirrorInterval"] = true + ctx.RenderWithErr(ctx.Tr("repo.mirror_interval_invalid"), tplSettingsOptions, &form) 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) - - ctx.Flash.Info("Mirror sync updated") + ctx.Flash.Success(ctx.Tr("repo.settings.update_settings_success")) ctx.Redirect(repo.Link() + "/settings") case "push-mirror-remove": diff --git a/templates/repo/settings/mirror_sync_modal.tmpl b/templates/repo/settings/mirror_sync_modal.tmpl index 2d81cd783f122..e299e74bad85c 100644 --- a/templates/repo/settings/mirror_sync_modal.tmpl +++ b/templates/repo/settings/mirror_sync_modal.tmpl @@ -3,29 +3,30 @@ Edit mirror sync
-
+ {{.CsrfTokenHtml}} - + +
- +
-
-
-
- - -
+ +
+ + +
+ diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index 18d09683a704e..32c64ae09ac30 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -203,7 +203,16 @@ {{$.locale.Tr "repo.settings.mirror_settings.direction.push"}} {{if .LastUpdateUnix}}{{DateTime "full" .LastUpdateUnix}}{{else}}{{$.locale.Tr "never"}}{{end}} {{if .LastError}}
{{$.locale.Tr "error"}}
{{end}} - +
{{$.CsrfTokenHtml}} diff --git a/web_src/js/features/repo-mirror.js b/web_src/js/features/repo-mirror.js index 653ea7c439ba2..5c51a50acd485 100644 --- a/web_src/js/features/repo-mirror.js +++ b/web_src/js/features/repo-mirror.js @@ -1,15 +1,15 @@ import $ from 'jquery'; -const {csrfToken} = window.config; - export function initMirrorRepoSyncUpdate() { - $('.mirror-sync-update-button').on('click', () => { - const mirrorSync = $('.mirror-sync-update-button'); - const mirrorAddress = mirrorSync.attr('data-mirror-address'); - const mirrorId = mirrorSync.attr('data-mirror-push-id'); - const syncTime = mirrorSync.attr('data-sync-time'); + $('.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 #mirror-id').val(mirrorId); + $('#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(); + }); }); } From d7910e893b46c7e5dca2e6ae79763625c3218ce0 Mon Sep 17 00:00:00 2001 From: puni9869 Date: Tue, 25 Jul 2023 18:54:26 +0530 Subject: [PATCH 3/8] Translations and css id fix --- options/locale/locale_en-US.ini | 2 ++ routers/web/repo/setting/setting.go | 3 +-- templates/repo/settings/mirror_sync_modal.tmpl | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 94ae490981575..c3a75c24398eb 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -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 diff --git a/routers/web/repo/setting/setting.go b/routers/web/repo/setting/setting.go index da48c6b5c240d..e8681354c73ee 100644 --- a/routers/web/repo/setting/setting.go +++ b/routers/web/repo/setting/setting.go @@ -311,8 +311,7 @@ func SettingsPost(ctx *context.Context) { interval, err := time.ParseDuration(form.PushMirrorInterval) if err != nil || (interval != 0 && interval < setting.Mirror.MinInterval) { - ctx.Data["Err_PushMirrorInterval"] = true - ctx.RenderWithErr(ctx.Tr("repo.mirror_interval_invalid"), tplSettingsOptions, &form) + ctx.RenderWithErr(ctx.Tr("repo.mirror_interval_invalid"), tplSettingsOptions, &forms.RepoSettingForm{}) return } diff --git a/templates/repo/settings/mirror_sync_modal.tmpl b/templates/repo/settings/mirror_sync_modal.tmpl index e299e74bad85c..443aac5a4fc8b 100644 --- a/templates/repo/settings/mirror_sync_modal.tmpl +++ b/templates/repo/settings/mirror_sync_modal.tmpl @@ -1,6 +1,6 @@