⚡ Sort optimization
This commit is contained in:
parent
09c4403812
commit
fdd29891d3
@ -233,7 +233,9 @@ export class DashboardComponent implements OnInit, AfterViewInit {
|
|||||||
p.description?.toLowerCase().includes(searchValue),
|
p.description?.toLowerCase().includes(searchValue),
|
||||||
);
|
);
|
||||||
|
|
||||||
this.visiblePlaces.sort((a, b) => a.name.localeCompare(b.name));
|
this.visiblePlaces.sort((a, b) =>
|
||||||
|
a.name < b.name ? -1 : a.name > b.name ? 1 : 0,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
resetFilters() {
|
resetFilters() {
|
||||||
@ -326,7 +328,7 @@ export class DashboardComponent implements OnInit, AfterViewInit {
|
|||||||
.subscribe({
|
.subscribe({
|
||||||
next: (place: Place) => {
|
next: (place: Place) => {
|
||||||
this.places = [...this.places, place].sort((a, b) =>
|
this.places = [...this.places, place].sort((a, b) =>
|
||||||
a.name.localeCompare(b.name),
|
a.name < b.name ? -1 : a.name > b.name ? 1 : 0,
|
||||||
);
|
);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.updateMarkersAndClusters();
|
this.updateMarkersAndClusters();
|
||||||
@ -372,7 +374,7 @@ export class DashboardComponent implements OnInit, AfterViewInit {
|
|||||||
.pipe(take(1))
|
.pipe(take(1))
|
||||||
.subscribe((places) => {
|
.subscribe((places) => {
|
||||||
this.places = [...this.places, ...places].sort((a, b) =>
|
this.places = [...this.places, ...places].sort((a, b) =>
|
||||||
a.name.localeCompare(b.name),
|
a.name < b.name ? -1 : a.name > b.name ? 1 : 0,
|
||||||
);
|
);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.updateMarkersAndClusters();
|
this.updateMarkersAndClusters();
|
||||||
@ -528,7 +530,9 @@ export class DashboardComponent implements OnInit, AfterViewInit {
|
|||||||
const places = [...this.places];
|
const places = [...this.places];
|
||||||
const idx = places.findIndex((p) => p.id == place.id);
|
const idx = places.findIndex((p) => p.id == place.id);
|
||||||
if (idx > -1) places.splice(idx, 1, place);
|
if (idx > -1) places.splice(idx, 1, place);
|
||||||
places.sort((a, b) => a.name.localeCompare(b.name));
|
places.sort((a, b) =>
|
||||||
|
a.name < b.name ? -1 : a.name > b.name ? 1 : 0,
|
||||||
|
);
|
||||||
this.places = places;
|
this.places = places;
|
||||||
this.selectedPlace = { ...place };
|
this.selectedPlace = { ...place };
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@ -631,7 +635,7 @@ export class DashboardComponent implements OnInit, AfterViewInit {
|
|||||||
.subscribe({
|
.subscribe({
|
||||||
next: (resp) => {
|
next: (resp) => {
|
||||||
this.places = [...this.places, ...resp.places].sort((a, b) =>
|
this.places = [...this.places, ...resp.places].sort((a, b) =>
|
||||||
a.name.localeCompare(b.name),
|
a.name < b.name ? -1 : a.name > b.name ? 1 : 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
this.categories = resp.categories;
|
this.categories = resp.categories;
|
||||||
@ -766,8 +770,8 @@ export class DashboardComponent implements OnInit, AfterViewInit {
|
|||||||
.subscribe({
|
.subscribe({
|
||||||
next: (category: Category) => {
|
next: (category: Category) => {
|
||||||
this.categories.push(category);
|
this.categories.push(category);
|
||||||
this.categories.sort((categoryA: Category, categoryB: Category) =>
|
this.categories.sort((a, b) =>
|
||||||
categoryA.name.localeCompare(categoryB.name),
|
a.name < b.name ? -1 : a.name > b.name ? 1 : 0,
|
||||||
);
|
);
|
||||||
this.activeCategories.add(category.name);
|
this.activeCategories.add(category.name);
|
||||||
},
|
},
|
||||||
@ -812,9 +816,8 @@ export class DashboardComponent implements OnInit, AfterViewInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sortCategories() {
|
sortCategories() {
|
||||||
this.categories = [...this.categories].sort(
|
this.categories = [...this.categories].sort((a, b) =>
|
||||||
(categoryA: Category, categoryB: Category) =>
|
a.name < b.name ? -1 : a.name > b.name ? 1 : 0,
|
||||||
categoryA.name.localeCompare(categoryB.name),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -247,7 +247,9 @@ export class SharedTripComponent implements AfterViewInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sortTripDays() {
|
sortTripDays() {
|
||||||
this.trip?.days.sort((a, b) => a.label.localeCompare(b.label));
|
this.trip?.days.sort((a, b) =>
|
||||||
|
a.label < b.label ? -1 : a.label > b.label ? 1 : 0,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleFiltering() {
|
toggleFiltering() {
|
||||||
@ -309,7 +311,7 @@ export class SharedTripComponent implements AfterViewInit {
|
|||||||
item.comment?.toLowerCase().includes(searchValue)
|
item.comment?.toLowerCase().includes(searchValue)
|
||||||
: true,
|
: true,
|
||||||
)
|
)
|
||||||
.sort((a, b) => a.time.localeCompare(b.time))
|
.sort((a, b) => (a.time < b.time ? -1 : a.time > b.time ? 1 : 0))
|
||||||
.map((item) => ({
|
.map((item) => ({
|
||||||
td_id: day.id,
|
td_id: day.id,
|
||||||
td_label: day.label,
|
td_label: day.label,
|
||||||
@ -337,7 +339,7 @@ export class SharedTripComponent implements AfterViewInit {
|
|||||||
setPlacesAndMarkers() {
|
setPlacesAndMarkers() {
|
||||||
this.computePlacesUsedInTable();
|
this.computePlacesUsedInTable();
|
||||||
this.places = [...(this.trip?.places ?? [])].sort((a, b) =>
|
this.places = [...(this.trip?.places ?? [])].sort((a, b) =>
|
||||||
a.name.localeCompare(b.name),
|
a.name < b.name ? -1 : a.name > b.name ? 1 : 0,
|
||||||
);
|
);
|
||||||
this.markerClusterGroup?.clearLayers();
|
this.markerClusterGroup?.clearLayers();
|
||||||
this.places.forEach((p) => {
|
this.places.forEach((p) => {
|
||||||
@ -471,7 +473,7 @@ export class SharedTripComponent implements AfterViewInit {
|
|||||||
const items = this.trip.days
|
const items = this.trip.days
|
||||||
.flatMap((day, idx) =>
|
.flatMap((day, idx) =>
|
||||||
day.items
|
day.items
|
||||||
.sort((a, b) => a.time.localeCompare(b.time))
|
.sort((a, b) => (a.time < b.time ? -1 : a.time > b.time ? 1 : 0))
|
||||||
.map((item) => {
|
.map((item) => {
|
||||||
let data = {
|
let data = {
|
||||||
text: item.text,
|
text: item.text,
|
||||||
@ -588,7 +590,7 @@ export class SharedTripComponent implements AfterViewInit {
|
|||||||
const idx = this.trip?.days.findIndex((d) => d.id === day_id);
|
const idx = this.trip?.days.findIndex((d) => d.id === day_id);
|
||||||
if (!this.trip || idx === undefined || idx == -1) return;
|
if (!this.trip || idx === undefined || idx == -1) return;
|
||||||
const data = this.trip.days[idx].items.sort((a, b) =>
|
const data = this.trip.days[idx].items.sort((a, b) =>
|
||||||
a.time.localeCompare(b.time),
|
a.time < b.time ? -1 : a.time > b.time ? 1 : 0,
|
||||||
);
|
);
|
||||||
const items = data
|
const items = data
|
||||||
.map((item) => {
|
.map((item) => {
|
||||||
@ -709,7 +711,11 @@ export class SharedTripComponent implements AfterViewInit {
|
|||||||
? a.packed
|
? a.packed
|
||||||
? 1
|
? 1
|
||||||
: -1
|
: -1
|
||||||
: a.text.localeCompare(b.text),
|
: a.text < b.text
|
||||||
|
? -1
|
||||||
|
: a.text > b.text
|
||||||
|
? 1
|
||||||
|
: 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
this.dispPackingList = sorted.reduce<Record<string, PackingItem[]>>(
|
this.dispPackingList = sorted.reduce<Record<string, PackingItem[]>>(
|
||||||
|
|||||||
@ -110,7 +110,7 @@ export class TripsComponent implements OnInit {
|
|||||||
return Number(!!a.archived) - Number(!!b.archived);
|
return Number(!!a.archived) - Number(!!b.archived);
|
||||||
}
|
}
|
||||||
|
|
||||||
return a.name.localeCompare(b.name);
|
return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -38,7 +38,9 @@ export class TripPlaceSelectModalComponent {
|
|||||||
) {
|
) {
|
||||||
this.apiService.getPlaces().subscribe({
|
this.apiService.getPlaces().subscribe({
|
||||||
next: (places) => {
|
next: (places) => {
|
||||||
this.places = places.sort((a, b) => a.name.localeCompare(b.name));
|
this.places = places.sort((a, b) =>
|
||||||
|
a.name < b.name ? -1 : a.name > b.name ? 1 : 0,
|
||||||
|
);
|
||||||
this.displayedPlaces = places;
|
this.displayedPlaces = places;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -78,7 +80,9 @@ export class TripPlaceSelectModalComponent {
|
|||||||
|
|
||||||
this.selectedPlacesID.push(p.id);
|
this.selectedPlacesID.push(p.id);
|
||||||
this.selectedPlaces.push(p);
|
this.selectedPlaces.push(p);
|
||||||
this.selectedPlaces.sort((a, b) => a.name.localeCompare(b.name));
|
this.selectedPlaces.sort((a, b) =>
|
||||||
|
a.name < b.name ? -1 : a.name > b.name ? 1 : 0,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
closeDialog() {
|
closeDialog() {
|
||||||
|
|||||||
@ -41,8 +41,8 @@ export class ApiService {
|
|||||||
|
|
||||||
_categoriesSubjectNext(categories: Category[]) {
|
_categoriesSubjectNext(categories: Category[]) {
|
||||||
this.categoriesSubject.next(
|
this.categoriesSubject.next(
|
||||||
[...categories].sort((categoryA: Category, categoryB: Category) =>
|
[...categories].sort((a, b) =>
|
||||||
categoryA.name.localeCompare(categoryB.name),
|
a.name < b.name ? -1 : a.name > b.name ? 1 : 0,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user