Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems removing topics: areas change from topic without notice #233

Open
numeroteca opened this issue Sep 16, 2019 · 1 comment
Open
Labels

Comments

@numeroteca
Copy link
Member

numeroteca commented Sep 16, 2019

I had forked a thread (http://pageonex.com/numeroteca/partidos-y-elecciones-20d/ to http://pageonex.com/numeroteca/partidos-y-elecciones-20d/) to rework one of the topics. I needed to erase all but one of the topics and I discover these bugs (I'll update this when I find more problems or can give specifics):

Given a thread with 4 topics (A, B, C, D) when the first topic (A) while editing-updating a thread:

  • Also the last topic (D) is removed.
  • Areas in topic A and B are removed.
  • Areas in topic C are converted to topic B; Areas in topic D are converted to topic C.

I made a test thread to see this behavior. To make it easier the thread I have just one day coded, where the full front page is assigned to a topic that has the name of that very same newspaper.

Original thread:
Screenshot from 2019-09-16 13-51-30

Thread after removing first topic:
Screenshot from 2019-09-16 13-52-55

I repeated the process with 5 topics with the same results:

  • When the first topic (A) is removed while editing-updating a thread, also the last one (E) is removed.
  • Areas in topic A and B are removed.
  • Areas in topic C are converted to topic B; Areas in topic D are converted to topic C; Areas in topic E are converted to topic D.

What is causing this problem?

From the topic template (/app/views/threads/_topic_form.html.erb) the delete topic button is formed with the class .delete_topic:

<div class="controls">
	<%= hidden_field_tag "topic_deleted_#{index}" %>
	<a id="delete_topic_<%= index %>" class="btn delete_topic">Delete Code/Topic</a>
</div>

It is used with this javascript /app/assets/javascripts/topic_form.js script to detect where the click happens and change the id of the topic with a particular index:

 var initDelete = function () {
    $('.delete_topic').unbind('click');
    $('.delete_topic').click(function () {
      var index = $(this).attr('id').substr('delete_topic_'.length);
      $("#topic_deleted_" + index).val('1');
      $("#topic_" + index).hide();
    });
  }

When you click in a delete topic button value="1" is added:
<input id="topic_deleted_0" name="topic_deleted_0" type="hidden" value="1">

so the ruby script /app/controllers/threads_controller.rb is able to detect this and destroy the Topic (called code in the project):

# Fetch existing code from database by id and update
code = @thread.codes.find_by_id(id)
if params["topic_deleted_#{index}"] == '1'
  code.destroy()
else

It seems there is a problem with the selection of these topics ids.

@numeroteca numeroteca added the bug label Sep 16, 2019
@numeroteca
Copy link
Member Author

numeroteca commented Sep 16, 2019

Either removing this part of the code:
https://github.com/montera34/pageonex/blob/master/app/controllers/threads_controller.rb#L200-L212

				# New code
				else
					# Fetch existing code from database by id and update
					code = @thread.codes.find_by_id(id)
					if params["topic_deleted_#{index}"] == '1'
						code.destroy()
					else
						unless code_name.empty?
							code.update_attributes({code_text: code_name,
								color: params["topic_color_#{index}"],
								code_description: params["topic_description_#{index}"]})
						end
					end

or this
https://github.com/montera34/pageonex/blob/master/app/controllers/threads_controller.rb#L215-L226

			@thread.codes.to_enum.with_index.each do |code,index|
				code_name = params["topic_name_#{index}"]
				if params["topic_deleted_#{index}"] == '1'
					code.destroy()
				else #To Do: it should save the new codes created
					unless code_name.empty?
						code.update_attributes({code_text: code_name,
							color: params["topic_color_#{index}"],
							code_description: params["topic_description_#{index}"]})
					end
				end
			end

fixes it. It seems there are two codes making a similar/same thing and causes the removal of two codes (not clear to me exactly why). Check #61, maybe relevant related info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant