From d90d170c9538c3ba010ea0662b87f6a76fb70b1b Mon Sep 17 00:00:00 2001 From: Luke Towers Date: Tue, 12 Nov 2019 17:12:15 -0600 Subject: [PATCH 1/2] Initial WIP on documenting the changes implemented in https://github.com/octobercms/october/pull/4764 --- Plugin.php | 10 +++++ controllers/Cities.php | 25 +++++++++++ controllers/Locations.php | 25 +++++++++++ controllers/cities/_list_toolbar.htm | 21 +++++++++ controllers/cities/config_form.yaml | 31 +++++++++++++ controllers/cities/config_list.yaml | 47 ++++++++++++++++++++ controllers/cities/create.htm | 48 ++++++++++++++++++++ controllers/cities/index.htm | 2 + controllers/cities/preview.htm | 19 ++++++++ controllers/cities/update.htm | 56 ++++++++++++++++++++++++ controllers/locations/_list_toolbar.htm | 21 +++++++++ controllers/locations/config_filter.yaml | 19 ++++++++ controllers/locations/config_form.yaml | 31 +++++++++++++ controllers/locations/config_list.yaml | 49 +++++++++++++++++++++ controllers/locations/create.htm | 48 ++++++++++++++++++++ controllers/locations/index.htm | 2 + controllers/locations/preview.htm | 19 ++++++++ controllers/locations/update.htm | 56 ++++++++++++++++++++++++ models/Channel.php | 2 - models/City.php | 31 +++++++++++++ models/Location.php | 47 ++++++++++++++++++++ models/city/columns.yaml | 11 +++++ models/city/fields.yaml | 8 ++++ models/location/columns.yaml | 15 +++++++ models/location/fields.yaml | 8 ++++ updates/create_tables.php | 19 ++++++++ updates/seed_tables.php | 33 +++++++++++++- 27 files changed, 699 insertions(+), 4 deletions(-) create mode 100644 controllers/Cities.php create mode 100644 controllers/Locations.php create mode 100644 controllers/cities/_list_toolbar.htm create mode 100644 controllers/cities/config_form.yaml create mode 100644 controllers/cities/config_list.yaml create mode 100644 controllers/cities/create.htm create mode 100644 controllers/cities/index.htm create mode 100644 controllers/cities/preview.htm create mode 100644 controllers/cities/update.htm create mode 100644 controllers/locations/_list_toolbar.htm create mode 100644 controllers/locations/config_filter.yaml create mode 100644 controllers/locations/config_form.yaml create mode 100644 controllers/locations/config_list.yaml create mode 100644 controllers/locations/create.htm create mode 100644 controllers/locations/index.htm create mode 100644 controllers/locations/preview.htm create mode 100644 controllers/locations/update.htm create mode 100644 models/City.php create mode 100644 models/Location.php create mode 100644 models/city/columns.yaml create mode 100644 models/city/fields.yaml create mode 100644 models/location/columns.yaml create mode 100644 models/location/fields.yaml diff --git a/Plugin.php b/Plugin.php index 8b66f68..02e22ee 100644 --- a/Plugin.php +++ b/Plugin.php @@ -87,6 +87,16 @@ public function registerNavigation() 'icon' => 'icon-database', 'url' => Backend::url('october/test/pages'), ], + 'cities' => [ + 'label' => 'Cities', + 'icon' => 'icon-database', + 'url' => Backend::url('october/test/cities'), + ], + 'locations' => [ + 'label' => 'Locations', + 'icon' => 'icon-database', + 'url' => Backend::url('october/test/locations'), + ], ], ], ]; diff --git a/controllers/Cities.php b/controllers/Cities.php new file mode 100644 index 0000000..ebbb65a --- /dev/null +++ b/controllers/Cities.php @@ -0,0 +1,25 @@ + + + New City + + + + diff --git a/controllers/cities/config_form.yaml b/controllers/cities/config_form.yaml new file mode 100644 index 0000000..3a6243e --- /dev/null +++ b/controllers/cities/config_form.yaml @@ -0,0 +1,31 @@ +# =================================== +# Form Behavior Config +# =================================== + +# Record name +name: City + +# Model Form Field configuration +form: $/october/test/models/city/fields.yaml + +# Model Class name +modelClass: October\Test\Models\City + +# Default redirect location +defaultRedirect: october/test/cities + +# Create page +create: + title: Create City + redirect: october/test/cities/update/:id + redirectClose: october/test/cities + +# Update page +update: + title: Edit City + redirect: october/test/cities + redirectClose: october/test/cities + +# Preview page +preview: + title: Preview City diff --git a/controllers/cities/config_list.yaml b/controllers/cities/config_list.yaml new file mode 100644 index 0000000..5f0fc4b --- /dev/null +++ b/controllers/cities/config_list.yaml @@ -0,0 +1,47 @@ +# =================================== +# List Behavior Config +# =================================== + +# Model List Column configuration +list: $/october/test/models/city/columns.yaml + +# Model Class name +modelClass: October\Test\Models\City + +# List Title +title: Manage Cities + +# Link URL for each record +recordUrl: october/test/cities/update/:id + +# Message to display if the list is empty +noRecordsMessage: backend::lang.list.no_records + +# Records to display per page +recordsPerPage: 20 + +# Display page numbers with pagination, disable to improve performance +showPageNumbers: true + +# Displays the list column set up button +showSetup: true + +# Displays the sorting link on each column +showSorting: true + +# Default sorting column +# defaultSort: +# column: created_at +# direction: desc + +# Display checkboxes next to each record +showCheckboxes: true + +# Toolbar widget configuration +toolbar: + # Partial for toolbar buttons + buttons: list_toolbar + + # Search widget configuration + search: + prompt: backend::lang.list.search_prompt diff --git a/controllers/cities/create.htm b/controllers/cities/create.htm new file mode 100644 index 0000000..daac95b --- /dev/null +++ b/controllers/cities/create.htm @@ -0,0 +1,48 @@ + + + + +fatalError): ?> + + 'layout']) ?> + +
+ formRender() ?> +
+ +
+
+ + + + or Cancel + +
+
+ + + + + +

