From f8e8653c5c765e743f5acb5328cd43e1d0dc10f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=8D=9A=E4=BA=9E?= Date: Mon, 1 May 2023 23:35:38 +0800 Subject: [PATCH] add widget --- app/controllers/property_hires_controller.rb | 41 ++++++++++++++++---- modules/property_hire/_widget1.html.erb | 17 ++++++++ modules/property_hire/info.json | 10 +++++ 3 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 modules/property_hire/_widget1.html.erb diff --git a/app/controllers/property_hires_controller.rb b/app/controllers/property_hires_controller.rb index 93e0982..04b40f1 100644 --- a/app/controllers/property_hires_controller.rb +++ b/app/controllers/property_hires_controller.rb @@ -2,10 +2,34 @@ class PropertyHiresController < ApplicationController include Admin::PropertyHiresHelper FrontendMethods = ["hire", "view_calendar", "hire_success"] def index - properties = Property.filter_by_categories.filter_by_tags.sort_order + properties = Property.filter_by_categories.sort_order + url = "/#{I18n.locale}#{OrbitHelper.page.get_url}" + data = index_data(properties, url) + headers = [ + { + "column" => t("property_hire.title") + }, + { + "column" => "" + }, + { + "column" => t("property_hire.location") + }, + { + "column" => t("property_hire.actions") + } + ] + { + "properties" => data, + "headers" => headers, + "total_pages" => (properties.total_pages rescue 1) + } + end + + def index_data(properties, url) data = properties.collect do |property| - actions = [] - url_to_show = OrbitHelper.url_to_show(property.to_param) + actions = [] + url_to_show = "#{url}/#{property.to_param}" if property.can_be_hired hire_url = url_to_show + "?method=hire" actions << { @@ -33,13 +57,16 @@ class PropertyHiresController < ApplicationController "actions" => actions } end + end + + def widget + properties = Property.filter_by_widget_categories.sort_order + url = OrbitHelper.get_current_widget.get_read_more_page_url + data = index_data(properties, url) headers = [ { "column" => t("property_hire.title") }, - { - "column" => "" - }, { "column" => t("property_hire.location") }, @@ -50,7 +77,7 @@ class PropertyHiresController < ApplicationController { "properties" => data, "headers" => headers, - "total_pages" => properties.total_pages + "total_pages" => (properties.total_pages rescue 1) } end diff --git a/modules/property_hire/_widget1.html.erb b/modules/property_hire/_widget1.html.erb new file mode 100644 index 0000000..06c3a9a --- /dev/null +++ b/modules/property_hire/_widget1.html.erb @@ -0,0 +1,17 @@ + + + + + + + + + + + + + +
{{column}}
{{title}}{{location}} + {{text}} +
+{{pagination_goes_here}} \ No newline at end of file diff --git a/modules/property_hire/info.json b/modules/property_hire/info.json index 7e2e252..f338727 100644 --- a/modules/property_hire/info.json +++ b/modules/property_hire/info.json @@ -24,5 +24,15 @@ }, "thumbnail" : "event_news_thumb2.png" } + ], + "widgets" : [ + { + "filename" : "widget1", + "name" : { + "zh_tw" : "1. 列表", + "en" : "1. List" + }, + "thumbnail" : "thumb.png" + } ] } \ No newline at end of file