Skip to content

Commit

Permalink
Merge pull request #38 from eHealthAfrica/refactor-code
Browse files Browse the repository at this point in the history
Refactor code
  • Loading branch information
Chima Alaebo authored Mar 15, 2017
2 parents 1107c53 + 6463268 commit d9e1baf
Show file tree
Hide file tree
Showing 188 changed files with 6,757 additions and 1,309 deletions.
9 changes: 5 additions & 4 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Contributing to the Ember front end for HospitalRun

Contributions are welcome via pull requests and issues. This project uses the style guides from Dockyard for [Ember](https://github.com/dockyard/styleguides/blob/master/engineering/ember.md) and [JavaScript](https://github.com/dockyard/styleguides/blob/master/engineering/javascript.md). These style guides are enforced via [Ember Suave](https://github.com/dockyard/ember-suave). Before submitting a pull request, please make sure all tests pass by running ```ember test```.
Contributions are welcome via pull requests and issues. Before submitting a pull request, please make sure all tests pass by running ```ember test```. This project uses the style guides from Dockyard for [Ember](https://github.com/dockyard/styleguides/blob/master/engineering/ember.md) and [JavaScript](https://github.com/dockyard/styleguides/blob/master/engineering/javascript.md). These style guides are enforced via ESLint, which is one of the linters described in the section on [linters](#linter) below.

## Slack / Communication

Expand Down Expand Up @@ -118,14 +118,15 @@ Ember, by default uses [JSON API](http://jsonapi.org) as a JSON convention. [Cou

A linter is a small program that checks code for stylistic or programming errors. Linters are available for most syntaxes, from Python to HTML.

Programming is hard. We are bound to make mistakes. The big advantage of using linter is that your code can be linted as you type (before saving your changes) and any errors are highlighted immediately, which is considerably easier than saving the file, switching to a terminal, running a linter, reading through a list of errors, then switching back to your editor to locate the errors!
Programming is hard. We are bound to make mistakes. The big advantage of using a linter is that your code can be linted as you type (before saving your changes) and any errors are highlighted immediately, which is considerably easier than saving the file, switching to a terminal, running a linter, reading through a list of errors, then switching back to your editor to locate the errors!

In addition, linters can help to enforce coding standards, find unused variables, find formatting discrepancies etc.

**HospitalRun** uses the following linters:

1. [ESLint](http://eslint.org/) for ECMAScript/JavaScript. You can find the ESLint User guide [here](http://eslint.org/docs/user-guide/).
2. [stylelint](http://stylelint.io/) for Stylesheets. You can find stylelint User guide [here](http://stylelint.io/user-guide/).
1. [ESLint](http://eslint.org/) for ECMAScript/JavaScript. You can find the ESLint User guide [here](http://eslint.org/docs/user-guide/). ESLint is setup to use eslint-plugin-ember-suave, you can find more information about that [here](https://github.com/DockYard/eslint-plugin-ember-suave).
2. [stylelint](http://stylelint.io/) for Stylesheets. You can find the stylelint User guide [here](http://stylelint.io/user-guide/).
3. [ember-template-lint](https://github.com/rwjblue/ember-template-lint) for Ember templates.

### Using Local Cache

Expand Down
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@ branches:
sudo: false

cache:
directories
directories:
- $HOME/.npm
- $HOME/.cache # includes bowers cache

before_install:
- npm config set spin false
- npm install -g bower
- npm install -g bower phantomjs-prebuilt
- bower --version
- npm install phantomjs-prebuilt
- node_modules/phantomjs-prebuilt/bin/phantomjs --version
- phantomjs --version

install:
- npm install
- bower install

script:
- npm test
- travis_retry npm test
51 changes: 51 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Contributor Covenant Code of Conduct

## Summary

In the interest of fostering an open and welcoming environment, we as community members and moderators pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, sexual identity and orientation, or any other factor that people might use to insult or belittle another person.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Community moderators and core maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.

Community moderators and core maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any community member for other behaviors that they deem inappropriate, threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the community. Examples of representing a community include using an official community e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by community moderators.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the community moderators at [email protected]. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The moderators are obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.

Community moderators and core maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ To start the frontend please do the following:
To run HospitalRun with Docker please do the following:
- Goto [https://docs.docker.com/engine/installation](https://docs.docker.com/engine/installation) to download and install Docker.
- Clone the repository with the command `git clone https://github.com/HospitalRun/hospitalrun-frontend.git`.
- Change to the hospitalrun-frontend directory `cd hosptialrun-frontend`.
- Build the HosptialRun image with `docker build -t hospitalrun-frontend .`
- Change to the hospitalrun-frontend directory `cd hospitalrun-frontend`.
- Build the HospitalRun image with `docker build -t hospitalrun-frontend .`
- Execute `docker run -it --name couchdb -d couchdb` to create the couchdb container.
- Execute `docker run -it --name hospitalrun-frontend -p 4200:4200 --link couchdb:couchdb -d hospitalrun-frontend` to create the HospitalRun container.

Expand Down Expand Up @@ -122,12 +122,6 @@ To run the test suite locally while developing, just run `ember test` from the p

Tests will also run automatically via Travis CI when you push a branch to the repository or a pull request. You can view output by going to the Travis test status from the Pull Request merge box.

### The SCSS linter

To keep our styling scalable and consistent, we are using an [scss linter](https://www.npmjs.com/package/ember-cli-scss-lint) that will throw an error in the build if you do not conform to it's syntax rules. The syntax rules are defined in the [`.scss-lint.yml`](https://github.com/HospitalRun/hospitalrun-frontend/blob/master/.scss-lint.yml) file, and documentation for each linter is [available here](https://github.com/brigade/scss-lint/blob/master/lib/scss_lint/linter/README.md).

The easiest way to work with styles in the project and abide by our linting rules is to install the [linter-scss-lint](https://atom.io/packages/linter-scss-lint) package for Atom. The package will then show you in real time where your styles are breaking the linter and how to correct them.

## Contributing

Again, contributions are welcome via pull requests and issues. Please see our [contributing guide](https://github.com/hospitalrun/hospitalrun-frontend/blob/master/.github/CONTRIBUTING.md) for more details.
Expand Down
60 changes: 32 additions & 28 deletions app/adapters/application.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import Ember from 'ember';
import { Adapter } from 'ember-pouch';
import UnauthorizedError from 'hospitalrun/utils/unauthorized-error';
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 @@ -193,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 @@ -204,7 +204,7 @@ export default Adapter.extend(PouchAdapterUtils, {
};
db.list(`${mapReduce}/sort/${mapReduce}`, listParams, (err, response) => {
if (err) {
reject(this._handleErrorResponse(err));
reject(database.handleErrorResponse(err));
} else {
let responseJSON = JSON.parse(response.body);
this._handleQueryResponse(responseJSON, store, type).then(resolve, reject);
Expand All @@ -213,7 +213,7 @@ export default Adapter.extend(PouchAdapterUtils, {
} else {
db.query(mapReduce, queryParams, (err, response) => {
if (err) {
reject(this._handleErrorResponse(err));
reject(database.handleErrorResponse(err));
} else {
this._handleQueryResponse(response, store, type).then(resolve, reject);
}
Expand All @@ -222,50 +222,54 @@ export default Adapter.extend(PouchAdapterUtils, {
} else {
db.allDocs(queryParams, (err, response) => {
if (err) {
reject(this._handleErrorResponse(err));
reject(database.handleErrorResponse(err));
} else {
this._handleQueryResponse(response, store, type).then(resolve, reject);
}
});
}
} catch(err) {
reject(this._handleErrorResponse(err));
reject(database.handleErrorResponse(err));
}
}, 'findQuery in application-pouchdb-adapter');
}
},

createRecord(store, type, record) {
return new Ember.RSVP.Promise((resolve, reject) => {
this._super(store, type, record).then(resolve, (err) => {
reject(this._handleErrorResponse(err));
});
});
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 new Ember.RSVP.Promise((resolve, reject) => {
this._super(store, type, record).then(resolve, (err) => {
reject(this._handleErrorResponse(err));
});
});
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) => {
this._super(store, type, record).then(resolve, (err) => {
reject(this._handleErrorResponse(err));
callPromise.then(resolve, (err) => {
let database = get(this, 'database');
reject(database.handleErrorResponse(err));
});
});
},

_handleErrorResponse(err) {
if (err.status) {
let detailedMessage = JSON.stringify(err, null, 2);
return new UnauthorizedError(err, detailedMessage);
} else {
return 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);
}
});
});
}
});
5 changes: 4 additions & 1 deletion app/admin/custom-forms/edit/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,13 @@ export default AbstractEditController.extend({
}),

formTypeValues: [
'incident',
'operativePlan',
'patient',
'socialwork',
'visit'
'visit',
'opdReport',
'dischargeReport'
],

formTypes: computed(function() {
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)));
}
});
Loading

0 comments on commit d9e1baf

Please sign in to comment.