Skip to content

Commit

Permalink
file displayers
Browse files Browse the repository at this point in the history
  • Loading branch information
ryssbowh committed Jun 4, 2021
1 parent a304dd4 commit 55757ce
Show file tree
Hide file tree
Showing 108 changed files with 4,248 additions and 3,137 deletions.
3,832 changes: 1,685 additions & 2,147 deletions package-lock.json

Large diffs are not rendered by default.

31 changes: 14 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,38 @@
{
"name": "vue",
"version": "0.1.0",
"private": true,
"scripts": {
"build": "BABEL_ENV=vue vue-cli-service build",
"watch": "BABEL_ENV=vue vue-cli-service build --watch --mode=development",
"lint": "BABEL_ENV=vue vue-cli-service lint"
},
"dependencies": {
"devDependencies": {
"axios": "^0.21.1",
"core-js": "^3.6.5",
"vue": "^3.0.0",
"core-js": "^3.13.0",
"vue": "^3.0.11",
"vuedraggable": "^4.0.1",
"vuex": "^4.0.0"
},
"devDependencies": {
"@babel/core": "^7.13.8",
"@babel/preset-env": "^7.13.9",
"@babel/register": "^7.13.8",
"@vue/cli-plugin-babel": "~4.5.0",
"@vue/cli-plugin-eslint": "~4.5.0",
"@vue/cli-service": "~4.5.0",
"@vue/compiler-sfc": "^3.0.0",
"vuex": "^4.0.1",
"@babel/core": "^7.14.3",
"@babel/preset-env": "^7.14.2",
"@babel/register": "^7.13.16",
"@vue/cli-plugin-babel": "^4.5.13",
"@vue/cli-plugin-eslint": "^4.5.13",
"@vue/cli-service": "^4.5.13",
"@vue/compiler-sfc": "^3.0.11",
"babel-eslint": "^10.1.0",
"browserify": "^17.0.0",
"craftcms-sass": "^3.5.7",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^7.0.0-0",
"eslint-plugin-vue": "^7.9.0",
"gulp": "^4.0.2",
"gulp-babel": "^8.0.0",
"gulp-clean-css": "^4.3.0",
"gulp-sass": "^4.1.0",
"gulp-sourcemaps": "^3.0.0",
"gulp-uglify": "^3.0.2",
"populate.js": "^1.2.2",
"sass": "^1.32.6",
"sass-loader": "^10.1.1"
"sass": "^1.34.0",
"sass-loader": "^10.2.0"
},
"eslintConfig": {
"root": true,
Expand Down
10 changes: 10 additions & 0 deletions src/Themes.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
use Ryssbowh\CraftThemes\interfaces\ThemeInterface;
use Ryssbowh\CraftThemes\models\Settings;
use Ryssbowh\CraftThemes\models\SystemBlockProvider;
use Ryssbowh\CraftThemes\services\FileDisplayerService;
use Ryssbowh\CraftThemes\services\{BlockProvidersService, BlockService, FieldDisplayerService, LayoutService, FieldsService, RulesService, ViewModeService, ViewService, ThemesRegistry, CacheService, DisplayService, GroupService, MatrixService};
use Ryssbowh\CraftThemes\twig\ThemesVariable;
use Ryssbowh\CraftThemes\twig\TwigTheme;
use craft\base\PluginInterface;
use craft\events\SectionEvent;
use craft\events\{CategoryGroupEvent, ConfigEvent, EntryTypeEvent, FieldEvent, GlobalSetEvent, RegisterUserPermissionsEvent, RouteEvent, TagGroupEvent, VolumeEvent, PluginEvent, RebuildConfigEvent, RegisterCacheOptionsEvent, RegisterCpNavItemsEvent, RegisterTemplateRootsEvent, RegisterUrlRulesEvent, TemplateEvent};
use craft\helpers\UrlHelper;
use craft\services\{Categories, Plugins, ProjectConfig, Routes, Sections, Volumes, UserPermissions, Tags, Globals, Fields};
Expand Down Expand Up @@ -260,6 +262,7 @@ protected function registerServices()
'display' => DisplayService::class,
'fields' => FieldsService::class,
'matrix' => MatrixService::class,
'fileDisplayers' => FileDisplayerService::class,
]);
}

