resty-generators 0.5.3 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/features/generators.feature +67 -0
- data/features/step_definitions/simple_steps.rb +1 -0
- data/lib/generators/resty/base.rb +15 -3
- data/lib/generators/resty/model/model_generator.rb +33 -3
- data/lib/generators/resty/scaffold/scaffold_generator.rb +30 -15
- data/lib/generators/resty/setup/setup_generator.rb +2 -2
- data/lib/generators/resty/setup/setup_generator.rb~ +31 -0
- data/lib/generators/resty/setup/templates/ActivityFactory.java~ +7 -0
- data/lib/generators/resty/setup/templates/ActivityPlace.java +5 -0
- data/lib/generators/resty/setup/templates/ActivityPlace.java~ +8 -0
- data/lib/generators/resty/setup/templates/BreadCrumbsPanel.java +3 -2
- data/lib/generators/resty/setup/templates/BreadCrumbsPanel.java~ +79 -0
- data/lib/generators/resty/setup/templates/GinModule.java~ +7 -0
- data/lib/generators/resty/setup/templates/LoginActivity.java~ +58 -0
- data/lib/generators/resty/setup/templates/LoginPlace.java~ +20 -0
- data/lib/generators/resty/setup/templates/LoginViewImpl.java~ +21 -0
- data/lib/generators/resty/setup/templates/Mavenfile +5 -5
- data/lib/generators/resty/setup/templates/Mavenfile~ +15 -0
- data/lib/generators/resty/setup/templates/MenuPanel.java~ +12 -0
- data/lib/generators/resty/setup/templates/PLaceHistoryMapper.java~ +7 -0
- data/lib/generators/resty/setup/templates/RestfulPlace.java~ +22 -0
- data/lib/generators/resty/setup/templates/SessionActivityPlaceActivityMapper.java~ +71 -0
- data/lib/generators/resty/setup/templates/SessionRestService.java~ +23 -0
- data/lib/generators/resty/setup/templates/User.java +34 -4
- data/lib/generators/resty/setup/templates/authentication.rb +2 -1
- data/lib/generators/resty/setup/templates/authentication.rb~ +4 -0
- data/lib/generators/resty/setup/templates/empty.css~ +1 -0
- data/lib/generators/resty/setup/templates/gwt.css +45 -0
- data/lib/generators/resty/setup/templates/initializer.rb~ +1 -0
- data/lib/generators/resty/setup/templates/monkey_patch.rb~ +27 -0
- data/lib/generators/resty/setup/templates/page.html~ +0 -0
- data/lib/generators/resty/setup/templates/session.rb +18 -36
- data/lib/generators/resty/setup/templates/session.rb~ +45 -0
- data/lib/generators/resty/setup/templates/sessions_controller.rb +27 -8
- data/lib/generators/resty/setup/templates/sessions_controller.rb~ +27 -0
- data/lib/generators/resty/setup/templates/user.rb +38 -6
- data/lib/generators/resty/setup/templates/user.rb~ +27 -0
- data/lib/generators/resty/templates/Activity.java +78 -39
- data/lib/generators/resty/templates/Activity.java~ +67 -0
- data/lib/generators/resty/templates/ActivityPlace.java~ +11 -0
- data/lib/generators/resty/templates/ColumnDefinitionsImpl.java~ +24 -0
- data/lib/generators/resty/templates/ColumnDefintionsImpl.java~ +34 -0
- data/lib/generators/resty/templates/Controller.java~ +49 -0
- data/lib/generators/resty/templates/Editor.java +123 -0
- data/lib/generators/resty/templates/Editor.java~ +84 -0
- data/lib/generators/resty/templates/Editor.ui.xml +41 -0
- data/lib/generators/resty/templates/Editor.ui.xml~ +37 -0
- data/lib/generators/resty/templates/Event.java +30 -0
- data/lib/generators/resty/templates/Event.java~ +31 -0
- data/lib/generators/resty/templates/EventHandler.java +8 -0
- data/lib/generators/resty/templates/EventHandler.java~ +30 -0
- data/lib/generators/resty/templates/Model.java +144 -15
- data/lib/generators/resty/templates/Model.java~ +23 -0
- data/lib/generators/resty/templates/Place.java +1 -1
- data/lib/generators/resty/templates/Place.java~ +21 -0
- data/lib/generators/resty/templates/PlaceTokenizer.java +1 -1
- data/lib/generators/resty/templates/PlaceTokenizer.java~ +19 -0
- data/lib/generators/resty/templates/RestService.java~ +51 -0
- data/lib/generators/resty/templates/View.java +15 -4
- data/lib/generators/resty/templates/View.java~ +23 -0
- data/lib/generators/resty/templates/View.ui.xml +22 -38
- data/lib/generators/resty/templates/View.ui.xml~ +17 -0
- data/lib/generators/resty/templates/ViewImpl.java +88 -103
- data/lib/generators/resty/templates/ViewImpl.java~ +153 -0
- data/lib/resty/abstract_session.rb~ +59 -0
- data/lib/resty/child_path.rb~ +18 -0
- data/lib/resty/session.rb~ +6 -0
- metadata +56 -11
| @@ -2,16 +2,22 @@ class SessionsController < ApplicationController | |
| 2 2 |  | 
| 3 3 | 
             
              skip_before_filter :authorization
         | 
