Skip to content

Commit

Permalink
feat: homepage projects custom priority (#1552)
Browse files Browse the repository at this point in the history
- Ajout d'une colonne baserow spécifique pour privilégier des projets
sur la page d'accueil.
- Ajout du code nécessaire pour prendre en compte cette nouvelle
priorisation uniquement sur la page d'accueil quand aucun tag n'est
sélectionné.

close #1430 
close #1432

---------
Co-authored-by: Yohann Valentin <pro@yohannvalentin.com>
  • Loading branch information
ttdm authored Jan 31, 2025
1 parent 19cb753 commit 52dabf4
Show file tree
Hide file tree
Showing 14 changed files with 280 additions and 229 deletions.
4 changes: 1 addition & 3 deletions apps/nuxt/src/components/catalog/CatalogProjects.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
>
<ProjectModalFilter />
</div>
<SimpleProjectList :project-list="sortedProjects" />
<SimpleProjectList :project-list="filteredProjects" />
</div>
<div class="fr-col-12 fr-mt-3v fr-mb-10v">
<OtherProject />
Expand All @@ -53,7 +53,6 @@ import { useCompanyData } from '@/stores/companyData'
import { useProjectStore } from '@/stores/project'
import { CompanyData } from '@/tools/companyData'
import { ProjectManager } from '@/tools/project/projectManager'
import ProjectSorter from '@/tools/project/projectSorter'
import { MetaSeo } from '@/tools/metaSeo'
import { computed } from 'vue'
import ProjectFilter from '@/tools/project/projectFilter'
Expand Down Expand Up @@ -92,7 +91,6 @@ const description = 'Accédez à la liste des projets de transition écologique
const theme = Theme.getThemeFromSelectedTheme()
const filteredProjects = ProjectFilter.filter(projects, theme)
const sortedProjects = ProjectSorter.sort(filteredProjects)
const countProjects = computed(() => {
return filteredProjects.value?.length || 0
Expand Down
18 changes: 14 additions & 4 deletions apps/nuxt/src/components/home/TeeHomeProjectList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
</div>
</template>
<script setup lang="ts">
import { Theme } from '@/tools/theme'
import ProjectFilter from '@/tools/project/projectFilter'
import ProjectSorter from '@/tools/project/projectSorter'
import { useProjectStore } from '@/stores/project'
import ProjectFilter from '@/tools/project/projectFilter'
import { ProjectManager } from '@/tools/project/projectManager'
import ProjectSorter from '@/tools/project/projectSorter'
import { Theme } from '@/tools/theme'
interface Props {
limit: number
Expand All @@ -46,7 +46,17 @@ const { projects, hasError } = storeToRefs(useProjectStore())
const { hasSpinner } = storeToRefs(useNavigationStore())
const filteredProjects = ProjectFilter.filter(projects, theme)
const sortedProjects = ProjectSorter.sort(filteredProjects)
const sortedProjects = computed(() => {
if (!filteredProjects.value) {
return []
}
if (!theme.value || !Theme.isTheme(theme.value)) {
return ProjectSorter.highlightSort(filteredProjects.value)
}
return filteredProjects.value
})
const projectList = computed(() => {
return props.limit ? sortedProjects.value.slice(0, props.limit) : sortedProjects.value
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</div>
<ProjectList
v-else
:sorted-projects="sortedProjects"
:sorted-projects="filteredProjects"
/>

<div
Expand All @@ -70,7 +70,6 @@
</template>

<script setup lang="ts">
import ProjectSorter from '@/tools/project/projectSorter'
import { ProjectType } from '@/types'
import { computed } from 'vue'
import UsedTrack from '@/tools/questionnaire/track/usedTrack'
Expand Down Expand Up @@ -106,8 +105,6 @@ const hasThemeCard = computed(() => {
return filtersStore.hasThemeTypeSelected() || (UsedTrack.isSpecificGoal() && UsedTrack.hasPriorityTheme())
})
const sortedProjects = ProjectSorter.sort(computed(() => props.filteredProjects))
const showNoResults = computed(() => {
return (props.hasError || (!countProjects.value && props.filteredProjects !== undefined)) && !useNavigationStore().hasSpinner
})
Expand Down
Binary file not shown.
Binary file removed apps/nuxt/src/public/images/projet/composteur.webp
Binary file not shown.
Binary file not shown.
17 changes: 8 additions & 9 deletions apps/nuxt/src/tools/project/projectSorter.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { ProjectType as ProjectType } from '@/types'
import { ComputedRef } from 'vue'

export default class ProjectSorter {
static readonly sort = (projects: ComputedRef<ProjectType[] | undefined>): ComputedRef<ProjectType[]> => {
return computed(() => {
if (!projects.value) {
return []
static readonly highlightSort = (projects: ProjectType[]): ProjectType[] => {
return projects.toSorted((a, b) => {
if (!a.highlightPriority) {
return 1
}

return projects.value.slice().sort((a, b) => {
return a.priority - b.priority
})
if (!b.highlightPriority) {
return -1
}
return a.highlightPriority - b.highlightPriority
})
}
}
8 changes: 8 additions & 0 deletions libs/backend-ddd/src/project/domain/projectFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,17 @@ export default class ProjectFeatures {
}

public getFiltered(projectQuery: ProjectFilterQuery): ProjectType[] {
this._sort(projects)
if (!projectQuery.codeNAF1) {
return projects
}

return projects.filter((project) => ProjectEligibility.isEligible(project, projectQuery.codeNAF1 as string))
}

private _sort(projects: ProjectType[]) {
projects.sort((a, b) => {
return a.priority - b.priority
})
}
}
1 change: 1 addition & 0 deletions libs/data/src/common/baserow/projectBaserow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export class ProjectBaserow extends AbstractBaserow {
programs: this._generateProgramList(baserowProject.Dispositifs),
linkedProjects: this._generateLinkedProjectList(baserowProject['Projets complémentaires']),
priority: baserowProject.Prio,
highlightPriority: baserowProject['Mise En Avant'],
sectors: this._generateSectors(baserowProject as BaserowSectors)
}
}
Expand Down
1 change: 1 addition & 0 deletions libs/data/src/common/baserow/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface BaserowProject extends Id, BaserowSectors {
'Thématiques secondaires': LinkObject[]
Dispositifs: LinkObject[]
Prio: number
'Mise En Avant': number | null
}

export interface LinkObject extends Id {
Expand Down
2 changes: 1 addition & 1 deletion libs/data/src/project/projectFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { FileManager } from '../common/fileManager'
export class ProjectFeatures {
private readonly __dirname = path.dirname(fileURLToPath(import.meta.url))
private readonly _outputFilePath: string = path.join(this.__dirname, '../../static/projects.json')
private readonly _outputImageDirectory: string = path.join(this.__dirname, '../../../../apps/web/public/images/projet')
private readonly _outputImageDirectory: string = path.join(this.__dirname, '../../../../apps/nuxt/src/public/images/projet')
private _programs: ProgramType[] = []
private _logger: Logger

Expand Down
1 change: 1 addition & 0 deletions libs/data/src/project/types/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface ProjectType {
programs: string[]
linkedProjects: ProjectId[]
priority: number
highlightPriority: number | null
sectors: string[]
}

Expand Down
5 changes: 2 additions & 3 deletions libs/data/static/project_images_download_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@
"recuperateur-eau-pluie": "2024-07-25T08:32:25.601520+00:00",
"economiseurs-eau-sanitaires": "2024-07-25T08:40:30.976626+00:00",
"seche-linge": "2024-09-12T12:55:07.160452+00:00",
"alimentation-durable": "2024-09-12T12:37:33.503971+00:00",
"frigo": "2024-09-12T15:13:28.768304+00:00",
"arrosage": "2024-09-12T14:55:53.801315+00:00",
"vegetalisation": "2024-09-12T13:55:39.173237+00:00",
"ombrage": "2024-09-12T14:26:17.245595+00:00",
"abris-velos": "2024-09-12T14:29:22.819844+00:00",
"biodiversite": "2024-09-12T14:49:37.954946+00:00",
"composteur": "2024-09-12T14:45:05.159088+00:00",
"thermostat": "2024-09-12T15:04:12.004179+00:00"
"thermostat": "2024-09-12T15:04:12.004179+00:00",
"menus-circuits-courts": "2025-01-23T13:33:16.700640+00:00"
}
Loading

0 comments on commit 52dabf4

Please sign in to comment.