import {BaseRelationalModel} from './base-relationalmodel';
import {ORInfoModel} from './orinfo-model';
export class CaseModel extends BaseRelationalModel{
url="http://localhosts/api/cases.json",
source="orrms",
primaryKey = "orrmscaseid",
relations = [
{
key: 'orinfo',
type: 'toOne',
model: ORInfoModel,
isOwner: true,
includeInJSON: true,
inverseKey: 'orcases',
inverseType: 'toMany',
create:true,
parse:true
}
],
attributes={
orrmscaseid: null,
hospitalcaseid: null,
surgdate: null,
orid: null,
orinfo: {},
serviceid: null,
scheduledprocedureinfo: {},
actualprocedureinfo: {},
operation:"",
asa:null,
urgency:"",
cancelled:false,
addon:false,
casetype: null,
surgattg: "",
surgres: null,
patid: null,
patinfo: null,
patcaseinfo: null,
orcasetimes: {},
staffbyorcase: [],
deleted: false,
datetimeinserted: null,
datetimemodified: null,
userinserting:null,
usermodifying:null
},
constructor(attrs:string, props:string, opts:string){
CaseModel.prototype.primaryKey = "orrmscaseid";
super(attrs, props, opts);
}
}
import {Injectable} from 'angular2/core';
import {Http} from 'angular2/http';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/observable/from';
import 'rxjs/add/operator/map';
import * as Store from 'enyo/src/Store';
import * as Model from 'enyo/src/Model';
import * as utils from 'enyo/src/utils';
@Injectable()
export abstract class BaseRelationalModel extends Model{
constructor(attrs:string, props:string, opts:string, http:Http){
this.http = http;
this.store = Store;
super(attrs, props, opts);
},
fetch(opts) {
var data = this.http.get(this.url)
.map(res => res.json())
.map(res => this.parse(res));
return data;
}
}
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
The code in Store looks like it should work OK so long as you set your kindName properly.
I'm super curious what you're up to with all that!
@RoySutton : in Store.add(), it is referencing ctor.prototype.kindName, which i think is why it's getting enyo.Model. It seems to be referring to the parent's kindName rather than its own.
Now, I am just directly importing and using my customized enyo models / collections in the Angular2 View Components. I created a DataService (HttpService) that accepts my customized child enyo model/collection and uses that to determine the URL to call. I might convert from using the Angular2 way for Ajax calls to the enyo.Collection.fetch / enyo.Source version in future but, for now, the Angular2 way is easier. I like its Subscribe method that allows auto updates from data source.
@RoySutton : To answer your original question as to what I'm trying to accomplish with Angular2 / enyo2 integration:
1. Trying to re-use my existing Enyo code, especially the relational data modeling in Enyo since I haven't found a great relational data modeling layer for Angular2 yet
2. Using Ionic2 for its HTML templates, rich widget set, and native mobile integration. Ionic2 is integrated with Angular2.
3. Using some Enyo components that don't exist in Ionic2 yet (e.g., a good progress bar component).
Now that I've gotten the above to work, things are moving quickly! Ionic2 has made it much easier to develop the UI because of its HTML templating system.
Next, I'm going to experiment with integrating DataList vs Ionic2 Lists to compare performance between the two!