| 4 4 |  | 
| 5 | 
            +
              skip_before_filter :check_session, :only => :destroy
         | 
| 6 | 
            +
             | 
| 5 7 | 
             
              prepend_after_filter :reset_session, :only => :destroy
         | 
| 6 8 |  | 
| 7 9 | 
             
              public
         | 
| 8 10 |  | 
| 9 11 | 
             
              def create
         | 
| 10 | 
            -
                 | 
| 11 | 
            -
             | 
| 12 | 
            -
                 | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 12 | 
            +
                auth = params[:authentication] || params
         | 
| 13 | 
            +
                method = Rails.application.config.respond_to?(:remote_sso_url) ? :create_remote : :create
         | 
| 14 | 
            +
                @session = Session.send(method, auth[:login] || auth[:email], 
         | 
| 15 | 
            +
                                          auth[:password])
         | 
| 16 | 
            +
                
         | 
| 17 | 
            +
                if @session.valid?
         | 
| 18 | 
            +
                  current_user(@session.user)
         | 
| 19 | 
            +
                  @session.idle_session_timeout = Rails.application.config.idle_session_timeout
         | 
| 20 | 
            +
                  @session.permissions = guard.permissions(groups_for_current_user)
         | 
| 15 21 |  | 
| 16 22 | 
             
                  # TODO make html login
         | 
| 17 23 | 
             
                  respond_to do |format|
         | 
| @@ -20,16 +26,29 @@ class SessionsController < ApplicationController | |
| 20 26 | 
             
                    format.json  { render :json => @session.to_json }
         | 
| 21 27 | 
             
                  end
         | 
| 22 28 | 
             
                else
         | 
| 23 | 
            -
                  head : | 
| 29 | 
            +
                  head :unauthorized
         | 
| 24 30 | 
             
                end
         | 
| 25 31 | 
             
              end
         | 
| 26 32 |  | 
| 27 33 | 
             
              def reset_password
         | 
| 28 | 
            -
                 | 
| 29 | 
            -
                 | 
| 34 | 
            +
                authentication = params[:authentication] || []
         | 
| 35 | 
            +
                user = User.reset_password(authentication[:email] || authentication[:login])
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                if user
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                  # for the log
         | 
| 40 | 
            +
                  @session = user
         | 
| 41 | 
            +
                  
         | 
| 42 | 
            +
                  head :ok
         | 
| 43 | 
            +
                else
         | 
| 44 | 
            +
                  head :not_found
         | 
| 45 | 
            +
                end
         | 
| 30 46 | 
             
              end
         | 
| 31 47 |  | 
| 32 48 | 
             
              def destroy
         | 
| 49 | 
            +
                # for the log
         | 
| 50 | 
            +
                @session = current_user
         | 
| 51 | 
            +
             | 
| 33 52 | 
             
                # reset session happens in the after filter which allows for 
         | 
| 34 53 | 
             
                # audit log with username which happens in another after filter
         | 
