Changeset 1475


Ignore:
Timestamp:
07/27/11 13:55:35 (13 years ago)
Author:
twagoo
Message:

ComponentUsageService? actually checks results of service call and includes them in event.
Editor shows names of items that use the component in the confirmation dialog.

Fixes #134

Location:
ComponentRegistry/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/editor/EditorAS.as

    r1473 r1475  
    105105                // Private components that are in updated require usage check call. If in use, the user can choose whether or not to save the changes .
    106106                if(inUserSpace && uploadAction == UploadService.UPDATE && !item.isProfile){
    107                         checkUsage(item);
     107                        checkUsage(item, inUserSpace);
    108108                }else{
    109109                        doUpload(uploadAction,item);
     
    117117 * Calls usage check for the specified component. If in use, asks user whether to proceed; if positive, initiates update.
    118118 */
    119 private function checkUsage(item:ItemDescription, uploadAction:int = UploadService.UPDATE):void{
    120         var componentUsageService:ComponentUsageService = new ComponentUsageService(item);
     119private function checkUsage(item:ItemDescription, inUserSpace:Boolean = true, uploadAction:int = UploadService.UPDATE):void{
     120        var componentUsageService:ComponentUsageService = new ComponentUsageService(item,inUserSpace);
    121121        componentUsageService.addEventListener(ComponentUsageCheckEvent.COMPONENT_IN_USE,
    122122                function (event:ComponentUsageCheckEvent):void{
    123123                        if(event.isComponentInUse){
    124                                 Alert.show("Component is used by other components and/or profiles. Changes in this component will affect these. Do you want to proceed?","Component is used", Alert.YES|Alert.NO,null,
     124                                var messageBody:String = "The component you are about to save is used by the following component(s) and/or profile(s):\n\n";
     125                                for each(var name:String in event.itemUsingComponent){
     126                                        messageBody += " - " + name + "\n";
     127                                }
     128                                messageBody += "\nChanges in this component will affect the above. Do you want to proceed?";
     129                                Alert.show(messageBody,"Component is used", Alert.YES|Alert.NO,null,
    125130                                        function (eventObj:CloseEvent):void{
    126131                                                if(eventObj.detail == Alert.YES){
  • ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/services/ComponentUsageCheckEvent.as

    r1473 r1475  
    33        import flash.events.Event;
    44       
     5        import mx.collections.ArrayCollection;
     6       
    57        public class ComponentUsageCheckEvent extends Event
    68        {       
    79                public static const COMPONENT_IN_USE:String = "componentInUse";
     10                private var _itemsUsingComponent:ArrayCollection;
    811               
    9                 public function ComponentUsageCheckEvent(type:String, componentInUse:Boolean,bubbles:Boolean = false, cancelable:Boolean = false)
     12                public function ComponentUsageCheckEvent(type:String, itemsUsingComponent:ArrayCollection, bubbles:Boolean = false, cancelable:Boolean = false)
    1013                {
    1114                        super(type, bubbles, cancelable);
    12                         this._isComponentInUse = componentInUse;
     15                        _itemsUsingComponent = itemsUsingComponent;
    1316                }
    1417               
     
    1619               
    1720                public function get isComponentInUse():Boolean{
    18                         return _isComponentInUse;
     21                        return _itemsUsingComponent != null && _itemsUsingComponent.length > 0;
     22                }
     23               
     24                /**
     25                 * Names of components that use the specified item
     26                 */
     27                public function get itemUsingComponent():ArrayCollection{
     28                        return _itemsUsingComponent;
    1929                }
    2030        }
  • ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/services/ComponentUsageService.as

    r1473 r1475  
    88        import flash.events.EventDispatcher;
    99       
     10        import mx.collections.ArrayCollection;
    1011        import mx.controls.Alert;
    1112        import mx.messaging.messages.HTTPRequestMessage;
     
    1516        import mx.rpc.events.ResultEvent;
    1617        import mx.rpc.http.HTTPService;
    17        
    1818        import mx.utils.StringUtil;
    1919       
     20        /**
     21         * Service that calls registry/components/usage/{id} for the specified component, which is used to check
     22         * whether the component is used by any other components or profiles in the same registry.
     23         */
    2024        [Event(name="componentInUse", type="clarin.cmdi.componentregistry.services.ComponentUsageCheckEvent")]
    2125        public class ComponentUsageService extends EventDispatcher
    2226        {
    2327                private var service:HTTPService;
    24                 private var serviceUrl:String;
    2528               
    26                 public function ComponentUsageService(itemDescription:ItemDescription)
     29                public function ComponentUsageService(itemDescription:ItemDescription, userSpace:Boolean)
    2730                {
    2831                        var url:URI = new URI(Config.instance.componentUsageUrl + itemDescription.id);
     32                        if (userSpace) {
     33                                url.setQueryValue(Config.PARAM_USERSPACE, "true");
     34                        }
    2935
    3036                        service = new HTTPService();
     
    4147               
    4248                private function result(resultEvent:ResultEvent):void {
     49                        // Result contains list of items that use the specified component
    4350                        var resultXml:XML = resultEvent.result as XML;
    44                         dispatchEvent(new ComponentUsageCheckEvent(ComponentUsageCheckEvent.COMPONENT_IN_USE, true));
     51                       
     52                        // Collect item names so the view can show them to the user
     53                        var resultItems:ArrayCollection = new ArrayCollection();
     54                        for each (var description:XML in resultXml.children()) {
     55                                resultItems.addItem(description.name.toString());
     56                        }
     57                       
     58                        var event:ComponentUsageCheckEvent = new ComponentUsageCheckEvent(ComponentUsageCheckEvent.COMPONENT_IN_USE, resultItems);                                     
     59                        dispatchEvent(event);
    4560                }
    4661               
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java

    r1463 r1475  
    205205    @Path("/components/usage/{componentId}")
    206206    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    207     public List<AbstractDescription> getComponentUsage(@PathParam("componentId") String componentId, @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
     207    public List<AbstractDescription> getComponentUsage(@PathParam("componentId") String componentId, @QueryParam(USERSPACE_PARAM) @DefaultValue("true") boolean userspace) throws ComponentRegistryException {
    208208        try {
    209209            final long start = System.currentTimeMillis();
Note: See TracChangeset for help on using the changeset viewer.