Commit 94dfd15e authored by Luke Bennett's avatar Luke Bennett

re-port

parent 56744742
import initForm from '../form'; import initForm from '../form';
import PushPull from './push_pull'; import MirrorRepos from './mirror_repos';
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
initForm(); initForm();
const pushPullContainer = document.querySelector('.js-mirror-settings'); const mirrorReposContainer = document.querySelector('.js-mirror-settings');
if (pushPullContainer) new PushPull(pushPullContainer).init(); if (mirrorReposContainer) new MirrorRepos(mirrorReposContainer).init();
}); });
...@@ -4,24 +4,32 @@ import { __ } from '~/locale'; ...@@ -4,24 +4,32 @@ import { __ } from '~/locale';
import Flash from '~/flash'; import Flash from '~/flash';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
export default class PushPull { export default class MirrorRepos {
constructor(container) { constructor(container) {
this.$container = $(container); this.$container = $(container);
this.$form = $('.js-mirror-form', this.$container); this.$form = $('.js-mirror-form', this.$container);
this.$urlInput = $('.js-mirror-url', this.$form); this.$urlInput = $('.js-mirror-url', this.$form);
this.$protectedBranchesInput = $('.js-mirror-protected', this.$form); this.$protectedBranchesInput = $('.js-mirror-protected', this.$form);
this.mirrorEndpoint = this.$form.data('projectMirrorEndpoint');
this.$table = $('.js-mirrors-table-body', this.$container); this.$table = $('.js-mirrors-table-body', this.$container);
this.mirrorEndpoint = this.$form.data('projectMirrorEndpoint');
} }
init() { init() {
this.registerUpdateListeners(); this.registerUpdateListeners();
this.initMirrorPush();
this.$table.on('click', '.js-delete-mirror', this.deleteMirror.bind(this)); this.$table.on('click', '.js-delete-mirror', this.deleteMirror.bind(this));
} }
updateUrl() { updateUrl() {
$('.js-mirror-url-hidden', this.$form).val(this.$urlInput.val()); let val = this.$urlInput.val();
if (this.$password) {
const password = this.$password.val();
if (password) val = val.replace('@', `:${password}@`);
}
$('.js-mirror-url-hidden', this.$form).val(val);
} }
updateProtectedBranches() { updateProtectedBranches() {
...@@ -32,10 +40,16 @@ export default class PushPull { ...@@ -32,10 +40,16 @@ export default class PushPull {
} }
registerUpdateListeners() { registerUpdateListeners() {
this.$urlInput.on('change', () => this.updateUrl()); this.debouncedUpdateUrl = _.debounce(() => this.updateUrl(), 200);
this.$urlInput.on('input', () => this.debouncedUpdateUrl());
this.$protectedBranchesInput.on('change', () => this.updateProtectedBranches()); this.$protectedBranchesInput.on('change', () => this.updateProtectedBranches());
} }
initMirrorPush() {
this.$password = $('.js-password', this.$form);
this.$password.on('input.updateUrl', () => this.debouncedUpdateUrl());
}
deleteMirror(event, existingPayload) { deleteMirror(event, existingPayload) {
const $target = $(event.currentTarget); const $target = $(event.currentTarget);
let payload = existingPayload; let payload = existingPayload;
......
...@@ -242,6 +242,10 @@ ...@@ -242,6 +242,10 @@
&:not(:last-child) { &:not(:last-child) {
margin-right: 5px; margin-right: 5px;
} }
&.hide {
display: none;
}
} }
} }
......
...@@ -201,7 +201,7 @@ label { ...@@ -201,7 +201,7 @@ label {
} }
.gl-show-field-errors { .gl-show-field-errors {
.form-control { .form-control:not(textarea) {
height: 34px; height: 34px;
} }
......
...@@ -311,3 +311,11 @@ ...@@ -311,3 +311,11 @@
.push-pull-table { .push-pull-table {
margin-top: 1em; margin-top: 1em;
} }
.push-pull-table {
margin-top: 1em;
.mirror-action-buttons {
padding-right: 0;
}
}
...@@ -8,4 +8,3 @@ ...@@ -8,4 +8,3 @@
%li %li
= _('This user will be the author of all events in the activity feed that are the result of an update, = _('This user will be the author of all events in the activity feed that are the result of an update,
like new branches being created or new commits being pushed to existing branches.') like new branches being created or new commits being pushed to existing branches.')
...@@ -29,9 +29,11 @@ ...@@ -29,9 +29,11 @@
= render 'projects/mirrors/instructions' = render 'projects/mirrors/instructions'
= render_if_exists 'projects/mirrors/direction_dropdown', options: options .form-group
= label_tag :mirror_direction, _('Mirror direction'), class: 'label-light'
= select_tag :mirror_direction, options_for_select(options), class: 'form-control js-mirror-direction'
= render 'projects/mirrors/push_pull_form', can_push: can_push, can_pull: can_pull, f: f = render 'projects/mirrors/mirror_repos_form', can_push: can_push, can_pull: can_pull, f: f
.form-check.append-bottom-10 .form-check.append-bottom-10
= check_box_tag :only_protected_branches, '1', false, class: 'js-mirror-protected form-check-input' = check_box_tag :only_protected_branches, '1', false, class: 'js-mirror-protected form-check-input'
...@@ -64,7 +66,7 @@ ...@@ -64,7 +66,7 @@
%td %td
- if mirror.last_error.present? - if mirror.last_error.present?
.badge.mirror-error-badge{ data: { toggle: 'tooltip', html: 'true' }, title: html_escape(mirror.last_error.try(:strip)) }= _('Error') .badge.mirror-error-badge{ data: { toggle: 'tooltip', html: 'true' }, title: html_escape(mirror.last_error.try(:strip)) }= _('Error')
%td %td.mirror-action-buttons
.btn-group.mirror-actions-group{ role: 'group' } .btn-group.mirror-actions-group.pull-right{ role: 'group' }
= render 'shared/remote_mirror_update_button', remote_mirror: mirror = render 'shared/remote_mirror_update_button', remote_mirror: mirror
%button.js-delete-mirror.btn.btn-danger{ type: 'button', data: { mirror_id: mirror.id, toggle: 'tooltip', container: 'body' }, title: _('Remove') }= icon('trash-o') %button.js-delete-mirror.btn.btn-danger{ type: 'button', data: { mirror_id: mirror.id, toggle: 'tooltip', container: 'body' }, title: _('Remove') }= icon('trash-o')
...@@ -3,4 +3,12 @@ ...@@ -3,4 +3,12 @@
= f.fields_for :remote_mirrors, @remote_mirror do |rm_f| = f.fields_for :remote_mirrors, @remote_mirror do |rm_f|
= rm_f.hidden_field :enabled, value: '1' = rm_f.hidden_field :enabled, value: '1'
= rm_f.hidden_field :url, class: 'js-mirror-url-hidden', required: true, pattern: "(#{protocols}):\/\/.+" = rm_f.hidden_field :url, class: 'js-mirror-url-hidden', required: true, pattern: "(#{protocols}):\/\/.+"
= rm_f.hidden_field :only_protected_branches, class: 'js-mirror-protected-hidden' = rm_f.hidden_field :only_protected_branches, class: 'js-mirror-protected-hidden'
\ No newline at end of file
.form-group
= label_tag :auth_method, _('Authentication method'), class: 'label-bold'
= select_tag :auth_method, options_for_select([[_('Password'), 'password']], 'password'), { class: "form-control js-auth-method", disabled: 'disabled' }
.form-group
= label_tag :password, _('Password'), class: 'label-bold'
= text_field_tag :password, '', class: 'form-control js-password'
= render 'projects/mirrors/push_pull' = render 'projects/mirrors/mirror_repos'
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment