Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Industry & Types template pages #226

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion app/Http/Controllers/SitemapController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}
Expand All @@ -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));
}
}
}
14 changes: 11 additions & 3 deletions app/Http/Controllers/TemplateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 24 additions & 0 deletions app/Service/SeoMetaResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}',
];

/**
Expand Down Expand Up @@ -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),
];
}
}
109 changes: 77 additions & 32 deletions resources/js/components/pages/templates/TemplatesList.vue
Original file line number Diff line number Diff line change
@@ -1,37 +1,81 @@
<template>
<section class="bg-white py-12">
<div class="px-4 sm:px-6 lg:px-8 max-w-7xl mx-auto">
<div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 sm:gap-6 relative z-20">
<div class="flex items-center gap-4">
<div class="flex-1 sm:flex-none">
<select-input v-model="selectedType" name="type"
:options="typesOptions" class="w-full sm:w-auto md:w-56"
/>
<div>
<section class="bg-white py-12">
<div class="px-4 sm:px-6 lg:px-8 max-w-7xl mx-auto">
<div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 sm:gap-6 relative z-20">
<div class="flex items-center gap-4">
<div class="flex-1 sm:flex-none">
<select-input v-model="selectedType" name="type"
:options="typesOptions" class="w-full sm:w-auto md:w-56"
/>
</div>
<div class="flex-1 sm:flex-none">
<select-input v-model="selectedIndustry" name="industry"
:options="industriesOptions" class="w-full sm:w-auto md:w-56"
/>
</div>
</div>
<div class="flex-1 sm:flex-none">
<select-input v-model="selectedIndustry" name="industry"
:options="industriesOptions" class="w-full sm:w-auto md:w-56"
/>
<div class="flex-1 w-full md:max-w-xs">
<text-input name="search" :form="searchTemplate" placeholder="Search..." />
</div>
</div>
<div class="flex-1 w-full md:max-w-xs">
<text-input name="search" :form="searchTemplate" placeholder="Search..." />

<div v-if="templatesLoading" class="text-center mt-4">
<loader class="h-6 w-6 text-nt-blue mx-auto" />
</div>
<p v-else-if="enrichedTemplates.length === 0" class="text-center mt-4">
No templates found.
</p>
<div v-else class="relative z-10">
<div class="grid grid-cols-1 mt-8 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-8 sm:gap-y-12">
<single-template v-for="template in enrichedTemplates" :key="template.id" :slug="template.slug" />
</div>
</div>
</div>
</section>

<div v-if="templatesLoading" class="text-center mt-4">
<loader class="h-6 w-6 text-nt-blue mx-auto" />
</div>
<p v-else-if="enrichedTemplates.length === 0" class="text-center mt-4">
No templates found.
</p>
<div v-else class="relative z-10">
<div class="grid grid-cols-1 mt-8 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-8 sm:gap-y-12">
<single-template v-for="template in enrichedTemplates" :key="template.id" :slug="template.slug" />
<template v-if="!onlyMy">
<section class="py-12 bg-white border-t border-gray-200 sm:py-16">
<div class="px-4 mx-auto sm:px-6 lg:px-8 max-w-7xl">
<div class="flex items-center justify-between">
<h4 class="text-xl font-bold tracking-tight text-gray-900 sm:text-2xl">
All Types
</h4>
</div>

<div class="grid grid-cols-1 gap-8 mt-8 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
<router-link v-for="row in types" :key="row.slug"
:to="{params:{slug:row.slug}, name:'templates.types.show'}"
:title="row.name"
class="text-gray-600 dark:text-gray-400 transition-colors duration-300 hover:text-nt-blue"
>
{{ row.name }}
</router-link>
</div>
</div>
</div>
</div>
</section>
</section>

<section class="py-12 bg-white border-t border-gray-200 sm:py-16">
<div class="px-4 mx-auto sm:px-6 lg:px-8 max-w-7xl">
<div class="flex items-center justify-between">
<h4 class="text-xl font-bold tracking-tight text-gray-900 sm:text-2xl">
All Industries
</h4>
</div>

<div class="grid grid-cols-1 gap-8 mt-8 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
<router-link v-for="row in industries" :key="row.slug"
:to="{params:{slug:row.slug}, name:'templates.industries.show'}"
:title="row.name"
class="text-gray-600 dark:text-gray-400 transition-colors duration-300 hover:text-nt-blue"
>
{{ row.name }}
</router-link>
</div>
</div>
</section>
</template>
</div>
</template>

<script>
Expand All @@ -41,11 +85,12 @@ import Form from 'vform'
import Fuse from 'fuse.js'
import SingleTemplate from './SingleTemplate.vue'

const loadTemplates = function () {
store.commit('open/templates/startLoading')
store.dispatch('open/templates/loadIfEmpty').then(() => {
store.commit('open/templates/stopLoading')
})
const loadTemplates = function (onlyMy) {
if(onlyMy){
store.dispatch('open/templates/loadAll', {'onlymy':true})
} else {
store.dispatch('open/templates/loadIfEmpty')
}
}

export default {
Expand All @@ -70,7 +115,7 @@ export default {
watch: {},

mounted () {
loadTemplates()
loadTemplates(this.onlyMy)
},

computed: {
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/pages/welcome/TemplatesSlider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default {
},

mounted() {
store.dispatch('open/templates/loadWithLimit', 10)
store.dispatch('open/templates/loadAll', {'limit':10})
},

methods: {
Expand Down
Loading
Loading