Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
ember-cp-validations migration continues #2
Browse files Browse the repository at this point in the history
  • Loading branch information
stukalin committed Mar 19, 2018
1 parent 4e7f5e7 commit 3041a30
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 114 deletions.
18 changes: 7 additions & 11 deletions app/admin/textreplace/controller.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import Ember from 'ember';
import EmberValidations from 'ember-validations';
import { validator, buildValidations } from 'ember-cp-validations';

export default Ember.Controller.extend(EmberValidations, {
const Validations = buildValidations({
'newExpansion.from': validator('presence', true),
'newExpansion.to': validator('presence', true)
});

export default Ember.Controller.extend(Validations, {
hideCancelButton: true,
updateCapability: 'update_config',

Expand All @@ -14,14 +19,5 @@ export default Ember.Controller.extend(EmberValidations, {
cancelExpansion() {
this.createExpansion();
}
},

validations: {
'newExpansion.from': {
presence: true
},
'newExpansion.to': {
presence: true
}
}
});
34 changes: 13 additions & 21 deletions app/models/lab.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@ import CanEditRequested from 'hospitalrun/mixins/can-edit-requested';
import DateFormat from 'hospitalrun/mixins/date-format';
import DS from 'ember-data';
import Ember from 'ember';
import PatientValidation from 'hospitalrun/utils/patient-validation';
import ResultValidation from 'hospitalrun/mixins/result-validation';
import { validator, buildValidations } from 'ember-cp-validations';

const { computed, get } = Ember;

export default AbstractModel.extend(CanEditRequested, DateFormat, ResultValidation, {
const Validations = buildValidations({
labTypeName: validator('presence', {
presence: true,
disabled: Ember.computed.not('model.isNew'),
message: 'Please select a lab type'
}),
patient: validator('presence', true),
patientTypeAhead: validator('patient-typeahead')
});

export default AbstractModel.extend(CanEditRequested, DateFormat, Validations, {
// Attributes
customForms: DS.attr('custom-forms'),
labDate: DS.attr('date'),
Expand All @@ -30,22 +39,5 @@ export default AbstractModel.extend(CanEditRequested, DateFormat, ResultValidati

requestedDateAsTime: computed('requestedDate', function() {
return this.dateToTime(get(this, 'requestedDate'));
}),

validations: {
labTypeName: {
presence: {
'if'(object) {
if (object.get('isNew')) {
return true;
}
},
message: 'Please select a lab type'
}
},
patientTypeAhead: PatientValidation.patientTypeAhead,
patient: {
presence: true
}
}
})
});
32 changes: 13 additions & 19 deletions app/models/patient.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import AbstractModel from 'hospitalrun/models/abstract';
import DOBDays from 'hospitalrun/mixins/dob-days';
import EmailValidation from 'hospitalrun/utils/email-validation';
import Ember from 'ember';
import DS from 'ember-data';
import PatientName from 'hospitalrun/mixins/patient-name';
import { validator, buildValidations } from 'ember-cp-validations';

const { computed, get } = Ember;

export default AbstractModel.extend(DOBDays, PatientName, {
const Validations = buildValidations({
firstName: validator('presence', true),
lastName: validator('presence', true),
email: validator('format', {
type: 'email',
message: 'Please, enter a valid email address',
allowBlank: true
})
});

export default AbstractModel.extend(DOBDays, PatientName, Validations, {
// Attributes
admitted: DS.attr('boolean', { defaultValue: false }),
additionalContacts: DS.attr(),
Expand Down Expand Up @@ -94,21 +104,5 @@ export default AbstractModel.extend(DOBDays, PatientName, {

shortDisplayName: computed('firstName', 'lastName', function() {
return this.getPatientDisplayName(this, true);
}),

validations: {
email: {
format: {
with: EmailValidation.emailRegex,
allowBlank: true,
message: 'please enter a valid email address'
}
},
firstName: {
presence: true
},
lastName: {
presence: true
}
}
})
});
22 changes: 10 additions & 12 deletions app/models/social-expense.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@
* Model for social worker family info
*/
import DS from 'ember-data';
import EmberValidations from 'ember-validations';
import { Model } from 'ember-pouch';
import { validator, buildValidations } from 'ember-cp-validations';

export default Model.extend(EmberValidations, {
const Validations = buildValidations({
category: validator('presence', true),
cost: validator('number', {
allowString: true
})
});

export default Model.extend(Validations, {
// Attributes
category: DS.attr('string'),
sources: DS.attr('string'),
cost: DS.attr(),

validations: {
category: {
presence: true
},
cost: {
numericality: true
}
}
cost: DS.attr()
});
20 changes: 8 additions & 12 deletions app/models/text-expansion.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import DS from 'ember-data';
import EmberValidations from 'ember-validations';
import { Model } from 'ember-pouch';
import { validator, buildValidations } from 'ember-cp-validations';

export default Model.extend(EmberValidations, {
from: DS.attr('string'),
to: DS.attr('string'),
const Validations = buildValidations({
from: validator('presence', true),
to: validator('presence', true)
});

validations: {
from: {
presence: true
},
to: {
presence: true
}
}
export default Model.extend(Validations, {
from: DS.attr('string'),
to: DS.attr('string')
});
23 changes: 10 additions & 13 deletions app/models/user.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import DS from 'ember-data';
import EmailValidation from 'hospitalrun/utils/email-validation';
import Ember from 'ember';
import EmberValidations from 'ember-validations';
import { validator, buildValidations } from 'ember-cp-validations';

const Validations = buildValidations({
email: validator('format', {
type: 'email',
message: 'Please, enter a valid email address'
})
});

const { computed } = Ember;

let User = DS.Model.extend(EmberValidations, {
let User = DS.Model.extend(Validations, {
// Attributes
derived_key: DS.attr('string'),
deleted: DS.attr('boolean'),
Expand All @@ -26,16 +32,7 @@ let User = DS.Model.extend(EmberValidations, {
if (!Ember.isEmpty(roles)) {
return roles[0];
}
}),

validations: {
email: {
format: {
with: EmailValidation.emailRegex,
message: 'Please, enter a valid email address'
}
}
}
})
});

export default User;
3 changes: 0 additions & 3 deletions app/utils/email-validation.js

This file was deleted.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
"ember-sinon-qunit": "^1.4.0",
"ember-source": "2.11.0",
"ember-truth-helpers": "2.0.0",
"ember-validations": "2.0.0-alpha.5",
"eslint-plugin-ember-suave": "^1.0.0",
"express": "^4.8.5",
"glob": "^7.1.0",
Expand Down
14 changes: 0 additions & 14 deletions tests/unit/utils/email-validation-test.js

This file was deleted.

9 changes: 1 addition & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5198,7 +5198,7 @@ [email protected]:
fullcalendar "^3.6.0"
fullcalendar-scheduler "^1.8.0"

ember-getowner-polyfill@^1.0.0, ember-getowner-polyfill@^1.1.0, ember-getowner-polyfill@^1.2.2:
ember-getowner-polyfill@^1.1.0, ember-getowner-polyfill@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/ember-getowner-polyfill/-/ember-getowner-polyfill-1.2.2.tgz#cdab739e89cc8f25af0f78735422df1a61193e92"
dependencies:
Expand Down Expand Up @@ -5454,13 +5454,6 @@ ember-try@^0.2.15:
rsvp "^3.0.17"
semver "^5.1.0"

[email protected]:
version "2.0.0-alpha.5"
resolved "https://registry.yarnpkg.com/ember-validations/-/ember-validations-2.0.0-alpha.5.tgz#95af5bb5fcf43a5d18a6ddebe64594280bf988c0"
dependencies:
ember-cli-babel "^5.1.6"
ember-getowner-polyfill "^1.0.0"

[email protected]:
version "1.0.4"
resolved "https://registry.yarnpkg.com/ember-validators/-/ember-validators-1.0.4.tgz#7d89c2511945c52bd20c5384e715138f902133bb"
Expand Down

0 comments on commit 3041a30

Please sign in to comment.