A platform for community discussion. Free, open, simple.
FIX: don't allow duplicate watched words (#5844)
OsamaSayegh0800098f1a89
diff --git a/app/assets/javascripts/admin/components/watched-word-form.js.es6 b/app/assets/javascripts/admin/components/watched-word-form.js.es6index 9b2213de617..e7ead641f2e 100644--- a/app/assets/javascripts/admin/components/watched-word-form.js.es6+++ b/app/assets/javascripts/admin/components/watched-word-form.js.es6@@ -5,7 +5,7 @@ export default Ember.Component.extend({classNames: ['watched-word-form'],formSubmitted: false,actionKey: null,- showSuccessMessage: false,+ showMessage: false,@computed('regularExpressions')placeholderKey(regularExpressions) {@@ -14,21 +14,33 @@ export default Ember.Component.extend({},@observes('word')- removeSuccessMessage() {- if (this.get('showSuccessMessage') && !Ember.isEmpty(this.get('word'))) {- this.set('showSuccessMessage', false);+ removeMessage() {+ if (this.get('showMessage') && !Ember.isEmpty(this.get('word'))) {+ this.set('showMessage', false);}},+ @computed('word')+ isUniqueWord(word) {+ const words = this.get("filteredContent") || [];+ const filtered = words.filter(content => content.action === this.get("actionKey"));+ return filtered.every(content => content.word.toLowerCase() !== word.toLowerCase());+ },+actions: {submit() {+ if (!this.get("isUniqueWord")) {+ this.setProperties({ showMessage: true, message: I18n.t('admin.watched_words.form.exists') });+ return;+ }+if (!this.get('formSubmitted')) {this.set('formSubmitted', true);const watchedWord = WatchedWord.create({ word: this.get('word'), action: this.get('actionKey') });watchedWord.save().then(result => {- this.setProperties({ word: '', formSubmitted: false, showSuccessMessage: true });+ this.setProperties({ word: '', formSubmitted: false, showMessage: true, message: I18n.t('admin.watched_words.form.success') });this.sendAction('action', WatchedWord.create(result));Ember.run.schedule('afterRender', () => this.$('.watched-word-input').focus());}).catch(e => {diff --git a/app/assets/javascripts/admin/templates/components/watched-word-form.hbs b/app/assets/javascripts/admin/templates/components/watched-word-form.hbsindex 7d2b460aa07..e4b2fab801f 100644--- a/app/assets/javascripts/admin/templates/components/watched-word-form.hbs+++ b/app/assets/javascripts/admin/templates/components/watched-word-form.hbs@@ -2,6 +2,6 @@{{text-field value=word disabled=formSubmitted class="watched-word-input" autocorrect="off" autocapitalize="off" placeholderKey=placeholderKey}}{{d-button action="submit" disabled=formSubmitted label="admin.watched_words.form.add"}}-{{#if showSuccessMessage}}- <span class="success-message">{{i18n 'admin.watched_words.form.success'}}</span>+{{#if showMessage}}+ <span class="success-message">{{message}}</span>{{/if}}diff --git a/app/assets/javascripts/admin/templates/watched-words-action.hbs b/app/assets/javascripts/admin/templates/watched-words-action.hbsindex ac0bc4175b5..1cf0f77cd92 100644--- a/app/assets/javascripts/admin/templates/watched-words-action.hbs+++ b/app/assets/javascripts/admin/templates/watched-words-action.hbs@@ -5,6 +5,7 @@{{watched-word-formactionKey=actionNameKeyaction="recordAdded"+ filteredContent=filteredContentregularExpressions=adminWatchedWords.regularExpressions}}{{watched-word-uploader uploading=uploading actionKey=actionNameKey done="uploadComplete"}}diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex 65f78257c43..76ba48799a5 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -3474,6 +3474,7 @@ en:placeholder_regexp: "regular expression"add: 'Add'success: 'Success'+ exists: 'Already exists'upload: "Upload"upload_successful: "Upload successful. Words have been added."