Skip to content

Commit 9b701f1

Browse files
committed
chore(systems): change module sorting to cluster by class only
1 parent dc76162 commit 9b701f1

1 file changed

Lines changed: 44 additions & 18 deletions

File tree

src/app/systems/system-state.service.ts

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ export class SystemStateService extends AsyncHandler {
533533
}
534534
}
535535

536-
public async sortModulesByType() {
536+
public async sortModulesByType(alphabetical: boolean = false) {
537537
const modules = this._modules.getValue();
538538
if (modules.length < 2) return;
539539

@@ -544,23 +544,49 @@ export class SystemStateService extends AsyncHandler {
544544
});
545545
if (!details || !details.reason) return;
546546
details.loading('Sorting modules by class...');
547-
548-
const sorted_modules = [...modules].sort((a, b) => {
549-
const class_a = (
550-
a.custom_name ||
551-
a.name ||
552-
a.driver?.class_name ||
553-
''
554-
).toLowerCase();
555-
const class_b = (
556-
b.custom_name ||
557-
b.name ||
558-
b.driver?.class_name ||
559-
''
560-
).toLowerCase();
561-
return class_a.localeCompare(class_b);
562-
});
563-
547+
let sorted_modules = [];
548+
if (alphabetical) {
549+
sorted_modules = [...modules].sort((a, b) => {
550+
const class_a = (
551+
a.custom_name ||
552+
a.name ||
553+
a.driver?.class_name ||
554+
''
555+
).toLowerCase();
556+
const class_b = (
557+
b.custom_name ||
558+
b.name ||
559+
b.driver?.class_name ||
560+
''
561+
).toLowerCase();
562+
return class_a.localeCompare(class_b);
563+
});
564+
} else {
565+
const processed = new Set<PlaceModule>();
566+
for (const mod_a of modules) {
567+
if (processed.has(mod_a)) continue;
568+
const mod_class =
569+
mod_a.custom_name ||
570+
mod_a.name ||
571+
mod_a.driver?.class_name ||
572+
'';
573+
sorted_modules.push(mod_a);
574+
processed.add(mod_a);
575+
// Find all other modules with the same class that come after this one
576+
for (const mod_b of modules) {
577+
if (processed.has(mod_b)) continue;
578+
const mod_b_class =
579+
mod_b.custom_name ||
580+
mod_b.name ||
581+
mod_b.driver?.class_name ||
582+
'';
583+
if (mod_class === mod_b_class) {
584+
sorted_modules.push(mod_b);
585+
processed.add(mod_b);
586+
}
587+
}
588+
}
589+
}
564590
const sorted_ids = sorted_modules.map((m) => m.id);
565591

566592
const resp = await lastValueFrom(

0 commit comments

Comments
 (0)