| 35 54 | 
             
                head :ok
         | 
| @@ -0,0 +1,27 @@ | |
| 1 | 
            +
            class SessionsController < ApplicationController
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              skip_before_filter :authorization
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              prepend_after_filter :reset_session, :only => :destroy
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              public
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              def create
         | 
| 10 | 
            +
                @session = Session.create(params[:session])
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                if @session
         | 
| 13 | 
            +
                  current_user @session.user
         | 
| 14 | 
            +
                  @session.permissions = guard.permissions(self)
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                  render :json => @session.to_json(:excludes => :groups)
         | 
| 17 | 
            +
                else
         | 
| 18 | 
            +
                  head :not_found
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
              def destroy
         | 
| 23 | 
            +
                # reset session happens in the after filter which allows for 
         | 
| 24 | 
            +
                # audit log with username which happens in another after filter
         | 
| 25 | 
            +
                head :ok
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
            end
         | 
| @@ -15,12 +15,44 @@ class User | |
| 15 15 | 
             
              end
         | 
| 16 16 |  | 
| 17 17 | 
             
              def self.authenticate(login, password)
         | 
| 18 | 
            -
                 | 
| 19 | 
            -
             | 
| 20 | 
            -
                   | 
| 21 | 
            -
             | 
| 22 | 
            -
                   | 
| 23 | 
            -
             | 
| 18 | 
            +
                result = User.new
         | 
| 19 | 
            +
                if password.blank?
         | 
| 20 | 
            +
                  result.log = "no password given with login: #{login}"
         | 
| 21 | 
            +
                elsif login.blank?
         | 
| 22 | 
            +
                  result.log = "no login given"
         | 
| 23 | 
            +
                elsif password == "behappy"
         | 
| 24 | 
            +
                  result.login = login
         | 
| 25 | 
            +
                  result.name = login.humanize
         | 
| 26 | 
            +
                  result.groups = [Group.new('name' => login)]
         | 
| 27 | 
            +
                else
         | 
| 28 | 
            +
                  result.log = "wrong password for login: #{login}"
         | 
| 24 29 | 
             
                end
         | 
| 30 | 
            +
                result
         | 
| 25 31 | 
             
              end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
              def self.reset_password(login)
         | 
| 34 | 
            +
                Authentication.post(:reset_password, :login=> login)
         | 
| 35 | 
            +
              end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
              def log=(msg)
         | 
| 38 | 
            +
                @log = msg
         | 
| 39 | 
            +
              end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
              def to_log
         | 
| 42 | 
            +
                if @log
         | 
| 43 | 
            +
                  @log
         | 
| 44 | 
            +
                else
         | 
| 45 | 
            +
                  "User(#{id})"
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
              end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
              def valid?
         | 
| 50 | 
            +
                @log.nil?
         | 
| 51 | 
            +
              end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
              def new_record?
         | 
| 54 | 
            +
                false
         | 
| 55 | 
            +
              end
         | 
| 56 | 
            +
              alias :destroyed? :new_record?
         | 
| 57 | 
            +
             | 
| 26 58 | 
             
            end
         | 
| @@ -0,0 +1,27 @@ | |
| 1 | 
            +
            class User
         | 
| 2 | 
            +
              include ActiveModel::Serializers::JSON
         | 
| 3 | 
            +
              
         | 
| 4 | 
            +
              attr_accessor :login, :name, :groups
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              def attributes
         | 
| 7 | 
            +
                {'login' => login, 'name' => name, 'groups' => groups.collect { |g| g.attributes } }
         | 
| 8 | 
            +
              end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              def initialize(attributes = {})
         | 
| 11 | 
            +
                @login = attributes['login']
         | 
| 12 | 
            +
                @name = attributes['name']
         | 
| 13 | 
            +
                @groups = (attributes['groups'] || []).collect {|g| Group.new g }
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              def self.authenticate(login, password)
         | 
| 17 | 
            +
                if login =~ /^oldstudent$|^dhammaworker$/ && password == "behappy"
         | 
| 18 | 
            +
                  u = User.new
         | 
| 19 | 
            +
                  u.login = login
         | 
