2019-12-13 19:11:49 +03:00
|
|
|
import Component from '@glimmer/component';
|
2017-08-22 10:53:26 +03:00
|
|
|
import {isEmpty} from '@ember/utils';
|
2015-10-28 14:36:45 +03:00
|
|
|
|
2015-06-07 06:19:19 +03:00
|
|
|
/**
|
|
|
|
* Renders one random error message when passed a DS.Errors object
|
|
|
|
* and a property name. The message will be one of the ones associated with
|
|
|
|
* that specific property. If there are no errors associated with the property,
|
|
|
|
* nothing will be rendered.
|
|
|
|
* @param {DS.Errors} errors The DS.Errors object
|
|
|
|
* @param {string} property The property name
|
|
|
|
*/
|
2019-12-13 19:11:49 +03:00
|
|
|
export default class GhErrorMessage extends Component {
|
|
|
|
get message() {
|
|
|
|
let {property, errors} = this.args;
|
2015-10-28 14:36:45 +03:00
|
|
|
let messages = [];
|
|
|
|
let index;
|
2015-06-07 06:19:19 +03:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
if (!isEmpty(errors) && errors.get(property)) {
|
|
|
|
errors.get(property).forEach((error) => {
|
2015-06-07 06:19:19 +03:00
|
|
|
messages.push(error);
|
|
|
|
});
|
|
|
|
index = Math.floor(Math.random() * messages.length);
|
|
|
|
return messages[index].message;
|
|
|
|
}
|
2019-06-24 18:33:21 +03:00
|
|
|
|
|
|
|
return '';
|
2019-12-13 19:11:49 +03:00
|
|
|
}
|
|
|
|
}
|