Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Magento 2 Frontend Assessment #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions David/CustomModule/Block/Index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
namespace David\CustomModule\Block;
class Index extends \Magento\Framework\View\Element\Template
{

}
20 changes: 20 additions & 0 deletions David/CustomModule/Controller/Index/Index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
namespace David\CustomModule\Controller\Index;

class Index extends \Magento\Framework\App\Action\Action
{
protected $_pageFactory;

public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $pageFactory)
{
$this->_pageFactory = $pageFactory;
return parent::__construct($context);
}

public function execute()
{
return $this->_pageFactory->create();
}
}
8 changes: 8 additions & 0 deletions David/CustomModule/etc/frontend/routes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
<route frontName="exercise1" id="exercise1">
<module name="David_CustomModule"/>
</route>
</router>
</config>
5 changes: 5 additions & 0 deletions David/CustomModule/etc/module.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="David_CustomModule" setup_version="1.0.0">
</module>
</config>
6 changes: 6 additions & 0 deletions David/CustomModule/registration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'David_CustomModule',
__DIR__
);
12 changes: 12 additions & 0 deletions David/CustomModule/view/frontend/layout/default.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../vendor/magento/framework/Module/etc/module.xsd">
<referenceBlock name="head">
<!-- <block class="Magento\Theme\Block\Html\Head\Script" name="requirejs" before="-">
<arguments>
<argument name="file" xsi:type="string">requirejs/require.js</argument>
</arguments>
</block> -->
<!-- Special block with necessary config is added on the page -->
<!-- <block class="Magento\RequireJs\Block\Html\Head\Config" name="requirejs-config" after="requirejs"/> -->
</referenceBlock>
</page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../vendor/magento/framework/Module/etc/module.xsd">
<head>
<css src="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" src_type="url" />
</head>
</page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<referenceContainer name="content">
<block class="David\CustomModule\Block\Index" name="exercise1_index_index" template="David_CustomModule::index.phtml" />
</referenceContainer>
</page>
10 changes: 10 additions & 0 deletions David/CustomModule/view/frontend/requirejs-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var config = {
paths:{
"jquery.bootstrap":"https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min"
},
shim:{
'jquery.bootstrap':{
'deps':['jquery']
}
}
};
38 changes: 38 additions & 0 deletions David/CustomModule/view/frontend/templates/index.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<div class="jumbotron jumbotron-fluid jumbotron-image">
<div class="container">
<h1 class="display-4 text-center font-weight-bold font-color-white">Hello Developer!</h1>
<p class="lead text-center mt-1 font-color-white">Lorem ipsum dolor, sit amet consectetur adipisicing elit</p>
</div>
</div>
<div class="container d-flex justify-content-center flex-wrap">
<div class="card">
<img class="card-img-top" src="<?php echo $this->getViewFileUrl('David_CustomModule::images/400x300.png'); ?>" alt="Card image cap">
<div class="card-body">
<!-- <h5 class="card-title">Card title</h5> -->
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<div class="d-flex justify-content-center">
<a href="#" class="btn btn-outline-dark">READ MORE</a>
</div>
</div>
</div>
<div class="card">
<img class="card-img-top" src="<?php echo $this->getViewFileUrl('David_CustomModule::images/400x300.png'); ?>" alt="Card image cap">
<div class="card-body">
<!-- <h5 class="card-title">Card title</h5> -->
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<div class="d-flex justify-content-center">
<a href="#" class="btn btn-outline-dark">READ MORE</a>
</div>
</div>
</div>
<div class="card">
<img class="card-img-top" src="<?php echo $this->getViewFileUrl('David_CustomModule::images/400x300.png'); ?>" alt="Card image cap">
<div class="card-body">
<!-- <h5 class="card-title">Card title</h5> -->
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<div class="d-flex justify-content-center">
<a href="#" class="btn btn-outline-dark">READ MORE</a>
</div>
</div>
</div>
</div>
72 changes: 72 additions & 0 deletions David/CustomModule/view/frontend/web/css/source/_module.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//
// Common
// _____________________________________________

& when (@media-common = true) {
.font-color-white {
color: @color-white;
}

.jumbotron-image {
background-repeat: no-repeat;
background-position: center;
}

.card {
margin: 10px;

.card-body {
a {
color: #000;
border-radius: 24px;
}
}
}
}
//
// Desktop
// _____________________________________________

.media-width(@extremum, @break) when (@extremum = 'min') and (@break = @screen__m) {
.jumbotron-image {
background-image: url("../images/1920x650.png");
}

.jumbotron {
.container {
h1 {
margin-bottom: 0px;
}
}
}

.card {
width: 22em;
}
}

//
// Mobile @screen__m
// _____________________________________________