fatalError) ?>

+

Return to cities list

+ + diff --git a/controllers/cities/index.htm b/controllers/cities/index.htm new file mode 100644 index 0000000..766877d --- /dev/null +++ b/controllers/cities/index.htm @@ -0,0 +1,2 @@ + +listRender() ?> diff --git a/controllers/cities/preview.htm b/controllers/cities/preview.htm new file mode 100644 index 0000000..6fcfea6 --- /dev/null +++ b/controllers/cities/preview.htm @@ -0,0 +1,19 @@ + + + + +fatalError): ?> + +
+ formRenderPreview() ?> +
+ + + +

fatalError) ?>

+

Return to cities list

+ + diff --git a/controllers/cities/update.htm b/controllers/cities/update.htm new file mode 100644 index 0000000..a970451 --- /dev/null +++ b/controllers/cities/update.htm @@ -0,0 +1,56 @@ + + + + +fatalError): ?> + + 'layout']) ?> + +
+ formRender() ?> +
+ +
+
+ + + + + or Cancel + +
+
+ + + + + +

fatalError) ?>

+

Return to cities list

+ + diff --git a/controllers/locations/_list_toolbar.htm b/controllers/locations/_list_toolbar.htm new file mode 100644 index 0000000..a537869 --- /dev/null +++ b/controllers/locations/_list_toolbar.htm @@ -0,0 +1,21 @@ +
+ + New Location + + + +
diff --git a/controllers/locations/config_filter.yaml b/controllers/locations/config_filter.yaml new file mode 100644 index 0000000..95d2702 --- /dev/null +++ b/controllers/locations/config_filter.yaml @@ -0,0 +1,19 @@ +# =================================== +# Filter Scope Definitions +# =================================== + +scopes: + country: + label: Country + type: group + conditions: country_id in (:filtered) + modelClass: October\Test\Models\Location + options: getCountryOptions + default: [1] + city: + label: City + type: group + conditions: city_id in (:filtered) + modelClass: October\Test\Models\Location + options: getCityOptions + dependsOn: country \ No newline at end of file diff --git a/controllers/locations/config_form.yaml b/controllers/locations/config_form.yaml new file mode 100644 index 0000000..5904071 --- /dev/null +++ b/controllers/locations/config_form.yaml @@ -0,0 +1,31 @@ +# =================================== +# Form Behavior Config +# =================================== + +# Record name +name: Location + +# Model Form Field configuration +form: $/october/test/models/location/fields.yaml + +# Model Class name +modelClass: October\Test\Models\Location + +# Default redirect location +defaultRedirect: october/test/locations + +# Create page +create: + title: Create Location + redirect: october/test/locations/update/:id + redirectClose: october/test/locations + +# Update page +update: + title: Edit Location + redirect: october/test/locations + redirectClose: october/test/locations + +# Preview page +preview: + title: Preview Location diff --git a/controllers/locations/config_list.yaml b/controllers/locations/config_list.yaml new file mode 100644 index 0000000..784fad4 --- /dev/null +++ b/controllers/locations/config_list.yaml @@ -0,0 +1,49 @@ +# =================================== +# List Behavior Config +# =================================== + +# Model List Column configuration +list: $/october/test/models/location/columns.yaml + +# Model Class name +modelClass: October\Test\Models\Location + +# List Title +title: Manage Locations + +# Link URL for each record +recordUrl: october/test/locations/update/:id + +# Message to display if the list is empty +noRecordsMessage: backend::lang.list.no_records + +# Records to display per page +recordsPerPage: 20 + +# Display page numbers with pagination, disable to improve performance +showPageNumbers: true + +# Displays the list column set up button +showSetup: true + +# Displays the sorting link on each column +showSorting: true + +# Default sorting column +# defaultSort: +# column: created_at +# direction: desc + +# Display checkboxes next to each record +showCheckboxes: true + +# Toolbar widget configuration +toolbar: + # Partial for toolbar buttons + buttons: list_toolbar + + # Search widget configuration + search: + prompt: backend::lang.list.search_prompt + +filter: config_filter.yaml \ No newline at end of file diff --git a/controllers/locations/create.htm b/controllers/locations/create.htm new file mode 100644 index 0000000..db6b369 --- /dev/null +++ b/controllers/locations/create.htm @@ -0,0 +1,48 @@ + + + + +fatalError): ?> + + 'layout']) ?> + +
+ formRender() ?> +
+ +
+
+ + + + or Cancel + +
+
+ + + + + +

