Skip to content
Merged
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: 5 additions & 1 deletion class/Controller/RoleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@ abstract class RoleController
{

protected $factory;
protected $view;
protected $role;
protected $id;

abstract protected function loadFactory();

abstract protected function loadView();

public function __construct($role)
{
$this->loadFactory();
$this->loadView();
$this->role = $role;
}

Expand Down Expand Up @@ -108,7 +112,7 @@ public function put(Request $request)
} else {
$method_name = $command . 'PutCommand';
}

if (!method_exists($this, $method_name)) {
throw new BadCommand($method_name);
}
Expand Down
29 changes: 11 additions & 18 deletions class/Controller/Show/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
namespace slideshow\Controller\Show;

use Canopy\Request;
use slideshow\Factory\NavBar;
use slideshow\Factory\ShowFactory;
use slideshow\View\ShowView;

class Admin extends Base
{
Expand All @@ -38,18 +38,20 @@ class Admin extends Base
*/
protected $factory;

public function postCommand(Request $request)
/**
* @var slideshow\View\ShowView
*/
protected $view;

protected function listHtmlCommand(Request $request)
{
$show = $this->factory->post($request);
return array('show'=>$show->getStringVars());
return $this->view->show();
}

protected function listHtmlCommand(Request $request)
public function postCommand(Request $request)
{
$script = $this->factory->scriptView('shows');
\Layout::addJSHeader($script);
$this->createShowButton();
return $this->factory->scriptView('shows');
$show = $this->factory->post($request);
return array('show'=>$show->getStringVars());
}

protected function listJsonCommand(Request $request)
Expand Down Expand Up @@ -86,13 +88,4 @@ protected function getJsonView($data, \Canopy\Request $request)
return new \phpws2\View\JsonView($result);
}

private function createShowButton()
{
$nav = new NavBar();
$create = <<<EOF
<button class="btn btn-success navbar-btn" id="createShow"><i class="fa fa-plus"></i> Create New SlideShow</button>
EOF;
$nav->addItem($create);
}

}
6 changes: 6 additions & 0 deletions class/Controller/Show/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

use Canopy\Request;
use slideshow\Factory\ShowFactory as Factory;
use slideshow\View\ShowView as View;
use slideshow\Controller\RoleController;

class Base extends RoleController
Expand All @@ -35,6 +36,11 @@ protected function loadFactory()
$this->factory = new Factory;
}

protected function loadView()
{
$this->view = new View;
}

protected function viewHtmlCommand(Request $request)
{
return 'Show.Base::viewHtmlCommand';
Expand Down
70 changes: 0 additions & 70 deletions class/Factory/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,74 +42,4 @@ function($letter) {
}
}

private function getScript($filename)
{
$root_directory = PHPWS_SOURCE_HTTP . 'mod/slideshow/javascript/';
if (SLIDESHOW_REACT_DEV) {
$path = "dev/$filename.js";
} else {
$path = "build/$filename.js";
}
$script = "<script type='text/javascript' src='{$root_directory}$path'></script>";
return $script;
}

public function scriptView($view_name, $add_anchor = true, $vars = null)
{
static $vendor_included = false;
if (!$vendor_included) {
$script[] = $this->getScript('vendor');
$vendor_included = true;
}
if (!empty($vars)) {
$script[] = $this->addScriptVars($vars);
}
$script[] = $this->getScript($view_name);
$react = implode("\n", $script);
if ($add_anchor) {
$content = <<<EOF
<div id="$view_name"></div>
$react
EOF;
return $content;
} else {
return $react;
}
}

private function addScriptVars($vars)
{
if (empty($vars)) {
return null;
}
foreach ($vars as $key => $value) {
$varList[] = "const $key = '$value';";
}
return '<script type="text/javascript">' . implode('', $varList) . '</script>';
}

protected function getRootDirectory()
{
return PHPWS_SOURCE_DIR . 'mod/slideshow/';
}

protected function getRootUrl()
{
return PHPWS_SOURCE_HTTP . 'mod/slideshow/';
}

private function getAssetPath($scriptName)
{
$rootDirectory = $this->getRootDirectory();
if (!is_file($rootDirectory . 'assets.json')) {
exit('Missing assets.json file. Run npm run prod in stories directory.');
}
$jsonRaw = file_get_contents($rootDirectory . 'assets.json');
$json = json_decode($jsonRaw, true);
if (!isset($json[$scriptName]['js'])) {
throw new \Exception('Script file not found among assets.');
}
return $json[$scriptName]['js'];
}

}
85 changes: 85 additions & 0 deletions class/View/BaseView.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php
/**
* MIT License
* Copyright (c) 2018 Electronic Student Services @ Appalachian State University
*
* See LICENSE file in root directory for copyright and distribution permissions.
*
* @author Matthew McNaney <mcnaneym@appstate.edu>
* @license https://opensource.org/licenses/MIT
*/
namespace slideshow\View;

abstract class BaseView
{

private function getScript($filename)
{
$root_directory = PHPWS_SOURCE_HTTP . 'mod/slideshow/javascript/';
if (SLIDESHOW_REACT_DEV) {
$path = "dev/$filename.js";
} else {
$path = "build/$filename.js";
}
$script = "<script type='text/javascript' src='{$root_directory}$path'></script>";
return $script;
}

public function scriptView($view_name, $add_anchor = true, $vars = null)
{
static $vendor_included = false;
if (!$vendor_included) {
$script[] = $this->getScript('vendor');
$vendor_included = true;
}
if (!empty($vars)) {
$script[] = $this->addScriptVars($vars);
}
$script[] = $this->getScript($view_name);
$react = implode("\n", $script);
if ($add_anchor) {
$content = <<<EOF
<div id="$view_name"></div>
$react
EOF;
return $content;
} else {
return $react;
}
}

private function addScriptVars($vars)
{
if (empty($vars)) {
return null;
}
foreach ($vars as $key => $value) {
$varList[] = "const $key = '$value';";
}
return '<script type="text/javascript">' . implode('', $varList) . '</script>';
}

protected function getRootDirectory()
{
return PHPWS_SOURCE_DIR . 'mod/slideshow/';
}

protected function getRootUrl()
{
return PHPWS_SOURCE_HTTP . 'mod/slideshow/';
}

private function getAssetPath($scriptName)
{
$rootDirectory = $this->getRootDirectory();
if (!is_file($rootDirectory . 'assets.json')) {
exit('Missing assets.json file. Run npm run prod in stories directory.');
}
$jsonRaw = file_get_contents($rootDirectory . 'assets.json');
$json = json_decode($jsonRaw, true);
if (!isset($json[$scriptName]['js'])) {
throw new \Exception('Script file not found among assets.');
}
return $json[$scriptName]['js'];
}
}
34 changes: 34 additions & 0 deletions class/View/ShowView.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* MIT License
* Copyright (c) 2018 Electronic Student Services @ Appalachian State University
*
* See LICENSE file in root directory for copyright and distribution permissions.
*
* @author Matthew McNaney <mcnaneym@appstate.edu>
* @author Tyler Craig <craigta1@appstae.edu>
* @license https://opensource.org/licenses/MIT
*/

namespace slideshow\View;

use slideshow\Factory\NavBar;

class ShowView extends BaseView
{

public function show()
{
$this->createShowButton();
return $this->scriptView('shows');
}

private function createShowButton()
{
$nav = new NavBar();
$create = <<<EOF
<button class="btn btn-success navbar-btn" id="createShow"><i class="fa fa-plus"></i> Create New SlideShow</button>
EOF;
$nav->addItem($create);
}
}