Skip to content

Commit

Permalink
Display failed addition top level validation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
eheinrich committed Nov 4, 2019
1 parent bc404fe commit f95908a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
12 changes: 10 additions & 2 deletions static/js/components/instrumentconfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@show="show = $event"
>
<customalert
v-for="error in errors.non_field_errors"
v-for="error in topLevelErrors"
:key="error"
alertclass="danger"
:dismissible="false"
Expand Down Expand Up @@ -143,7 +143,12 @@
<script>
import _ from 'lodash';
import { collapseMixin, lampFlatDefaultExposureTime, arcDefaultExposureTime } from '../utils.js';
import {
collapseMixin,
lampFlatDefaultExposureTime,
arcDefaultExposureTime,
extractTopLevelErrors
} from '../utils.js';
import customfield from './util/customfield.vue';
import customselect from './util/customselect.vue';
import panel from './util/panel.vue';
Expand Down Expand Up @@ -185,6 +190,9 @@ export default {
}
},
computed: {
topLevelErrors: function() {
return extractTopLevelErrors(this.errors);
},
instrumentHasRotatorModes: function() {
return this.available_instruments[this.selectedinstrument] && 'rotator' in this.available_instruments[this.selectedinstrument].modes;
},
Expand Down
9 changes: 7 additions & 2 deletions static/js/components/window.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@show="show = $event"
>
<customalert
v-for="error in errors.non_field_errors"
v-for="error in topLevelErrors"
:key="error"
alertclass="danger"
:dismissible="false"
Expand Down Expand Up @@ -107,7 +107,7 @@
import $ from 'jquery';
import _ from 'lodash';
import { collapseMixin } from '../utils.js';
import { collapseMixin, extractTopLevelErrors } from '../utils.js';
import panel from './util/panel.vue';
import customalert from './util/customalert.vue';
import customdatetime from './util/customdatetime.vue';
Expand Down Expand Up @@ -145,6 +145,11 @@
jitter: 12.0
};
},
computed: {
topLevelErrors: function() {
return extractTopLevelErrors(this.errors);
},
},
methods: {
update: function() {
this.$emit('windowupdate');
Expand Down
17 changes: 16 additions & 1 deletion static/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,20 @@ function formatValue(value){
return value;
}

function extractTopLevelErrors(errors) {
let topLevelErrors = [];
if (_.isString(errors)) {
// The error will be a string if a validate_xxx method of the parent serializer
// returned an error, for example the validate_instrument_configs method on the
// ConfigurationSerializer. These should be displayed at the top of a section.
topLevelErrors = _.concat(topLevelErrors, [errors]);
}
if (errors.non_field_errors) {
topLevelErrors = _.concat(topLevelErrors, errors.non_field_errors);
}
return topLevelErrors;
}

function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie !== '') {
Expand Down Expand Up @@ -345,5 +359,6 @@ export {
semesterStart, semesterEnd, sexagesimalRaToDecimal, sexagesimalDecToDecimal, QueryString, formatJson, formatValue,
formatDate, formatField, datetimeFormat, collapseMixin, siteToColor, siteCodeToName, arcDefaultExposureTime,
lampFlatDefaultExposureTime, observatoryCodeToNumber, telescopeCodeToName, colorPalette, julianToModifiedJulian,
getFieldDescription, decimalRaToSexigesimal, decimalDecToSexigesimal, tooltipConfig, addCsrfProtection
getFieldDescription, decimalRaToSexigesimal, decimalDecToSexigesimal, tooltipConfig, addCsrfProtection,
extractTopLevelErrors
};

0 comments on commit f95908a

Please sign in to comment.