Skip to content

Commit

Permalink
Making websites with October CMS - Part 17 - Adding Options for Compo…
Browse files Browse the repository at this point in the history
…nents
  • Loading branch information
Ivan Doric committed Oct 23, 2016
1 parent ff38239 commit 146095f
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 101 deletions.
108 changes: 13 additions & 95 deletions octobermovies.sublime-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -519,29 +519,11 @@
},
"buffers":
[
{
"file": "plugins/watchlearn/movies/Plugin.php",
"settings":
{
"buffer_size": 542,
"encoding": "UTF-8",
"line_ending": "Unix"
}
},
{
"file": "plugins/watchlearn/movies/components/Actors.php",
"settings":
{
"buffer_size": 486,
"encoding": "UTF-8",
"line_ending": "Unix"
}
},
{
"file": "plugins/watchlearn/movies/components/actors/default.htm",
"settings":
{
"buffer_size": 149,
"buffer_size": 1634,
"encoding": "UTF-8",
"line_ending": "Unix"
}
Expand Down Expand Up @@ -813,24 +795,24 @@
"expanded_folders":
[
"/Users/ivan/Development/public/octobermovies",
"/Users/ivan/Development/public/octobermovies/_assets_",
"/Users/ivan/Development/public/octobermovies/plugins",
"/Users/ivan/Development/public/octobermovies/plugins/watchlearn",
"/Users/ivan/Development/public/octobermovies/plugins/watchlearn/movies",
"/Users/ivan/Development/public/octobermovies/plugins/watchlearn/movies/components",
"/Users/ivan/Development/public/octobermovies/plugins/watchlearn/movies/components/actors",
"/Users/ivan/Development/public/octobermovies/plugins/watchlearn/movies/formwidgets",
"/Users/ivan/Development/public/octobermovies/plugins/watchlearn/movies/formwidgets/actorbox",
"/Users/ivan/Development/public/octobermovies/plugins/watchlearn/movies/formwidgets/actorbox/assets/css",
"/Users/ivan/Development/public/octobermovies/plugins/watchlearn/movies/formwidgets/actorbox/assets/js",
"/Users/ivan/Development/public/octobermovies/themes",
"/Users/ivan/Development/public/octobermovies/themes/olympos",
"/Users/ivan/Development/public/octobermovies/themes/olympos/pages"
],
"file_history":
[
"/Users/ivan/Development/public/octobermovies/plugins/watchlearn/movies/components/actors/default.htm",
"/Users/ivan/Development/public/octobermovies/plugins/watchlearn/movies/Plugin.php",
"/Users/ivan/components/Actors.php",
"/Users/ivan/Development/public/octobermovies/plugins/watchlearn/movies/models/movie/fields.yaml",
"/Users/ivan/Development/public/octobermovies/plugins/watchlearn/movies/Plugin.php",
"/Users/ivan/Development/public/octobermovies/plugins/watchlearn/movies/models/Movie.php",
"/Users/ivan/Development/public/octobermovies/plugins/watchlearn/movies/models/Actor.php",
"/Users/ivan/Development/public/octobermovies/themes/olympos/pages/movie-single.htm",
Expand Down Expand Up @@ -954,12 +936,11 @@
"/Users/ivan/Development/public/springfall/vendor/laravel/framework/src/Illuminate/Foundation/Auth/RegistersUsers.php",
"/Users/ivan/Development/public/springfall/resources/views/partials/footer.blade.php",
"/Users/ivan/Development/public/springfall/.env",
"/Users/ivan/Development/public/springfall/app/Role.php",
"/Users/ivan/Library/Application Support/Sublime Text 3/Packages/Laravel Blade Highlighter/blade.sublime-syntax"
"/Users/ivan/Development/public/springfall/app/Role.php"
],
"find":
{
"height": 37.0
"height": 44.0
},
"find_in_files":
{
Expand Down Expand Up @@ -1162,55 +1143,24 @@
"groups":
[
{
"selected": 2,
"selected": 0,
"sheets":
[
{
"buffer": 0,
"file": "plugins/watchlearn/movies/Plugin.php",
"semi_transient": false,
"settings":
{
"buffer_size": 542,
"regions":
{
},
"selection":
[
[
238,
238
]
],
"settings":
{
"incomplete_sync": null,
"remote_loading": false,
"synced": false,
"syntax": "Packages/PHP/PHP.sublime-syntax"
},
"translation.x": 0.0,
"translation.y": 0.0,
"zoom_level": 1.0
},
"stack_index": 1,
"type": "text"
},
{
"buffer": 1,
"file": "plugins/watchlearn/movies/components/Actors.php",
"semi_transient": false,
"settings":
{
"buffer_size": 486,
"buffer_size": 1634,
"regions":
{
},
"selection":
[
[
446,
446
1188,
1188
]
],
"settings":
Expand All @@ -1222,39 +1172,7 @@
"syntax": "Packages/PHP/PHP.sublime-syntax"
},
"translation.x": 0.0,
"translation.y": 223.0,
"zoom_level": 1.0
},
"stack_index": 2,
"type": "text"
},
{
"buffer": 2,
"file": "plugins/watchlearn/movies/components/actors/default.htm",
"semi_transient": false,
"settings":
{
"buffer_size": 149,
"regions":
{
},
"selection":
[
[
91,
91
]
],
"settings":
{
"_anf_new": "",
"incomplete_sync": null,
"remote_loading": false,
"synced": false,
"syntax": "Packages/Twig/Syntaxes/HTML (Twig).tmLanguage"
},
"translation.x": 0.0,
"translation.y": 0.0,
"translation.y": 1889.0,
"zoom_level": 1.0
},
"stack_index": 0,
Expand All @@ -1265,7 +1183,7 @@
],
"incremental_find":
{
"height": 37.0
"height": 44.0
},
"input":
{
Expand Down Expand Up @@ -1306,7 +1224,7 @@
"project": "octobermovies.sublime-project",
"replace":
{
"height": 70.0
"height": 84.0
},
"save_all_on_build": true,
"select_file":
Expand Down
42 changes: 41 additions & 1 deletion plugins/watchlearn/movies/components/Actors.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,52 @@ public function componentDetails(){
];
}

public function defineProperties(){
return [
'results' => [
'title' => 'Number of Actors',
'description' => 'How many actors do you want to display?',
'default' => 0,
'validationPattern' => '^[0-9]+$',
'validationMessage' => 'Only numbers allowed'
],

'sortOrder' => [
'title' => 'Sort Actors',
'description' => 'Sort those actors',
'type' => 'dropdown',
'default' => 'name asc'
]
];
}

public function getSortOrderOptions(){
return [
'name asc' => 'Name (ascending)',
'name desc' => 'Name (descending)'
];
}

public function onRun(){
$this->actors = $this->loadActors();
}

protected function loadActors(){
return Actor::all();
$query = Actor::all();

if($this->property('sortOrder') == 'name asc'){
$query = $query->sortBy('name');
}

if($this->property('sortOrder') == 'name desc'){
$query = $query->sortByDesc('name');
}

if($this->property('results') > 0){
$query = $query->take($this->property('results'));
}

return $query;
}

public $actors;
Expand Down
9 changes: 4 additions & 5 deletions themes/olympos/pages/homepage.htm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
is_hidden = 0

[actors]
results = 0
sortOrder = "name desc"
==
<h2>This is our homepage! Yay!</h2>

Expand All @@ -18,8 +20,5 @@ <h2>This is our homepage! Yay!</h2>
<p>Tenetur iure quidem ratione perferendis molestias repudiandae officiis consequatur repellat perspiciatis nulla, dolorum incidunt rem assumenda minus exercitationem. Ea, accusamus!</p>
<p>Nihil laborum quasi ab harum omnis deserunt debitis distinctio laboriosam odit, vero explicabo voluptate veritatis facilis aliquid voluptatibus inventore. Perferendis.</p>{% set actors = actors.actors %}

<ul>
{% for actor in actors %}
<li>{{ actor.name }} {{ actor.lastname }}</li>
{% endfor %}
</ul>

{% component 'actors' %}

0 comments on commit 146095f

Please sign in to comment.