fatalError) ?>

+

Return to locations list

+ + diff --git a/controllers/locations/index.htm b/controllers/locations/index.htm new file mode 100644 index 0000000..766877d --- /dev/null +++ b/controllers/locations/index.htm @@ -0,0 +1,2 @@ + +listRender() ?> diff --git a/controllers/locations/preview.htm b/controllers/locations/preview.htm new file mode 100644 index 0000000..4175ba6 --- /dev/null +++ b/controllers/locations/preview.htm @@ -0,0 +1,19 @@ + + + + +fatalError): ?> + +
+ formRenderPreview() ?> +
+ + + +

fatalError) ?>

+

Return to locations list

+ + diff --git a/controllers/locations/update.htm b/controllers/locations/update.htm new file mode 100644 index 0000000..d9aa490 --- /dev/null +++ b/controllers/locations/update.htm @@ -0,0 +1,56 @@ + + + + +fatalError): ?> + + 'layout']) ?> + +
+ formRender() ?> +
+ +
+
+ + + + + or Cancel + +
+
+ + + + + +

fatalError) ?>

+

Return to locations list

+ + diff --git a/models/Channel.php b/models/Channel.php index 5b51b08..bfa40cb 100644 --- a/models/Channel.php +++ b/models/Channel.php @@ -7,7 +7,6 @@ */ class Channel extends Model { - use \October\Rain\Database\Traits\NestedTree; /** @@ -50,5 +49,4 @@ public function getCustomTitleAttribute() { return $this->title.' (#'.$this->id.')'; } - } \ No newline at end of file diff --git a/models/City.php b/models/City.php new file mode 100644 index 0000000..65033ec --- /dev/null +++ b/models/City.php @@ -0,0 +1,31 @@ + Location::class]; + public $belongsTo = ['country' => Country::class]; +} diff --git a/models/Location.php b/models/Location.php new file mode 100644 index 0000000..ed9cfee --- /dev/null +++ b/models/Location.php @@ -0,0 +1,47 @@ + Country::class, + 'city' => City::class, + ]; + + public function getCountryOptions() + { + return Country::lists('name', 'id'); + } + + public function getCityOptions($scopes = null) + { + if (!empty($scopes['country']->value)) { + return City::whereIn('country_id', array_keys($scopes['country']->value))->lists('name', 'id'); + } else { + return City::lists('name', 'id'); + } + } +} diff --git a/models/city/columns.yaml b/models/city/columns.yaml new file mode 100644 index 0000000..c5a3352 --- /dev/null +++ b/models/city/columns.yaml @@ -0,0 +1,11 @@ +# =================================== +# List Column Definitions +# =================================== + +columns: + name: + label: Name + country_name: + label: Country + relation: country + select: name \ No newline at end of file diff --git a/models/city/fields.yaml b/models/city/fields.yaml new file mode 100644 index 0000000..c611f31 --- /dev/null +++ b/models/city/fields.yaml @@ -0,0 +1,8 @@ +# =================================== +# Form Field Definitions +# =================================== + +fields: + id: + label: ID + disabled: true diff --git a/models/location/columns.yaml b/models/location/columns.yaml new file mode 100644 index 0000000..a335544 --- /dev/null +++ b/models/location/columns.yaml @@ -0,0 +1,15 @@ +# =================================== +# List Column Definitions +# =================================== + +columns: + name: + label: Name + city_name: + label: City + relation: city + select: name + country_name: + label: Country + relation: country + select: name diff --git a/models/location/fields.yaml b/models/location/fields.yaml new file mode 100644 index 0000000..c611f31 --- /dev/null +++ b/models/location/fields.yaml @@ -0,0 +1,8 @@ +# =================================== +# Form Field Definitions +# =================================== + +fields: + id: + label: ID + disabled: true diff --git a/updates/create_tables.php b/updates/create_tables.php index f49484e..d441b16 100644 --- a/updates/create_tables.php +++ b/updates/create_tables.php @@ -300,10 +300,29 @@ public function up() $table->integer('type')->unsigned(); $table->text('content')->nullable(); }); + + /** + * Test 9: Locations + */ + Schema::create('october_test_cities', function ($table) { + $table->engine = 'InnoDB'; + $table->increments('id')->unsigned(); + $table->integer('country_id')->unsigned(); + $table->string('name'); + }); + Schema::create('october_test_locations', function ($table) { + $table->engine = 'InnoDB'; + $table->increments('id')->unsigned(); + $table->integer('country_id')->unsigned(); + $table->integer('city_id')->unsigned(); + $table->string('name'); + }); } public function down() { + Schema::dropIfExists('october_test_locations'); + Schema::dropIfExists('october_test_cities'); Schema::dropIfExists('october_test_gallery_entity'); Schema::dropIfExists('october_test_galleries'); Schema::dropIfExists('october_test_comments'); diff --git a/updates/seed_tables.php b/updates/seed_tables.php index 1afdfbb..3587c83 100644 --- a/updates/seed_tables.php +++ b/updates/seed_tables.php @@ -16,6 +16,8 @@ use October\Test\Models\Member; use October\Test\Models\Category; use October\Test\Models\Attribute; +use October\Test\Models\City; +use October\Test\Models\Location; use October\Rain\Database\Updates\Seeder; class SeedAllTables extends Seeder @@ -77,7 +79,7 @@ public function run() /* * Test 4: Countries */ - Country::create([ + $country1 = Country::create([ 'name' => 'Petoria', 'code' => 'petoria', 'language' => 'eh', @@ -92,7 +94,7 @@ public function run() ] ]); - Country::create([ + $country2 = Country::create([ 'name' => 'Blueseed', 'code' => 'blueseed', 'language' => 'bs', @@ -105,6 +107,33 @@ public function run() ] ]); + /* + * Test 9: Locations + */ + $cities = [ + $country1->id => ['Regina', 'Vancouver', 'Toronto', 'Ottawa'], + $country2->id => ['New York', 'Seattle', 'Boston', 'San Francisco'], + ]; + + $insertCities = []; + foreach ($cities as $countryId => $cityNames) { + foreach ($cityNames as $name) { + $insertCities[] = ['country_id' => $countryId, 'name' => $name]; + } + } + + City::insert($insertCities); + Location::insert([ + ['country_id' => $country1->id, 'city_id' => 1, 'name' => '240 5th Ave'], + ['country_id' => $country1->id, 'city_id' => 2, 'name' => '101 McKay Street'], + ['country_id' => $country1->id, 'city_id' => 3, 'name' => '123 Nowhere Lane'], + ['country_id' => $country1->id, 'city_id' => 4, 'name' => '10099 Bob Loop'], + ['country_id' => $country2->id, 'city_id' => 5, 'name' => '9442 Scary Street'], + ['country_id' => $country2->id, 'city_id' => 6, 'name' => '5309 Imagination Crescrent'], + ['country_id' => $country2->id, 'city_id' => 7, 'name' => '22 2201 Seymour Drive'], + ['country_id' => $country2->id, 'city_id' => 8, 'name' => '2322 Xray Alphabet'], + ]); + /* * Test 5: Reviews */ From 3149843a46e04f75b08ebefeac2bba9542fc0200 Mon Sep 17 00:00:00 2001 From: Luke Towers Date: Wed, 13 Nov 2019 13:53:32 -0600 Subject: [PATCH 2/2] remove broken default --- controllers/locations/config_filter.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/controllers/locations/config_filter.yaml b/controllers/locations/config_filter.yaml index 95d2702..f2a94d7 100644 --- a/controllers/locations/config_filter.yaml +++ b/controllers/locations/config_filter.yaml @@ -9,7 +9,6 @@ scopes: conditions: country_id in (:filtered) modelClass: October\Test\Models\Location options: getCountryOptions - default: [1] city: label: City type: group