From 2d0d4a65c2c85dfbdb8559a3f7ea8af0424ae00c Mon Sep 17 00:00:00 2001 From: formsdev <136701234+formsdev@users.noreply.github.com> Date: Wed, 25 Oct 2023 00:25:15 +0530 Subject: [PATCH] Industry & Types template pages (#226) * Industry & Types template pages * fix sitemap for templates --- app/Http/Controllers/SitemapController.php | 20 +- app/Http/Controllers/TemplateController.php | 14 +- app/Service/SeoMetaResolver.php | 24 ++ .../pages/templates/TemplatesList.vue | 111 ++++++--- .../pages/welcome/TemplatesSlider.vue | 2 +- .../js/pages/templates/industries-show.vue | 232 +++++++++++++++++ resources/js/pages/templates/types-show.vue | 233 ++++++++++++++++++ resources/js/router/routes.js | 2 + resources/js/store/modules/open/templates.js | 34 +-- 9 files changed, 618 insertions(+), 54 deletions(-) create mode 100644 resources/js/pages/templates/industries-show.vue create mode 100644 resources/js/pages/templates/types-show.vue diff --git a/app/Http/Controllers/SitemapController.php b/app/Http/Controllers/SitemapController.php index 8596b1f..7dca3e1 100644 --- a/app/Http/Controllers/SitemapController.php +++ b/app/Http/Controllers/SitemapController.php @@ -21,7 +21,7 @@ class SitemapController extends Controller ['/login', 0.4], ['/register', 0.4], ['/password/reset', 0.3], - ['/templates', 0.9], + ['/form-templates', 0.9], ]; public function getSitemap(Request $request) @@ -31,6 +31,8 @@ class SitemapController extends Controller $sitemap->add($this->createUrl($url[0], $url[1])); } $this->addTemplatesUrls($sitemap); + $this->addTemplatesTypesUrls($sitemap); + $this->addTemplatesIndustriesUrls($sitemap); return $sitemap->toResponse($request); } @@ -48,4 +50,20 @@ class SitemapController extends Controller } }); } + + private function addTemplatesTypesUrls(Sitemap $sitemap) + { + $types = json_decode(file_get_contents(resource_path('data/forms/templates/types.json')), true); + foreach ($types as $type) { + $sitemap->add($this->createUrl('/form-templates/types/' . $type['slug'], 0.7)); + } + } + + private function addTemplatesIndustriesUrls(Sitemap $sitemap) + { + $industries = json_decode(file_get_contents(resource_path('data/forms/templates/industries.json')), true); + foreach ($industries as $industry) { + $sitemap->add($this->createUrl('/form-templates/industries/' . $industry['slug'], 0.7)); + } + } } diff --git a/app/Http/Controllers/TemplateController.php b/app/Http/Controllers/TemplateController.php index 474d0ad..8a89614 100644 --- a/app/Http/Controllers/TemplateController.php +++ b/app/Http/Controllers/TemplateController.php @@ -18,12 +18,20 @@ class TemplateController extends Controller $limit = (int) $request->get('limit'); } - $templates = Template::where('publicly_listed', true) - ->when(Auth::check(), function ($query) { + $onlyMy = false; + if ($request->offsetExists('onlymy') && $request->get('onlymy')) { + $onlyMy = true; + } + + $templates = Template::limit($limit) + ->when(Auth::check() && !$onlyMy, function ($query) { + $query->where('publicly_listed', true); $query->orWhere('creator_id', Auth::id()); }) + ->when(Auth::check() && $onlyMy, function ($query) { + $query->where('creator_id', Auth::id()); + }) ->orderByDesc('created_at') - ->limit($limit) ->get(); return FormTemplateResource::collection($templates); diff --git a/app/Service/SeoMetaResolver.php b/app/Service/SeoMetaResolver.php index 95c3ac3..7cbd84a 100644 --- a/app/Service/SeoMetaResolver.php +++ b/app/Service/SeoMetaResolver.php @@ -36,6 +36,8 @@ class SeoMetaResolver 'integrations' => '/integrations', 'templates' => '/form-templates', 'templates_show' => '/form-templates/{slug}', + 'templates_types_show' => '/form-templates/types/{slug}', + 'templates_industries_show' => '/form-templates/industries/{slug}', ]; /** @@ -192,4 +194,26 @@ class SeoMetaResolver 'image' => $template->image_url ]; } + + private function getTemplatesTypesShowMeta(): array + { + $types = json_decode(file_get_contents(resource_path('data/forms/templates/types.json')), true); + $type = $types[array_search($this->patternData['slug'], array_column($types, 'slug'))]; + + return [ + 'title' => $type['meta_title'], + 'description' => Str::of($type['meta_description'])->limit(140), + ]; + } + + private function getTemplatesIndustriesShowMeta(): array + { + $industries = json_decode(file_get_contents(resource_path('data/forms/templates/industries.json')), true); + $industry = $industries[array_search($this->patternData['slug'], array_column($industries, 'slug'))]; + + return [ + 'title' => $industry['meta_title'], + 'description' => Str::of($industry['meta_description'])->limit(140), + ]; + } } diff --git a/resources/js/components/pages/templates/TemplatesList.vue b/resources/js/components/pages/templates/TemplatesList.vue index f3e0258..5b34ec3 100644 --- a/resources/js/components/pages/templates/TemplatesList.vue +++ b/resources/js/components/pages/templates/TemplatesList.vue @@ -1,37 +1,81 @@ + + diff --git a/resources/js/pages/templates/types-show.vue b/resources/js/pages/templates/types-show.vue new file mode 100644 index 0000000..b91ef87 --- /dev/null +++ b/resources/js/pages/templates/types-show.vue @@ -0,0 +1,233 @@ + + + + + + diff --git a/resources/js/router/routes.js b/resources/js/router/routes.js index 281ff78..8d67a56 100644 --- a/resources/js/router/routes.js +++ b/resources/js/router/routes.js @@ -70,6 +70,8 @@ export default [ { path: '/my-templates', name: 'my_templates', component: page('templates/my_templates.vue') }, { path: '/form-templates', name: 'templates', component: page('templates/templates.vue') }, { path: '/form-templates/:slug', name: 'templates.show', component: page('templates/show.vue') }, + { path: '/form-templates/types/:slug', name: 'templates.types.show', component: page('templates/types-show.vue') }, + { path: '/form-templates/industries/:slug', name: 'templates.industries.show', component: page('templates/industries-show.vue') }, { path: '*', component: page('errors/404.vue') } ] diff --git a/resources/js/store/modules/open/templates.js b/resources/js/store/modules/open/templates.js index 3e229fa..15f96de 100644 --- a/resources/js/store/modules/open/templates.js +++ b/resources/js/store/modules/open/templates.js @@ -91,12 +91,26 @@ export const actions = { context.commit('stopLoading') }) }, - loadAll (context) { + loadAll (context, options=null) { context.commit('startLoading') context.dispatch('loadTypesAndIndustries') - return axios.get(templatesEndpoint).then((response) => { - context.commit('append', response.data) - context.commit('setAllLoaded', true) + + // Prepare with options + let queryStr = '' + if(options !== null){ + for (const [key, value] of Object.entries(options)) { + queryStr += '&' + encodeURIComponent(key) + '=' + encodeURIComponent(value) + } + queryStr = queryStr.slice(1) + } + return axios.get((queryStr) ? templatesEndpoint + '?' + queryStr : templatesEndpoint).then((response) => { + if(options !== null){ + context.commit('set', response.data) + context.commit('setAllLoaded', false) + } else { + context.commit('append', response.data) + context.commit('setAllLoaded', true) + } context.commit('stopLoading') }).catch((error) => { context.commit('stopLoading') @@ -108,17 +122,5 @@ export const actions = { } context.commit('stopLoading') return Promise.resolve() - }, - loadWithLimit (context, limit) { - context.commit('startLoading') - context.dispatch('loadTypesAndIndustries') - - return axios.get(templatesEndpoint + '?limit=' + limit).then((response) => { - context.commit('set', response.data) - context.commit('setAllLoaded', false) - context.commit('stopLoading') - }).catch((error) => { - context.commit('stopLoading') - }) } }