view · edit · sidebar · attach · print · history

Index>

20170328-davaz-tooltip

Summary

Commits

Index

Admin user cannot list tooltip

Visiting en/gallery/tooltips/ (when logged in) produces the following backtrace. Looking how the link_id is implemented, and why it is not present in the model being displayed.

Found the following lines in src/util/app.rb, where I suspect the error stems from

    def load_links
      # TODO: Where should we use the old definition of @db_manager.load_links?
      @db_manager.load_serie_artobjects('Site Links', 'series.name')
    end

The method load_links was changed in src/util/app in commit Cleanup app. Removed duplicated methods. Fixed this problem. Now I see a lot less links when visiting en/communication/links/, as I removed yesterday manually various artobjecs. Reloading the database dump.

Now the manual tests work. Adding visiting tooltip and links to the watir tests. Refactoring to distinguish between load_links and load_tooltips_links as the commit https://github.com/grauwoelfchen/davaz.com/commit/c0d1cce301c1d0e99c487e5cae389368b9774627 introduced a second conflicting definition for load_links in src/util/app.rb.

When running bundle exec rake test I get several failures in movies_test, which I do not have when running the unit test separatly via bundle exec test/feature/movies_test.rb. Ignoring this problem for the time being.

Pushed commit https://github.com/ngiger/davaz.com/commit/a1a978f8fdaf741cc4dde3debb06ec218443ea7a1Fixed load_links and visiting tooltips and links Also found that there are no unit tests for multiples.

When clicking "Add new element" as admin user under en/gallery/tooltips/, a reload is necessary to edit the item. This should not be necessary. Click on the link "unkown" does not work.

I thinks in the last commit it would have been better not to add _tooltip to various methods name but better to rename the load_links method to load_site_links.

When adding a new tooltip item, one cannot click on the FROM URL, but must first set the "From" integer to a given artobject_id.

First debugging how adding a new element in en/gallery/tooltips/ works. It calls adminAddNewTooltipElement.new(@session, @model) in src/state/gallery/tooltips.rb. There is a method with the same name in src/state/communication/links.rb.

With pry the situation when adding a new element in tooltips is

From: /var/www/davaz.com/src/state/gallery/tooltips.rb @ line 32 DaVaz::State::Gallery::AdminAddNewTooltipElement#init:

    23:       def init
    24:         values = {
    25:           # dummy artobejct_id, linked_artobject_id
    26:           :artobject_id        => '1',
    27:           :word                => 'tooltip',
    28:           :linked_artobject_id => '1'
    29:         }
    30:         insert_id = @session.app.insert_link(values)
    31:         require 'pry'; binding.pry
 => 32:         @model = @session.app.load_link(insert_id)
    33:       end

