From 0eea8c885743575b0e93a98846b3663e9903aa66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Thu, 30 Jun 2016 17:34:19 +0200 Subject: Support slash commands in noteable description and notes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some important things to note: - commands are removed from noteable.description / note.note - commands are translated to params so that they are treated as normal params in noteable Creation services - the logic is not in the models but in the Creation services, which is the right place for advanced logic that has nothing to do with what models should be responsible of! - UI/JS needs to be updated to handle notes which consist of commands only - the `/merge` command is not handled yet Other improvements: - Don't process commands in commit notes and display a flash is note is only commands - Add autocomplete for slash commands - Add description and params to slash command DSL methods - Ensure replying by email with a commands-only note works - Use :subscription_event instead of calling noteable.subscribe - Support :todo_event in IssuableBaseService Signed-off-by: Rémy Coutable --- app/assets/javascripts/gfm_auto_complete.js | 272 ---------------------------- 1 file changed, 272 deletions(-) delete mode 100644 app/assets/javascripts/gfm_auto_complete.js (limited to 'app/assets/javascripts/gfm_auto_complete.js') diff --git a/app/assets/javascripts/gfm_auto_complete.js b/app/assets/javascripts/gfm_auto_complete.js deleted file mode 100644 index 2e5b15f4b77..00000000000 --- a/app/assets/javascripts/gfm_auto_complete.js +++ /dev/null @@ -1,272 +0,0 @@ -(function() { - if (window.GitLab == null) { - window.GitLab = {}; - } - - GitLab.GfmAutoComplete = { - dataLoading: false, - dataLoaded: false, - cachedData: {}, - dataSource: '', - Emoji: { - template: '
  • ${name} ${name}
  • ' - }, - Members: { - template: '
  • ${username} ${title}
  • ' - }, - Labels: { - template: '
  • ${title}
  • ' - }, - Issues: { - template: '
  • ${id} ${title}
  • ' - }, - Milestones: { - template: '
  • ${title}
  • ' - }, - Loading: { - template: '
  • Loading...
  • ' - }, - DefaultOptions: { - sorter: function(query, items, searchKey) { - if ((items[0].name != null) && items[0].name === 'loading') { - return items; - } - return $.fn.atwho["default"].callbacks.sorter(query, items, searchKey); - }, - filter: function(query, data, searchKey) { - if (data[0] === 'loading') { - return data; - } - return $.fn.atwho["default"].callbacks.filter(query, data, searchKey); - }, - beforeInsert: function(value) { - if (!GitLab.GfmAutoComplete.dataLoaded) { - return this.at; - } else { - return value; - } - } - }, - setup: function(input) { - this.input = input || $('.js-gfm-input'); - this.destroyAtWho(); - this.setupAtWho(); - if (this.dataSource) { - if (!this.dataLoading && !this.cachedData) { - this.dataLoading = true; - setTimeout((function(_this) { - return function() { - var fetch; - fetch = _this.fetchData(_this.dataSource); - return fetch.done(function(data) { - _this.dataLoading = false; - return _this.loadData(data); - }); - }; - })(this), 1000); - } - if (this.cachedData != null) { - return this.loadData(this.cachedData); - } - } - }, - setupAtWho: function() { - this.input.atwho({ - at: ':', - displayTpl: (function(_this) { - return function(value) { - if (value.path != null) { - return _this.Emoji.template; - } else { - return _this.Loading.template; - } - }; - })(this), - insertTpl: ':${name}:', - data: ['loading'], - callbacks: { - sorter: this.DefaultOptions.sorter, - filter: this.DefaultOptions.filter, - beforeInsert: this.DefaultOptions.beforeInsert - } - }); - this.input.atwho({ - at: '@', - displayTpl: (function(_this) { - return function(value) { - if (value.username != null) { - return _this.Members.template; - } else { - return _this.Loading.template; - } - }; - })(this), - insertTpl: '${atwho-at}${username}', - searchKey: 'search', - data: ['loading'], - callbacks: { - sorter: this.DefaultOptions.sorter, - filter: this.DefaultOptions.filter, - beforeInsert: this.DefaultOptions.beforeInsert, - beforeSave: function(members) { - return $.map(members, function(m) { - var title; - if (m.username == null) { - return m; - } - title = m.name; - if (m.count) { - title += " (" + m.count + ")"; - } - return { - username: m.username, - title: sanitize(title), - search: sanitize(m.username + " " + m.name) - }; - }); - } - } - }); - this.input.atwho({ - at: '#', - alias: 'issues', - searchKey: 'search', - displayTpl: (function(_this) { - return function(value) { - if (value.title != null) { - return _this.Issues.template; - } else { - return _this.Loading.template; - } - }; - })(this), - data: ['loading'], - insertTpl: '${atwho-at}${id}', - callbacks: { - sorter: this.DefaultOptions.sorter, - filter: this.DefaultOptions.filter, - beforeInsert: this.DefaultOptions.beforeInsert, - beforeSave: function(issues) { - return $.map(issues, function(i) { - if (i.title == null) { - return i; - } - return { - id: i.iid, - title: sanitize(i.title), - search: i.iid + " " + i.title - }; - }); - } - } - }); - this.input.atwho({ - at: '%', - alias: 'milestones', - searchKey: 'search', - displayTpl: (function(_this) { - return function(value) { - if (value.title != null) { - return _this.Milestones.template; - } else { - return _this.Loading.template; - } - }; - })(this), - insertTpl: '${atwho-at}"${title}"', - data: ['loading'], - callbacks: { - beforeSave: function(milestones) { - return $.map(milestones, function(m) { - if (m.title == null) { - return m; - } - return { - id: m.iid, - title: sanitize(m.title), - search: "" + m.title - }; - }); - } - } - }); - this.input.atwho({ - at: '!', - alias: 'mergerequests', - searchKey: 'search', - displayTpl: (function(_this) { - return function(value) { - if (value.title != null) { - return _this.Issues.template; - } else { - return _this.Loading.template; - } - }; - })(this), - data: ['loading'], - insertTpl: '${atwho-at}${id}', - callbacks: { - sorter: this.DefaultOptions.sorter, - filter: this.DefaultOptions.filter, - beforeInsert: this.DefaultOptions.beforeInsert, - beforeSave: function(merges) { - return $.map(merges, function(m) { - if (m.title == null) { - return m; - } - return { - id: m.iid, - title: sanitize(m.title), - search: m.iid + " " + m.title - }; - }); - } - } - }); - return this.input.atwho({ - at: '~', - alias: 'labels', - searchKey: 'search', - displayTpl: this.Labels.template, - insertTpl: '${atwho-at}${title}', - callbacks: { - beforeSave: function(merges) { - var sanitizeLabelTitle; - sanitizeLabelTitle = function(title) { - if (/[\w\?&]+\s+[\w\?&]+/g.test(title)) { - return "\"" + (sanitize(title)) + "\""; - } else { - return sanitize(title); - } - }; - return $.map(merges, function(m) { - return { - title: sanitizeLabelTitle(m.title), - color: m.color, - search: "" + m.title - }; - }); - } - } - }); - }, - destroyAtWho: function() { - return this.input.atwho('destroy'); - }, - fetchData: function(dataSource) { - return $.getJSON(dataSource); - }, - loadData: function(data) { - this.cachedData = data; - this.dataLoaded = true; - this.input.atwho('load', '@', data.members); - this.input.atwho('load', 'issues', data.issues); - this.input.atwho('load', 'milestones', data.milestones); - this.input.atwho('load', 'mergerequests', data.mergerequests); - this.input.atwho('load', ':', data.emojis); - this.input.atwho('load', '~', data.labels); - return $(':focus').trigger('keyup'); - } - }; - -}).call(this); -- cgit v1.2.3