Permalink
Browse files

i hope i didn't fuck things up

  • Loading branch information...
2 parents dab4d90 + 76b976e commit 7cd51f4ace9480f4b6ea53ae65745c015fc3ffef @erichsueh erichsueh committed Feb 17, 2017
@@ -1,9 +1,12 @@
import ActiveModelAdapter from 'active-model-adapter';
import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin';
import config from '../config/environment';
-
+import DS from 'ember-data';
+import AjaxServiceSupport from 'ember-ajax/mixins/ajax-support';
export default ActiveModelAdapter.extend(DataAdapterMixin, {
host: `${config.host}`,
authorizer: 'authorizer:custom'
- });
+ });
+
+export default DS.JSONAPIAdapter.extend(AjaxServiceSupport);
@@ -0,0 +1,54 @@
+import Ember from 'ember';
+
+export default Ember.Controller.extend({
+ ajax: Ember.inject.service(),
+ //let cName, let cAddress, let cPhone,
+ actions: {
+ submitNewCient(){
+ self = this;
+ //let cName = this.get('clientName');
+ //TODO check inputs
+ let ajaxPost = this.get('ajax').post('/api/client' , {
+ type: 'application/json',
+ data: {client: {
+ name: this.get('clientName'),
+ address: this.get('clientAddress'),
+ phoneNumber: this.get('clientPhone'),
+ email: this.get('clientEmail'),
+ licos: this.get('clientLICO'),
+ aish: this.get('clientAISH'),
+ socialAssistance: this.get('clientAS'),
+ pets: "",
+ created_at: new Date(),
+ updated_at: "",
+ clientID: this.get('clientID'),
+ alternativeContactName: this.get('alternativeName'),
+ alternativeContactPhoneNumber: this.get('alternativePrimaryPhone'),
+ alternativeContactAddress: this.get('alternativeAddress'),
+ notes: this.get('clientNotes'),
+ alternativeContact2ndPhone: this.get('alternativeSecondaryPhone'),
+ alternativeContactEmail: this.get('alternativeEmail')
+ // name: 'Boby',
+ // address: '123 somewehere st, Edmonton',
+ // phoneNumber: '780-555-1234',
+ // email: 'someBoby@email.com',
+ // licos: '12345',
+ // socialAssistance: '4313',
+ // pets: ''
+ }},
+ }).then(function(data){
+ //console.log("name is " + cName);
+ // TODO display confrimation page
+ // TODO prevent user from going back into this page
+ console.log("status is " + JSON.stringify(data));
+ self.transitionToRoute('login');
+ },
+ function(data){
+ console.log("status is " + JSON.stringify(data));
+ });
+ //createNewCLient();
+ //this.transitionToRoute('/login');
+ return ajaxPost;
+ }
+ }
+});
@@ -0,0 +1,12 @@
+import DS from 'ember-data';
+
+export default DS.Model.extend({
+ clientName: DS.attr('string'),
+ clientAddress: DS.attr('string'),
+ clientPhone: DS.attr('string'),
+ clientEmail: DS.attr('string'),
+ clientID: DS.attr('string')
+
+ // TODO
+ //add other info
+});
View
@@ -8,7 +8,9 @@ const Router = Ember.Router.extend({
Router.map(function() {
this.route('login');
+ this.route('new-client');
this.route('new_patient');
});
export default Router;
+
@@ -0,0 +1,20 @@
+import Ember from 'ember';
+
+export default Ember.Route.extend({
+ model() {
+ return this.store.createRecord('newClient');
+ }
+ // actions:{
+ // createNewClient(){
+ // // let clientInfo = this.modelFor(this.routeName);
+ // // clientInfo.save().then(function () {
+ // // //sendRequest();
+ // // //this.transitionTo('new-client');
+ // // }).catch(function (reason){
+
+ // // });
+ // console.log("made new client");
+ // this.transitionTo('new-client');
+ // }
+ // }
+});
View
@@ -0,0 +1,12 @@
+import Ember from 'ember';
+import AjaxService from 'ember-ajax/services/ajax';
+
+// export default Ember.Service.extend({
+
+// });
+
+export default AjaxService.extend({
+ //TODO add header of the format
+ // “Authorization”: “Bearer ” + JWT
+ host: 'https://ahas.herokuapp.com'
+});
@@ -0,0 +1,59 @@
+<div class = "container">
+
+ <form {{action "submitNewCient" on="submit"}}>
+ <h3>Please fill in the client's contact information</h3>
+
+ <label for = "clientName">Client's name</label>
+ {{input id='clientName' value=clientName required='true'}}
+ <br>
+ <label for = "clientAddress">Client's Address</label>
+ {{textarea id='clientAddress' value=clientAddress required='true' cols="50" rows="4"}}
+ <br>
+ <label for = "clientPhone">Client's Phone Number</label>
+ {{input id='clientPhone' value=clientPhone required='true'}}
+ <br>
+ <label for = "clientEmail">Client's Email</label>
+ {{input id='clienEmail' value=clientEmail required='true'}}
+ <br>
+ <label for = "clientID">Client's ID</label>
+ {{input id='clienID' value=clientID required='true'}}
+ <br>
+ <br>
+
+ <h3>Please fill in the client's documentation</h3>
+
+ <label for = "licoDocumentation">LICO</label>
+ {{input id='clientLICO' value=clientLICO}}
+ <br>
+ <label for = "aishDocumentation">AISH</label>
+ {{input id='clientAISH' value=clientAISH}}
+ <br>
+ <label for = "saDocumentation">SA</label>
+ {{input id='clientSA' value=clientSA}}
+ <br>
+ <label for = "notesDocumentation">Notes</label>
+ {{textarea id='clientNotes' value=clientNotes cols="80" rows="6"}}
+ <br>
+
+ <h3>Please fill in the alternative contact's contact information</h3>
+
+ <label for = "alternativeName">Alternative Contact's Name</label>
+ {{input id='alternativName' value=alternativeName required='true'}}
+ <br>
+ <label for = "alternativeAddress">Alternative Contact's Address</label>
+ {{textarea id='alternativeAdress' value=alternativeAddress required='true' cols="50" rows="4"}}
+ <br>
+ <label for = "alternativePrimaryPhone">Alternative Contact's Primary Phone Number</label>
+ {{input id='alternativePrimaryPhone' value=alternativePrimaryPhone}}
+ <br>
+ <label for = "alternativeSecondaryPhone">Alternative Contact's Secondary Phone Number</label>
+ {{input id='alternativeSecondaryPhone' value=alternativeSecondaryPhone}}
+ <br>
+ <label for = "alternativeEmail">Alternative Contact's Email</label>
+ {{input id='alternativEmail' value=alternativeEmail required='true'}}
+ <br>
+ <br>
+ <button type = "submit">Create Client</button>
+
+ </form>
+</div>
@@ -35,6 +35,9 @@ module.exports = function(environment) {
// ENV.APP.LOG_TRANSITIONS = true;
// ENV.APP.LOG_TRANSITIONS_INTERNAL = true;
// ENV.APP.LOG_VIEW_LOOKUPS = true;
+ ENV['ember-cli-mirage'] = {
+ enabled: false
+ };
}
if (environment === 'test') {
View
@@ -23,4 +23,8 @@ export default function() {
http://www.ember-cli-mirage.com/docs/v0.2.x/shorthands/
*/
+ this.namespace = 'https://ahas.herokuapp.com/api';
+
+ this.get('/client', 'new-client');
+
}
View
@@ -15,8 +15,9 @@
"test": "ember test"
},
"devDependencies": {
+ "active-model-adapter": "2.1.1",
"broccoli-asset-rev": "^2.4.5",
- "ember-ajax": "^2.4.1",
+ "ember-ajax": "2.5.5",
"ember-cli": "2.11.0",
"ember-cli-app-version": "^2.0.0",
"ember-cli-babel": "^5.1.7",
@@ -27,6 +28,7 @@
"ember-cli-inject-live-reload": "^1.4.1",
"ember-cli-jshint": "^2.0.1",
"ember-cli-mirage": "0.2.5",
+ "ember-cli-pretender": "1.0.1",
"ember-cli-qunit": "^3.0.1",
"ember-cli-release": "^0.2.9",
"ember-cli-sass": "6.1.1",
@@ -0,0 +1,83 @@
+import { test } from 'qunit';
+import moduleForAcceptance from 'ahasweb/tests/helpers/module-for-acceptance';
+
+import Pretender from 'pretender';
+
+let serv;
+
+// moduleForAcceptance('Acceptance | new client');
+
+// test('visiting /new-client', function(assert) {
+// visit('/new-client');
+
+// andThen(function() {
+// assert.equal(currentURL(), '/new-client');
+// });
+// });
+
+moduleForAcceptance('ajax-get component', {
+ beforeEach(){
+ serv = new Pretender();
+ },
+ afterEach(){
+ serv.shutdown();
+ }
+});
+
+
+test('waiting for a route with async widget', function (assert){
+ // this test is based on the test from https://www.npmjs.com/package/ember-ajax
+ // const PAYLOAD = [{name: 'bob',
+ // address: '123 somewehere st, Edmonton',
+ // phoneNumber: '780-555-1234',
+ // email: 'some@email.com',
+ // licos: '12345',
+ // socialAssistance: '4313'},
+ // {name: 'Alice',
+ // address: '41 somewehere ave, Edmonton',
+ // phoneNumber: '780-555-2222',
+ // email: 'some1535@email.com',
+ // licos: '125235',
+ // socialAssistance: '5555'}];
+ const PAYLOAD = [{ title: 'Foo' }, { title: 'Bar' }, { title: 'Baz' }];
+ serv.get('/api/client', function(){
+ return [200, {"Content-Type": "application/json"}, JSON.stringyfy(PAYLOAD)];
+ }, 300);
+
+ visit('/new-client');
+
+ andThen(function() {
+ assert.equal(currentURL(), '/new-client');
+ assert.ok($('.ajax-get').length === 1, 'ajax-get component is rendered');
+ });
+
+ click('button:contains(Create Client)');
+
+ andThen(function(){
+ assert.equal($('.ajax-get li:eq(0)').text(), 'Foo');
+ assert.equal($('.ajax-get li:eq(1)').text(), 'Bar');
+ assert.equal($('.ajax-get li:eq(2)').text(), 'Baz');
+ });
+});
+
+test('should fill in form with correct data', function (assert){
+
+ visit('/new-client');
+
+ andThen(function(){
+ assert.equal(currentURL(), '/new-client');
+ assert.equal(find('clientName').text(), '');
+ });
+
+
+ fillIn('#clientName', 'Alice').then(function(){
+ assert.equal(find('clientName').text(), 'Alice');
+ });
+ //find('#clientName').change();
+
+ // andThen(function(){
+ // assert.equal(find('clientName')., 'Alice');
+ // });
+
+
+});
@@ -0,0 +1,12 @@
+import { moduleFor, test } from 'ember-qunit';
+
+moduleFor('controller:new-client', 'Unit | Controller | new client', {
+ // Specify the other units that are required for this test.
+ // needs: ['controller:foo']
+});
+
+// Replace this with your real tests.
+test('it exists', function(assert) {
+ let controller = this.subject();
+ assert.ok(controller);
+});
@@ -0,0 +1,12 @@
+import { moduleForModel, test } from 'ember-qunit';
+
+moduleForModel('new-client', 'Unit | Model | new client', {
+ // Specify the other units that are required for this test.
+ needs: []
+});
+
+test('it exists', function(assert) {
+ let model = this.subject();
+ // let store = this.store();
+ assert.ok(!!model);
+});
@@ -0,0 +1,11 @@
+import { moduleFor, test } from 'ember-qunit';
+
+moduleFor('route:new-client', 'Unit | Route | new client', {
+ // Specify the other units that are required for this test.
+ // needs: ['controller:foo']
+});
+
+test('it exists', function(assert) {
+ let route = this.subject();
+ assert.ok(route);
+});
@@ -0,0 +1,12 @@
+import { moduleFor, test } from 'ember-qunit';
+
+moduleFor('service:ajax', 'Unit | Service | ajax', {
+ // Specify the other units that are required for this test.
+ // needs: ['service:foo']
+});
+
+// Replace this with your real tests.
+test('it exists', function(assert) {
+ let service = this.subject();
+ assert.ok(service);
+});

0 comments on commit 7cd51f4

Please sign in to comment.