Commit aa51f1fd authored by laurent l's avatar laurent l

more ios port

parent ef63b1d0
import {Couchbase} from 'nativescript-couchbase';
import {Persistable, Serializable, DataSource} from './persistable';
import { Couchbase } from 'nativescript-couchbase';
import { Persistable, Serializable, DataSource } from './persistable';
export class Database implements DataSource {
protected static _current: Database;
......@@ -38,13 +38,13 @@ export class Database implements DataSource {
return this;
}
public save(model: Persistable): Database {
if (!model.validate())
return this;
model.beforeSave(this);
(new DatabaseTransaction(this, model)).save();
model.afterSave(this);
......@@ -60,17 +60,17 @@ export class Database implements DataSource {
}
public findAll<T extends Persistable>(modelClass:{new():T;}): Array<T> {
public findAll<T extends Persistable>(modelClass: { new(): T; }): Array<T> {
return this
._views
.findAll(modelClass,
(document) => {
return this._materialize(modelClass, document);
});
(document) => {
return this._materialize(modelClass, document);
});
}
public find<T extends Persistable>(modelClass:{new():T;}, id:string): T {
public find<T extends Persistable>(modelClass: { new(): T; }, id: string): T {
if (!id)
return null;
......@@ -82,12 +82,12 @@ export class Database implements DataSource {
}
public createView(name:string, revision:string, callback:Function) {
public createView(name: string, revision: string, callback: Function) {
return this._views.createView(name, revision, callback);
}
public executeQuery(name:string) {
public executeQuery(name: string) {
return this._db.executeQuery(name);
}
......@@ -102,7 +102,7 @@ export class Database implements DataSource {
}
protected _materialize<T extends Persistable>(modelClass: {new(id:string):T;}, document:any): T {
protected _materialize<T extends Persistable>(modelClass: { new(id: string): T; }, document: any): T {
let model: T = new modelClass(document._id);
model.materializeFrom(new DatabaseDocument(this, document));
return model;
......@@ -111,7 +111,6 @@ export class Database implements DataSource {
class DatabaseViews {
protected _db: Couchbase;
protected _declared_views: Set<string>;
......@@ -122,24 +121,24 @@ class DatabaseViews {
}
public createView(name:string, revision:string, callback:Function): DatabaseViews {
public createView(name: string, revision: string, callback: Function): DatabaseViews {
this._declared_views.add(name);
this._db.createView(name, revision, callback);
return this;
}
public executeQueryForModel(modelName:string) {
public executeQueryForModel(modelName: string) {
let viewname = "all-" + modelName.toLowerCase() + "s";
this._ensureView(viewname, modelName);
return this._db.executeQuery(viewname);
}
public findAll<T extends Persistable>(modelClass:{new():T;}, callback:Function): Array<T> {
public findAll<T extends Persistable>(modelClass: { new(): T; }, callback: Function): Array<T> {
let models: Array<T> = new Array<T>();
for(let document of this.executeQueryForModel(modelClass.name)) {
for (let document of this.executeQueryForModel(modelClass.name)) {
models.push(callback(document));
};
return models;
......@@ -151,12 +150,12 @@ class DatabaseViews {
return this;
this.createView(viewname,
"1",
(document, emitter) => {
if (document.model == modelName) {
emitter.emit(document._id, document);
}
});
"1",
(document, emitter) => {
if (document.model == modelName) {
emitter.emit(document._id, document);
}
});
}
}
......@@ -168,7 +167,7 @@ class DatabaseTransaction {
protected _model: Persistable;
public constructor(db:Database, model:Persistable) {
public constructor(db: Database, model: Persistable) {
this._db = db;
this._model = model;
}
......@@ -195,7 +194,7 @@ class DatabaseTransaction {
protected _update(document): DatabaseTransaction {
this._db.updateDocument(this._model.getId(),
document.serialize());
document.serialize());
return this;
}
}
......@@ -207,19 +206,19 @@ class DatabaseDocument implements Serializable {
protected _properties = {};
protected _db: Database;
public constructor(db: Database, properties?:Object) {
public constructor(db: Database, properties?: Object) {
this._db = db;
this._properties = properties ? properties : {};
}
public set(name:string, value:number|string|boolean): Serializable {
this._properties[name] = (null == value ? '' : value);
public set(name: string, value: number | string | boolean): Serializable {
this._properties[name] = (null == value ? '' : value);
return this;
}
public get<T extends Persistable>(name:string, modelClass?:{new():T;}): number|string|boolean|T {
public get<T extends Persistable>(name: string, modelClass?: { new(): T; }): number | string | boolean | T {
return modelClass
? this._db.find(modelClass, this._properties[name])
: this._properties[name];
......@@ -227,6 +226,6 @@ class DatabaseDocument implements Serializable {
public serialize(): Object {
return this._properties;
return JSON.parse(JSON.stringify(this._properties));
}
}
......@@ -5,7 +5,7 @@
android.windowContentOverlay="@drawable/actionbar_shadow">
<NavigationButton icon="res://icon" tap="{{ showAboutAction }}"/>
<ActionItem text="{{ L('menu') }}" tap="{{ toggleDrawerAction }}">
<ActionItem text="{{ L('menu') }}" tap="{{ toggleDrawerAction }}" ios.position="right">
<ActionItem.actionView>
<Label text='&#xf0c9;'/>
</ActionItem.actionView>
......
......@@ -3,7 +3,7 @@
<ActionBar title="{{ L('accounts') }}" icon="">
<NavigationButton icon="res://icon" tap="{{ showAboutAction }}"/>
<ActionItem text="{{ L('menu') }}" tap="{{ toggleDrawerAction }}">
<ActionItem text="{{ L('menu') }}" tap="{{ toggleDrawerAction }}" ios.position="right">
<ActionItem.actionView>
<Label text='&#xf0c9;'/>
</ActionItem.actionView>
......
......@@ -3,7 +3,7 @@
<ActionBar title="{{ page_title }}" icon="">
<NavigationButton android.systemIcon="ic_menu_back" tap="{{ goBack }}"/>
<ActionItem text="{{ L('menu') }}" tap="{{ toggleDrawerAction }}">
<ActionItem text="{{ L('menu') }}" tap="{{ toggleDrawerAction }}" ios.position="right">
<ActionItem.actionView>
<Label text='&#xf0c9;'/>
</ActionItem.actionView>
......
......@@ -3,13 +3,13 @@
<ActionBar title="{{ page_title }}" icon="">
<NavigationButton android.systemIcon="ic_menu_back" tap="{{ goHomeAction }}"/>
<ActionItem text="{{ L('refresh') }}" tap="{{ refreshLoansAndHoldsAction }}">
<ActionItem text="{{ L('refresh') }}" tap="{{ refreshLoansAndHoldsAction }}" ios.position="right">
<ActionItem.actionView>
<Label text='&#xf021;'/>
</ActionItem.actionView>
</ActionItem>
<ActionItem text="{{ L('menu') }}" tap="{{ toggleDrawerAction }}">
<ActionItem text="{{ L('menu') }}" tap="{{ toggleDrawerAction }}" ios.position="right">
<ActionItem.actionView>
<Label text='&#xf0c9;'/>
</ActionItem.actionView>
......
......@@ -2,7 +2,7 @@
<Page.actionBar>
<ActionBar title="{{ L('novelties') }}" icon="">
<NavigationButton android.systemIcon="ic_menu_back" tap="{{ goBack }}"/>
<ActionItem text="{{ L('menu') }}" tap="{{ toggleDrawerAction }}">
<ActionItem text="{{ L('menu') }}" tap="{{ toggleDrawerAction }}" ios.position="right">
<ActionItem.actionView>
<Label text='&#xf0c9;'/>
</ActionItem.actionView>
......
......@@ -3,7 +3,7 @@
<ActionBar title="{{ page_title }}" icon="">
<NavigationButton android.systemIcon="ic_menu_back" tap="{{ goBack }}"/>
<ActionItem text="{{ L('menu') }}" tap="{{ toggleDrawerAction }}">
<ActionItem text="{{ L('menu') }}" tap="{{ toggleDrawerAction }}" ios.position="right">
<ActionItem.actionView>
<Label text='&#xf0c9;'/>
</ActionItem.actionView>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment