Module: nagvis Branch: master Commit: af39e0fb39844e63af1d79793aa6b809be73726c URL: http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis/commit/?id=af39e0fb39844e63af1d79793aa6b809be73726c
Author: Roman Kyrylych <[email protected]> Date: Wed Aug 12 14:10:19 2009 +0300 gmap: Implemented auto-updating of location states and markers Signed-off-by: Roman Kyrylych <[email protected]> --- share/netmap/Location.php | 83 ++++++++------------ uifx/src/modules/gmap/data/LocationsData.as | 9 ++- uifx/src/modules/gmap/domain/Location.as | 21 +++++ uifx/src/modules/gmap/mate/GeneralEM.mxml | 2 +- uifx/src/modules/gmap/mate/LocationsEM.mxml | 4 +- .../gmap/view/controls/GMapLocationsControl.as | 1 - .../modules/gmap/view/controls/LocationMarker.as | 38 +++++++++- 7 files changed, 102 insertions(+), 56 deletions(-) diff --git a/share/netmap/Location.php b/share/netmap/Location.php index eb15e52..e377dba 100644 --- a/share/netmap/Location.php +++ b/share/netmap/Location.php @@ -102,16 +102,47 @@ class Location } /** + * @param boolean $problemonly * @return array of Location */ - public function getAll() + public function getAll($problemonly = false) { if (($xml = @simplexml_load_file('locations.xml')) === FALSE) throw new Exception('Could not read locations.xml'); + $db = new Database(); + $locations = array(); - foreach ($xml->location as $location) - $locations[] = Location::fromXML($location); + foreach ($xml->location as $node) + { + $location = Location::fromXML($node); + + if (isset($location->object)) + switch (get_class($location->object)) + { + case 'Host': + $location->state = $db->getHostState($location->object); + break; + + case 'HostGroup': + $location->state = $db->getHostGroupState($location->object); + break; + + case 'Service': + $location->state = $db->getServiceState($location->object); + break; + + case 'ServiceGroup': + $location->state = $db->getServiceGroupState($location->object); + break; + + default: + throw new Exception('Unknown object type in locations.xml'); + } + + if (!$problemonly || $location->state != self::STATE_OK) + $locations[] = $location; + } return $locations; } @@ -201,52 +232,6 @@ class Location return $locations; } - - /** - * @return array of Location - */ - public function checkAll() - { - if (($xml = @simplexml_load_file('locations.xml')) === FALSE) - throw new Exception('Could not read locations.xml'); - - $db = new Database(); - - $locations = array(); - foreach ($xml->location as $node) - { - $location = Location::fromXML($node); - - if (!isset($location->object)) - continue; - - switch (get_class($location->object)) - { - case 'Host': - $location->state = $db->getHostState($location->object); - break; - - case 'HostGroup': - $location->state = $db->getHostGroupState($location->object); - break; - - case 'Service': - $location->state = $db->getServiceState($location->object); - break; - - case 'ServiceGroup': - $location->state = $db->getServiceGroupState($location->object); - break; - - default: - throw new Exception('Unknown object type in locations.xml'); - } - - $locations[] = $location; - } - - return $locations; - } } ?> diff --git a/uifx/src/modules/gmap/data/LocationsData.as b/uifx/src/modules/gmap/data/LocationsData.as index d255049..1e2540f 100644 --- a/uifx/src/modules/gmap/data/LocationsData.as +++ b/uifx/src/modules/gmap/data/LocationsData.as @@ -5,6 +5,7 @@ package modules.gmap.data import modules.gmap.domain.Location; import mx.collections.ArrayCollection; + import mx.controls.Alert; public class LocationsData extends ArrayCollection { @@ -48,7 +49,13 @@ package modules.gmap.data else location.update(item); } - + + public function addUpdateItems(items : Array) : void + { + for each(var location : Location in items) + this.addUpdateItem(location); + } + public function removeItemById(id:String):void { removeItemAt(getItemIndex(getItemById(id))); diff --git a/uifx/src/modules/gmap/domain/Location.as b/uifx/src/modules/gmap/domain/Location.as index fda6274..8edbccf 100644 --- a/uifx/src/modules/gmap/domain/Location.as +++ b/uifx/src/modules/gmap/domain/Location.as @@ -28,12 +28,18 @@ package modules.gmap.domain [Event(name="change", type="modules.gmap.LocationEvent")] public class Location { + public static const STATE_UNKNOWN : Number = 0; + public static const STATE_OK : Number = 1; + public static const STATE_WARNING : Number = 2; + public static const STATE_ERROR : Number = 3; + private var _id : String; private var _point : String; private var _label : String; private var _address : String; private var _description : String; private var _object : Object; + private var _state : Number; public function get id() : String { @@ -119,6 +125,20 @@ package modules.gmap.domain } } + public function get state() : Number + { + return this._state; + } + + public function set state(value : Number) : void + { + if(_state != value) + { + this._state = value; + dispatchEvent(new LocationEvent('change', this)); + } + } + public function update(value : Location) : void { this.id = value.id; @@ -127,6 +147,7 @@ package modules.gmap.domain this.address = value.address; this.description = value.description; this.object = value.object; + this.state = value.state; } } } diff --git a/uifx/src/modules/gmap/mate/GeneralEM.mxml b/uifx/src/modules/gmap/mate/GeneralEM.mxml index 5e45940..25d63bd 100644 --- a/uifx/src/modules/gmap/mate/GeneralEM.mxml +++ b/uifx/src/modules/gmap/mate/GeneralEM.mxml @@ -17,7 +17,7 @@ </mx:Script> <EventHandlers type="{UnhandledFaultEvent.FAULT}"> - <InlineInvoker method="Alert.show" arguments="{[event.fault.faultString, 'Error']}"/> + <InlineInvoker method="Alert.show" arguments="{[event.fault.faultDetail, 'Error']}"/> </EventHandlers> <EventHandlers type="resized"> diff --git a/uifx/src/modules/gmap/mate/LocationsEM.mxml b/uifx/src/modules/gmap/mate/LocationsEM.mxml index 1e1e730..7557430 100644 --- a/uifx/src/modules/gmap/mate/LocationsEM.mxml +++ b/uifx/src/modules/gmap/mate/LocationsEM.mxml @@ -60,9 +60,9 @@ </EventHandlers> <EventHandlers type="{Poller.TIMEOUT}"> - <RemoteObjectInvoker instance="{LocationsService}" method="checkAll"> + <RemoteObjectInvoker instance="{LocationsService}" method="getAll" arguments="true"> <resultHandlers> - <InlineInvoker method="Alert.show" arguments="state checked"/> + <MethodInvoker generator="{LocationsData}" method="addUpdateItems" arguments="{resultObject}"/> </resultHandlers> </RemoteObjectInvoker> </EventHandlers> diff --git a/uifx/src/modules/gmap/view/controls/GMapLocationsControl.as b/uifx/src/modules/gmap/view/controls/GMapLocationsControl.as index 48f6ecc..f251089 100644 --- a/uifx/src/modules/gmap/view/controls/GMapLocationsControl.as +++ b/uifx/src/modules/gmap/view/controls/GMapLocationsControl.as @@ -152,6 +152,5 @@ package modules.gmap.view.controls { dispatchEvent(event); } - } } \ No newline at end of file diff --git a/uifx/src/modules/gmap/view/controls/LocationMarker.as b/uifx/src/modules/gmap/view/controls/LocationMarker.as index a2a62f5..bcd3cbe 100644 --- a/uifx/src/modules/gmap/view/controls/LocationMarker.as +++ b/uifx/src/modules/gmap/view/controls/LocationMarker.as @@ -5,6 +5,8 @@ package modules.gmap.view.controls import com.google.maps.overlays.Marker; import com.google.maps.overlays.MarkerOptions; + import flash.events.Event; + import modules.gmap.domain.Location; import modules.gmap.events.LocationEvent; @@ -43,9 +45,10 @@ package modules.gmap.view.controls super(point, options); - _location = location; - this.addEventListener(MapMouseEvent.CLICK, this.onClick); + + _location = location; + _location.addEventListener('change', this.onChange); } protected function onClick(event : *):void @@ -55,6 +58,37 @@ package modules.gmap.view.controls ); } + protected function onChange(event : *):void + { + if(location.id && location.id.length > 0) + { + var options : MarkerOptions = new MarkerOptions(); + + switch (_location.state) + { + case Location.STATE_OK: + options.icon = new okIcon(); + break; + + case Location.STATE_WARNING: + options.icon = new warningIcon(); + break; + + case Location.STATE_ERROR: + options.icon = new errorIcon(); + break; + + case Location.STATE_UNKNOWN: + default: + options.icon = new unknownIcon(); + } + options.iconAlignment = MarkerOptions.ALIGN_HORIZONTAL_CENTER || MarkerOptions.ALIGN_VERTICAL_CENTER; + options.hasShadow = false; + + this.setOptions(options); + } + } + public function get location():Location { return _location; ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Nagvis-checkins mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/nagvis-checkins
