From ea108254507028c8aa1d7f99ced88015d50143f4 Mon Sep 17 00:00:00 2001 From: Forms Dev Date: Mon, 23 Oct 2023 08:57:11 +0530 Subject: [PATCH 1/2] Industry & Types template pages --- app/Http/Controllers/SitemapController.php | 18 ++ app/Http/Controllers/TemplateController.php | 14 +- app/Service/SeoMetaResolver.php | 24 ++ .../pages/templates/TemplatesList.vue | 109 +++++--- .../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, 616 insertions(+), 52 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 8596b1f35..0b930d0e6 100644 --- a/app/Http/Controllers/SitemapController.php +++ b/app/Http/Controllers/SitemapController.php @@ -31,6 +31,8 @@ public function getSitemap(Request $request) $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 @@ private function addTemplatesUrls(Sitemap $sitemap) } }); } + + 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 474d0add0..8a89614d6 100644 --- a/app/Http/Controllers/TemplateController.php +++ b/app/Http/Controllers/TemplateController.php @@ -18,12 +18,20 @@ public function index(Request $request) $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 95c3ac35d..7cbd84a75 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 @@ private function getTemplatesShowMeta(): array '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 f3e0258ef..5b34ec306 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 000000000..b91ef873d --- /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 281ff7807..8d67a5654 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 3e229fad2..15f96de67 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') - }) } } From ab8e859f486e717a9761606357ff94063cb82585 Mon Sep 17 00:00:00 2001 From: Forms Dev Date: Mon, 23 Oct 2023 08:59:35 +0530 Subject: [PATCH 2/2] fix sitemap for templates --- app/Http/Controllers/SitemapController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/SitemapController.php b/app/Http/Controllers/SitemapController.php index 0b930d0e6..7dca3e16d 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)