User import is now a popover

This commit is contained in:
Frederic Guillot
2016-05-15 21:20:46 -04:00
parent 4eaab1f6da
commit 20052c7dd2
10 changed files with 80 additions and 74 deletions

View File

@@ -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());
}

View File

@@ -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);
}

View File

@@ -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());

View File

@@ -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()));
}
}

View File

@@ -7,40 +7,63 @@ use Kanboard\Core\Csv;
/**
* User Import controller
*
* @package controller
* @package Kanboard\Controller
* @author Frederic Guillot
*/
class UserImport extends BaseController
class UserImportController extends BaseController
{
/**
* Upload the file and ask settings
*
* @param array $values
* @param array $errors
*/
public function step1(array $values = array(), array $errors = array())
public function show(array $values = array(), array $errors = array())
{
$this->response->html($this->helper->layout->app('user_import/step1', 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(),
'title' => t('Import users from CSV file'),
)));
}
/**
* Process CSV file
*
* Submit form
*/
public function step2()
public function save()
{
$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'))));
$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'));
@@ -50,17 +73,5 @@ class UserImport extends BaseController
} 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()));
}
}