Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Q:a Searchable Photo Gallery  (Read 9037 times)
eco_bach
Courseware Beta
Sr. Member
***
Posts: 81


View Profile Email
« on: December 18, 2009, 02:24:29 »

As a personal project currently working on a searchable photo gallery.
A user will be able to search for photos by date and tags as well as number of photos returned in search query.
At the very least I know I will need a 'SearchProxy' with a corresponding VO containing values for all the current search parameters.

But after selecting a specific photo returned in the initial search I also want to be able to retrieve additional info specific to that photo from the server.

Just not sure about the best way to architect this....

Should I implement an additional proxy or keep the logic for the 'additional info' query in the same proxy??
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: December 19, 2009, 10:17:21 »

I usually have one Proxy per data type. A PhotoProxy might handle both the call to get a list which might have partially Photo objects (i.e. name, id), as well as the call to get a fully populated Photo object. It might also have save and delete functionality as well.

-=Cliff>
Logged
eco_bach
Courseware Beta
Sr. Member
***
Posts: 81


View Profile Email
« Reply #2 on: December 21, 2009, 06:31:11 »

Thanks Cliff. I guess what had me stumped is that I thought there was always a 1:1 correspondence between a Proxy and its associated VO.

In this case the search or 'photo' proxy returns a list of photos...and I though a VO by default usually represents or contains information for a single object.

So would the VO for this 'PhotoProxy' represent this entire list??? or would there somehow be multiple VO's, each representing just ONE photo?


Logged
mariusht
Full Member
***
Posts: 26


View Profile Email
« Reply #3 on: December 27, 2009, 08:40:14 »

PhotoVO would represents a single photo.

My suggestion to your project:
Use 'PhotosProxy' instead of 'PhotoProxy'. Sometimes you can think about the proxy as a representation of your table.
You have the table 'Photos' with columns: 'id', 'filename', 'type', 'size', 'date' and maybe 'keywords'.
I would create PhotosProxy with methods:
getPhotos(date:String, tags:String) - returns XML(only photos with the same date and keywords), PhotosProxy converts retrieved XML into arrayCollection of photos(single VOs) and sends note PhotosProxy.PHOTOS_RETRIEVED

You need one more method getPhotoDetails(photo:PhotoVO) - returns information about a specific photo, PhotosProxy sends note PhotosProxy.PHOTO_RETRIEVED

public function PhotosProxy()
{
super(NAME, new ArrayCollection);
}

public function get photos():ArrayCollection
{
return data as ArrayCollection;
}

public function getPhotos(date:String, tags:keywords):void
{
//call service to get photos
}

private function photosResults(event:Event):void
{
//convert XML into arrayCollection of PhotoVO
sendNotification(PHOTOS_RETRIEVED, photos);
}

public function getPhotosDetails(photo:PhotoVO):void
{
//call service
}

private function photoResult(event:Event):void
{
//convert XML into PhotoVO
sendNotification(PHOTO_RETRIEVED, photo);
}

You can add getPhotoDetails(photo:PhotoVO) to PhotosProxy or you can create a separate proxy 'PhotoProxy'.
It all depends on your project. I would create PhotoProxy in case where for example by clicking 'edit' button i open a dialog box(DialogBox, DialogBoxMediator). This mediator needs to know currently selected photo. dialogBoxMediator would get data from photoProxy.photo.

Mariush T.
Freelance Flex Developer
http://mariusht.com/blog/

Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #4 on: December 27, 2009, 11:44:30 »

Have a look at this response to a recent Proxy style question:
http://forums.puremvc.org/index.php?topic=1586.msg7206#msg7206

I describe how you might want to have a proxy that manages the list and a separate proxy for handling the individual vos. If there is a lot of create, update, delete functionality needed for the VO, then making a separate VO that can be registered multiple times (using the ID of the VO as the proxy name for instance), can relieve the list handling VO of having to also do CRUD for the individuals.

-=Cliff>
Logged
eco_bach
Courseware Beta
Sr. Member
***
Posts: 81


View Profile Email
« Reply #5 on: December 27, 2009, 03:00:10 »

Thanks both Mariush and Cliff!
Since my original post I also came across this tutorial on consuming restful services in AS3 only projects
http://blog.martinlegris.com/2009/12/11/tutorial-consuming-rest-web-services-in-actionscript-3-part-4/

Adapting the example to PureMVC I think the idea of using an iterator as the list manager or 'vo' for PhotosProxy makes lots of sense. Also creating an abstract proxy as mentioned by Cliff  to handle any type of restful service call.
« Last Edit: December 27, 2009, 03:14:51 by eco_bach » Logged
Pages: [1]
Print