Newer
Older

Timothee P
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<template>
<div class="item">
<div class="content">
<div>
<router-link
:to="{
name: 'details-signalement-filtre',
params: {
slug_type_signal: item.properties.feature_type.slug,
},
query,
}"
>
{{ item.properties.title || item.id }}
</router-link>
</div>
<div class="description">
<em>
[{{ item.properties.created_on }}
<span v-if="user && item.properties.creator">
, par
{{
item.properties.creator.full_name
? item.properties.creator.full_name
: item.properties.creator.username
}}
</span>
]
</em>
</div>
</div>
</div>
</template>
<script>
import { mapState } from 'vuex';
import axios from '@/axios-client.js';
export default {
name: 'ProjectLastFeatures',
props: {
item: {
type: Object,
default: () => {},
}
},
data() {
return {
position: null,
slug: this.$route.params.slug,
};
},
computed: {
...mapState([
'user'
]),
...mapState('projects', [
'project'
]),
query() {
const searchParams = { ordering: this.project.feature_browsing_default_sort };
if (this.project && this.project.feature_browsing_default_filter === 'feature_type') { // when feature_type is the default filter of the project,
searchParams['feature_type_slug'] = this.item.properties.feature_type.slug; // get its slug for the current feature
}
if (this.position >= 0) {
searchParams['offset'] = this.position; // get its slug for the current feature
}
return searchParams;
},
},
created() {
this.getFeaturePosition(this.item.id).then((position) => {
if (position >= 0) {
this.position = position;
}
});
},
methods: {
async getFeaturePosition(featureId) {
const url = new URL(`${this.$store.state.configuration.VUE_APP_DJANGO_API_BASE}projects/${this.slug}/feature/${featureId}/position-in-list/`);
url.search = new URLSearchParams(this.query);
const response = await axios.get(url);
if (response && response.status === 200) {
return response.data;
}
return null;
},
}
};
</script>