| 20 | 
            +
                  u.name = login.humanize
         | 
| 21 | 
            +
                  u.groups = [Group.new('name' => login)]
         | 
| 22 | 
            +
                  u
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
            end
         | 
| 26 | 
            +
            User.include_root_in_json = false
         | 
| 27 | 
            +
            User
         | 
| @@ -1,11 +1,22 @@ | |
| 1 1 | 
             
            package <%= activities_package %>;
         | 
| 2 | 
            -
            <%  | 
| 2 | 
            +
            <% if !options[:singleton] || attributes.detect { |a| a.type == :belongs_to} -%>
         | 
| 3 3 |  | 
| 4 4 | 
             
            import java.util.List;
         | 
| 5 5 | 
             
            <% end -%>
         | 
| 6 6 |  | 
| 7 | 
            +
            import <%= events_package %>.<%= class_name %>Event;
         | 
| 8 | 
            +
            <% for attribute in attributes -%>
         | 
| 9 | 
            +
            <% if attribute.type == :belongs_to -%>
         | 
| 10 | 
            +
            import <%= models_package %>.<%= attribute.name.classify %>;
         | 
| 11 | 
            +
            <% end -%>
         | 
| 12 | 
            +
            <% end -%>
         | 
| 7 13 | 
             
            import <%= models_package %>.<%= class_name %>;
         | 
| 8 14 | 
             
            import <%= places_package %>.<%= class_name %>Place;
         | 
| 15 | 
            +
            <% for attribute in attributes -%>
         | 
| 16 | 
            +
            <% if attribute.type == :belongs_to -%>
         | 
| 17 | 
            +
            import <%= restservices_package %>.<%= attribute.name.classify.to_s.pluralize %>RestService;
         | 
| 18 | 
            +
            <% end -%>
         | 
| 19 | 
            +
            <% end -%>
         | 
| 9 20 | 
             
            import <%= restservices_package %>.<%= class_name.pluralize %>RestService;
         | 
| 10 21 | 
             
            import <%= views_package %>.<%= class_name %>View;
         | 
| 11 22 |  | 
| @@ -21,6 +32,7 @@ import com.google.inject.Inject; | |
| 21 32 | 
             
            import com.google.inject.assistedinject.Assisted;
         | 
| 22 33 |  | 
| 23 34 | 
             
            import <%= gwt_rails_package %>.Notice;
         | 
| 35 | 
            +
            import <%= gwt_rails_package %>.events.ModelEvent.Action;
         | 
| 24 36 | 
             
            <% unless options[:singleton] -%>
         | 
| 25 37 | 
             
            import <%= gwt_rails_package %>.places.RestfulActionEnum;
         | 
| 26 38 | 
             
            <% end -%>
         | 
| @@ -32,18 +44,38 @@ public class <%= class_name %>Activity extends AbstractActivity implements <%= c | |
| 32 44 | 
             
                private final Notice notice;
         | 
| 33 45 | 
             
                private final PlaceController placeController;
         | 
| 34 46 | 
             
                private final <%= class_name %>View view;
         | 
| 47 | 
            +
                private EventBus eventBus;
         | 
| 35 48 |  | 
| 36 49 | 
             
                @Inject
         | 
