Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
fminzoni committed Sep 16, 2011
2 parents fd289f6 + 378fa2b commit d24ac68
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 13 deletions.
Binary file added src/assets/back.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/com/kdata/mobile/MobileActionMongoConfig.mxml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


<application:InitHandler /> <application:InitHandler />
<application:MongoHandler /> <application:MongoHandler />

<presentation:Documents/>
<domain:AppInit /> <domain:AppInit />


<infrastructure:MongoQuery /> <infrastructure:MongoQuery />
Expand Down
25 changes: 23 additions & 2 deletions src/com/kdata/mobile/application/MongoHandler.as
Original file line number Original file line Diff line number Diff line change
@@ -1,10 +1,16 @@
package com.kdata.mobile.application package com.kdata.mobile.application
{ {
import com.kdata.mobile.infrastructure.MongoQuery; import com.kdata.mobile.infrastructure.MongoQuery;

import com.kdata.mobile.presentation.Documents;
import com.kdata.mobile.presentation.MobileActionMongoHome;
import com.kdata.mobile.presentation.PopUp;

import mx.collections.ArrayCollection;
import mx.core.FlexGlobals;

public class MongoHandler public class MongoHandler
{ {

[Inject] [Bindable] public var model : Documents;
[Inject] public var mongoQuery : MongoQuery; [Inject] public var mongoQuery : MongoQuery;


/** /**
Expand All @@ -28,8 +34,23 @@ package com.kdata.mobile.application
case MongoQueryEvent.MONGO_REPLY_RECEIVED: case MongoQueryEvent.MONGO_REPLY_RECEIVED:
// set the results // set the results
trace(event.result); trace(event.result);
model.documents=event.result;
break;

case MongoQueryEvent.MONGO_LOGIN_RESULT:
FlexGlobals.topLevelApplication.navigator.pushView(MobileActionMongoHome);
break; break;


case MongoQueryEvent.MONGO_LOGIN_FAULT:
var obj:Object = new Object();
obj.title = "Error";
obj.text = "Login Failed";
var popup:PopUp = new PopUp();
popup.show(obj);
break;
case MongoQueryEvent.MONGO_DISCONNECT:
mongoQuery.disconnect();
break;
default: default:
// should never get here // should never get here
trace( "MongoHandler:mongoHandler: unknown event type" ); trace( "MongoHandler:mongoHandler: unknown event type" );
Expand Down
30 changes: 29 additions & 1 deletion src/com/kdata/mobile/application/MongoQueryEvent.as
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ package com.kdata.mobile.application
import flash.events.Event; import flash.events.Event;


import mx.collections.ArrayCollection; import mx.collections.ArrayCollection;
import mx.rpc.http.HTTPService;


public class MongoQueryEvent extends Event public class MongoQueryEvent extends Event
{ {
public static const MONGO_LOGIN : String = "mongoLogin"; public static const MONGO_LOGIN : String = "mongoLogin";
public static const MONGO_SEND_QUERY : String = "mongoSendQuery"; public static const MONGO_SEND_QUERY : String = "mongoSendQuery";
public static const MONGO_REPLY_RECEIVED : String = "mongoReplyReceived"; public static const MONGO_REPLY_RECEIVED : String = "mongoReplyReceived";
public static const MONGO_LOGIN_RESULT : String = "mongoLoginResult";
public static const MONGO_LOGIN_FAULT : String = "mongoLoginFault";
public static const MONGO_DISCONNECT : String = "mongoDisconnect";


public var result : ArrayCollection; public var result : ArrayCollection;


Expand All @@ -35,7 +39,7 @@ package com.kdata.mobile.application
* @return A MongoQueryEvent * @return A MongoQueryEvent
*/ */
public static function getMongoSendQuery() : MongoQueryEvent { public static function getMongoSendQuery() : MongoQueryEvent {
return new MongoQueryEvent( MONGO_SEND_QUERY, null ); return new MongoQueryEvent(MONGO_SEND_QUERY, null );
} }
/** /**
* @brief Produce a MongoQueryEvent * @brief Produce a MongoQueryEvent
Expand All @@ -44,5 +48,29 @@ package com.kdata.mobile.application
public static function getMongoReplyReceived( result : ArrayCollection ) : MongoQueryEvent { public static function getMongoReplyReceived( result : ArrayCollection ) : MongoQueryEvent {
return new MongoQueryEvent( MONGO_REPLY_RECEIVED, result ); return new MongoQueryEvent( MONGO_REPLY_RECEIVED, result );
} }

/**
* @brief Produce a MongoQueryEvent
* @return A MongoQueryEvent
*/
public static function getMongoLoginResult() : MongoQueryEvent {
return new MongoQueryEvent( MONGO_LOGIN_RESULT, null );
}

/**
* @brief Produce a MongoQueryEvent
* @return A MongoQueryEvent
*/
public static function getMongoLoginFault() : MongoQueryEvent {
return new MongoQueryEvent( MONGO_LOGIN_FAULT, null );
}

/**
* @brief Produce a MongoQueryEvent
* @return A MongoQueryEvent
*/
public static function getMongoDisconnect() : MongoQueryEvent {
return new MongoQueryEvent( MONGO_DISCONNECT, null );
}
} }
} }
14 changes: 14 additions & 0 deletions src/com/kdata/mobile/infrastructure/MongoQuery.as
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ package com.kdata.mobile.infrastructure
db.connect(); db.connect();
var credentials:Credentials = new Credentials(mongoConfig.dbUser,mongoConfig.dbPassword); var credentials:Credentials = new Credentials(mongoConfig.dbUser,mongoConfig.dbPassword);
var auth:Authentication = new Authentication(db,credentials); var auth:Authentication = new Authentication(db,credentials);
auth.login(loginHandler);
}

private function loginHandler(logged:Boolean):void
{
if(logged)
dispatchMessage(MongoQueryEvent.getMongoLoginResult());
else
dispatchMessage(MongoQueryEvent.getMongoLoginFault());
} }


/** /**
Expand All @@ -49,5 +58,10 @@ package com.kdata.mobile.infrastructure
} }
dispatchMessage( MongoQueryEvent.getMongoReplyReceived( documents ) ); dispatchMessage( MongoQueryEvent.getMongoReplyReceived( documents ) );
} }

public function disconnect():void
{
db.close();
}
} }
} }
9 changes: 9 additions & 0 deletions src/com/kdata/mobile/presentation/Documents.as
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.kdata.mobile.presentation
{
import mx.collections.ArrayCollection;

public class Documents
{
[Bindable] public var documents : ArrayCollection;
}
}
10 changes: 1 addition & 9 deletions src/com/kdata/mobile/presentation/LoginView.mxml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -29,14 +29,7 @@
// connect to MongoDB // connect to MongoDB
dispatchMessage( InitEvent.getAppReady() ); dispatchMessage( InitEvent.getAppReady() );
} }
public function test() : void {
// query to MongoDB
dispatchMessage( MongoQueryEvent.getMongoSendQuery() );
}
]]> ]]>
</fx:Script> </fx:Script>


Expand All @@ -59,7 +52,6 @@
</s:FormItem> </s:FormItem>
<s:HGroup> <s:HGroup>
<s:Button id="btnConnect" label="Connect" click="login()" /> <s:Button id="btnConnect" label="Connect" click="login()" />
<s:Button id="btnTest" label="Test" click="test()" />
</s:HGroup> </s:HGroup>
</s:Form> </s:Form>


Expand Down
33 changes: 33 additions & 0 deletions src/com/kdata/mobile/presentation/MobileActionMongoHome.mxml
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" title="MobileActionMongoHome" xmlns:parsley="http://www.spicefactory.org/parsley">
<fx:Declarations>
<parsley:Configure />
</fx:Declarations>

<fx:Script>
<![CDATA[
import com.kdata.mobile.application.MongoHandler;
import com.kdata.mobile.application.MongoQueryEvent;
import mx.collections.ArrayCollection;
[MessageDispatcher] public var dispatchMessage : Function;
[Inject] [Bindable] public var model :Documents;
public function test() : void {
// query to MongoDB
dispatchMessage( MongoQueryEvent.getMongoSendQuery());
}
]]>
</fx:Script>

<s:navigationContent>
<s:Button icon="@Embed('assets/back.png')" click="dispatchMessage(MongoQueryEvent.getMongoDisconnect()); navigator.popView()"/>
</s:navigationContent>

<s:Label left="10" top="10" text="login ok"/>
<s:Button id="btnTest" left="10" top="30" label="Test" click="test()"/>
<s:DataGrid top="80" width="100%" height="100%" dataProvider="{model.documents}" />
</s:View>
45 changes: 45 additions & 0 deletions src/com/kdata/mobile/presentation/PopUp.mxml
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" width="200" height="150">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.core.FlexGlobals;
import mx.managers.PopUpManager;
[Bindable]
private var data:Object = new Object();
public function show(data:Object):void
{
this.data=data;
PopUpManager.addPopUp(this,FlexGlobals.topLevelApplication.navigator.activeView);
PopUpManager.centerPopUp(this);
}
protected function close():void
{
PopUpManager.removePopUp(this);
}
]]>
</fx:Script>
<s:BorderContainer width="100%" height="100%" backgroundColor="0x333333" borderColor="#949494"
borderWeight="4" cornerRadius="10">
<s:VGroup left="10" right="10" top="10" bottom="10" width="100%" height="100%" gap="5">
<s:Label width="100%" color="white" fontSize="32" fontWeight="bold" lineThrough="false"
paddingTop="12" text="{data.title}" left="5"/>
<s:Line width="100%">
<s:stroke>
<s:SolidColorStroke color="0x5b5b5b" weight="2"/>
</s:stroke>
</s:Line>
<s:Label width="100%" color="white" text="{data.text}" left="5"/>
</s:VGroup>
<s:Button x="0" y="0" height="34" label="Close" click="close()" bottom="5" right="5"/>
</s:BorderContainer>
</s:Group>

0 comments on commit d24ac68

Please sign in to comment.