Commit d3d7f0b4 authored by Sebastian Castro's avatar Sebastian Castro

Improve Saas home page list

parent 6f62ba07
......@@ -44,15 +44,15 @@ class ProjectController extends AbstractSaasController
{
if (!$this->isAuthorized()) return $this->redirectToRoute('biopen_homepage');
$odm = $this->get('doctrine_mongodb')->getManager();
$domain = $request->request->get('form')['domainName'];
$odm = $this->get('doctrine_mongodb')->getManager();
$domain = $request->request->get('form')['domainName'];
if ($domain) // if submiting the form
{
$existingProject = $odm->getRepository(Project::class)->findOneByDomainName($domain);
// fix a bug sometime the form says that the project already exist but actually we just created it
// but it has not been initialized
// so redirect to initialize project
if ($existingProject && $existingProject->getDataSize() == 0)
if ($existingProject && $existingProject->getDataSize() == 0)
return $this->redirect($this->generateUrlForProject($existingProject, 'biopen_saas_initialize_project'));
}
......@@ -61,11 +61,11 @@ class ProjectController extends AbstractSaasController
$projectForm = $this->createFormBuilder($project)
->add('name', null, array('required' => true))
->add('domainName', null, array('required' => true))
->getForm();
->getForm();
if ($projectForm->handleRequest($request)->isValid())
{
$odm->persist($project);
{
$odm->persist($project);
$odm->flush();
// initialize commands
$commands = (new GoGoMainCommand())->scheduledCommands;
......@@ -81,16 +81,16 @@ class ProjectController extends AbstractSaasController
// Switch to new project ODM
$projectOdm = $this->getOdmForProject($project);
// Clone the root configuration into the new project
// Due to conflicts between ODM, we get the Configuration froma Json API, and convert it to an object
$baseUrl = $this->getParameter('base_url');
if ($baseUrl == 'saas.localhost') $baseUrl = "127.0.0.1"; # Fixs for docker in localhost
$configUrl = 'http://' . $baseUrl . $this->generateUrl('biopen_api_configuration');
$rootConfigToCopy = json_decode(file_get_contents($configUrl));
$rootConfigToCopy = json_decode(file_get_contents($configUrl));
$rootConfigToCopy->appName = $project->getName();
$rootConfigToCopy->appBaseLine = "";
$rootConfigToCopy->dbName = $project->getDbName();
$rootConfigToCopy->dbName = $project->getDbName();
// Duplicate configuration
$confLoader = new LoadConfiguration();
$configuration = $confLoader->load($projectOdm, $this->container, $rootConfigToCopy, $request->request->get('contrib'));
......@@ -103,10 +103,10 @@ class ProjectController extends AbstractSaasController
$mains = array(
array('Catégorie 1' , 'fa fa-recycle' , '#98a100'),
array('Catégorie 2' , 'fa fa-home' , '#7e3200'),
array('Catégorie 2' , 'fa fa-home' , '#7e3200'),
);
foreach ($mains as $key => $main)
foreach ($mains as $key => $main)
{
$new_main = new Option();
$new_main->setName($main[0]);
......@@ -115,26 +115,26 @@ class ProjectController extends AbstractSaasController
$new_main->setIsFixture(true);
$mainCategory->addOption($new_main);
}
$projectOdm->flush(); // flush before taxonomy creating otherwise strange bug creating option with only DBRef
$projectOdm->flush(); // flush before taxonomy creating otherwise strange bug creating option with only DBRef
$taxonomy = new Taxonomy();
$projectOdm->persist($taxonomy);
$projectOdm->flush();
$projectOdm->persist($taxonomy);
$projectOdm->flush();
$projectOdm->getSchemaManager()->updateIndexes();
$projectOdm->getSchemaManager()->updateIndexes();
$url = $this->generateUrlForProject($project, 'biopen_saas_initialize_project');
return $this->redirect($url);
}
$config = $odm->getRepository('BiopenCoreBundle:Configuration')->findConfiguration();
return $this->render('@BiopenSaasBundle/projects/create.html.twig', ['form' => $projectForm->createView(), 'config' => $config]);
}
public function homeAction()
{
{
if (!$this->isAuthorized()) return $this->redirectToRoute('biopen_homepage');
$odm = $this->get('doctrine_mongodb')->getManager();
......@@ -142,37 +142,37 @@ class ProjectController extends AbstractSaasController
$config = $odm->getRepository('BiopenCoreBundle:Configuration')->findConfiguration();
$projects = $repository->findBy([], ['id' => 'DESC']);
$projects = $repository->findBy([], ['dataSize' => 'DESC']);
foreach ($projects as $project) {
$project->setHomeUrl($this->generateUrlForProject($project));
}
return $this->render('@BiopenSaasBundle/home.html.twig', array('projects' => $projects, 'config' => $config));
}
return $this->render('@BiopenSaasBundle/home.html.twig', array('projects' => $projects, 'config' => $config));
}
public function initializeAction(Request $request)
public function initializeAction(Request $request)
{
$odm = $this->get('doctrine_mongodb')->getManager();
$users = $odm->getRepository('BiopenCoreBundle:User')->findAll();
if (count($users) > 0) return $this->redirectToRoute('biopen_homepage');
$userManager = $this->container->get('fos_user.user_manager');
$user = $userManager->createUser();
$user = $userManager->createUser();
$form = $this->get('form.factory')->create(RegistrationFormType::class, $user);
if ($form->handleRequest($request)->isValid()) {
$user = $form->getData();
$user->setEnabled(true);
$user->setRoles(array('ROLE_SUPER_ADMIN','ROLE_ADMIN', 'ROLE_SONATA_ADMIN'));
$userManager->updateUser($user, true);
$userManager->updateUser($user, true);
$this->get('session')->getFlashBag()->add('success', "<b>Bienvenue dans votre espace Administrateur !</b></br>
L'aventure commence tout juste pour vous, il vous faut maintenant commencer à configurer votre site :)</br>
Je vous invite à consulter les <a target='_blank' href='https://video.colibris-outilslibres.org/video-channels/gogocarto_channel/videos'>vidéos tutoriels</a> pour vous apprendre à configurer votre carte !</br>
Si vous avez des questions (après avoir regardé ces vidéos) rendez vous sur <a target='_blank' href='https://chat.lescommuns.org/channel/gogocarto'>le chat #gogocarto</a> !");
$response = $this->redirectToRoute('sonata_admin_dashboard');
$response = $this->redirectToRoute('sonata_admin_dashboard');
$this->authenticateUser($user, $response);
......@@ -195,7 +195,7 @@ class ProjectController extends AbstractSaasController
}
// The project is being deleted by the owner
public function deleteCurrProjectAction()
public function deleteCurrProjectAction()
{
$saasHelper = new SaasHelper();
$dbname = $saasHelper->getCurrentProjectCode();
......@@ -204,10 +204,10 @@ class ProjectController extends AbstractSaasController
$process->start();
$url = $this->generateUrl('biopen_project_delete_saas_record', ['dbName' => $dbname], true);
$url = str_replace($dbname . '.', '', $url);
return $this->redirect($url);
return $this->redirect($url);
}
public function deleteSaasRecordAction($dbName)
public function deleteSaasRecordAction($dbName)
{
$dm = $this->get('doctrine_mongodb')->getManager();
$command = "mongo --eval 'db.getMongo().getDBNames().indexOf(\"{$dbName}\")'";
......@@ -220,7 +220,7 @@ class ProjectController extends AbstractSaasController
$dm->remove($project);
$dm->flush();
}
return $this->redirectToRoute('biopen_homepage');
}
}
......@@ -14,7 +14,7 @@
</section>
<section class="projects">
<h2>Liste des projets déjà créés</h2>
<h2>Liste des projets déjà créés ({{ projects|length }})</h2>
<div class="project-list">
{% for row in projects|batch(3) %}
<div class="row">
......@@ -26,8 +26,8 @@
{% else %}
<img class="project-logo default" src="{{ asset('assets/img/default-icon.png') }}">
{% endif %}
<div class="project-content">
<div class="project-content">
<div class="name">{{ project.name|capitalize }}</div>
<div class="data-size gogo-bg-primary">{{ project.dataSize }}<span class="icon gogo-icon-marker-symbol"></span></div>
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment