Pages: Add default pages + categories during installation

Add index page + add edit button
pull/4020/head^2
Julio 3 years ago
parent d40d17fbfd
commit 8eb698f0a6
  1. 20
      assets/vue/pages/Home.vue
  2. 22
      assets/vue/pages/Index.vue
  3. 46
      src/CoreBundle/DataFixtures/PageFixtures.php
  4. 1
      src/CoreBundle/Entity/Page.php

@ -25,8 +25,12 @@
{{ page.title }}
</p>
<p v-html="page.content"/>
</v-card-text>
<v-card-actions v-if="isAdmin">
<q-btn flat label="Edit" color="primary" v-close-popup @click="handleClick(page)"/>
</v-card-actions>
</v-card>
</div>
</div>
@ -39,13 +43,22 @@
import axios from "axios";
import {reactive, toRefs} from 'vue'
import {ENTRYPOINT} from "../config/entrypoint";
import {mapGetters} from "vuex";
import {useRouter} from "vue-router";
export default {
name: "Home",
setup() {
const router = useRouter();
const state = reactive({
announcements: [],
pages: [],
handleClick: function (page) {
router
.push({name: `PageUpdate`, params: {id: '/api/pages/' + page['id']}})
.catch(() => {
});
}
});
axios.get('/news/list').then(response => {
@ -65,6 +78,11 @@ export default {
});
return toRefs(state);
},
computed: {
...mapGetters({
'isAdmin': 'security/isAdmin',
}),
}
}
</script>

@ -44,10 +44,30 @@
<script>
import Login from '../components/Login';
import {reactive, toRefs} from 'vue'
import axios from "axios";
import {ENTRYPOINT} from "../config/entrypoint";
export default {
name: "Index",
components: {
Login
},
name: "Index"
setup() {
const state = reactive({
announcements: [],
pages: [],
});
axios.get(ENTRYPOINT + 'pages.json?category.title=index&enabled=1').then(response => {
if (Array.isArray(response.data)) {
state.pages = response.data;
}
}).catch(function (error) {
console.log(error);
});
return toRefs(state);
}
}
</script>

@ -6,23 +6,67 @@ declare(strict_types=1);
namespace Chamilo\CoreBundle\DataFixtures;
use Chamilo\CoreBundle\Entity\Page;
use Chamilo\CoreBundle\Entity\PageCategory;
use Chamilo\CoreBundle\Entity\User;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class PageFixtures extends Fixture
class PageFixtures extends Fixture implements ContainerAwareInterface
{
private ContainerInterface $container;
public function setContainer(ContainerInterface $container = null): void
{
$this->container = $container;
}
public function load(ObjectManager $manager): void
{
/** @var User $admin */
$admin = $this->getReference(AccessUserFixtures::ADMIN_USER_REFERENCE);
$url = $this->getReference(AccessUserFixtures::ACCESS_URL_REFERENCE);
$category = (new PageCategory())
->setTitle('home')
->setType('grid')
->setCreator($admin)
;
$manager->persist($category);
$locale = $this->container->get('translator')->getLocale();
$page = (new Page())
->setTitle('Welcome')
->setContent('Welcome to Chamilo')
->setCategory($category)
->setCreator($admin)
->setLocale($locale)
->setEnabled(true)
->setUrl($url)
;
$manager->persist($page);
$indexCategory = (new PageCategory())
->setTitle('index')
->setType('grid')
->setCreator($admin)
;
$manager->persist($indexCategory);
$indexPage = (new Page())
->setTitle('Welcome')
->setContent('<img src="/img/document/images/mr_chamilo/svg/teaching.svg" />')
->setCategory($indexCategory)
->setCreator($admin)
->setLocale($locale)
->setEnabled(true)
->setUrl($url)
;
$manager->persist($indexPage);
$manager->flush();
}
}

@ -67,6 +67,7 @@ class Page
* @ORM\Id
* @ORM\GeneratedValue()
*/
#[Groups(['page:read'])]
protected ?int $id = null;
/**

Loading…
Cancel
Save