Commit 40cf00ca authored by Thomas Citharel's avatar Thomas Citharel 🌲

Merge branch 'modules' into 'framasites'

Better choice page

Closes #16

See merge request framasoft/framasite!5
parents a05d81fc 92e4c74e
Pipeline #25785 passed with stage
in 4 minutes and 4 seconds
# This file is a template, and might need editing before it works on your project.
# Select image from https://hub.docker.com/_/php/
image: tetraweb/php
image: php:7.1
# Select what we should cache between builds
cache:
......@@ -34,7 +34,7 @@ test:
- cp app/config/tests/parameters_test.pgsql.yml app/config/parameters_test.yml
- curl -sS https://getcomposer.org/installer | php
- SYMFONY_ENV=test php composer.phar install -o --no-interaction --no-progress --prefer-dist
- npm install
# - npm install TODO: Activate me later
- git clone https://framagit.org/framasoft/framasite-grav grav
- mkdir blog/users -p
- mkdir wiki/users -p
......
......@@ -188,6 +188,42 @@ $(document).ready(() => {
subdomain.on('invalid', () => {
subdomain.parent().addClass('has-error');
});
// Site modules
const blogHomepageSelector = $('#blog_homepage');
let homepageChoice = [];
let modulesLabels = [];
const blogHomepages = document.getElementById('blog_homepage').options;
for (let option of blogHomepages) {
modulesLabels[option.value] = option.text;
}
let checkboxesValues = [];
const checkboxes = $('input[name*="siteModules"]');
checkboxes.change((checkbox) => {
if (checkbox.target.checked) {
homepageChoice[checkbox.target.value] = $(checkbox.target).parent().text();
} else {
homepageChoice.splice(checkbox.target.value);
}
updateHomePageChoice();
});
function updateHomePageChoice() {
blogHomepageSelector.empty();
homepageChoice.forEach((option, i) => {
console.log(option);
console.log(i);
let opt = document.createElement('option');
opt.text = option;
opt.value = i;
blogHomepageSelector.get(0).add(opt, null);
});
if (homepageChoice.length > 2) {
blogHomepageSelector.parent().parent().removeClass('hidden');
} else {
blogHomepageSelector.parent().parent().addClass('hidden');
}
}
}
$('.passwordToCheck').on('change', () => {
......
......@@ -162,6 +162,11 @@ site:
type:
blog: Site
wiki: Wiki
module:
blog: Blog
cv: CV
one_page: Page unique
one_page_carrousel: Page unique avec carrousel
shortcuts:
admin: Modifier mon %type%
add_user: Ajouter un utilisateur
......@@ -206,6 +211,12 @@ site:
label: Mots-clés du site
desc: Quelques mots clés associés à votre site, séparés par des virgules
placeholder: "Par exemple : Champignons, Quercy, Mycologie"
site_modules:
label: Modules du site
desc: Il s'agit des modules que votre site doit contenir lorsque nous allons le créer. Vous pourrez bien entendu en changer par la suite.
site_homepage:
label: Page d'accueil du site
desc: Il s'agit de la page d'accueil de votre site
policy:
label: Gestion des contrôles d'accès
type:
......@@ -424,13 +435,19 @@ help:
introjs:
next: Suivant
prev: Précédent
blog:
create: Vous pouvez créer un site web…
admin: Ce lien vous emmène sur l'administration de votre site, pour créer vos premières pages
manage: Ici vous pouvez gérer certaines choses comme les utilisateurs de votre site et les domaines attachés au site
wiki:
create: …ou un wiki !
create: …ou un wiki pour partager vos connaissances…
site:
blog:
create: Vous pouvez créer un blog…
cv:
create: …ou bien une page pour vous présenter…
one_page:
create: …ou enfin une page pour présenter simplement votre projet ou votre activité
personalize:
create: Si vous avez les connaissances nécessaires, vous pouvez composer vous même votre site, en choisissant les modules (Blog, CV, Page unique,...) activés et la page d'accueil si vous avez plus d'un module.
admin: Ce lien vous emmène sur l'administration de votre site, pour créer vos premières pages
manage: Ici vous pouvez gérer certaines choses comme les utilisateurs de votre site et les domaines attachés au site
create: Vous pouvez créer jusqu'à 20 sites et 20 wikis…
new:
subdomain: "Ce sous-domaine sera l'URL à laquelle sera accessible votre site, comme par exemple : <em>https://champignons-quercy.frama.site</em>"
......
......@@ -17,6 +17,24 @@
<small class="help-block">{{ 'site.new.informations.site_keywords.desc' | trans }}</small>
</div>
</div>
<div class="form-group {% if not show_modules %}hidden{% endif %}" data-intro="{{ 'help.site.new.modules' | trans }}">
{{ form_errors(form.siteModules) }}
{{ form_label(form.siteModules) }}
<div class="col-sm-10">
{{ form_widget(form.siteModules) }}
<small class="help-block">{{ 'site.new.informations.site_modules.desc' | trans }}</small>
</div>
</div>
<div class="form-group hidden" data-intro="{{ 'help.site.new.homepage' | trans }}">
{{ form_errors(form.homepage) }}
{{ form_label(form.homepage) }}
<div class="col-sm-10">
{{ form_widget(form.homepage) }}
<small class="help-block">{{ 'site.new.informations.site_homepage.desc' | trans }}</small>
</div>
</div>
{% endblock %}
{% block user %}
......
......@@ -109,14 +109,77 @@ class AsyncAccountGrav extends AbstractMakeAccount implements AsyncAccountInterf
$fs->symlink( $this->enginePath . '/user/themes/', $this->accountsPath . '/' . $this->site->getSubdomain() . '/user/themes');
$this->logger->info("Created theme symlink for " . $this->site->getSubdomain());
$customHomePage = null;
/** Pages */
$this->rcopy($this->enginePath . '/user/pages/', $this->accountsPath . '/' . $this->site->getSubdomain() . '/user/pages/');
if (null === $this->site->getSiteModules() || empty($this->site->getSiteModules())) { // if we have no selections on modules, give them all
$this->rcopy(
$this->enginePath . '/user/pages/',
$this->accountsPath . '/' . $this->site->getSubdomain() . '/user/pages/'
);
} else {
/** Copy common things */
$this->rcopy(
$this->enginePath . '/user/pages/common/',
$this->accountsPath . '/' . $this->site->getSubdomain() . '/user/pages/common'
);
$this->rcopy(
$this->enginePath . '/user/pages/06.contact/',
$this->accountsPath . '/' . $this->site->getSubdomain() . '/user/pages/06.contact'
);
/**
* For each module, give what we need
*/
foreach ($this->site->getSiteModules() as $module) {
switch ($module) {
case Blog::MODULE_BLOG:
$this->rcopy(
$this->accountsPath . '/demo-blog/user/pages/04.blog/',
$this->accountsPath . '/' . $this->site->getSubdomain() . '/user/pages/04.blog'
);
$customHomePage = '/blog';
break;
case Blog::MODULE_CV:
$this->rcopy(
$this->accountsPath . '/demo-cv/user/pages/05.a-propos/',
$this->accountsPath . '/' . $this->site->getSubdomain() . '/user/pages/05.a-propos'
);
$customHomePage = '/a-propos';
break;
case Blog::MODULE_SINGLE_PAGE:
$this->rcopy(
$this->accountsPath . '/demo-page/user/pages/02.page_simple/',
$this->accountsPath . '/' . $this->site->getSubdomain() . '/user/pages/02.page_simple'
);
$customHomePage = '/page_simple';
break;
case Blog::MODULE_SINGLE_PAGE_CARROUSEL:
// disable this for now
break;
default:
break;
}
}
/**
* Set homepage for module
*/
}
/** Data */
$this->rcopy($this->enginePath . '/user/data/', $this->accountsPath . '/' . $this->site->getSubdomain() . '/user/data/');
/** Config */
$fs->copy($this->enginePath . '/user/config/system.yaml', $this->accountsPath . '/' . $this->site->getSubdomain() . '/user/config/system.yaml');
$systemFilePath = $this->accountsPath . '/' . $this->site->getSubdomain() . '/user/config/system.yaml';
$fs->copy($this->enginePath . '/user/config/system.yaml', $systemFilePath);
if (null != $customHomePage) {
$system = Yaml::parse(file_get_contents($systemFilePath));
$system['home']['alias'] = $customHomePage;
file_put_contents($systemFilePath, Yaml::dump($system));
}
$fs->symlink($this->enginePath . '/user/config/media.yaml', $this->accountsPath . '/' . $this->site->getSubdomain() . '/user/config/media.yaml');
$this->rcopy($this->enginePath . '/user/config/plugins/', $this->accountsPath . '/' . $this->site->getSubdomain() . '/user/config/plugins/');
}
......
......@@ -99,11 +99,12 @@ class SiteController extends Controller
/**
* Create a new blog
*
* @Route("/site/new/blog", name="new-blog")
* @Route("/site/new/site/{type}", name="new-blog", defaults={"type": null})
* @param Request $request
* @param string|null $type
* @return Response
*/
public function newBlogAction(Request $request): Response
public function newBlogAction(Request $request, string $type = null): Response
{
$user = $this->getUser();
......@@ -117,6 +118,22 @@ class SiteController extends Controller
$site = new Blog();
if (null != $type) {
switch ($type) {
case 'blog':
$site->setSiteModules([Blog::MODULE_BLOG]);
break;
case 'cv':
$site->setSiteModules([Blog::MODULE_CV]);
break;
case 'single-page':
$site->setSiteModules([Blog::MODULE_SINGLE_PAGE]);
break;
default:
$site->setSiteModules([]);
}
}
$fs = new Finder();
$languages = [];
$engineLanguages = $fs->files()->in($this->getParameter('app.path_grav') . '/system/languages')->name('*.yaml');
......@@ -167,6 +184,7 @@ class SiteController extends Controller
return $this->render('default/site/new/blog.html.twig', [
'form' => $newSiteForm->createView(),
'site_type' => $this->get('translator.default')->trans('site.type.blog'),
'show_modules' => empty($site->getSiteModules()),
]);
}
......
......@@ -34,6 +34,21 @@ class Blog extends Site
*/
protected $siteKeywords;
/**
* @var array
*/
protected $siteModules;
const MODULE_BLOG = 1;
const MODULE_CV = 2;
const MODULE_SINGLE_PAGE = 3;
const MODULE_SINGLE_PAGE_CARROUSEL = 4;
/**
* @var int
*/
protected $homepage;
/**
* @return string
*/
......@@ -88,6 +103,42 @@ class Blog extends Site
return $this;
}
/**
* @return array
*/
public function getSiteModules()
{
return $this->siteModules;
}
/**
* @param array $siteModules
* @return Blog
*/
public function setSiteModules(array $siteModules): Blog
{
$this->siteModules = $siteModules;
return $this;
}
/**
* @return int
*/
public function getHomepage()
{
return $this->homepage;
}
/**
* @param int $homepage
* @return Blog
*/
public function setHomepage(int $homepage): Blog
{
$this->homepage = $homepage;
return $this;
}
public function __toString()
{
return $this->subdomain . '.frama.site';
......
......@@ -4,6 +4,8 @@ namespace AppBundle\Form\Blog;
use AppBundle\Entity\Blog\Blog;
use AppBundle\Form\SiteType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
......@@ -29,6 +31,30 @@ class BlogType extends SiteType
'attr' => ['placeholder' => 'site.new.informations.site_keywords.placeholder'],
'label_attr' => ['class' => 'col-sm-2'],
])
->add('siteModules', ChoiceType::class, [
'label' => 'site.new.informations.site_modules.label',
'label_attr' => ['class' => 'col-sm-2 checkbox-inline'],
'expanded' => true,
'multiple' => true,
'choices' => [
'site.module.blog' => Blog::MODULE_BLOG,
'site.module.cv' => Blog::MODULE_CV,
'site.module.one_page' => Blog::MODULE_SINGLE_PAGE,
'site.module.one_page_carrousel' => Blog::MODULE_SINGLE_PAGE_CARROUSEL,
]
])
->add('homepage', ChoiceType::class, [
'label' => 'site.new.informations.site_homepage.label',
'label_attr' => ['class' => 'col-sm-2'],
'expanded' => false,
'multiple' => false,
'choices' => [
'site.module.blog' => Blog::MODULE_BLOG,
'site.module.cv' => Blog::MODULE_CV,
'site.module.one_page' => Blog::MODULE_SINGLE_PAGE,
'site.module.one_page_carrousel' => Blog::MODULE_SINGLE_PAGE_CARROUSEL,
],
])
->add('siteUsers', BlogUserType::class, [
'lang_choices' => $options['lang_choices'],
'user' => $options['user'],
......
......@@ -10,7 +10,7 @@ class SettingsControllerTest extends FramasitesTestCase {
{
$client = $this->getClient();
$client->request('GET', '/site/new/blog');
$client->request('GET', '/site/new/site');
$this->assertEquals(302, $client->getResponse()->getStatusCode());
$this->assertContains('login', $client->getResponse()->headers->get('location'));
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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