diff --git a/README.md b/README.md index 321cc922..db00ac0d 100644 --- a/README.md +++ b/README.md @@ -284,7 +284,7 @@ The Search Filters section shows your chosen search criteria. - Click “Export Questions” and select “XML” -This will download an `.xml` file (e.g. `questions-2023-12-13_15_38_01_508.classic-question-canvas.qti.xml`). To upload that file into Canvass you will need to convert the downloaded XML file into a `.zip` file. The way to do this varies by operating system. +This will download an `.xml` file (e.g. `questions-2023-12-13_15_38_01_508.classic-question-canvas.qti.xml`). To upload that file into Canvas you will need to convert the downloaded XML file into a `.zip` file. The way to do this varies by operating system. As of <2023-12-13 Wed> we export into a “classic question” format; the rationalization being two fold: @@ -305,7 +305,7 @@ In the `Rails` console run the following: User.create!(email: "", password: "") ``` -### Reseting Questions and Data +### Resetting Questions and Data Over the course of testing and experimenting, you might want to reset the questions. diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 4697c96f..a9b17747 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -22,7 +22,7 @@ def index # conversations with the client, we're looking to only export classic (as you can migrate a # classic question to new format). This filename is another "helpful clue" and introduces # later considerations for what the file format might be. - filename = "questions-#{now.strftime('%Y-%m-%d_%H:%M:%S:%L')}.classic-question-canvas.qti.xml" + filename = "#{export_filename(now)}.classic-question-canvas.qti.xml" @questions = Question.filter(**filter_values) if any_question_has_images? @@ -35,8 +35,35 @@ def index end end + # download bookmarked questions + def download + @questions = Question.where(id: Bookmark.select(:question_id)) + case params[:format] + when 'md' + md_download + when 'txt' + text_download + else + redirect_to authenticated_root_path, alert: t('.alert') + end + end + private + def export_filename(now = Time.current) + "questions-#{now.strftime('%Y-%m-%d_%H:%M:%S:%L')}" + end + + def text_download + content = @questions.map { |question| QuestionFormatter::PlainTextService.new(question).format_content }.join('') + send_data content, filename: "#{export_filename}.txt", type: 'text/plain' + end + + def md_download + content = @questions.map { |question| QuestionFormatter::MarkdownService.new(question).format_content }.join('') + send_data content, filename: "#{export_filename}.md", type: 'text/plain' + end + def any_question_has_images? @questions.any? { |question| question.images.any? } end diff --git a/app/javascript/components/ui/Footer/index.jsx b/app/javascript/components/ui/Footer/index.jsx index 7c64ed6e..01baa6f6 100644 --- a/app/javascript/components/ui/Footer/index.jsx +++ b/app/javascript/components/ui/Footer/index.jsx @@ -11,7 +11,7 @@ const Footer = () => { Settings diff --git a/app/javascript/components/ui/Search/SearchBar.jsx b/app/javascript/components/ui/Search/SearchBar.jsx index 5cd72abf..b1380db3 100644 --- a/app/javascript/components/ui/Search/SearchBar.jsx +++ b/app/javascript/components/ui/Search/SearchBar.jsx @@ -134,7 +134,7 @@ const SearchBar = (props) => { {query && (