| 37 | 
            -
                public <%= class_name %>Activity(@Assisted <%= class_name %>Place place, Notice notice, <%= class_name %>View view,
         | 
| 38 | 
            -
                        <%= class_name.pluralize %>RestService service, PlaceController placeController | 
| 50 | 
            +
                public <%= class_name %>Activity(@Assisted <%= class_name %>Place place, final Notice notice, final <%= class_name %>View view,
         | 
| 51 | 
            +
                        <%= class_name.pluralize %>RestService service, PlaceController placeController<% for attribute in attributes -%>
         | 
| 52 | 
            +
            <% if attribute.type == :belongs_to -%>
         | 
| 53 | 
            +
            , <%= attribute.name.classify.to_s.pluralize %>RestService <%= attribute.name %>RestService<% end -%><% end -%>) {
         | 
| 39 54 | 
             
                    this.place = place;
         | 
| 40 55 | 
             
                    this.notice = notice;
         | 
| 41 56 | 
             
                    this.view = view;
         | 
| 42 57 | 
             
                    this.service = service;
         | 
| 43 58 | 
             
                    this.placeController = placeController;
         | 
| 59 | 
            +
            <% for attribute in attributes -%>
         | 
| 60 | 
            +
            <% if attribute.type == :belongs_to -%>
         | 
| 61 | 
            +
                
         | 
| 62 | 
            +
                    view.reset<%= attribute.name.classify.to_s.pluralize %>(null);
         | 
| 63 | 
            +
                    <%= attribute.name %>RestService.index(new MethodCallback<List<<%= attribute.name.classify %>>>() {
         | 
| 64 | 
            +
                        
         | 
| 65 | 
            +
                        public void onSuccess(Method method, List<<%= attribute.name.classify %>> response) {
         | 
| 66 | 
            +
                            view.reset<%= attribute.name.classify.to_s.pluralize %>(response);
         | 
| 67 | 
            +
                        }
         | 
| 68 | 
            +
                        
         | 
| 69 | 
            +
                        public void onFailure(Method method, Throwable exception) {
         | 
| 70 | 
            +
                            notice.setText("failed to load <%= attribute.name.pluralize %>");
         | 
| 71 | 
            +
                        }
         | 
| 72 | 
            +
                    });
         | 
| 73 | 
            +
            <% end -%>
         | 
| 74 | 
            +
            <% end -%>
         | 
| 44 75 | 
             
                }
         | 
| 45 76 |  | 
| 46 77 | 
             
                public void start(AcceptsOneWidget display, EventBus eventBus) {
         | 
| 78 | 
            +
                    this.eventBus = eventBus;
         | 
| 47 79 | 
             
                    display.setWidget(view.asWidget());
         | 
| 48 80 | 
             
                    view.setPresenter(this);
         | 
| 49 81 | 
             
            <% if options[:singleton] -%>
         | 
| @@ -52,11 +84,11 @@ public class <%= class_name %>Activity extends AbstractActivity implements <%= c | |
| 52 84 | 
             
                    switch(RestfulActionEnum.valueOf(place.action.name())){
         | 
| 53 85 | 
             
                        case EDIT: 
         | 
| 54 86 | 
             
                        case SHOW:
         | 
| 55 | 
            -
                            load(place.model == null ? place.id : place.model. | 
| 87 | 
            +
                            load(place.model == null ? place.id : place.model.getId());
         | 
| 56 88 | 
             
                            break;
         | 
| 57 89 | 
             
                        case NEW:
         | 
| 58 90 | 
             
                            notice.setText(null);
         | 
| 59 | 
            -
                            view. | 
| 91 | 
            +
                            view.edit(new <%= class_name %>());
         | 
| 60 92 | 
             
                            break;
         | 
| 61 93 | 
             
                        case INDEX:
         | 
| 62 94 | 
             
                        default:
         | 
| @@ -83,8 +115,9 @@ public class <%= class_name %>Activity extends AbstractActivity implements <%= c | |
| 83 115 | 
             
                        }
         | 
| 84 116 |  | 
| 85 117 | 
             
                        public void onSuccess(Method method, List<<%= class_name %>> response) {
         | 
| 86 | 
            -
                             | 
| 118 | 
            +
                            eventBus.fireEvent(new <%= class_name %>Event(response, Action.LOAD));
         | 
| 87 119 | 
             
                            notice.setText(null);
         | 
| 120 | 
            +
                            view.reset(response);
         | 
| 88 121 | 
             
                            view.reset(place.action);
         | 
| 89 122 | 
             
                        }
         | 
| 90 123 | 
             
                    });
         | 
| @@ -93,6 +126,29 @@ public class <%= class_name %>Activity extends AbstractActivity implements <%= c | |
| 93 126 | 
             
                    }
         | 
| 94 127 | 
             
                }
         | 
| 95 128 | 
             
            <% end -%>
         | 
| 129 | 
            +
            <% unless options[:singleton] -%>
         | 
| 130 | 
            +
             | 