.media-width(@extremum, @break) when (@extremum = 'max') and (@break = @screen__m) {
.page-wrapper {
.page-header {
margin-bottom: 0px;
}
}

.page-main {
padding-left: 0px;
padding-right: 0px;
}

.jumbotron-image {
background-image: url("../images/600x600.png");
}

.card {
width: 100%;
padding: 20px;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions David/CustomModule2/Block/Index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
namespace David\CustomModule2\Block;

use Magento\Framework\View\Element\Template\Context;
use Magento\Framework\Controller\Result\JsonFactory;

class Index extends \Magento\Framework\View\Element\Template
{
protected $resultPageFactory;

public function __construct(Context $context, JsonFactory $resultJsonFactory)
{
parent::__construct($context);
$this->resultJsonFactory = $resultJsonFactory;
}

public function getListData() {
$data = [
[
"title"=> "Section 1",
"content"=> "<p>Maecenas nec semper ante, pellentesque posuere lorem. Nullam ipsum massa, consequat eget urna ut, pulvinar dignissim lorem. Nulla facilisi. Nam mattis eleifend metus. Fusce at commodo lorem. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Phasellus pellentesque elit sem, vel blandit posuere.</p>"
],
[
"title"=> "Section 2",
"content"=> "<p>Mauris a orci sodales, scelerisque velit vitae, gravida nisl. Ut non laoreet eros, vel laoreet nisi. Praesent sed dolor dui. Proin non fringilla quam. Aliquam erat volutpat. Vestibulum vel arcu semper, lobortis turpis ac, ultricies nisi. Praesent id.</p>"
],
[
"title"=> "Section 3",
"content"=> "<p>Sed elementum sapien ut sapien imperdiet, eu venenatis enim rhoncus. Praesent euismod tincidunt rhoncus. Duis cras amet:</p><ul><li>List item one</li><li>List item two</li><li>List item three</li></ul>"
],
[
"title"=> "Section 4",
"content"=> "<p>Cras dictum. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Aenean lacinia mauris vel est.</p><p>Suspendisse eu nisl. Nullam ut libero. Integer dignissim consequat lectus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.</p>"
]
];

$result = $this->resultJsonFactory->create();
// $result->setData($data);
$writer = new \Zend_Log_Writer_Stream(BP . '/var/log/custom.log');
$logger = new \Zend_Log();
$logger->addWriter($writer);
$logger->info('Your text message' . json_encode($result->setData(['json_data' => 'come from json'])));

return json_encode($data);
}
}
20 changes: 20 additions & 0 deletions David/CustomModule2/Controller/Index/Index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
namespace David\CustomModule2\Controller\Index;

class Index extends \Magento\Framework\App\Action\Action
{
protected $_pageFactory;

public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $pageFactory)
{
$this->_pageFactory = $pageFactory;
return parent::__construct($context);
}

public function execute()
{
return $this->_pageFactory->create();
}
}
8 changes: 8 additions & 0 deletions David/CustomModule2/etc/frontend/routes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
<route frontName="exercise2" id="exercise2">
<module name="David_CustomModule2"/>
</route>
</router>
</config>
5 changes: 5 additions & 0 deletions David/CustomModule2/etc/module.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="David_CustomModule2" setup_version="1.0.0">
</module>
</config>
6 changes: 6 additions & 0 deletions David/CustomModule2/registration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'David_CustomModule2',
__DIR__
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<referenceContainer name="content">
<block class="David\CustomModule2\Block\Index" name="exercise2_index_index" template="David_CustomModule2::index.phtml" />
</referenceContainer>
</page>
7 changes: 7 additions & 0 deletions David/CustomModule2/view/frontend/requirejs-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var config = {
map: {
'*': {
customScript:'David_CustomModule2/js/script',
}
}
};
28 changes: 28 additions & 0 deletions David/CustomModule2/view/frontend/templates/index.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<div class="container">
<div class="container-desktop">
<div id="custom-tab" class="product data items" >
<?php foreach (json_decode($block->getListData()) as $key => $data): ?>
<div class="item title" data-role="collapsible">
<a class="switch" data-toggle="trigger" href="#<?=$data->title?>"><?=$data->title?></a>
</div>
<div <?=$key > 0 ? 'style="display:none;"' : ''?> id="<?=$data->title?>" class="item content" data-role="content"><?=$data->content?></div>
<?php endforeach; ?>
</div>
</div>
<div class="container-mobile">
<div data-mage-init='{"customScript": {}}'>
<div id="custom-accordion">
<?php foreach (json_decode($block->getListData()) as $key => $data): ?>
<div data-role="collapsible">
<div data-role="trigger">
<span><b style="cursor:pointer"><?=$data->title?></b></span>
</div>
<div <?=$key > 0 ? 'style="display:none;"' : ''?> data-role="content"><?=$data->content?></div>
</div>
<?php endforeach; ?>
</div>
</div>
</div>



34 changes: 34 additions & 0 deletions David/CustomModule2/view/frontend/web/css/source/_module.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Common
// _____________________________________________

& when (@media-common = true) {
body {
}
}

//
// Desktop
// _____________________________________________

.media-width(@extremum, @break) when (@extremum = 'min') and (@break = @screen__m) {
.container-desktop {
display: block;
}
.container-mobile {
display: none;
}
}

//
// Mobile @screen__m
// _____________________________________________

.media-width(@extremum, @break) when (@extremum = 'max') and (@break = @screen__m) {
.container-desktop {
display: none;
}
.container-mobile {
display: block;
}
}
Loading