Skip to content

Commit

Permalink
Made the list component configurable for list view
Browse files Browse the repository at this point in the history
  • Loading branch information
colintucker committed Sep 27, 2017
1 parent 19b4391 commit 7c101c4
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 11 deletions.
2 changes: 1 addition & 1 deletion client/dist/styles/bundle.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions client/src/styles/components/BaseListComponent.scss
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,18 @@

> section.content {

header a {
color: inherit;
header {

margin-bottom: $spacer-half;

> * {
margin-bottom: 0;
}

a {
color: inherit;
}

}

div.details {
Expand Down
7 changes: 1 addition & 6 deletions client/src/styles/components/TileComponent.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,10 @@

margin-top: auto;

header > * {
font-size: 1rem;
line-height: 1.2;
}

div.details > span {
display: block;
margin-right: 0;
margin-bottom: $spacer-half;
margin-bottom: $spacer-quarter;
}

}
Expand Down
42 changes: 42 additions & 0 deletions src/Extensions/Lists/ListViewExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use SilverWare\Forms\FieldSection;
use SilverWare\Forms\ViewportsField;
use SilverWare\ORM\FieldType\DBViewports;
use SilverWare\Tools\ClassTools;
use SilverWare\Tools\ImageTools;
use SilverWare\Tools\ViewTools;

Expand All @@ -59,6 +60,7 @@ class ListViewExtension extends DataExtension
* @config
*/
private static $db = [
'ListClass' => 'Varchar(255)',
'ListConfig' => 'Text'
];

Expand Down Expand Up @@ -173,6 +175,11 @@ public function updateCMSFields(FieldList $fields)
'ListViewOptions',
$this->owner->fieldLabel('ListView'),
[
DropdownField::create(
'ListClass',
$this->owner->fieldLabel('ListClass'),
$this->owner->getListClassOptions()
)->setEmptyString(' ')->setAttribute('data-placeholder', $placeholder),
TextField::create(
$this->nestName('Title'),
$this->owner->fieldLabel('ListTitle')
Expand Down Expand Up @@ -319,6 +326,7 @@ public function updateFieldLabels(&$labels)
$labels['NumberOfItems'] = _t(__CLASS__ . '.NUMBEROFITEMS', 'Number of items');
$labels['ReverseItems'] = _t(__CLASS__ . '.REVERSEITEMS', 'Reverse items');
$labels['ImageItems'] = _t(__CLASS__ . '.IMAGEITEMS', 'Show only items with images');
$labels['ListClass'] = _t(__CLASS__ . '.LISTCLASS', 'List class');
}

/**
Expand Down Expand Up @@ -494,6 +502,24 @@ public function getListSource()
*/
public function getListComponentClass()
{
if ($class = $this->owner->ListClass) {
return $class;
}

return $this->owner->getDefaultListComponentClass();
}

/**
* Answers the default class to use for the list component.
*
* @return string
*/
public function getDefaultListComponentClass()
{
if ($class = $this->owner->config()->list_component_class) {
return $class;
}

return Config::inst()->get(self::class, 'default_list_component_class');
}

Expand Down Expand Up @@ -553,6 +579,22 @@ public function hasListComponent()
return ($this->owner->ListComponent instanceof BaseListComponent);
}

/**
* Answers an array of options for the list class field.
*
* @return array
*/
public function getListClassOptions()
{
$classes = ClassTools::singleton()->getVisibleSubClasses(BaseListComponent::class);

foreach ($classes as $key => $value) {
$classes[$key] = Injector::inst()->get($key)->i18n_singular_name();
}

return $classes;
}

/**
* Answers true if the given value is considered to be an 'empty' value.
*
Expand Down
4 changes: 2 additions & 2 deletions src/Tools/ClassTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ public function getVisibleSubClasses($name)
$instance = Injector::inst()->get($class);

if ($ancestor = $instance->stat('hide_ancestor')) {
$remove[$ancestor] = $ancestor;
$remove[strtolower($ancestor)] = $ancestor;
}

if ($instance instanceof HiddenClass) {
$remove[$class] = $class;
$remove[strtolower($class)] = $class;
}

}
Expand Down

0 comments on commit 7c101c4

Please sign in to comment.