diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2016-05-10 15:48:41 +0200 |
---|---|---|
committer | Stas Vilchik <vilchiks@gmail.com> | 2016-05-10 15:48:50 +0200 |
commit | 7a59b82ec1d9c7b18b067ede96076b2a3bdd5e05 (patch) | |
tree | f81f92276e4592fda9d29f31047b29fdd1cf63a5 /server/sonar-web/src/main/js/apps/quality-profiles | |
parent | b9e18905cfdc955d75edc902ad60f920e838d14b (diff) | |
download | sonarqube-7a59b82ec1d9c7b18b067ede96076b2a3bdd5e05.tar.gz sonarqube-7a59b82ec1d9c7b18b067ede96076b2a3bdd5e05.zip |
SONAR-7518 Restore Profile does not warn on missing rules
Diffstat (limited to 'server/sonar-web/src/main/js/apps/quality-profiles')
-rw-r--r-- | server/sonar-web/src/main/js/apps/quality-profiles/restore-profile-view.js | 37 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/apps/quality-profiles/templates/quality-profiles-restore-profile.hbs | 33 |
2 files changed, 50 insertions, 20 deletions
diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/restore-profile-view.js b/server/sonar-web/src/main/js/apps/quality-profiles/restore-profile-view.js index ca291aa302a..3c5bad5adb7 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/restore-profile-view.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/restore-profile-view.js @@ -17,27 +17,32 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import $ from 'jquery'; -import _ from 'underscore'; import ModalFormView from '../../components/common/modal-form'; -import uploader from '../../components/common/file-upload'; import Profile from './profile'; import Template from './templates/quality-profiles-restore-profile.hbs'; +import { restoreQualityProfile } from '../../api/quality-profiles'; export default ModalFormView.extend({ template: Template, onFormSubmit (e) { - const that = this; ModalFormView.prototype.onFormSubmit.apply(this, arguments); - uploader({ form: $(e.currentTarget) }).done(function (r) { - if (_.isArray(r.errors) || _.isArray(r.warnings)) { - that.showErrors(r.errors, r.warnings); - } else { - that.addProfile(r.profile); - that.destroy(); - } - }); + const data = new FormData(e.currentTarget); + + this.disableForm(); + + restoreQualityProfile(data) + .then(r => { + this.profile = r.profile; + this.ruleSuccesses = r.ruleSuccesses; + this.ruleFailures = r.ruleFailures; + this.render(); + this.addProfile(r.profile); + }) + .catch(e => { + this.enableForm(); + e.response.json().then(r => this.showErrors(r.errors, r.warnings)); + }); }, addProfile (profileData) { @@ -47,5 +52,13 @@ export default ModalFormView.extend({ if (addedProfile != null) { addedProfile.trigger('select', addedProfile); } + }, + + serializeData() { + return Object.assign({}, ModalFormView.prototype.serializeData.apply(this, arguments), { + profile: this.profile, + ruleSuccesses: this.ruleSuccesses, + ruleFailures: this.ruleFailures + }); } }); diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/templates/quality-profiles-restore-profile.hbs b/server/sonar-web/src/main/js/apps/quality-profiles/templates/quality-profiles-restore-profile.hbs index faffd5950ae..9a8b0182717 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/templates/quality-profiles-restore-profile.hbs +++ b/server/sonar-web/src/main/js/apps/quality-profiles/templates/quality-profiles-restore-profile.hbs @@ -1,17 +1,34 @@ -<form id="restore-profile-form" action="{{link '/api/qualityprofiles/restore'}}" enctype="multipart/form-data" - method="POST"> +<form id="restore-profile-form"> <div class="modal-head"> <h2>{{t 'quality_profiles.restore_profile'}}</h2> </div> + <div class="modal-body"> <div class="js-modal-messages"></div> - <div class="modal-field"> - <label for="restore-profile-backup">{{t 'backup'}}<em class="mandatory">*</em></label> - <input type="file" id="restore-profile-backup" name="backup" required> - </div> + {{#if profile}} + {{#if ruleFailures}} + <div class="alert alert-warning"> + {{tp 'quality_profiles.restore_profile.warning' profile.name ruleSuccesses ruleFailures}} + </div> + {{else}} + <div class="alert alert-success"> + {{tp 'quality_profiles.restore_profile.success' profile.name ruleSuccesses}} + </div> + {{/if}} + {{else}} + <div class="modal-field"> + <label for="restore-profile-backup">{{t 'backup'}}<em class="mandatory">*</em></label> + <input type="file" id="restore-profile-backup" name="backup" required> + </div> + {{/if}} </div> + <div class="modal-foot"> - <button id="restore-profile-submit">{{t 'restore'}}</button> - <a href="#" class="js-modal-close" id="restore-profile-cancel">{{t 'cancel'}}</a> + {{#notNull ruleSuccesses}} + <a href="#" class="js-modal-close">{{t 'close'}}</a> + {{else}} + <button id="restore-profile-submit">{{t 'restore'}}</button> + <a href="#" class="js-modal-close" id="restore-profile-cancel">{{t 'cancel'}}</a> + {{/notNull}} </div> </form> |