[1] pry(#<DaVaz::State::Gallery::AdminAddNewTooltipElement>)> values
=> {:artobject_id=>"1", :word=>"tooltip", :linked_artobject_id=>"1"}
[2] pry(#<DaVaz::State::Gallery::AdminAddNewTooltipElement>)> insert_id
=> 113
[3] pry(#<DaVaz::State::Gallery::AdminAddNewTooltipElement>)> link =  @session.app.load_link(insert_id)
=> #<DaVaz::Model::Link:0x007fb4703d3a70
 @artobject_id=1,
 @artobjects=
  [#<DaVaz::Model::ArtObject:0x007fb4703d39f8
    @artgroup_id=nil,
    @artobject_id=nil,
    @author=nil,
    @charset=nil,
    @country_id=nil,
    @date=nil,
    @language=nil,
    @links=[],
    @location=nil,
    @material_id=nil,
    @movie_type=nil,
    @price=nil,
    @public=nil,
    @serie_id=nil,
    @serie_position=nil,
    @size=nil,
    @tags=[],
    @text=nil,
    @title=nil,
    @tool_id=nil,
    @url=nil,
    @wordpress_url=nil>],
 @link_id=113,
 @word="tooltip">

When adding a new link element I see in the pry session


From: /var/www/davaz.com/src/state/communication/links.rb @ line 27 DaVaz::State::Communication::AdminAjaxAddNewLinkElement#init:

    18: def init
    19:   values = {
    20:     :serie_id => @model.serie_id,
    21:     :url      => @session.lookandfeel.lookup(:click2edit),
    22:     :date     => Date.today.to_s,
    23:     :text     => @session.lookandfeel.lookup(:click2edit_textarea),
    24:   }
    25:   require 'pry'; binding.pry                
    26: 
 => 27:   insert_id = @session.app.insert_artobject(values)
    28:   @model = @session.app.load_artobject(insert_id)
    29: end

[1] pry(#<DaVaz::State::Communication::AdminAjaxAddNewLinkElement>)> values
=> {:serie_id=>"AFG", :url=>"Please click here to edit.", :date=>"2017-03-28", :text=>"Please click here to edit the textarea."}
[2] pry(#<DaVaz::State::Communication::AdminAjaxAddNewLinkElement>)> next

From: /var/www/davaz.com/src/state/communication/links.rb @ line 28 DaVaz::State::Communication::AdminAjaxAddNewLinkElement#init:

    18: def init
    19:   values = {
    20:     :serie_id => @model.serie_id,
    21:     :url      => @session.lookandfeel.lookup(:click2edit),
    22:     :date     => Date.today.to_s,
    23:     :text     => @session.lookandfeel.lookup(:click2edit_textarea),
    24:   }
    25:   require 'pry'; binding.pry                
    26: 
    27:   insert_id = @session.app.insert_artobject(values)
 => 28:   @model = @session.app.load_artobject(insert_id)
    29: end

[2] pry(#<DaVaz::State::Communication::AdminAjaxAddNewLinkElement>)> insert_id
=> 1791
[3] pry(#<DaVaz::State::Communication::AdminAjaxAddNewLinkElement>)> x =  @session.app.load_artobject(insert_id)
=> #<DaVaz::Model::ArtObject:0x007fb4703e50e0
 @artgroup=nil,
 @artgroup_id="",
 @artobject_id=1791,
 @author="",
 @charset=nil,
 @country=nil,
 @country_id="",
 @date=#<Date: 2017-03-28 ((2457841j,0s,0n),+0s,2299161j)>,
 @language="",
 @links=[],
 @location="",
 @material=nil,
 @material_id=0,
 @movie_type="none",
 @price=nil,
 @public=1,
 @serie="Site Links",
 @serie_id="AFG",
 @serie_position="",
 @size="",
 @tags=[],
 @text="Please click here to edit the textarea.",
 @title="",
 @tool=nil,
 @tool_id=0,
 @url="Please click here to edit.",
 @wordpress_url=nil>
<several next till before to_hml in session.process, where we display the newly added and an old element.
[9] pry(#<DaVaz::Util::Session>)> app.load_site_links.first
=> #<DaVaz::Model::ArtObject:0x007fb47039b328
 @artgroup=nil,
 @artgroup_id="",
 @artobject_id=1791,
 @author="",
 @charset=nil,
 @country=nil,
 @country_id="",
 @date=#<Date: 2017-03-28 ((2457841j,0s,0n),+0s,2299161j)>,
 @language="",
 @links=[],
 @location="",
 @material=nil,
 @material_id=0,
 @movie_type="none",
 @price=nil,
 @public=1,
 @serie="Site Links",
 @serie_id="AFG",
 @serie_position="",
 @size="",
 @tags=[],
 @text="Please click here to edit the textarea.",
 @title="",
 @tool=nil,
 @tool_id=0,
 @url="Please click here to edit.",
 @wordpress_url=nil>
[10] pry(#<DaVaz::Util::Session>)> app.load_site_links.last
=> #<DaVaz::Model::ArtObject:0x00563d0a6099b8
 @artgroup=nil,
 @artgroup_id="",
 @artobject_id=1321,
 @author="",
 @charset=nil,
 @country=nil,
 @country_id="",
 @date=#<Date: 2004-09-08 ((2453257j,0s,0n),+0s,2299161j)>,
 @language="",
 @links=[],
 @location="",
 @material=nil,
 @material_id=0,
 @movie_type="none",
 @price=nil,
 @public=1,
 @serie="Site Links",
 @serie_id="AFG",
 @serie_position="",
 @size="",
 @tags=[],
 @text="Intellectual Capital Connected.",
 @title="",
 @tool=nil,
 @tool_id=0,
 @url="http://www.ywesee.com",
 @wordpress_url="">
[11] pry(#<DaVaz::Util
<presssing next gives us now an error>
[11] pry(#<DaVaz::Util::Session>)> next

From: /var/www/davaz.com/vendor/ruby240/ruby/2.4.0/gems/sbsm-1.3.6/lib/sbsm/session.rb @ line 243 SBSM::Session#process_rack:

    238:         to_html
    239:       end
    240:       (@@stats[@request_path] ||= []).push(Time.now - start)
    241:       html
    242:     rescue  => err
 => 243:         SBSM.info "Error in process_rack #{err.backtrace[0..5].join("\n")}"
    244:         raise err
    245:     end
    246:                def error(key)
    247:                        @state.error(key) if @state.respond_to?(:error)
    248:                end

[11] pry(#<DaVaz::Util::Session>)> err.backtrace
=> ["/var/www/davaz.com/src/view/_partial/select.rb:28:in `selection'",
 "/home/niklaus/git/htmlgrid/lib/htmlgrid/select.rb:35:in `block in to_html'",
 "/usr/local/ruby-2.4.0/lib/ruby/2.4.0/cgi/html.rb:15:in `nn_element'",
 "/usr/local/ruby-2.4.0/lib/ruby/2.4.0/cgi/html.rb:21:in `nn_element_def'",
 "/home/niklaus/git/htmlgrid/lib/htmlgrid/select.rb:34:in `to_html'",
 "/var/www/davaz.com/src/view/_partial/select.rb:46:in `to_html'",
 "/var/www/davaz.com/vendor/ruby240/ruby/2.4.0/gems/sbsm-1.3.6/lib/sbsm/state.rb:174:in `to_html'",
 "/var/www/davaz.com/vendor/ruby240/ruby/2.4.0/gems/sbsm-1.3.6/lib/sbsm/session.rb:478:in `to_html'",
 "/var/www/davaz.com/vendor/ruby240/ruby/2.4.0/gems/sbsm-1.3.6/lib/sbsm/session.rb:238:in `block in process_rack'",
 "/var/www/davaz.com/vendor/ruby240/ruby/2.4.0/gems/sbsm-1.3.6/lib/sbsm/session.rb:208:in `synchronize'",
 "/var/www/davaz.com/vendor/ruby240/ruby/2.4.0/gems/sbsm-1.3.6/lib/sbsm/session.rb:208:in `process_rack'",
 "/var/www/davaz.com/vendor/ruby240/ruby/2.4.0/gems/sbsm-1.3.6/lib/sbsm/app.rb:119:in `call'",
 "/var/www/davaz.com/vendor/ruby240/ruby/2.4.0/gems/rack-2.0.1/lib/rack/lint.rb:49:in `_call'",
 "/var/www/davaz.com/vendor/ruby240/ruby/2.4.0/gems/rack-2.0.1/lib/rack/lint.rb:37:in `call'",
 "/var/www/davaz.com/vendor/ruby240/ruby/2.4.0/gems/rack-2.0.1/lib/rack/show_exceptions.rb:23:in `call'",
 "/var/www/davaz.com/vendor/ruby240/ruby/2.4.0/gems/rack-2.0.1/lib/rack/content_length.rb:15:in `call'",
 "/var/www/davaz.com/vendor/ruby240/ruby/2.4.0/gems/rack-2.0.1/lib/rack/static.rb:149:in `call'",
 "/var/www/davaz.com/vendor/ruby240/ruby/2.4.0/gems/rack-2.0.1/lib/rack/common_logger.rb:33:in `call'",
 "/var/www/davaz.com/vendor/ruby240/ruby/2.4.0/gems/rack-2.0.1/lib/rack/tempfile_reaper.rb:15:in `call'",
 "/var/www/davaz.com/vendor/ruby240/ruby/2.4.0/gems/rack-2.0.1/lib/rack/lint.rb:49:in `_call'",
 "/var/www/davaz.com/vendor/ruby240/ruby/2.4.0/gems/rack-2.0.1/lib/rack/lint.rb:37:in `call'",
 "/var/www/davaz.com/vendor/ruby240/ruby/2.4.0/gems/rack-2.0.1/lib/rack/show_exceptions.rb:23:in `call'",
 "/var/www/davaz.com/vendor/ruby240/ruby/2.4.0/gems/rack-2.0.1/lib/rack/common_logger.rb:33:in `call'",
 "/var/www/davaz.com/vendor/ruby240/ruby/2.4.0/gems/rack-2.0.1/lib/rack/chunked.rb:54:in `call'",
 "/var/www/davaz.com/vendor/ruby240/ruby/2.4.0/gems/rack-2.0.1/lib/rack/content_length.rb:15:in `call'",
 "/var/www/davaz.com/vendor/ruby240/ruby/2.4.0/gems/rack-2.0.1/lib/rack/handler/webrick.rb:86:in `service'",
 "/usr/local/ruby-2.4.0/lib/ruby/2.4.0/webrick/httpserver.rb:140:in `service'",
 "/usr/local/ruby-2.4.0/lib/ruby/2.4.0/webrick/httpserver.rb:96:in `run'",
 "/usr/local/ruby-2.4.0/lib/ruby/2.4.0/webrick/server.rb:290:in `block in start_thread'"]

The new generated AdminLinks has a OpenStruct as model class, whereas tooltips is a DaVaz::Model::Oneliner. As the exception comes in the to_html method, I must also look how the corresonding view is generated. Comparing for src/view/communication/oneliners.rb and /mnt/oddb-ci2/git/davaz.com/src/view/communication/links.rb

After adding a self parameter to line 24 of src/view/communicationlinks.rb (span = HtmlGrid::Span.new(model, @session, self) the error NoMethodError: undefined method `selection' for #<DaVaz::Model::ArtObject still showed up. However it could be that the whole functionality was not used for a long time as the last new link is from the year 2006.

After inserting return nil unless defined?(@model.selection) at the top of the method selection(context) in src/view/_partial/select.rb the new element is displayed like this:

Maybe we really have to create a correct view. Making src/view/communication/news.rb and links.rb look even more similar, eg. links.rb was missing @@ require 'view/_partial/list' and require 'util/image_helper'@@

I don't have a good idea what the errors is. Therefore looking at the problem, that an upload of the file is not possible. pry shows me

# src/state/_partial/image.rb @ line 49
[4] pry(#<DaVaz::State::AdminAjaxUploadImage>)> string_io
=> {:filename=>"new_links.png",
 :type=>"image/png",
 :name=>"image_file",
 :tempfile=>#<File:/tmp/RackMultipart20170328-8162-186qd2k.png>,
 :head=>"Content-Disposition: form-data; name=\"image_file\"; filename=\"new_links.png\"\r\n" + "Content-Type: image/png\r\n"}
[11] pry(#<DaVaz::State::AdminAjaxUploadImage>)> string_io[:filename]
=> "new_links.png"
[12] pry(#<DaVaz::State::AdminAjaxUploadImage>)> File.exist? string_io[:filename]
=> false
[16] pry(#<DaVaz::State::AdminAjaxUploadImage>)> img =  Image.from_blob(IO.read( string_io[:tempfile]))
=> [ PNG 572x182 3840x1080+379+254 DirectClass 8-bit 93kb]

Modifying it a little bit more I see that the image file is correctly stored, but it has no effect, because it affects an OpenStruct object and not a new artobject in the status DaVaz::State::AdminAjaxUploadImage

[2] pry(#<DaVaz::State::AdminAjaxUploadImage>)> path
=> "/var/www/davaz.com/doc/resources/uploads/tmp/images/1490709465.png"
[3] pry(#<DaVaz::State::AdminAjaxUploadImage>)> next

From: /var/www/davaz.com/src/state/_partial/image.rb @ line 57 DaVaz::State::AdminAjaxUploadImage#init:

    52:             path = File.join(
    53:               DaVaz::Util::ImageHelper.tmp_image_dir,
    54:               Time.now.to_i.to_s + "." + image.format.downcase
    55:             )
    56:             image.write(path)
 => 57:             obj.tmp_image_path = path
    58:           end
    59:         elsif artobject_id
    60:           DaVaz::Util::ImageHelper.store_upload_image(
    61:             string_io, artobject_id)
    62:           model = OpenStruct.new

[3] pry(#<DaVaz::State::AdminAjaxUploadImage>)> obj.class
=> OpenStruct
[4] pry(#<DaVaz::State::AdminAjaxUploadImage>)> .ls -l /var/www/davaz.com/doc/resources/uploads/tmp/images/1490709465.png
-rw-r--r-- 1 apache apache 96938 Mar 28 15:57 /var/www/davaz.com/doc/resources/uploads/tmp/images/1490709465.png

Found the problem why "Add new element" did not work. We must use the class AdminAddNewElement instead of AdminAjaxAddNewElement

Pushed the commits Replaced load_links by load_site_links, <x>_tooltip_link -> <x>_link and Fix add new item for links

Now returning to the problem why we cannot add a new image. The images are now correctly stored into /var/www/davaz.com/doc/resources/uploads/tmp/images/, but as there is no valid art_object present when the method init of AdminAjaxUploadImage is called, nothing is stored. This is the case for a newly added link and when trying to add new image to an existing link. Deleting a link works okay. Will continue tomorrow.

view · edit · sidebar · attach · print · history
Page last modified on March 28, 2017, at 05:44 PM