Commit 21ab3ed7 authored by Nicolas Widart's avatar Nicolas Widart

Removing the workshop module

parent 49902948
rules:
php.interface_has_no_interface_suffix:
enabled: false
language: php
php:
- 5.6
- 5.5
- 5.4
- hhvm
<?php namespace Modules\Workshop\Composers;
use Illuminate\Contracts\View\View;
use Modules\Workshop\Manager\ModuleManager;
class MigrateViewComposer
{
/**
* @var ModuleManager
*/
private $module;
public function __construct(ModuleManager $module)
{
$this->module = $module;
}
public function compose(View $view)
{
$view->modules = $this->module->enabled();
}
}
<?php namespace Modules\Workshop\Composers;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Request;
use Modules\Core\Composers\BaseSidebarViewComposer;
class SidebarViewComposer extends BaseSidebarViewComposer
{
public function compose(View $view)
{
$view->items->put('workbench', Collection::make([
[
'weight' => '1',
'request' => Request::is("*/{$view->prefix}/modules*") or Request::is("*/{$view->prefix}/workbench*"),
'route' => '#',
'icon-class' => 'fa fa-cogs',
'title' => 'Workshop',
'permission' => $this->auth->hasAccess('modules.index') or $this->auth->hasAccess('workbench.index')
],
[
'request' => "*/{$view->prefix}/modules*",
'route' => 'dashboard.modules.index',
'icon-class' => 'fa fa-cog',
'title' => 'Modules',
'permission' => $this->auth->hasAccess('modules.index')
],
[
'request' => "*/{$view->prefix}/workbench*",
'route' => 'dashboard.workbench.index',
'icon-class' => 'fa fa-terminal',
'title' => 'Workbench',
'permission' => $this->auth->hasAccess('workbench.index')
]
]));
}
}
<?php
return [
'modules' => [
'index',
'store',
],
'workbench' => [
'index',
'generate',
'migrate',
'install',
'seed',
],
'generate' => [
'generate'
],
'install' => [
'install'
],
'migrate' => [
'migrate'
],
'seed' => [
'seed'
]
];
<?php namespace Modules\Workshop\Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
class WorkshopDatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
}
}
<?php namespace Modules\Workshop\Http\Controllers;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\View;
use Laracasts\Flash\Flash;
use Modules\Core\Http\Controllers\Admin\AdminBaseController;
use Modules\Workshop\Http\Requests\ModulesRequest;
use Modules\Workshop\Manager\ModuleManager;
class ModulesController extends AdminBaseController
{
/**
* @var ModuleManager
*/
private $moduleManager;
public function __construct(ModuleManager $moduleManager)
{
parent::__construct();
$this->moduleManager = $moduleManager;
}
public function index()
{
$modules = $this->moduleManager->all();
$coreModules = $this->moduleManager->getCoreModules();
return View::make('workshop::admin.modules.index', compact('modules', 'coreModules'));
}
public function store(ModulesRequest $request)
{
$enabledModules = $this->moduleManager->getFlippedEnabledModules();
$modules = $request->modules;
foreach ($modules as $module => $value) {
if (isset($enabledModules[$module])) {
unset($enabledModules[$module]);
unset($modules[$module]);
}
}
$this->moduleManager->disableModules($enabledModules);
$this->moduleManager->enableModules($modules);
Flash::success('Modules configuration saved!');
return Redirect::route('dashboard.modules.index');
}
}
<?php namespace Modules\Workshop\Http\Controllers;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\View;
use Laracasts\Flash\Flash;
use Modules\Core\Http\Controllers\Admin\AdminBaseController;
use Modules\Workshop\Http\Requests\GenerateModuleRequest;
use Modules\Workshop\Http\Requests\InstallModuleRequest;
use Modules\Workshop\Http\Requests\MigrateModuleRequest;
use Modules\Workshop\Http\Requests\SeedModuleRequest;
use Symfony\Component\Console\Output\BufferedOutput;
class WorkbenchController extends AdminBaseController
{
public function __construct()
{
parent::__construct();
}
/**
* Show the index view
* @return mixed
*/
public function index()
{
return View::make('workshop::admin.workbench.index');
}
/**
* Generate a module given its name
* @param GenerateModuleRequest $request
* @return mixed
*/
public function generate(GenerateModuleRequest $request)
{
$output = new BufferedOutput;
Artisan::call('module:make', ['name' => $request->name], $output);
Flash::message($output->fetch());
return Redirect::route('dashboard.workbench.index');
}
/**
* Run the migration for the given module
* @param MigrateModuleRequest $request
* @return mixed
*/
public function migrate(MigrateModuleRequest $request)
{
$output = new BufferedOutput;
Artisan::call('module:migrate', ['module' => $request->module], $output);
Flash::message($output->fetch());
return Redirect::route('dashboard.workbench.index');
}
/**
* Run the install command for the given vendor/module
* @param InstallModuleRequest $request
* @return mixed
*/
public function install(InstallModuleRequest $request)
{
$output = new BufferedOutput;
$arguments['name'] = $request->vendorName;
if ($request->subtree) {
$arguments['--tree'] = '';
}
Artisan::call('module:install', $arguments, $output);
Flash::message($output->fetch());
return Redirect::route('dashboard.workbench.index');
}
/**
* Run the seed command for the given module
* @param SeedModuleRequest $request
* @return mixed
*/
public function seed(SeedModuleRequest $request)
{
$output = new BufferedOutput;
Artisan::call('module:seed', ['module' => $request->module], $output);
Flash::message($output->fetch());
return Redirect::route('dashboard.workbench.index');
}
}
<?php namespace Modules\Workshop\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class GenerateModuleRequest extends FormRequest
{
public function rules()
{
return [
'name' => 'required'
];
}
public function authorize()
{
return true;
}
public function messages()
{
return [];
}
}
<?php namespace Modules\Workshop\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class InstallModuleRequest extends FormRequest
{
public function rules()
{
return [
'vendorName' => 'required'
];
}
public function authorize()
{
return true;
}
public function messages()
{
return [];
}
}
<?php namespace Modules\Workshop\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class MigrateModuleRequest extends FormRequest
{
public function rules()
{
return [
'module' => 'required'
];
}
public function authorize()
{
return true;
}
public function messages()
{
return [];
}
}
<?php namespace Modules\Workshop\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class ModulesRequest extends FormRequest
{
public function rules()
{
return [];
}
public function authorize()
{
return true;
}
public function messages()
{
return [];
}
}
<?php namespace Modules\Workshop\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class SeedModuleRequest extends FormRequest
{
public function rules()
{
return [
'module' => 'required'
];
}
public function authorize()
{
return true;
}
public function messages()
{
return [];
}
}
<?php
use Illuminate\Routing\Router;
$router->group(['prefix' => LaravelLocalization::setLocale(), 'before' => 'LaravelLocalizationRedirectFilter|auth.admin|permissions'], function(Router $router)
{
$router->group(['prefix' => Config::get('core::core.admin-prefix'), 'namespace' => 'Modules\Workshop\Http\Controllers'],
function (Router $router) {
$router->get('modules', ['as' => 'dashboard.modules.index', 'uses' => 'ModulesController@index']);
$router->post('modules', ['as' => 'dashboard.modules.store', 'uses' => 'ModulesController@store']);
# Workbench
$router->get('workbench', ['as' => 'dashboard.workbench.index', 'uses' => 'WorkbenchController@index']);
$router->post('generate', ['as' => 'dashboard.workbench.generate.index', 'uses' => 'WorkbenchController@generate']);
$router->post('migrate', ['as' => 'dashboard.workbench.migrate.index', 'uses' => 'WorkbenchController@migrate']);
$router->post('install', ['as' => 'dashboard.workbench.install.index', 'uses' => 'WorkbenchController@install']);
$router->post('seed', ['as' => 'dashboard.workbench.seed.index', 'uses' => 'WorkbenchController@seed']);
}
);
});
<?php namespace Modules\Workshop\Manager;
use Illuminate\Config\Repository as Config;
use Pingpong\Modules\Module;
class ModuleManager
{
/**
* @var Module
*/
private $module;
/**
* @var Config
*/
private $config;
/**
* @param Config $config
*/
public function __construct(Config $config)
{
$this->module = app('modules');
$this->config = $config;
}
/**
* Return all modules
* @return array
*/
public function all()
{
return $this->module->all();
}
/**
* Return all the enabled modules
* @return array
*/
public function enabled()
{
return $this->module->enabled();
}
/**
* Get the core modules that shouldn't be disabled
* @return array|mixed
*/
public function getCoreModules()
{
$coreModules = $this->config->get('core::config.CoreModules');
$coreModules = array_flip($coreModules);
return $coreModules;
}
/**
* Get the enabled modules, with the module name as the key
* @return array
*/
public function getFlippedEnabledModules()
{
$enabledModules = $this->module->enabled();
$enabledModules = array_map(function(Module $module) {
return $module->getName();
}, $enabledModules);
return array_flip($enabledModules);
}
/**
* Disable the given modules
* @param $enabledModules
*/
public function disableModules($enabledModules)
{
$coreModules = $this->getCoreModules();
foreach ($enabledModules as $moduleToDisable => $value) {
if (isset($coreModules[$moduleToDisable])) {
continue;
}
$module = $this->module->get($moduleToDisable);
$module->disable();
}
}
/**
* Enable the given modules
* @param $modules
*/
public function enableModules($modules)
{
foreach ($modules as $moduleToEnable => $value) {
$module = $this->module->get($moduleToEnable);
$module->enable();
}
}
}
<?php namespace Modules\Workshop\Providers;
use Illuminate\Routing\Router;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class RouteServiceProvider extends ServiceProvider
{
/**
* The root namespace to assume when generating URLs to actions.
*
* @var string
*/
protected $rootUrlNamespace = 'Modules\Workshop\Http\Controllers';
/**
* The controllers to scan for route annotations.
*
* @var array
*/
protected $scan = [
'Modules\Workshop\Http\Controllers',
];
/**
* Called before routes are registered.
*
* Register any model bindings or pattern based filters.
*
* @param Router $router
* @return void
*/
public function before(Router $router)
{
//
}
/**
* Define the routes for the application.
*
* @return void
*/
public function map(Router $router)
{
require __DIR__ . '/../Http/routes.php';
}
}
<?php namespace Modules\Workshop\Providers;
use Illuminate\Routing\Router;
use Illuminate\Support\ServiceProvider;
class WorkshopServiceProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;
/**
* The filters base class name.
*
* @var array
*/
protected $filters = [
'Core' => [
'permissions' => 'PermissionFilter'
]
];
/**
* Register the filters.
*
* @param Router $router
* @return void
*/
public function registerFilters(Router $router)
{
foreach ($this->filters as $module => $filters) {
foreach ($filters as $name => $filter) {
$class = "Modules\\{$module}\\Http\\Filters\\{$filter}";
$router->filter($name, $class);
}
}
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->booted(function ($app) {
$this->registerFilters($app['router']);
});
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array();
}
}
<?php
return [
'title' => 'Module Management',
'breadcrumb' => [
'modules' => 'Modules'
],
'tab' => [
'module list' => 'Module list'
],
'button' => [
'save module configuration' => 'Save module configuration'
]
];
<?php
return [
'title' => 'Module helpers',
'subtitle' => [
'generate new module' => 'Generate a new module',
'install new module by vendor name' => 'Install a module by vendor/name',
],
'tab' => [
'generators' => 'Generators',
'migrations' => 'Migrations',
'seeds' => 'Seeds',
],
'form' => [
'module name' => 'Module name',
'vendor name of the module' => 'Vendor/name of the module',
'install as subtree' => 'Install as a subtree?',
],
'button' => [
'generate new module' => 'Generate new module',
'install new module' => 'Install new module',
'migrate' => 'Migrate',
'seed' => 'Seed',
]
];
<?php
return [
'title' => 'Gérer les modules',
'breadcrumb' => [
'modules' => 'Modules'
],
'tab' => [
'module list' => 'Liste de modules'
],
'button' => [
'save module configuration' => 'Sauvez la configuration de modules'
]
];
<?php
return [
'title' => 'Aide au modules',
'subtitle' => [
'generate new module' => 'Générer un nouveau module',
'install new module by vendor name' => 'Installer un nouveau module par son vendor/name',
],
'tab' => [
'generators' => 'Generators',
'migrations' => 'Migrations',
'seeds' => 'Seeds',
],
'form' => [
'module name' => 'Nom du module',
'vendor name of the module' => 'Vendor/name du module',
'install as subtree' => 'Installer en tant que subtree?',
],
'button' => [
'generate new module' => 'Generer le module',
'install new module' => 'Installer le module',
'migrate' => 'Migrer',
'seed' => 'Seed',
]
];
@extends('core::layouts.master')
@section('content-header')
<h1>
{{ trans('workshop::modules.title') }}
</h1>
<ol class="breadcrumb">
<li><a href="{{ URL::route('dashboard.index') }}"><i class="fa fa-dashboard"></i> {{ trans('user::users.breadcrumb.home') }}</a></li>
<li class="active">{{ trans('workshop::modules.breadcrumb.modules') }}</li>
</ol>
@stop
@section('styles')
<link href="{{{ Module::asset('core:css/vendor/iCheck/flat/blue.css') }}}" rel="stylesheet" type="text/css" />
@stop
@section('content')
{!! Form::open(['route' => 'dashboard.modules.store', 'method' => 'post']) !!}
<div class="row">
<div class="col-md-12">
<div class="nav-tabs-custom">
<ul class="nav nav-tabs">
<li class="active"><a href="#tab_1-1" data-toggle="tab">{{ trans('workshop::modules.tab.module list') }}</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tab_1-1">
<ul>
@foreach($modules as $module)
<li>
<div class="checkbox">
<label for="{{ $module }}">
<input id="{{ $module }}" name="modules[{{ $module }}]" type="checkbox" class="flat-blue" <?php echo Module::active($module) ? 'checked' : '' ?> <?php echo isset($coreModules[$module->getName()]) ? 'disabled' : ''; ?> value="true" /> {{ $module }}
</label>
</div>
</li>
@endforeach
</ul>
<div class="box-footer">
<button type="submit" class="btn btn-primary btn-flat">{{ trans('workshop::modules.button.save module configuration') }}</button>
</div>
</div>
</div>
</div>
</div>
</div>
{!! Form::close() !!}
@stop
@section('scripts')
<script>
$( document ).ready(function() {
$('input[type="checkbox"].flat-blue, input[type="radio"].flat-blue').iCheck({
checkboxClass: 'icheckbox_flat-blue',
radioClass: 'iradio_flat-blue'
});
});
</script>
@stop
@extends('core::layouts.master')
@section('content-header')
<h1>
{{ trans('workshop::workbench.title') }}
</h1>
<ol class="breadcrumb">
<li><a href="{{ URL::route('dashboard.index') }}"><i class="fa fa-dashboard"></i> {{ trans('user::users.breadcrumb.home') }}</a></li>
<li class="active">{{ trans('workshop::workbench.title') }}</li>
</ol>
@stop
@section('styles')
<link href="{{{ Module::asset('core:css/vendor/iCheck/flat/blue.css') }}}" rel="stylesheet" type="text/css" />
@stop
@section('content')
<div class="row">
<div class="col-md-12">
<div class="nav-tabs-custom">
<ul class="nav nav-tabs">
<li class="active"><a href="#tab_1-1" data-toggle="tab">{{ trans('workshop::workbench.tab.generators') }}</a></li>
<li><a href="#tab_2-2" data-toggle="tab">{{ trans('workshop::workbench.tab.migrations') }}</a></li>
<li><a href="#tab_3-3" data-toggle="tab">{{ trans('workshop::workbench.tab.seeds') }}</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tab_1-1">
@include('workshop::admin.workbench.tabs.generate')
</div>
<div class="tab-pane" id="tab_2-2">
@include('workshop::admin.workbench.tabs.migrate')
</div>
<div class="tab-pane" id="tab_3-3">
@include('workshop::admin.workbench.tabs.seed')
</div>
</div>
</div>
</div>
</div>
@stop
@section('scripts')
<script>
$( document ).ready(function() {
$('input[type="checkbox"].flat-blue, input[type="radio"].flat-blue').iCheck({
checkboxClass: 'icheckbox_flat-blue',
radioClass: 'iradio_flat-blue'
});
});
</script>
@stop
<div class="row">
<div class="col-md-6">
{!! Form::open(['route' => 'dashboard.workbench.generate.index', 'method' => 'post']) !!}
<div class="box-body">
<h4>{{ trans('workshop::workbench.subtitle.generate new module') }}</h4>
<div class='form-group{{ $errors->has('name') ? ' has-error' : '' }}'>
{!! Form::label('name', trans('workshop::workbench.form.module name')) !!}
{!! Form::text('name', Input::old('name'), ['class' => 'form-control', 'placeholder' => trans('workshop::workbench.form.module name')]) !!}
{!! $errors->first('name', '<span class="help-block">:message</span>') !!}
</div>
</div>
<div class="box-footer">
<button type="submit" class="btn btn-primary btn-flat">{{ trans('workshop::workbench.button.generate new module') }}</button>
</div>
{!! Form::close() !!}
</div>
<div class="col-md-6">
{!! Form::open(['route' => 'dashboard.workbench.install.index', 'method' => 'post']) !!}
<div class="box-body">
<h4>{{ trans('workshop::workbench.subtitle.install new module by vendor name') }}</h4>
<div class='form-group{{ $errors->has('vendorName') ? ' has-error' : '' }}'>
{!! Form::label('vendorName', trans('workshop::workbench.form.vendor name of the module')) !!}
{!! Form::text('vendorName', Input::old('vendorName'), ['class' => 'form-control', 'placeholder' => trans('workshop::workbench.form.vendor name of the module')]) !!}
{!! $errors->first('vendorName', '<span class="help-block">:message</span>') !!}
</div>
<div class="checkbox">
<label for="subtree">
<input id="subtree" name="subtree" type="checkbox" class="flat-blue" value="true" /> {{ trans('workshop::workbench.form.install as subtree') }}
</label>
</div>
</div>
<div class="box-footer">
<button type="submit" class="btn btn-primary btn-flat">{{ trans('workshop::workbench.button.install new module') }}</button>
</div>
{!! Form::close() !!}
</div>
</div>
{!! Form::open(['route' => 'dashboard.workbench.migrate.index', 'method' => 'post']) !!}
<div class="box-body">
<div class='form-group{{ $errors->has('module') ? ' has-error' : '' }}'>
{!! Form::label('module', trans('workshop::workbench.form.module name')) !!}
{!! Form::select('module', $modules, null, ['class' => 'form-control']) !!}
{!! $errors->first('module', '<span class="help-block">:message</span>') !!}
</div>
</div>
<div class="box-footer">
<button type="submit" class="btn btn-primary btn-flat">{{ trans('workshop::workbench.button.migrate') }}</button>
</div>
{!! Form::close() !!}
{!! Form::open(['route' => 'dashboard.workbench.seed.index', 'method' => 'post']) !!}
<div class="box-body">
<div class='form-group{{ $errors->has('module') ? ' has-error' : '' }}'>
{!! Form::label('module', trans('workshop::workbench.form.module name')) !!}
{!! Form::select('module', $modules, null, ['class' => 'form-control']) !!}
{!! $errors->first('module', '<span class="help-block">:message</span>') !!}
</div>
</div>
<div class="box-footer">
<button type="submit" class="btn btn-primary btn-flat">{{ trans('workshop::workbench.button.seed') }}</button>
</div>
{!! Form::close() !!}
{
"name": "asgardcms/workshop-module",
"type": "asgard-module",
"description": "Workshop module for AsgardCMS. Handles the activation of modules.",
"keywords": [
"asgardcms",
"workshop",
"modules"
],
"license": "MIT",
"authors": [
{
"name": "Nicolas Widart",
"email": "info@asgardcms.com",
"role": "Developer"
}
],
"support": {
"email": "support@asgardcms.com",
"issues": "https://github.com/AsgardCms/Workshop/issues",
"source": "https://github.com/AsgardCms/Workshop"
},
"require": {
"php": ">=5.4",
"composer/installers": "~1.0"
},
"minimum-stability": "dev"
}
<?php
View::composer('core::partials.sidebar-nav', 'Modules\Workshop\Composers\SidebarViewComposer');
View::composer([
'workshop::admin.workbench.tabs.migrate',
'workshop::admin.workbench.tabs.seed',
], 'Modules\Workshop\Composers\MigrateViewComposer');
{
"name": "Workshop",
"alias": "workshop",
"description": "",
"keywords": [
],
"active": 1,
"providers": [
"Modules\\Workshop\\Providers\\RouteServiceProvider",
"Modules\\Workshop\\Providers\\WorkshopServiceProvider"
],
"files": [
"start.php"
]
}
# Workshop Module
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/d6258dc8-cd2a-4288-94a5-8a8089e6609e/mini.png)](https://insight.sensiolabs.com/projects/d6258dc8-cd2a-4288-94a5-8a8089e6609e)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/AsgardCms/Workshop/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/AsgardCms/Workshop/?branch=master)
[![Code Climate](https://codeclimate.com/github/AsgardCms/Workshop/badges/gpa.svg)](https://codeclimate.com/github/AsgardCms/Workshop)
<?php
require __DIR__ . '/composers.php';
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