Skip to content

Commit

Permalink
Contacts and groups basic functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
javascriptboss99 committed Jul 25, 2016
0 parents commit eb1fa35
Show file tree
Hide file tree
Showing 98 changed files with 2,704 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
@@ -0,0 +1,10 @@
# Specifies files to intentionally ignore when using Git
# http://git-scm.com/docs/gitignore

node_modules/
www/build/
platforms/
plugins/
*.swp
.DS_Store
Thumbs.db
17 changes: 17 additions & 0 deletions app/app.html
@@ -0,0 +1,17 @@
<ion-menu [content]="content">

<ion-toolbar>
<ion-title>Pages</ion-title>
</ion-toolbar>

<ion-content>
<ion-list>
<button ion-item *ngFor="let p of pages" (click)="openPage(p)">
{{p.title}}
</button>
</ion-list>
</ion-content>

</ion-menu>

<ion-nav [root]="rootPage" #content swipe-back-enabled="false"></ion-nav>
53 changes: 53 additions & 0 deletions app/app.ts
@@ -0,0 +1,53 @@
import {provide, Component, ViewChild} from '@angular/core';
import {ionicBootstrap, Platform, MenuController, Nav} from 'ionic-angular';
import {StatusBar} from 'ionic-native';
import {HelloIonicPage} from './pages/hello-ionic/hello-ionic';
// import {ListPage} from './pages/list/list';
import {GroupListCmp} from './pages/group/group-list';
import {ContactListCmp} from './pages/contact-list/contact-list';
import {HTTP_PROVIDERS, Http, RequestOptions} from '@angular/http';
import {DfRequestOptions} from './config/interceptors';

@Component({
templateUrl: 'build/app.html'
})
class MyApp {
@ViewChild(Nav) nav: Nav;

rootPage: any = ContactListCmp;
pages: Array<{ title: string, component: any }>;

constructor(
private platform: Platform,
private menu: MenuController
) {
this.initializeApp();

// set our app's pages
this.pages = [
{ title: 'Groups', component: GroupListCmp },
{ title: 'Contact List', component: ContactListCmp}
];
}

initializeApp() {
this.platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
StatusBar.styleDefault();
});
}

openPage(page) {
// close the menu when clicking a link from the menu
this.menu.close();
// navigate to the new page if it is not the current page
this.nav.setRoot(page.component);
}
}

ionicBootstrap(MyApp, [
HTTP_PROVIDERS,
provide(RequestOptions, { useClass: DfRequestOptions }),
provide(Window, { useValue: window })
]);
2 changes: 2 additions & 0 deletions app/config/constants.ts
@@ -0,0 +1,2 @@
export const DSP_API_KEY: string = '771976d7b0cf049dc3e63da8c247832eefc57098a41bedf09dfe2edb6a7cbd4e';
export const DSP_INSTANCE_URL: string = 'https://ft-enzomori.vz2.dreamfactory.com';
28 changes: 28 additions & 0 deletions app/config/exception-handler.ts
@@ -0,0 +1,28 @@
import { ExceptionHandler } from 'angular2/core';


class _ArrayLogger {
res = [];
log(s: any): void { this.res.push(s); }
logError(s: any): void { this.res.push(s); }
logGroup(s: any): void { this.res.push(s); }
logGroupEnd() {
this.res.forEach(error => {
console.error(error);
})
};
}
export class CustomExceptionHandler extends ExceptionHandler {
constructor() {
super(new _ArrayLogger(), true);
}

call(exception: any, stackTrace: any, reason: string): void {

if (~[401, 404].indexOf(exception.status)) {
window.location.hash = '/login';
} else {
super.call(exception, stackTrace, reason);
}
}
}
17 changes: 17 additions & 0 deletions app/config/interceptors.ts
@@ -0,0 +1,17 @@
import {HTTP_PROVIDERS, Headers, Http, BaseRequestOptions} from '@angular/http';
import * as constants from './constants';


export class DfRequestOptions extends BaseRequestOptions {

constructor () {
super();
console.log('somehow here')
this.headers.set('X-Dreamfactory-API-Key' ,constants.DSP_API_KEY);

var token = localStorage.getItem('session_token');
if (token) {
this.headers.set('X-Dreamfactory-Session-Token', token);
}
}
}
28 changes: 28 additions & 0 deletions app/config/request.ts
@@ -0,0 +1,28 @@
import {Injectable} from '@angular/core';
import {Http, Request, RequestMethod, RequestOptionsArgs, Response, Headers} from '@angular/http';

import * as constants from './constants';
import {Observable} from 'rxjs/Observable';