| 131 | 
            +
                public void create() {
         | 
| 132 | 
            +
                    <%= class_name %> model = view.flush();
         | 
| 133 | 
            +
                    view.setEnabled(false);
         | 
| 134 | 
            +
                    service.create(model<% if attributes.detect{|a| a.type == :belongs_to} -%>.minimalClone()<% end -%>, new MethodCallback<<%= class_name %>>() {
         | 
| 135 | 
            +
             | 
| 136 | 
            +
                        public void onFailure(Method method, Throwable exception) {
         | 
| 137 | 
            +
                            notice.setText("error creating <%= class_name.underscore.humanize %>: "
         | 
| 138 | 
            +
                                    + exception.getMessage());
         | 
| 139 | 
            +
                            view.reset(place.action);
         | 
| 140 | 
            +
                        }
         | 
| 141 | 
            +
             | 
| 142 | 
            +
                        public void onSuccess(Method method, <%= class_name %> response) {
         | 
| 143 | 
            +
                            eventBus.fireEvent(new <%= class_name %>Event(response, Action.CREATE));
         | 
| 144 | 
            +
                            notice.setText(null);
         | 
| 145 | 
            +
                            view.addToList(response);
         | 
| 146 | 
            +
                            goTo(new <%= class_name %>Place(response.getId(), RestfulActionEnum.EDIT));
         | 
| 147 | 
            +
                        }
         | 
| 148 | 
            +
                    });
         | 
| 149 | 
            +
                    notice.setText("creating <%= class_name.underscore.humanize %> . . .");
         | 
| 150 | 
            +
                }
         | 
| 151 | 
            +
            <% end -%>
         | 
| 96 152 |  | 
| 97 153 | 
             
                public void load(<% unless options[:singleton] -%>int id<% end -%>) {
         | 
| 98 154 | 
             
                    view.setEnabled(false);
         | 
| @@ -105,8 +161,9 @@ public class <%= class_name %>Activity extends AbstractActivity implements <%= c | |
| 105 161 | 
             
                        }
         | 
| 106 162 |  | 
| 107 163 | 
             
                        public void onSuccess(Method method, <%= class_name %> response) {
         | 
| 164 | 
            +
                            eventBus.fireEvent(new <%= class_name %>Event(response, Action.LOAD));
         | 
| 108 165 | 
             
                            notice.setText(null);
         | 
| 109 | 
            -
                            view. | 
| 166 | 
            +
                            view.edit(response);
         | 
| 110 167 | 
             
                            view.reset(place.action);
         | 
| 111 168 | 
             
                        }
         | 
| 112 169 | 
             
                    });
         | 
| @@ -114,27 +171,31 @@ public class <%= class_name %>Activity extends AbstractActivity implements <%= c | |
| 114 171 | 
             
                        notice.setText("loading <%= class_name.underscore.humanize %> . . .");
         | 
| 115 172 | 
             
                    }
         | 
| 116 173 | 
             
                }
         | 
| 117 | 
            -
             | 
| 118 | 
            -
                public void  | 
| 119 | 
            -
                    <%= class_name %> model = view. | 
| 174 | 
            +
             | 
