summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/blob
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-10-10 09:06:08 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-10 09:06:08 +0000
commitc157f963db87a40a3ba7b94b339530ee83194bc8 (patch)
tree9f8f9468daf727cce39bc7487af8bd9a53b8c59d /app/assets/javascripts/blob
parentbd1e1afde56a9bd97e03ca24298e260dc071999e (diff)
downloadgitlab-ce-c157f963db87a40a3ba7b94b339530ee83194bc8.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/blob')
-rw-r--r--app/assets/javascripts/blob/file_template_mediator.js49
-rw-r--r--app/assets/javascripts/blob/template_selectors/ci_yaml_selector.js1
-rw-r--r--app/assets/javascripts/blob/template_selectors/dockerfile_selector.js1
-rw-r--r--app/assets/javascripts/blob/template_selectors/gitignore_selector.js1
-rw-r--r--app/assets/javascripts/blob/template_selectors/license_selector.js1
-rw-r--r--app/assets/javascripts/blob/template_selectors/type_selector.js1
6 files changed, 28 insertions, 26 deletions
diff --git a/app/assets/javascripts/blob/file_template_mediator.js b/app/assets/javascripts/blob/file_template_mediator.js
index 106fe2e0cef..b371f6be268 100644
--- a/app/assets/javascripts/blob/file_template_mediator.js
+++ b/app/assets/javascripts/blob/file_template_mediator.js
@@ -7,6 +7,8 @@ import BlobCiYamlSelector from './template_selectors/ci_yaml_selector';
import DockerfileSelector from './template_selectors/dockerfile_selector';
import GitignoreSelector from './template_selectors/gitignore_selector';
import LicenseSelector from './template_selectors/license_selector';
+import toast from '~/vue_shared/plugins/global_toast';
+import { __ } from '~/locale';
export default class FileTemplateMediator {
constructor({ editor, currentAction, projectId }) {
@@ -19,6 +21,7 @@ export default class FileTemplateMediator {
this.initDomElements();
this.initDropdowns();
this.initPageEvents();
+ this.cacheFileContents();
}
initTemplateSelectors() {
@@ -40,6 +43,7 @@ export default class FileTemplateMediator {
return {
name: cfg.name,
key: cfg.key,
+ id: cfg.key,
};
}),
});
@@ -58,6 +62,7 @@ export default class FileTemplateMediator {
this.$fileContent = $fileEditor.find('#file-content');
this.$commitForm = $fileEditor.find('form');
this.$navLinks = $fileEditor.find('.nav-links');
+ this.$templateTypes = this.$templateSelectors.find('.template-type-selector');
}
initDropdowns() {
@@ -113,7 +118,11 @@ export default class FileTemplateMediator {
}
});
- this.typeSelector.setToggleText(item.name);
+ this.setFilename(item.name);
+
+ if (this.editor.getValue() !== '') {
+ this.setTypeSelectorToggleText(item.name);
+ }
this.cacheToggleText();
}
@@ -123,15 +132,24 @@ export default class FileTemplateMediator {
}
selectTemplateFile(selector, query, data) {
+ const self = this;
+
selector.renderLoading();
- // in case undo menu is already there
- this.destroyUndoMenu();
+
this.fetchFileTemplate(selector.config.type, query, data)
.then(file => {
- this.showUndoMenu();
this.setEditorContent(file);
- this.setFilename(selector.config.name);
selector.renderLoaded();
+ this.typeSelector.setToggleText(selector.config.name);
+ toast(__(`${query} template applied`), {
+ action: {
+ text: __('Undo'),
+ onClick: (e, toastObj) => {
+ self.restoreFromCache();
+ toastObj.goAway(0);
+ },
+ },
+ });
})
.catch(err => new Flash(`An error occurred while fetching the template: ${err}`));
}
@@ -173,22 +191,6 @@ export default class FileTemplateMediator {
return this.templateSelectors.find(selector => selector.config.key === key);
}
- showUndoMenu() {
- this.$undoMenu.removeClass('hidden');
-
- this.$undoBtn.on('click', () => {
- this.restoreFromCache();
- this.destroyUndoMenu();
- });
- }
-
- destroyUndoMenu() {
- this.cacheFileContents();
- this.cacheToggleText();
- this.$undoMenu.addClass('hidden');
- this.$undoBtn.off('click');
- }
-
hideTemplateSelectorMenu() {
this.$templatesMenu.hide();
}
@@ -210,6 +212,7 @@ export default class FileTemplateMediator {
this.setEditorContent(this.cachedContent);
this.setFilename(this.cachedFilename);
this.setTemplateSelectorToggleText();
+ this.setTypeSelectorToggleText(__('Select a template type'));
}
getTemplateSelectorToggleText() {
@@ -228,6 +231,10 @@ export default class FileTemplateMediator {
return this.typeSelector.getToggleText();
}
+ setTypeSelectorToggleText(text) {
+ this.typeSelector.setToggleText(text);
+ }
+
getFilename() {
return this.$filenameInput.val();
}
diff --git a/app/assets/javascripts/blob/template_selectors/ci_yaml_selector.js b/app/assets/javascripts/blob/template_selectors/ci_yaml_selector.js
index 43f7aead8b9..d819452df68 100644
--- a/app/assets/javascripts/blob/template_selectors/ci_yaml_selector.js
+++ b/app/assets/javascripts/blob/template_selectors/ci_yaml_selector.js
@@ -19,7 +19,6 @@ export default class BlobCiYamlSelector extends FileTemplateSelector {
data: this.$dropdown.data('data'),
filterable: true,
selectable: true,
- toggleLabel: item => item.name,
search: {
fields: ['name'],
},
diff --git a/app/assets/javascripts/blob/template_selectors/dockerfile_selector.js b/app/assets/javascripts/blob/template_selectors/dockerfile_selector.js
index 659d57e6a6f..7d5e98889d3 100644
--- a/app/assets/javascripts/blob/template_selectors/dockerfile_selector.js
+++ b/app/assets/javascripts/blob/template_selectors/dockerfile_selector.js
@@ -20,7 +20,6 @@ export default class DockerfileSelector extends FileTemplateSelector {
data: this.$dropdown.data('data'),
filterable: true,
selectable: true,
- toggleLabel: item => item.name,
search: {
fields: ['name'],
},
diff --git a/app/assets/javascripts/blob/template_selectors/gitignore_selector.js b/app/assets/javascripts/blob/template_selectors/gitignore_selector.js
index a8067ec5c84..39a8937641d 100644
--- a/app/assets/javascripts/blob/template_selectors/gitignore_selector.js
+++ b/app/assets/javascripts/blob/template_selectors/gitignore_selector.js
@@ -18,7 +18,6 @@ export default class BlobGitignoreSelector extends FileTemplateSelector {
data: this.$dropdown.data('data'),
filterable: true,
selectable: true,
- toggleLabel: item => item.name,
search: {
fields: ['name'],
},
diff --git a/app/assets/javascripts/blob/template_selectors/license_selector.js b/app/assets/javascripts/blob/template_selectors/license_selector.js
index d01ab9257d6..f4041835a7d 100644
--- a/app/assets/javascripts/blob/template_selectors/license_selector.js
+++ b/app/assets/javascripts/blob/template_selectors/license_selector.js
@@ -18,7 +18,6 @@ export default class BlobLicenseSelector extends FileTemplateSelector {
data: this.$dropdown.data('data'),
filterable: true,
selectable: true,
- toggleLabel: item => item.name,
search: {
fields: ['name'],
},
diff --git a/app/assets/javascripts/blob/template_selectors/type_selector.js b/app/assets/javascripts/blob/template_selectors/type_selector.js
index db3c144cbe3..cb4e1aaa9ac 100644
--- a/app/assets/javascripts/blob/template_selectors/type_selector.js
+++ b/app/assets/javascripts/blob/template_selectors/type_selector.js
@@ -16,7 +16,6 @@ export default class FileTemplateTypeSelector extends FileTemplateSelector {
data: this.config.dropdownData,
filterable: false,
selectable: true,
- toggleLabel: item => item.name,
clicked: options => this.mediator.selectTemplateTypeOptions(options),
text: item => item.name,
});