message: Usage of API to get the data
diff: @@ -125,23 +125,20 @@ export class RESTAPIApplicationsService {
  }
  recentFlows() {
  - return new Promise((resolve, reject)=> {
  - resolve(this.recent);
  - });
  + return this._http.get('/v1/api/flows/recent').toPromise()
  + .then(response=> response.json().data);
  }
  - list() {
  - return new Promise((resolve, reject) => {
  - this._http.get('/v1/api/apps').toPromise()
  + getAllApps() {
  + return this._http.get('/v1/api/apps').toPromise()
  .then(response => {
  if (response.text()) {
  let apps: Array<IFlogoApplicationModel> = response.json().data;
  - resolve(apps);
  + return apps;
  } else {
  - reject(response)
  + return response;
  }
  });
  - });
  }
  allFlows() {
  @@ -158,39 +155,36 @@ export class RESTAPIApplicationsService {
  });
  }
  - add() {
  + createNewApp(): Promise<any> {
  + return this.getNewAppName(UNTITLED_APP).then( appName => {
  let application: any = {
  - id: this.applications.length + 1,
  - name: this.getNewAppName(UNTITLED_APP),
  + name: appName,
  version: '',
  - description: '',
  - createdAt: new Date(),
  - updatedAt: null
  + description: ''
  };
  - this.applications.unshift(application);
  - return new Promise((resolve, reject)=> {
  - resolve(application);
  - });
  - }
  + let headers = new Headers({'Content-Type': 'application/json'});
  + let options = new RequestOptions({headers: headers});
  + let body = JSON.stringify(application);
  - delete(id:string) {
  - _.remove(this.applications, (n:IFlogoApplicationModel)=> {
  - return n.id === id;
  - });
  -
  - return new Promise((resolve, reject)=> {
  - resolve(true);
  - });
  + return this._http.post('/v1/api/apps', body, options).toPromise()
  + .then(response => response.json().data);
  + })
  }
  - get(id:string) {
  - let application = this.applications.find((item)=> {
  - return item.id == id;
  - });
  + deleteApp(appId:string) {
  + return this._http.delete('/v1/api/apps/' + appId).toPromise();
  + }
  - return new Promise((resolve, reject)=> {
  - resolve(application);
  + getApp(appId: string) {
  + return this._http.get('/v1/api/apps/' + appId).toPromise()
  + .then(response => {
  + if (response.text()) {
  + let app: IFlogoApplicationModel = response.json().data;
  + return app;
  + } else {
  + return response;
  + }
  });
  }
  @@ -198,14 +192,16 @@ export class RESTAPIApplicationsService {
  let appName: string = name + (count > 0 ? ` (${count})` : '');
  let found: IFlogoApplicationModel;
  - found = this.applications.find((app: IFlogoApplicationModel)=> {
  + return this.getAllApps().then((apps:Array<IFlogoApplicationModel>) => {
  + found = _.find(apps, (app: IFlogoApplicationModel) => {
  return app.name == appName;
  });
  -
  if (found) {
  return this.getNewAppName(name, ++count);
  } else {
  return appName;
  }
  + });
  +
  }
  }
  