From 0deb4c4cccb4b1ed8eb76476127a6e081e8c1785 Mon Sep 17 00:00:00 2001 From: Georg G Date: Tue, 5 Jan 2016 20:54:38 +0100 Subject: [PATCH] added export view/controller/routes --- app/controllers/user_controller.rb | 19 +++++++++++++++- app/views/user/export.haml | 35 ++++++++++++++++++++++++++++++ config/routes.rb | 2 ++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 app/views/user/export.haml diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 39d971a0..104062c6 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -1,7 +1,7 @@ class UserController < ApplicationController include ThemeHelper - before_filter :authenticate_user!, only: %w(edit update edit_privacy update_privacy edit_theme update_theme preview_theme delete_theme data) + before_filter :authenticate_user!, only: %w(edit update edit_privacy update_privacy edit_theme update_theme preview_theme delete_theme data export begin_export) def show @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).first! @@ -156,4 +156,21 @@ class UserController < ApplicationController end redirect_to edit_user_theme_path end + + def export + if current_user.export_processing + flash[:info] = 'An export is currently in progress for this account.' + end + end + + def begin_export + if current_user.can_export? + ExportWorker.perform_async(current_user.id) + flash[:success] = 'Your account is currently being exported. This will take a little while.' + else + flash[:error] = 'Nice try, kid.' + end + + redirect_to user_export_path + end end diff --git a/app/views/user/export.haml b/app/views/user/export.haml new file mode 100644 index 00000000..363a5138 --- /dev/null +++ b/app/views/user/export.haml @@ -0,0 +1,35 @@ +- provide(:title, generate_title("Export")) +.container.j2-page + = render 'settings_tabs' + .col-md-9.col-xs-12.col-sm-8 + = render 'layouts/messages' + .panel.panel-default + .panel-body + %h2 Export your data + %p + Blah blah blah introduction text because of announced + = succeed "," do + %a{href: "http://blog.retrospring.net/saying-goodbye/"} shutdown and everything + and also some more text to fill this. Oh well, just push that + button below. + %p + Please note that you can only export your data once a week. Exporting your data + will take a while, so please be patient. You will receive a question once exporting + is done. + - if current_user.can_export? + %form{action: begin_user_export_path, method: 'POST'} + %p.centre + %button#export-btn.btn.btn-lg.btn-primary{type: :submit} Export + = hidden_field_tag :authenticity_token, form_authenticity_token + - else + %p.centre + %button.btn.btn-lg.btn-primary.disabled{disabled: :disabled} Export + %p + - if current_user.export_url.nil? + Once exporting your account is done, a download link will appear here. + - else + Here is your export from + = succeed ':' do + = current_user.export_created_at + %a{href: current_user.export_url} + = File.basename current_user.export_url diff --git a/config/routes.rb b/config/routes.rb index 3e610c79..8723e78b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -74,6 +74,8 @@ Rails.application.routes.draw do match '/settings/privacy', to: 'user#update_privacy', via: :patch, as: :update_user_privacy match '/settings/data', to: 'user#data', via: :get, as: :user_data + match '/settings/export', to: 'user#export', via: :get, as: :user_export + match '/settings/export', to: 'user#begin_export', via: :post, as: :begin_user_export namespace :ajax do match '/ask', to: 'question#create', via: :post, as: :ask