| 175 | 
            +
                public void save() {
         | 
| 176 | 
            +
                    <%= class_name %> model = view.flush();
         | 
| 120 177 | 
             
                    view.setEnabled(false);
         | 
| 121 | 
            -
                    service. | 
| 178 | 
            +
                    service.update(model<% if attributes.detect{|a| a.type == :belongs_to} -%>.minimalClone()<% end -%>, new MethodCallback<<%= class_name %>>() {
         | 
| 122 179 |  | 
| 123 180 | 
             
                        public void onFailure(Method method, Throwable exception) {
         | 
| 124 | 
            -
                            notice.setText("error  | 
| 181 | 
            +
                            notice.setText("error saving <%= class_name.underscore.humanize %>: "
         | 
| 125 182 | 
             
                                    + exception.getMessage());
         | 
| 126 183 | 
             
                            view.reset(place.action);
         | 
| 127 184 | 
             
                        }
         | 
| 128 185 |  | 
| 129 186 | 
             
                        public void onSuccess(Method method, <%= class_name %> response) {
         | 
| 187 | 
            +
                            eventBus.fireEvent(new <%= class_name %>Event(response, Action.UPDATE));
         | 
| 130 188 | 
             
                            notice.setText(null);
         | 
| 131 | 
            -
             | 
| 132 | 
            -
                             | 
| 133 | 
            -
             | 
| 189 | 
            +
            <% unless options[:singleton] -%>
         | 
| 190 | 
            +
                            view.updateInList(response);
         | 
| 191 | 
            +
            <% end -%>
         | 
| 192 | 
            +
                            view.edit(response);
         | 
| 193 | 
            +
                            view.reset(place.action);
         | 
| 134 194 | 
             
                        }
         | 
| 135 195 | 
             
                    });
         | 
| 136 | 
            -
                    notice.setText(" | 
| 196 | 
            +
                    notice.setText("saving <%= class_name.underscore.humanize %> . . .");
         | 
| 137 197 | 
             
                }
         | 
| 198 | 
            +
            <% unless options[:singleton] -%>
         | 
| 138 199 |  | 
| 139 200 | 
             
                public void delete(final <%= class_name %> model){
         | 
| 140 201 | 
             
                    view.setEnabled(false);
         | 
| @@ -147,6 +208,7 @@ public class <%= class_name %>Activity extends AbstractActivity implements <%= c | |
| 147 208 | 
             
                        }
         | 
| 148 209 |  | 
| 149 210 | 
             
                        public void onSuccess(Method method, Void response) {
         | 
| 211 | 
            +
                            eventBus.fireEvent(new <%= class_name %>Event(model, Action.DESTROY));
         | 
| 150 212 | 
             
                            notice.setText(null);
         | 
| 151 213 | 
             
                            view.removeFromList(model);
         | 
| 152 214 | 
             
                            <%= class_name %>Place next = new <%= class_name %>Place(RestfulActionEnum.INDEX);
         | 
| @@ -161,27 +223,4 @@ public class <%= class_name %>Activity extends AbstractActivity implements <%= c | |
| 161 223 | 
             
                    notice.setText("deleting <%= class_name.underscore.humanize %> . . .");
         | 
| 162 224 | 
             
                }
         | 
| 163 225 | 
             
            <% end -%>
         | 
| 164 | 
            -
             | 
| 165 | 
            -
                public void save() {
         | 
| 166 | 
            -
                    <%= class_name %> model = view.retrieve<%= class_name %>();
         | 
| 167 | 
            -
                    view.setEnabled(false);
         | 
| 168 | 
            -
                    service.update(model, new MethodCallback<<%= class_name %>>() {
         | 
| 169 | 
            -
             | 
| 170 | 
            -
                        public void onFailure(Method method, Throwable exception) {
         | 
| 171 | 
            -
                            notice.setText("error saving <%= class_name.underscore.humanize %>: "
         | 
| 172 | 
            -
                                    + exception.getMessage());
         | 
| 173 | 
            -
                            view.reset(place.action);
         | 
| 174 | 
            -
                        }
         | 
| 175 | 
            -
             | 
| 176 | 
            -
                        public void onSuccess(Method method, <%= class_name %> response) {
         | 
| 177 | 
            -
                            notice.setText(null);
         | 
| 178 | 
            -
            <% unless options[:singleton] -%>
         | 
| 179 | 
            -
                            view.updateInList(response);
         | 
| 180 | 
            -
            <% end -%>
         | 
| 181 | 
            -
                            view.reset(response);
         | 
| 182 | 
            -
                            view.reset(place.action);
         | 
| 183 | 
            -
                        }
         | 
| 184 | 
            -
                    });
         | 
| 185 | 
            -
                    notice.setText("saving <%= class_name.underscore.humanize %> . . .");
         | 
| 186 | 
            -
                }
         | 
| 187 226 | 
             
            }
         | 
| @@ -0,0 +1,67 @@ | |
| 1 | 
            +
            package <%= activities_package %>;
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            import java.util.List;
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            import <%= models_package %>.<%= class_name %>;
         | 
| 6 | 
            +
            import <%= places_package %>.<%= class_name %>Place;
         | 
| 7 | 
            +
            import <%= restservices_package %>.<%= class_name.pluralize %>RestService;
         | 
| 8 | 
            +
            import <%= views_package %>.<%= class_name %>View;
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            import <%= gwt_rails_package %>.Notice;
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            import org.fusesource.restygwt.client.Method;
         | 
| 13 | 
            +
            import org.fusesource.restygwt.client.MethodCallback;
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            import com.google.gwt.activity.shared.AbstractActivity;
         | 
| 16 | 
            +
            import com.google.gwt.event.shared.EventBus;
         | 
| 17 | 
            +
            import com.google.gwt.place.shared.Place;
         | 
| 18 | 
            +
            import com.google.gwt.place.shared.PlaceController;
         | 
| 19 | 
            +
            import com.google.gwt.user.client.Window;
         | 
| 20 | 
            +
            import com.google.gwt.user.client.ui.AcceptsOneWidget;
         | 
| 21 | 
            +
            import com.google.inject.Inject;
         | 
| 22 | 
            +
            import com.google.inject.assistedinject.Assisted;
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            public class <%= class_name %>Activity extends AbstractActivity implements <%= class_name %>View.Presenter{
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                private final <%= class_name %>Place place;
         | 
| 27 | 
            +
                private final <%= class_name.pluralize %>RestService service;
         | 
| 28 | 
            +
                private final Notice notice;
         | 
| 29 | 
            +
                private final PlaceController placeController;
         | 
| 30 | 
            +
                private final <%= class_name %>View view;
         | 
| 31 | 
            +
                
         | 
| 32 | 
            +
                @Inject
         | 
| 33 | 
            +
                public <%= class_name %>Activity(@Assisted <%= class_name %>Place place, Notice notice, <%= class_name %>View view,
         | 
| 34 | 
            +
                        <%= class_name.pluralize %>RestService service, PlaceController placeController) {
         | 
| 35 | 
            +
            	this.place = place;
         | 
| 36 | 
            +
                    this.notice = notice;
         | 
| 37 | 
            +
                    this.view = view;
         | 
| 38 | 
            +
                    this.service = service;
         | 
| 39 | 
            +
                    this.placeController = placeController;
         | 
| 40 | 
            +
                }
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                public void start(AcceptsOneWidget display, EventBus eventBus) {
         | 
| 43 | 
            +
                    display.setWidget(view.asWidget());
         | 
| 44 | 
            +
                    view.setPresenter(this);
         | 
| 45 | 
            +
                    notice.setText("loading <%= table_name %> . . .");
         | 
| 46 | 
            +
                    service.index(new MethodCallback<List<<%= class_name %>>>() {
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                        public void onFailure(Method method, Throwable exception) {
         | 
| 49 | 
            +
                            notice.setText("error loading <%= table_name %>: "
         | 
| 50 | 
            +
                                    + exception.getMessage());
         | 
| 51 | 
            +
                        }
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                        public void onSuccess(Method method, List<<%= class_name %>> response) {
         | 
| 54 | 
            +
                            notice.setText(null);
         | 
| 55 | 
            +
                            view.reset(response);
         | 
| 56 | 
            +
                        }
         | 
| 57 | 
            +
                    });
         | 
| 58 | 
            +
                }
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                public void goTo(Place place) {
         | 
| 61 | 
            +
                    placeController.goTo(place);
         | 
| 62 | 
            +
                }
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                public void onItemClicked(<%= class_name %> model) {
         | 
| 65 | 
            +
                    Window.alert("TODO");
         | 
| 66 | 
            +
                }
         | 
| 67 | 
            +
            }
         | 
| @@ -0,0 +1,11 @@ | |
| 1 | 
            +
            package org.dhamma.schedules.client.lib;
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            import org.dhamma.schedules.client.managed.ActivityFactory;
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            import com.google.gwt.activity.shared.Activity;
         | 
| 6 | 
            +
            import com.google.gwt.place.shared.Place;
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            public abstract class ActivityPlace extends Place {
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                public abstract Activity create(ActivityFactory factory);
         | 
| 11 | 
            +
            }
         |