From 20052c7dd295464c7782350628701675b1f07db7 Mon Sep 17 00:00:00 2001
From: Frederic Guillot <fred@kanboard.net>
Date: Sun, 15 May 2016 21:20:46 -0400
Subject: User import is now a popover

---
 app/Controller/Config.php               |  2 +-
 app/Controller/Export.php               |  2 +-
 app/Controller/FileViewer.php           |  2 +-
 app/Controller/TaskImport.php           |  2 +-
 app/Controller/UserImport.php           | 66 ----------------------------
 app/Controller/UserImportController.php | 77 +++++++++++++++++++++++++++++++++
 6 files changed, 81 insertions(+), 70 deletions(-)
 delete mode 100644 app/Controller/UserImport.php
 create mode 100644 app/Controller/UserImportController.php

(limited to 'app/Controller')

diff --git a/app/Controller/Config.php b/app/Controller/Config.php
index ebb541d2..deafd05b 100644
--- a/app/Controller/Config.php
+++ b/app/Controller/Config.php
@@ -176,7 +176,7 @@ class Config extends BaseController
     public function downloadDb()
     {
         $this->checkCSRFParam();
-        $this->response->withDownload('db.sqlite.gz');
+        $this->response->withFileDownload('db.sqlite.gz');
         $this->response->binary($this->config->downloadDatabase());
     }
 
diff --git a/app/Controller/Export.php b/app/Controller/Export.php
index f5783b72..7e1d2fdc 100644
--- a/app/Controller/Export.php
+++ b/app/Controller/Export.php
@@ -29,7 +29,7 @@ class Export extends BaseController
 
         if ($from && $to) {
             $data = $this->$model->$method($project['id'], $from, $to);
-            $this->response->withDownload($filename.'.csv');
+            $this->response->withFileDownload($filename.'.csv');
             $this->response->csv($data);
         }
 
diff --git a/app/Controller/FileViewer.php b/app/Controller/FileViewer.php
index a990e12a..52ff0d0e 100644
--- a/app/Controller/FileViewer.php
+++ b/app/Controller/FileViewer.php
@@ -123,7 +123,7 @@ class FileViewer extends BaseController
     {
         try {
             $file = $this->getFile();
-            $this->response->withDownload($file['name']);
+            $this->response->withFileDownload($file['name']);
             $this->objectStorage->output($file['path']);
         } catch (ObjectStorageException $e) {
             $this->logger->error($e->getMessage());
diff --git a/app/Controller/TaskImport.php b/app/Controller/TaskImport.php
index 5dbf8678..5e37fb2f 100644
--- a/app/Controller/TaskImport.php
+++ b/app/Controller/TaskImport.php
@@ -69,7 +69,7 @@ class TaskImport extends BaseController
      */
     public function template()
     {
-        $this->response->withDownload('tasks.csv');
+        $this->response->withFileDownload('tasks.csv');
         $this->response->csv(array($this->taskImport->getColumnMapping()));
     }
 }
diff --git a/app/Controller/UserImport.php b/app/Controller/UserImport.php
deleted file mode 100644
index b99e56a0..00000000
--- a/app/Controller/UserImport.php
+++ /dev/null
@@ -1,66 +0,0 @@
-<?php
-
-namespace Kanboard\Controller;
-
-use Kanboard\Core\Csv;
-
-/**
- * User Import controller
- *
- * @package  controller
- * @author   Frederic Guillot
- */
-class UserImport extends BaseController
-{
-    /**
-     * Upload the file and ask settings
-     *
-     */
-    public function step1(array $values = array(), array $errors = array())
-    {
-        $this->response->html($this->helper->layout->app('user_import/step1', array(
-            'values' => $values,
-            'errors' => $errors,
-            'max_size' => ini_get('upload_max_filesize'),
-            'delimiters' => Csv::getDelimiters(),
-            'enclosures' => Csv::getEnclosures(),
-            'title' => t('Import users from CSV file'),
-        )));
-    }
-
-    /**
-     * Process CSV file
-     *
-     */
-    public function step2()
-    {
-        $values = $this->request->getValues();
-        $filename = $this->request->getFilePath('file');
-
-        if (! file_exists($filename)) {
-            $this->step1($values, array('file' => array(t('Unable to read your file'))));
-        }
-
-        $csv = new Csv($values['delimiter'], $values['enclosure']);
-        $csv->setColumnMapping($this->userImport->getColumnMapping());
-        $csv->read($filename, array($this->userImport, 'import'));
-
-        if ($this->userImport->counter > 0) {
-            $this->flash->success(t('%d user(s) have been imported successfully.', $this->userImport->counter));
-        } else {
-            $this->flash->failure(t('Nothing have been imported!'));
-        }
-
-        $this->response->redirect($this->helper->url->to('userImport', 'step1'));
-    }
-
-    /**
-     * Generate template
-     *
-     */
-    public function template()
-    {
-        $this->response->withDownload('users.csv');
-        $this->response->csv(array($this->userImport->getColumnMapping()));
-    }
-}
diff --git a/app/Controller/UserImportController.php b/app/Controller/UserImportController.php
new file mode 100644
index 00000000..b3cb52d1
--- /dev/null
+++ b/app/Controller/UserImportController.php
@@ -0,0 +1,77 @@
+<?php
+
+namespace Kanboard\Controller;
+
+use Kanboard\Core\Csv;
+
+/**
+ * User Import controller
+ *
+ * @package  Kanboard\Controller
+ * @author   Frederic Guillot
+ */
+class UserImportController extends BaseController
+{
+    /**
+     * Upload the file and ask settings
+     *
+     * @param array $values
+     * @param array $errors
+     */
+    public function show(array $values = array(), array $errors = array())
+    {
+        $this->response->html($this->template->render('user_import/show', array(
+            'values' => $values,
+            'errors' => $errors,
+            'max_size' => ini_get('upload_max_filesize'),
+            'delimiters' => Csv::getDelimiters(),
+            'enclosures' => Csv::getEnclosures(),
+        )));
+    }
+
+    /**
+     * Submit form
+     */
+    public function save()
+    {
+        $values = $this->request->getValues();
+        $filename = $this->request->getFilePath('file');
+
+        if (! file_exists($filename)) {
+            $this->flash->failure(t('Unable to read your file'));
+        } else {
+            $this->importFile($values, $filename);
+        }
+
+        $this->response->redirect($this->helper->url->to('user', 'index'));
+    }
+
+    /**
+     * Generate template
+     *
+     */
+    public function template()
+    {
+        $this->response->withFileDownload('users.csv');
+        $this->response->csv(array($this->userImport->getColumnMapping()));
+    }
+
+    /**
+     * Process file
+     *
+     * @param array $values
+     * @param       $filename
+     */
+    private function importFile(array $values, $filename)
+    {
+        $csv = new Csv($values['delimiter'], $values['enclosure']);
+        $csv->setColumnMapping($this->userImport->getColumnMapping());
+        $csv->read($filename, array($this->userImport, 'import'));
+
+        if ($this->userImport->counter > 0) {
+            $this->flash->success(t('%d user(s) have been imported successfully.', $this->userImport->counter));
+        } else {
+            $this->flash->failure(t('Nothing have been imported!'));
+        }
+    }
+}
-- 
cgit v1.2.3