Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remoting #277

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions core_src/beluga/Beluga.hx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class Beluga {
public var api(default, null) : BelugaApi;
private var modules = new ObjectMap<Dynamic, Module>();
private static var instance = null;
public var remoting = new haxe.remoting.Context();

public static var remotingCtx;
public static function getInstance(cnx: Connection = null) : Beluga {
if (instance == null) {
instance = new Beluga(cnx);
Expand All @@ -66,7 +66,6 @@ class Beluga {
initDatabase(cnx);
//Create beluga API
api = new BelugaApi();
remotingCtx = new haxe.remoting.Context();

//Compile JS assets
beluga.resource.JavascriptBuilder.compile();
Expand Down Expand Up @@ -131,8 +130,8 @@ class Beluga {
throw new BelugaException("Beluga Rest Api not yet supported");
},
doDefault: function(d : Dispatch) {
if (!haxe.remoting.HttpConnection.handleRequest(remotingCtx)) {
d.dispatch(api);
if (!haxe.remoting.HttpConnection.handleRequest(remoting)) {
d.dispatch(api);
}
}

Expand Down
2 changes: 1 addition & 1 deletion core_src/beluga/ConfigLoader.hx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class ConfigLoader {

macro private static function loadConfig() : Expr {
//Load configuration
builtConfigString = File.getContent(configFilePath);
builtConfigString = File.getContent(Context.resolvePath(configFilePath));
var xml = Xml.parse(builtConfigString);
clearForTarget(xml, getCompilationTarget());

Expand Down
8 changes: 6 additions & 2 deletions module_src/beluga/module/account/Account.hx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ class Account extends Module {
this.widgets = new AccountWidget();
beluga.db.initTable(User);
beluga.api.register("account", new AccountApi(beluga, this));
beluga.remoting.addObject("Account", {
login : function (param1, param2) {
return "param receive " + param1 + " " + param2;
}
});
}

public function getLoggedUser() : User {
Expand All @@ -68,12 +73,11 @@ class Account extends Module {
this.loggedUser = null;
triggers.afterLogout.dispatch();
}

public function login(args : {
login : String,
password : String
}) {

var user : List<User> = User.manager.dynamicSearch({login : args.login});
if (user.length > 1) {
//Somethings wrong in database
Expand Down
19 changes: 0 additions & 19 deletions module_src/beluga/module/account/view/js/Login.hx

This file was deleted.

43 changes: 43 additions & 0 deletions module_src/beluga/module/account/view/js/LoginFormJs.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2014 The Beluga Project Developers. See the LICENCE.md
// file at the top-level directory of this distribution and at
// http://haxebeluga.github.io/licence.html.
//
// Licensed under the MIT License.
// This file may not be copied, modified, or distributed
// except according to those terms.

package beluga.module.account.view.js;

#if js
import js.Browser;
#end

class LoginFormJs implements beluga.resource.Javascript {

#if js
private var cnx : haxe.remoting.HttpAsyncConnection ;
#end

public function new() {
#if js
//Called when the script is loaded
js.Browser.window.console.log("LoginFormJs script started");
cnx = haxe.remoting.HttpAsyncConnection.urlConnect("http://" + Browser.location.host + "/beluga/");
cnx.setErrorHandler( function(err) { trace("Error : " + Std.string(err)); } );
cnx.Account.login.call(["toto", "tata"], onLogin);
#end
}

public function onLogin(v) {
trace(v);
}

public function ready()
{
#if js
//Called when the DOM is ready
js.Browser.window.console.log("DOM Ready");
#end
}

}
2 changes: 2 additions & 0 deletions module_src/beluga/module/account/widget/LoginForm.hx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import beluga.I18n;
import beluga.tool.DynamicTool;
import beluga.resource.ResourceManager;

import beluga.module.account.view.js.LoginFormJs;

class LoginForm extends MttWidget<Account> {

public function new (?mttfile : String) {
Expand Down
2 changes: 1 addition & 1 deletion test/src/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ class Main {
notification = new NotificationTest(beluga);
if (!beluga.handleRequest()) {
Dispatch.run(beluga.getDispatchUri(), Web.getParams(), new Main());
Log.flush();
}
beluga.cleanup();
Log.flush();
} catch (e: BelugaException) {
trace(e);
}
Expand Down
14 changes: 14 additions & 0 deletions test/src/ModuleTestApi.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ;

import haxe.macro.Expr;
import haxe.web.Dispatch;

class ModuleTestApi
{
public static var module_test_map = new Map <String, Dynamic>();

macro public static function addModule(name : Expr, module : Expr) {
return macro ModuleTestApi.module_test_map[${name}] = haxe.web.Dispatch.make(${module});
}

}