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

Commit

Permalink
Merge branch 'master' into greenkeeper/ember-cli-eslint-3.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jkleinsc authored Feb 6, 2017
2 parents f6325f1 + d5c3ba4 commit 35e3ca1
Show file tree
Hide file tree
Showing 167 changed files with 4,249 additions and 992 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ module.exports = {
'dymo': true,
'Filer': true,
'logDebug': true,
'moment': true,
'Pikaday': true,
'PouchDB': true,
'Promise': true,
Expand Down
51 changes: 45 additions & 6 deletions app/adapters/application.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import Ember from 'ember';
import { Adapter } from 'ember-pouch';
import PouchAdapterUtils from 'hospitalrun/mixins/pouch-adapter-utils';
import uuid from 'npm:uuid';

const {
get,
run: {
bind
}
} = Ember;

export default Adapter.extend(PouchAdapterUtils, {
export default Adapter.extend({
database: Ember.inject.service(),
db: Ember.computed.reads('database.mainDB'),

Expand Down Expand Up @@ -192,6 +192,7 @@ export default Adapter.extend(PouchAdapterUtils, {
} else if (query.containsValue) {
return this._executeContainsSearch(store, type, query);
}
let database = get(this, 'database');
return new Ember.RSVP.Promise((resolve, reject) => {
let db = this.get('db');
try {
Expand All @@ -203,7 +204,7 @@ export default Adapter.extend(PouchAdapterUtils, {
};
db.list(`${mapReduce}/sort/${mapReduce}`, listParams, (err, response) => {
if (err) {
this._pouchError(reject)(err);
reject(database.handleErrorResponse(err));
} else {
let responseJSON = JSON.parse(response.body);
this._handleQueryResponse(responseJSON, store, type).then(resolve, reject);
Expand All @@ -212,7 +213,7 @@ export default Adapter.extend(PouchAdapterUtils, {
} else {
db.query(mapReduce, queryParams, (err, response) => {
if (err) {
this._pouchError(reject)(err);
reject(database.handleErrorResponse(err));
} else {
this._handleQueryResponse(response, store, type).then(resolve, reject);
}
Expand All @@ -221,16 +222,54 @@ export default Adapter.extend(PouchAdapterUtils, {
} else {
db.allDocs(queryParams, (err, response) => {
if (err) {
this._pouchError(reject)(err);
reject(database.handleErrorResponse(err));
} else {
this._handleQueryResponse(response, store, type).then(resolve, reject);
}
});
}
} catch(err) {
this._pouchError(reject)(err);
reject(database.handleErrorResponse(err));
}
}, 'findQuery in application-pouchdb-adapter');
}
},

createRecord(store, type, record) {
return this._checkForErrors(this._super(store, type, record));
},

findAll(store, type) {
return this._checkForErrors(this._super(store, type));
},

findMany(store, type, ids) {
return this._checkForErrors(this._super(store, type, ids));
},

findHasMany(store, record, link, rel) {
return this._checkForErrors(this._super(store, record, link, rel));
},

findRecord(store, type, id) {
return this._checkForErrors(this._super(store, type, id));
},

updateRecord(store, type, record) {
return this._checkForErrors(this._super(store, type, record));
},

deleteRecord(store, type, record) {
return this._checkForErrors(this._super(store, type, record));
},

_checkForErrors(callPromise) {
return new Ember.RSVP.Promise((resolve, reject) => {
callPromise.then(resolve, (err) => {
let database = get(this, 'database');
reject(database.handleErrorResponse(err));
});
});
}

});
26 changes: 22 additions & 4 deletions app/adapters/user.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import Ember from 'ember';
import DS from 'ember-data';
import UserSession from 'hospitalrun/mixins/user-session';

const { get } = Ember;

export default DS.RESTAdapter.extend(UserSession, {
database: Ember.inject.service(),
session: Ember.inject.service(),
Expand Down Expand Up @@ -82,7 +85,12 @@ export default DS.RESTAdapter.extend(UserSession, {
*/
find(store, type, id) {
let findUrl = this.endpoint + id;
return this.ajax(findUrl, 'GET');
return new Ember.RSVP.Promise((resolve, reject) => {
this.ajax(findUrl, 'GET').then(resolve, (error) => {
let database = get(this, 'database');
reject(database.handleErrorResponse(error));
});
});
},

headers: function() {
Expand Down Expand Up @@ -126,8 +134,13 @@ export default DS.RESTAdapter.extend(UserSession, {
}
data = this._cleanPasswordAttrs(data);
let putURL = `${this.endpoint}${Ember.get(record, 'id')}`;
return this.ajax(putURL, 'PUT', {
data
return new Ember.RSVP.Promise((resolve, reject) => {
this.ajax(putURL, 'PUT', {
data
}).then(resolve, (error) => {
let database = get(this, 'database');
reject(database.handleErrorResponse(error));
});
});
},

Expand All @@ -153,7 +166,12 @@ export default DS.RESTAdapter.extend(UserSession, {
}
};
let allURL = `${this.endpoint}_all_docs`;
return this.ajax(allURL, 'GET', ajaxData);
return new Ember.RSVP.Promise((resolve, reject) => {
this.ajax(allURL, 'GET', ajaxData).then(resolve, (error) => {
let database = get(this, 'database');
reject(database.handleErrorResponse(error));
});
});
},

/**
Expand Down
34 changes: 20 additions & 14 deletions app/admin/address/route.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
import AbstractEditRoute from 'hospitalrun/routes/abstract-edit-route';
import Ember from 'ember';
import { translationMacro as t } from 'ember-i18n';
import UnauthorizedError from 'hospitalrun/utils/unauthorized-error';

export default AbstractEditRoute.extend({
hideNewButton: true,
newTitle: t('admin.address.newTitle'),
editTitle: t('admin.address.editTitle'),
model() {
return new Ember.RSVP.Promise(function(resolve) {
this.get('store').find('option', 'address_options').then(function(addressOptions) {
return new Ember.RSVP.Promise((resolve, reject) => {
this.get('store').find('option', 'address_options').then((addressOptions) => {
resolve(addressOptions);
}, function() {
let store = this.get('store');
let newConfig = store.push(store.normalize('option', {
id: 'address_options',
value: {
address1Label: this.get('i18n').t('admin.address.addressLabel'),
address1Include: true
}
}));
resolve(newConfig);
}.bind(this));
}.bind(this));
}, (err) => {
if (err instanceof UnauthorizedError) {
reject(err);
} else {
let store = this.get('store');
let newConfig = store.push(store.normalize('option', {
id: 'address_options',
value: {
address1Label: this.get('i18n').t('admin.address.addressLabel'),
address1Include: true
}
}));
resolve(newConfig);
}
});
});
}
});
1 change: 1 addition & 0 deletions app/admin/custom-forms/edit/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export default AbstractEditController.extend({
}),

formTypeValues: [
'operativePlan',
'patient',
'socialwork',
'visit'
Expand Down
10 changes: 8 additions & 2 deletions app/admin/loaddb/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@ import AbstractEditRoute from 'hospitalrun/routes/abstract-edit-route';
import Ember from 'ember';
import { translationMacro as t } from 'ember-i18n';
import UserSession from 'hospitalrun/mixins/user-session';

const { get, inject } = Ember;

export default AbstractEditRoute.extend(UserSession, {
hideNewButton: true,
editTitle: t('admin.loaddb.editTitle'),

database: inject.service(),

beforeModel() {
if (!this.currentUserCan('load_db')) {
this.transitionTo('application');
}
},

// No model needed for import.
// Make sure database is available for import
model() {
return Ember.RSVP.resolve(Ember.Object.create({}));
let database = get(this, 'database');
return database.getDBInfo().catch((err) => this.send('error', database.handleErrorResponse(err)));
}
});
2 changes: 1 addition & 1 deletion app/admin/lookup/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default AbstractIndexRoute.extend({
hideNewButton: true,
pageTitle: t('admin.lookup.pageTitle'),
model() {
return this.store.findAll('lookup');
return this.store.findAll('lookup').catch((error) => this.send('error', error));
},

afterModel(model) {
Expand Down
4 changes: 3 additions & 1 deletion app/admin/roles/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ export default AbstractEditController.extend(UserRoles, UserSession, {
name: 'patients',
capabilities: [
'patients',
'addAllergy',
'addDiagnosis',
'addNote',
'addOperativePlan',
'addOperationReport',
'addPhoto',
'addPatient',
'addProcedure',
Expand Down Expand Up @@ -163,7 +166,6 @@ export default AbstractEditController.extend(UserRoles, UserSession, {
Object.keys(defaultCapabilities).forEach((capability) => {
let capabilityRoles = defaultCapabilities[capability];
if (capabilityRoles.includes(role)) {
console.log(`Role has capability: ${capability}`);
this.set(capability.camelize(), true);
} else {
this.set(capability.camelize(), false);
Expand Down
112 changes: 112 additions & 0 deletions app/appointments/calendar/controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import AppointmentIndexController from 'hospitalrun/appointments/index/controller';
import AppointmentStatuses from 'hospitalrun/mixins/appointment-statuses';
import moment from 'moment';
import VisitTypes from 'hospitalrun/mixins/visit-types';
import SelectValues from 'hospitalrun/utils/select-values';
import Ember from 'ember';

const {
computed,
computed: {
alias
},
get,
inject,
isEmpty,
set
} = Ember;

export default AppointmentIndexController.extend(AppointmentStatuses, VisitTypes, {
appointmentType: null,
endDate: null,
location: null,
provider: null,
queryParams: ['appointmentType', 'endDate', 'provider', 'status', 'startDate', 'location', 'viewType'],
startDate: null,
status: null,
viewType: 'agendaWeek',

appointmentsController: inject.controller('appointments'),
locations: alias('appointmentsController.locationList.value'),
physicians: alias('appointmentsController.physicianList.value'),

calendarDate: computed('startDate', function() {
let startDate = get(this, 'startDate');
if (!isEmpty(startDate)) {
return moment(parseInt(startDate));
}
}),

locationList: computed('locations', function() {
return SelectValues.selectValues(get(this, 'locations'), true);
}),

physicianList: computed('physicians', function() {
return SelectValues.selectValues(get(this, 'physicians'), true);
}),

_getSelectedFilteringCriteria() {
let rawCriteria = {
status: get(this, 'model.selectedStatus'),
type: get(this, 'model.selectedAppointmentType'),
provider: get(this, 'model.selectedProvider'),
location: get(this, 'model.selectedLocation')
};

return {
status: isEmpty(rawCriteria.status) ? null : rawCriteria.status,
type: isEmpty(rawCriteria.type) ? null : rawCriteria.type,
provider: isEmpty(rawCriteria.provider) ? null : rawCriteria.provider,
location: isEmpty(rawCriteria.location) ? null : rawCriteria.location
};
},

actions: {
clearFilteringCriteria() {
set(this, 'model.selectedStatus', null);
set(this, 'model.selectedAppointmentType', null);
set(this, 'model.selectedProvider', null);
set(this, 'model.selectedLocation', null);
this.send('filter');
},

createNewAppointment(dateClicked) {
let newAppointment = this.store.createRecord('appointment', {
appointmentType: 'Admission',
allDay: false,
selectPatient: true,
startDate: dateClicked.local().toDate()
});
this.send('editAppointment', newAppointment);
},

filter() {
let criteria = this._getSelectedFilteringCriteria();
this.setProperties({
appointmentType: criteria.type,
provider: criteria.provider,
status: criteria.status,
location: criteria.location
});
},

handleVisualConfigurationChanged(newConfiguration) {
this.setProperties(newConfiguration);
},

navigateToAppointment(calendarEvent) {
this.send('editAppointment', calendarEvent.referencedAppointment);
},

updateAppointment(calendarEvent) {
let appointmentToUpdate = calendarEvent.referencedAppointment;
let newEnd = calendarEvent.end.local().toDate();
let newStart = calendarEvent.start.local().toDate();
set(appointmentToUpdate, 'startDate', newStart);
set(appointmentToUpdate, 'endDate', newEnd);
appointmentToUpdate.save().catch((error) => {
this.send('error', error, 'appointments.calendar');
});
}
}
});
Loading

0 comments on commit 35e3ca1

Please sign in to comment.