Commit ebd3f9bb authored by laurent l's avatar laurent l

--bundle works

parent edf594db
......@@ -2,29 +2,29 @@
import 'nativescript-i18n';
import * as app from 'tns-core-modules/application';
import {Database, Manager, NSHTTPClient, BackgroundJobs} from './models';
import { Database, Manager, NSHTTPClient, BackgroundJobs } from './models';
import * as config from "./config/config";
import { AccountsController } from './controllers/accounts';
import * as Frames from 'ui/frame';
function myReloadPage() {
let frame:any = Frames.topmost();
if (frame && frame._currentEntry) {
if (frame.currentPage && frame.currentPage.modal) {
frame.currentPage.modal.closeModal();
}
let currentEntry = frame._currentEntry.entry;
let newEntry = {
animated: false,
clearHistory: true,
context: currentEntry.context,
bindingContext: currentEntry.bindingContext,
create: currentEntry.create,
moduleName: currentEntry.moduleName,
backstackVisible: currentEntry.backstackVisible
};
frame.navigate(newEntry);
let frame: any = Frames.topmost();
if (frame && frame._currentEntry) {
if (frame.currentPage && frame.currentPage.modal) {
frame.currentPage.modal.closeModal();
}
let currentEntry = frame._currentEntry.entry;
let newEntry = {
animated: false,
clearHistory: true,
context: currentEntry.context,
bindingContext: currentEntry.bindingContext,
create: currentEntry.create,
moduleName: currentEntry.moduleName,
backstackVisible: currentEntry.backstackVisible
};
frame.navigate(newEntry);
}
}
global.__onLiveSyncCore = myReloadPage;
......@@ -36,5 +36,7 @@ Database.open('prod');
new BackgroundJobs().setupScheduleJob(Database.current())
let manager = new Manager(config.MANAGER_URL, new NSHTTPClient())
app.start({ moduleName: 'views/accounts/list',
bindingContext: new AccountsController( manager ) })
app.start({
moduleName: 'views/accounts/list-page',
bindingContext: new AccountsController(manager)
})
if ((<any>global).TNS_WEBPACK) {
//registers tns-core-modules UI framework modules
require("bundle-entry-points");
global.registerModule("nativescript-pro-ui/sidedrawer",
()=> require('../node_modules/nativescript-pro-ui/sidedrawer'));
//register application modules
global.registerModule("main-page", () => require("./app.ts"));
}
import {ObservableArray} from 'data/observable-array'
import {Observable} from 'data/observable'
import {Page} from 'ui/page'
import {Controller} from './controller'
import {LibraryController} from './library'
import {MyBibAppController} from './mybibapp'
import {SettingsController} from './settings'
import {Account, Database, Portal, PortalAdapter, Manager, MBPortal} from '../models'
import { ObservableArray } from 'data/observable-array'
import { Observable } from 'data/observable'
import { Page } from 'ui/page'
import { Controller } from './controller'
import { LibraryController } from './library'
import { MyBibAppController } from './mybibapp'
import { SettingsController } from './settings'
import { Account, Database, Portal, PortalAdapter, Manager, MBPortal } from '../models'
import { TokenModel } from "nativescript-ui-autocomplete"
import { SwissArmyKnife } from "nativescript-swiss-army-knife"
import { RadSideDrawer } from 'nativescript-ui-sidedrawer'
......@@ -32,21 +32,25 @@ export class AccountsController extends Controller {
this.set('show_add_account_hint', true)
return this
}
public addAccountAction() {
this._createAccountForm()
this.navigate({ moduleName: 'views/accounts/add_account',
bindingContext: this,
backstackVisible: false})
this.navigate({
moduleName: 'views/accounts/add_account-page',
bindingContext: this,
backstackVisible: false
})
}
public addAdvancedAccountAction() {
this.set('currently_edited', null)
this._createAccountForm()
this.navigate({moduleName: "views/accounts/add",
bindingContext: this})
this.navigate({
moduleName: "views/accounts/add-page",
bindingContext: this
})
}
......@@ -57,18 +61,18 @@ export class AccountsController extends Controller {
let library_controller = new LibraryController(account, this._manager)
library_controller.doRefreshLoansAndHolds()
this.navigate({
moduleName: "views/library/items",
bindingContext: library_controller
moduleName: "views/library/items-page",
bindingContext: library_controller
})
}
public showAboutAction() {
this.navigate({
moduleName: "views/mybibapp/about",
bindingContext: new MyBibAppController()
moduleName: "views/mybibapp/about-page",
bindingContext: new MyBibAppController()
})
}
......@@ -82,10 +86,10 @@ export class AccountsController extends Controller {
cancelButtonText: L('cancel'),
actions: [L('about'), L('delete'), L('account_parameters')]
})
.then( (result) => {
.then((result) => {
if (result == L('about'))
return this.displayAccountInfo(account)
if (result == L('account_parameters'))
return this.editAccount(account)
......@@ -115,29 +119,29 @@ export class AccountsController extends Controller {
return portal.label == event.text
})
let form = this.get('account')
form.set('portal', selected_portal)
form.set('url', selected_portal.url)
SwissArmyKnife.dismissSoftKeyboard()
}
public onAddAccountPageLoaded(args) {
this._view = args.object;
this.set('portalsVisible', true)
this._portals = new Array<MBPortal>()
let portals_cache = this._portals
this._manager.portals().then( (portals) => {
portals.map( (element) => { portals_cache.push(element) })
this._manager.portals().then((portals) => {
portals.map((element) => { portals_cache.push(element) })
})
let suggest = this._view.getViewById("portals")
if (!suggest)
return this
suggest.loadSuggestionsAsync = (input) => {
return this._loadSuggestionsAsync(input, portals_cache)
}
......@@ -147,11 +151,11 @@ export class AccountsController extends Controller {
protected _loadSuggestionsAsync(input, portals_cache) {
let tokensByInput = () => {
return portals_cache
.map( (element) => { return new PortalToken(element) } )
.filter( (token) => { return token.matches(input) } )
.map((element) => { return new PortalToken(element) })
.filter((token) => { return token.matches(input) })
}
return Promise.resolve( tokensByInput() )
return Promise.resolve(tokensByInput())
}
......@@ -162,46 +166,54 @@ export class AccountsController extends Controller {
public displayAccountInfo(account: Account) {
this.navigate( {
moduleName: "views/library/account_info",
this.navigate({
moduleName: "views/library/account_info-page",
bindingContext: (new LibraryController(account, this._manager)).showAccountInfo()
} )
})
}
public openAccountAction(args) {
let account = this._accounts.getItem(args.index)
this.navigate({moduleName: "views/library/items",
bindingContext: new LibraryController(account, this._manager)})
this.navigate({
moduleName: "views/library/items-page",
bindingContext: new LibraryController(account, this._manager)
})
}
public deleteAccountAction() {
this.dialogs
.confirm({title: L('confirm'),
message: L('sure_to_delete'),
okButtonText: L('OK'),
cancelButtonText: L('cancel')})
.confirm({
title: L('confirm'),
message: L('sure_to_delete'),
okButtonText: L('OK'),
cancelButtonText: L('cancel')
})
.then((result) => {
if (!result)
return
let account = this.get('currently_edited')
if(account)
if (account)
Database.current().delete(account)
this.navigate({ moduleName: "views/accounts/list",
bindingContext: this,
clearHistory: true })
this.navigate({
moduleName: "views/accounts/list-page",
bindingContext: this,
clearHistory: true
})
})
}
public saveAccountAdvancedAction() {
if (this._saveAccount()) {
this.navigate({ moduleName: "views/accounts/list",
bindingContext: this,
clearHistory: true })
this.navigate({
moduleName: "views/accounts/list-page",
bindingContext: this,
clearHistory: true
})
}
}
......@@ -212,7 +224,7 @@ export class AccountsController extends Controller {
(<Page>args.object).on(Page.navigatedToEvent, () => {
this._refreshAccounts()
})
this._showAccountsOrNewAccount()
}
......@@ -232,7 +244,7 @@ export class AccountsController extends Controller {
public editAccount(account: Account) {
this.set('currently_edited', account)
let form = new Observable()
form.set('label', account.label)
form.set('url', account.url)
......@@ -242,23 +254,27 @@ export class AccountsController extends Controller {
let portal: PortalAdapter = this._portal.findAdapterIdentifiedBy(account.credentials['portal'])
form.set('selectedPortalIndex', form.get('portals').indexOf(portal.getLabel()))
this.set('account', form)
this.navigate({ moduleName: "views/accounts/edit",
bindingContext: this })
this.navigate({
moduleName: "views/accounts/edit-page",
bindingContext: this
})
}
protected _saveAccount(): boolean {
let form = this.get('account')
if (!this._isValid(form)) {
this.dialogs.alert({title: L('alert'),
message: L('invalid'),
okButtonText: L('OK')})
this.dialogs.alert({
title: L('alert'),
message: L('invalid'),
okButtonText: L('OK')
})
return false
}
let portal_label = form.portals[form.selectedPortalIndex]
let portal: PortalAdapter = Array.from(this._portal.adapters.values())
.filter((a) => {
......@@ -269,10 +285,12 @@ export class AccountsController extends Controller {
account
.setLabel(form.label)
.setUrl(form.url)
.setCredentials({portal: portal.getIdentifier(),
login: form.login,
password: form.password})
.setCredentials({
portal: portal.getIdentifier(),
login: form.login,
password: form.password
})
Database.current().save(account)
return true
}
......@@ -299,7 +317,7 @@ export class AccountsController extends Controller {
account.set('portalLabel', portal ? portal.getLabel() : '')
this._accounts.push(account)
})
return this
}
......@@ -333,7 +351,7 @@ export class AccountsController extends Controller {
return valid
}
protected _populateWithAdapters(form): AccountsController {
form.portals = Array.from(this._portal.adapters.values())
......@@ -344,8 +362,10 @@ export class AccountsController extends Controller {
public openSettingsAction(): this {
this.navigate({ moduleName: 'views/settings/list',
bindingContext: new SettingsController() })
this.navigate({
moduleName: 'views/settings/list-page',
bindingContext: new SettingsController()
})
return this;
}
......@@ -353,23 +373,25 @@ export class AccountsController extends Controller {
public dumpDBAction(): this {
let db: Database = Database.current()
db.createView("all-records",
"1",
(document, emitter) => {
emitter.emit(document._id, document);
})
"1",
(document, emitter) => {
emitter.emit(document._id, document);
})
let records: Array<object> = db.executeQuery("all-records")
const documents: Folder = <Folder>knownFolders.temp();
const file: File = <File>documents.getFile('mybibapp_dump.txt');
file.writeTextSync(records.map((r) => {
return JSON.stringify(r)
}).join("\n"))
this.dialogs.confirm( { title: L('dump_complete'),
message: L('filename') + ' : ' + file.path,
okButtonText: L('OK')});
this.dialogs.confirm({
title: L('dump_complete'),
message: L('filename') + ' : ' + file.path,
okButtonText: L('OK')
});
return this
}
}
......@@ -385,8 +407,8 @@ class PortalToken extends TokenModel {
this._portal = portal
}
public matches(input:string): boolean {
public matches(input: string): boolean {
return (this._portal.label).toLowerCase().includes(input.toLowerCase())
}
......
import {Observable} from 'data/observable';
import { Observable } from 'data/observable';
import * as Frames from 'ui/frame';
import dialogs = require('ui/dialogs');
import {Label} from 'ui/label';
import * as Views from 'ui/core/view';
import * as dialogs from 'ui/dialogs';
import { Label } from 'ui/label';
import * as Utils from "tns-core-modules/utils/utils"
let validator = require('validator');
......@@ -60,14 +59,14 @@ export abstract class Controller extends Observable {
protected isNotEmpty(id, value) {
return this
.validateWith(id, value,
() => { return !validator.isEmpty(value + ''); });
() => { return !validator.isEmpty(value + ''); });
}
protected isUrl(id, value) {
return this
.validateWith(id, value,
() => { return validator.isURL(value + ''); });
() => { return validator.isURL(value + ''); });
}
......@@ -75,7 +74,7 @@ export abstract class Controller extends Observable {
let error_label: Label = <Label>(this.getViewByIdInTopmost(id));
if (!error_label)
return true;
if (closure(value)) {
error_label.visibility = 'collapse';
return true;
......
......@@ -80,7 +80,7 @@ export class LibraryController extends Controller {
public goHomeAction() {
this.navigate({
moduleName: "views/accounts/list",
moduleName: "views/accounts/list-page",
bindingContext: new AccountsController(this._manager),
clearHistory: true
});
......@@ -98,7 +98,7 @@ export class LibraryController extends Controller {
this.set('card_img', imageSource.fromNativeSource(card_img));
this.set('card_number', this._account.getCard().getNumber());
this.navigate({
moduleName: "views/library/card",
moduleName: "views/library/card-page",
bindingContext: this
});
}
......@@ -111,7 +111,7 @@ export class LibraryController extends Controller {
this.set('novelties', novelties);
}
this.navigate({
moduleName: "views/library/novelties",
moduleName: "views/library/novelties-page",
bindingContext: this
});
}
......@@ -134,7 +134,7 @@ export class LibraryController extends Controller {
public openLoansAndHoldsAction() {
this.navigate({
moduleName: "views/library/items",
moduleName: "views/library/items-page",
bindingContext: this
});
}
......@@ -175,9 +175,9 @@ export class LibraryController extends Controller {
openSettingsIfPermissionWasPreviouslyDenied: true
})
.then(
(result) => {
return result.text;
})
(result) => {
return result.text;
})
.then((barcode) => {
this._turnBusyIndicator('on');
return this._portal.fetchItem(this._account, barcode);
......@@ -186,7 +186,7 @@ export class LibraryController extends Controller {
this._turnBusyIndicator('off');
this.set('item', item);
this.navigate({
moduleName: "views/library/loan_item",
moduleName: "views/library/loan_item-page",
backstackVisible: false,
bindingContext: this
});
......@@ -208,9 +208,9 @@ export class LibraryController extends Controller {
this._manager
.loan(Database.current(),
this._account,
r.text,
this.get('item').getBarcode())
this._account,
r.text,
this.get('item').getBarcode())
.then((result) => {
if (result['success'])
return this.dialogs.alert({
......@@ -247,13 +247,13 @@ export class LibraryController extends Controller {
openSettingsIfPermissionWasPreviouslyDenied: true
})
.then(
(result) => {
this._account.credentials['login'] = result.text;
this._askLoginPassword();
},
(result) => {
this._account.credentials['login'] = result.text;
this._askLoginPassword();
},
(error) => {
});
(error) => {
});
}
......@@ -375,7 +375,7 @@ export class LibraryController extends Controller {
this.navigate(
{
moduleName: "views/accounts/list",
moduleName: "views/accounts/list-page",
bindingContext: (new AccountsController(this._manager)).showAddAccountHint(),
clearHistory: true
});
......@@ -399,7 +399,7 @@ export class LibraryController extends Controller {
this._on_loans_page_loaded = this._on_successful_login;
this.set('account_label', account.label);
this.navigate({
moduleName: "views/library/account_label",
moduleName: "views/library/account_label-page",
bindingContext: this
});
})
......@@ -423,19 +423,19 @@ export class LibraryController extends Controller {
oauth_web_view
.login(this._account)
.then(
(token) => {
this._account.credentials['token'] = token;
this._authenticationDone(this._account);
},
() => {
this.dialogs.alert({
title: L('alert'),
message: L('wrong_login_password'),
okButtonText: L('OK')
});
this._doOAuthLogin(oauth_web_view);
}
(token) => {
this._account.credentials['token'] = token;
this._authenticationDone(this._account);
},
() => {
this.dialogs.alert({
title: L('alert'),
message: L('wrong_login_password'),
okButtonText: L('OK')
});
this._doOAuthLogin(oauth_web_view);
}
);
}
......@@ -445,7 +445,7 @@ export class LibraryController extends Controller {
let doOpenWebsite = () => {
this.navigate({
moduleName: "views/library/website",
moduleName: "views/library/website-page",
bindingContext: this
});
this.set