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

Add import from json #90

Open
dreamos82 opened this issue Oct 3, 2020 · 1 comment
Open

Add import from json #90

dreamos82 opened this issue Oct 3, 2020 · 1 comment

Comments

@dreamos82
Copy link
Owner

Add import of parameters from json

@dreamos82
Copy link
Owner Author

dreamos82 commented Oct 3, 2020

(The following comment was a reply to someone that commented he wanted to help implementing it, but probably frightened out and deleted the comment XD)

Hi,
Yeah i'll try to explain more or less what is needed for it.

Ok to be honest is little bit trickier than a good first issue. But i can try to help you doing it in the process.

So at the moment only one format is supported for import: CSV.

Little bit of background information about how it works. One of the problems with browser extension is that they are closed automatically when they lose focus, and all the content is destroyed, so if you show an open file dialog from a chrome extension, it get the focus, causing the extension popup to be closed, and all the code destroyed, so when you click the open button nothing happens, because the code that called it is no longer existing, if you want a more detailed explanation you can check my question on stackoverflow i posted several years ago, when i faced this issue: https://stackoverflow.com/questions/26884140/open-import-file-in-a-chrome-extension

So this is more or less what is needed to be done
Do like it is done in the export option: when the use click on import it should show options for the format to be used (So it will be CSV and JSON), it involve editing this portion of code

	} else if(e.target.id=="import"){
		get_current_tab(function(tab){
			var externalScript = "src/content_script.js";
			if(!isChrome){
				externalScript = "content_script.js"
			}
			browser_handler.tabs.executeScript(tab.id, {file: externalScript}, function(element){});
		});

Probably you should do something similar to the export case, and add a function appendImportOptions (or maybe just refactor the existing one to be more generic and usable in both cases, import/export

I suggest you to have a look how the export flow works, because part of the flow for import will be similar. I think we will have to create a new function similar to export_parameters_list, https://github.com/dreamos82/chrome_parameters/blob/master/src/popup.js#L244 but what will do in this case is one of the following:

  • For each new type supported (at the moment will be CSV, xml) create a content_script_format.js file (the code will be similar to the code in the content_script.js file, and in the export_parameters_list the externalScript variable will depend on the type selected, so if the user click xml, it will call the newly created content_script_xml.js. This file will contain the actual code for import.
  • Another option is to add a file filter to the open dialog (pretty easy to do), and then in the content_script.js file, once the file is opened, check the exntesion and depending on the extension of the file call the custom import code (actually i think that this could be the easiest way).

If you want to do this task, feel free to ask all the question, it looks hard, but i think it will be less than 50 lines of code.

I strongly suggest you to understand how the export mechanism works, since we are going to have a similar flow.
And reading that stackoverrflow question and its accepted answer will give help you understand how it actually work the import process. (that actually is a workaround XD, but there are no alt5ernatives)

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

No branches or pull requests

1 participant