Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge remote-tracking branch 'upstream/master'

  • Loading branch information...
commit d24ac6826e32a65225bef00d775a2fbe6685bec3 2 parents fd289f6 + 378fa2b
@fminzoni authored
View
BIN  src/assets/back.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
2  src/com/kdata/mobile/MobileActionMongoConfig.mxml
@@ -13,7 +13,7 @@
<application:InitHandler />
<application:MongoHandler />
-
+ <presentation:Documents/>
<domain:AppInit />
<infrastructure:MongoQuery />
View
25 src/com/kdata/mobile/application/MongoHandler.as
@@ -1,10 +1,16 @@
package com.kdata.mobile.application
{
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
{
-
+ [Inject] [Bindable] public var model : Documents;
[Inject] public var mongoQuery : MongoQuery;
/**
@@ -28,8 +34,23 @@ package com.kdata.mobile.application
case MongoQueryEvent.MONGO_REPLY_RECEIVED:
// set the results
trace(event.result);
+ model.documents=event.result;
+ break;
+
+ case MongoQueryEvent.MONGO_LOGIN_RESULT:
+ FlexGlobals.topLevelApplication.navigator.pushView(MobileActionMongoHome);
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:
// should never get here
trace( "MongoHandler:mongoHandler: unknown event type" );
View
30 src/com/kdata/mobile/application/MongoQueryEvent.as
@@ -3,12 +3,16 @@ package com.kdata.mobile.application
import flash.events.Event;
import mx.collections.ArrayCollection;
+ import mx.rpc.http.HTTPService;
public class MongoQueryEvent extends Event
{
public static const MONGO_LOGIN : String = "mongoLogin";
public static const MONGO_SEND_QUERY : String = "mongoSendQuery";
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;
@@ -35,7 +39,7 @@ package com.kdata.mobile.application
* @return A MongoQueryEvent
*/
public static function getMongoSendQuery() : MongoQueryEvent {
- return new MongoQueryEvent( MONGO_SEND_QUERY, null );
+ return new MongoQueryEvent(MONGO_SEND_QUERY, null );
}
/**
* @brief Produce a MongoQueryEvent
@@ -44,5 +48,29 @@ package com.kdata.mobile.application
public static function getMongoReplyReceived( result : ArrayCollection ) : MongoQueryEvent {
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 );
+ }
}
}
View
14 src/com/kdata/mobile/infrastructure/MongoQuery.as
@@ -32,6 +32,15 @@ package com.kdata.mobile.infrastructure
db.connect();
var credentials:Credentials = new Credentials(mongoConfig.dbUser,mongoConfig.dbPassword);
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());
}
/**
@@ -49,5 +58,10 @@ package com.kdata.mobile.infrastructure
}
dispatchMessage( MongoQueryEvent.getMongoReplyReceived( documents ) );
}
+
+ public function disconnect():void
+ {
+ db.close();
+ }
}
}
View
9 src/com/kdata/mobile/presentation/Documents.as
@@ -0,0 +1,9 @@
+package com.kdata.mobile.presentation
+{
+ import mx.collections.ArrayCollection;
+
+ public class Documents
+ {
+ [Bindable] public var documents : ArrayCollection;
+ }
+}
View
10 src/com/kdata/mobile/presentation/LoginView.mxml
@@ -29,14 +29,7 @@
// connect to MongoDB
dispatchMessage( InitEvent.getAppReady() );
- }
-
- public function test() : void {
-
- // query to MongoDB
- dispatchMessage( MongoQueryEvent.getMongoSendQuery() );
- }
-
+ }
]]>
</fx:Script>
@@ -59,7 +52,6 @@
</s:FormItem>
<s:HGroup>
<s:Button id="btnConnect" label="Connect" click="login()" />
- <s:Button id="btnTest" label="Test" click="test()" />
</s:HGroup>
</s:Form>
View
33 src/com/kdata/mobile/presentation/MobileActionMongoHome.mxml
@@ -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>
View
45 src/com/kdata/mobile/presentation/PopUp.mxml
@@ -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>
Please sign in to comment.
Something went wrong with that request. Please try again.