@Injectable()
export class DfRequest {
constructor(private http: Http) {}

_request (url: string | Request, options?: RequestOptionsArgs): Observable<Response> {
let request:any;

if (typeof url === 'string') {
options = options || { headers: new Headers() };
} else {
let req:Request = <Request>url;
req.headers = req.headers || new Headers();
req.headers.set('X-DreamFactory-API-Key', constants.DSP_API_KEY);

request = this.http.request(req);
}

return request;
}
}
34 changes: 34 additions & 0 deletions app/models/contact-group.ts
@@ -0,0 +1,34 @@
import {Contact} from './contact';
import {Group} from './group';


export class ContactGroup {
constructor(
public id: string,
public contact: Contact = null,
public group: Group = null
) { }


static fromJson(json: any) {
if (!json) return;

return new ContactGroup(
json.id,
new Contact(json.contact_id),
new Group(json.contact_group_id)
);
}


toJson(stringify?: boolean): any {
var doc = {
id: this.id,
contact_id: this.contact && this.contact.id,
contact_group_id: this.group && this.group.id
};

return stringify ? JSON.stringify({ resource: [doc] }) : doc;
}

}
58 changes: 58 additions & 0 deletions app/models/contact-info.ts
@@ -0,0 +1,58 @@

export enum ContactInfoTypes {
home,
work,
mobile
}

export class ContactInfo {
constructor (
public id:string = null,
public contactId:string = null,
public address:string = null,
public city:string = null,
public state:string = null,
public zip:string = null,
public country:string = null,
public email:string = null,
public infoType:ContactInfoTypes = null,
public phone:string = null
) { }


static fromJson (json:any) {
if (!json) return;

return new ContactInfo (
json.id,
json.contact_id,
json.address,
json.city,
json.state,
json.zip,
json.country,
json.email,
json.info_type,
json.phone
);
}


toJson (stringify?: boolean): any {
var doc = {
id: this.id,
contact_id: this.contactId,
address: this.address,
city: this.city,
state: this.state,
zip: this.zip,
country: this.country,
email: this.email,
info_type: this.infoType,
phone: this.phone
};

return stringify ? JSON.stringify({ resource: [doc] }) : doc;
}

}
43 changes: 43 additions & 0 deletions app/models/contact.ts
@@ -0,0 +1,43 @@

export class Contact {
constructor (
public id:string = '',
public firstName:string = '',
public lastName:string = '',
public image:string = '',
public skype:string = '',
public twitter:string = '',
public notes:string = ''
) { }


static fromJson (json:any) {
if (!json) return;

return new Contact (
json.id,
json.first_name,
json.last_name,
json.image_url,
json.skype,
json.twitter,
json.notes
);
}


toJson (stringify?: boolean):any {
var doc = {
id: this.id,
first_name: this.firstName,
last_name: this.lastName,
image_url: this.image,
skype: this.skype,
twitter: this.twitter,
notes: this.notes
};

return stringify ? JSON.stringify({ resource: [doc] }) : doc;
}

}
28 changes: 28 additions & 0 deletions app/models/group.ts
@@ -0,0 +1,28 @@

export class Group {
constructor(
public id: string = null,
public name: string = null
) { }


static fromJson(json: any) {
if (!json) return;

return new Group(
json.id,
json.name
);
}


toJson(stringify?: boolean): any {
var doc = {
id: this.id,
name: this.name
};

return stringify ? JSON.stringify({ resource: [doc] }) : doc;
}

}
37 changes: 37 additions & 0 deletions app/pages/contact-info/contact-info-list.html
@@ -0,0 +1,37 @@
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="text-center">
Contact info
<a class="fa fa-plus pull-right btn btn-primary" (click)="add()"></a>
</h3>
</div>

<div class="panel-body">
<table class="table table-hover">
<thead>
<tr>
<th *ngFor="#field of contactInfoFields" [ngClass]="{ 'hidden-xs hidden-sm': !field.mobileShow }">
{{ field.label }}
</th>
<th></th>
</tr>
</thead>

<tbody>
<tr *ngFor="#item of contactInfo">
<td *ngFor="#field of contactInfoFields" [ngClass]="{ 'hidden-xs hidden-sm': !field.mobileShow }">
{{ item[field.key] }}
</td>
<td>
<button type="button" class="fa fa-trash btn btn-danger pull-right" (click)="remove(item.id)">
</button>


<button type="button" class="fa fa-edit btn btn-success pull-right" (click)="edit(item.id)">
</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>

0 comments on commit eb1fa35

Please sign in to comment.