Expand Down Expand Up @@ -294,6 +297,13 @@ protected function registerClearCacheEvent()
*/
protected function registerCraftEvents()
{
Event::on(Sections::class, Sections::EVENT_AFTER_SAVE_SECTION, function (SectionEvent $e) {
$type = LayoutService::ENTRY_HANDLE;
foreach ($e->section->entryTypes as $entryType) {
$uid = $entryType->uid;
Themes::$plugin->layouts->onCraftElementSaved($type, $uid);
}
});
Event::on(Sections::class, Sections::EVENT_AFTER_SAVE_ENTRY_TYPE, function (EntryTypeEvent $e) {
$type = LayoutService::ENTRY_HANDLE;
$uid = $e->entryType->uid;
Expand Down
3 changes: 3 additions & 0 deletions src/assets/BlockOptionsAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class BlockOptionsAsset extends AssetBundle
'blockOptions.js'
];

/**
* @inheritDoc
*/
public function init()
{
parent::init();
Expand Down
3 changes: 3 additions & 0 deletions src/assets/BlocksAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class BlocksAssets extends AssetBundle
BlockOptionsAsset::class
];

/**
* @inheritDoc
*/
public function init()
{
parent::init();
Expand Down
6 changes: 5 additions & 1 deletion src/assets/DisplayAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class DisplayAssets extends AssetBundle

public $js = [
'chunk-vendors.js',
'displayers.js',
'fieldDisplayers.js',
'fileDisplayers.js',
'display.js',
];

Expand All @@ -20,6 +21,9 @@ class DisplayAssets extends AssetBundle
JquerySerializeJSON::class
];

/**
* @inheritDoc
*/
public function init()
{
parent::init();
Expand Down
29 changes: 26 additions & 3 deletions src/controllers/CpAjaxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

class CpAjaxController extends Controller
{
/**
* @inheritDoc
*/
public function beforeAction($action)
{
$this->requirePermission('accessPlugin-themes');
Expand All @@ -19,12 +22,21 @@ public function beforeAction($action)
return true;
}

/**
* @inheritDoc
*/
public function afterAction($action, $result)
{
return $this->asJson($result);
}

public function actionEntries(string $uid)
/**
* Return entries for an entry type uid
*
* @param string $uid
* @return array
*/
public function actionEntries(string $uid): array
{
$entryTypes = array_values(array_filter(\Craft::$app->sections->getAllEntryTypes(), function ($entryType) use ($uid) {
return $uid == $entryType->uid;
Expand All @@ -43,7 +55,13 @@ public function actionEntries(string $uid)
];
}

public function actionCategories(string $uid)
/**
* Return categories for a category group uid
*
* @param string $uid
* @return array
*/
public function actionCategories(string $uid): array
{
$group = \Craft::$app->categories->getGroupByUid($uid);
$categories = array_map(function ($category) {
Expand All @@ -60,7 +78,12 @@ public function actionCategories(string $uid)
];
}

public function actionUsers()
/**
* Return users
*
* @return array
*/
public function actionUsers(): array
{
$users = array_map(function ($user) {
return [
Expand Down
47 changes: 13 additions & 34 deletions src/controllers/CpBlocksAjaxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

class CpBlocksAjaxController extends Controller
{
/**
* @inheritDoc
*/
public function beforeAction($action)
{
$this->requirePermission('manageThemesBlocks');
Expand All @@ -17,6 +20,9 @@ public function beforeAction($action)
return true;
}

/**
* @inheritDoc
*/
public function afterAction($action, $result)
{
return $this->asJson($result);
Expand All @@ -38,9 +44,9 @@ public function actionBlockProviders()
* Delete a layout by id
*
* @param int $id
* @return Response
* @return array
*/
public function actionDeleteLayout(int $id)
public function actionDeleteLayout(int $id): array
{
$layout = $this->layouts->getById($id);
$layout->hasBlocks = 0;
Expand All @@ -54,12 +60,12 @@ public function actionDeleteLayout(int $id)
}

/**
* Get all blocks for a layout as json
* Get all blocks for a layout
*
* @param int $layout
* @return Response
* @return array
*/
public function actionBlocks(int $layout)
public function actionBlocks(int $layout): array
{
$layout = $this->layouts->getById($layout);
return [
Expand All @@ -70,9 +76,9 @@ public function actionBlocks(int $layout)
/**
* Save blocks
*
* @return Response
* @return array
*/
public function actionSaveBlocks()
public function actionSaveBlocks(): array
{
$_this = $this;
$blocksData = $this->request->getRequiredParam('blocks');
Expand Down Expand Up @@ -104,31 +110,4 @@ public function actionSaveBlocks()
'layout' => $layout
];
}

public function actionEntries(string $uid)
{
$entryTypes = array_values(array_filter(\Craft::$app->sections->getAllEntryTypes(), function ($entryType) use ($uid) {
return $uid == $entryType->uid;
}));
$entries = array_map(function ($entry) {
return [
'uid' => $entry->uid,
'title' => $entry->title
];
}, Entry::find()->type($entryTypes[0])->all());
usort($entries, function ($a, $b) {
return ($a['title'] < $b['title']) ? -1 : 1;
});
return [
'entries' => $entries
];
}

public function actionEntryViewModes(string $uid, string $theme)
{
$layout = Themes::$plugin->layouts->get($theme, LayoutService::ENTRY_HANDLE, $uid);
return [
'viewModes' => $layout->viewModes
];
}
}
2 changes: 2 additions & 0 deletions src/controllers/CpRulesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Ryssbowh\CraftThemes\Themes;
use Ryssbowh\CraftThemes\assets\RulesAssets;
use Ryssbowh\CraftThemes\services\RulesService;

class CpRulesController extends Controller
{
Expand Down Expand Up @@ -77,6 +78,7 @@ public function actionSave()
if (!\Craft::$app->getPlugins()->savePluginSettings($plugin, $settings)) {
$this->setFailFlash(\Craft::t('themes', 'Couldn’t save theme rules'));
} else {
Themes::$plugin->cache->flushGroup(RulesService::CACHE_GROUP);
$this->setSuccessFlash(\Craft::t('themes', 'Rules have been saved'));
}
$this->redirect('themes/rules');
Expand Down
10 changes: 6 additions & 4 deletions src/events/FieldDisplayerEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Ryssbowh\CraftThemes\exceptions\FieldDisplayerException;
use Ryssbowh\CraftThemes\interfaces\FieldDisplayerInterface;
use Ryssbowh\CraftThemes\models\fieldDisplayers\AssetLink;
use Ryssbowh\CraftThemes\models\fieldDisplayers\AssetRenderFile;
use Ryssbowh\CraftThemes\models\fieldDisplayers\AssetRendered;
use Ryssbowh\CraftThemes\models\fieldDisplayers\AuthorDefault;
use Ryssbowh\CraftThemes\models\fieldDisplayers\CategoryList;
Expand All @@ -21,10 +22,10 @@
use Ryssbowh\CraftThemes\models\fieldDisplayers\MultiSelectDefault;
use Ryssbowh\CraftThemes\models\fieldDisplayers\NumberDefault;
use Ryssbowh\CraftThemes\models\fieldDisplayers\PlainTextFull;
use Ryssbowh\CraftThemes\models\fieldDisplayers\PlainTextTrimmed;
use Ryssbowh\CraftThemes\models\fieldDisplayers\PlainTextTruncated;
use Ryssbowh\CraftThemes\models\fieldDisplayers\RadioButtonsDefault;
use Ryssbowh\CraftThemes\models\fieldDisplayers\RedactorFull;
use Ryssbowh\CraftThemes\models\fieldDisplayers\RedactorTrimmed;
use Ryssbowh\CraftThemes\models\fieldDisplayers\RedactorTruncated;
use Ryssbowh\CraftThemes\models\fieldDisplayers\TagsDefault;
use Ryssbowh\CraftThemes\models\fieldDisplayers\TimeDefault;
use Ryssbowh\CraftThemes\models\fieldDisplayers\TitleDefault;
Expand All @@ -44,6 +45,7 @@ public function init()
$this->registerMany([
AssetLink::class,
AssetRendered::class,
AssetRenderFile::class,
AuthorDefault::class,
CategoryRendered::class,
CategoryList::class,
Expand All @@ -59,10 +61,10 @@ public function init()
MultiSelectDefault::class,
NumberDefault::class,
PlainTextFull::class,
PlainTextTrimmed::class,
PlainTextTruncated::class,
RadioButtonsDefault::class,
RedactorFull::class,
RedactorTrimmed::class,
RedactorTruncated::class,
TagsDefault::class,
TimeDefault::class,
TitleDefault::class,
Expand Down
Loading

0 comments on commit 55757ce

Please sign in to comment.