mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-06-18 14:58:15 +00:00
Update new-template-dialog.component.ts
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
import { Component, Input, OnInit, ChangeDetectorRef } from '@angular/core';
|
import { Component, Input, OnInit, ChangeDetectorRef } from '@angular/core';
|
||||||
import { MatDialogRef } from '@angular/material';
|
import { MatDialogRef, Sort } from '@angular/material';
|
||||||
import { Server } from '../../../models/server';
|
import { Server } from '../../../models/server';
|
||||||
import { Node } from '../../../cartography/models/node';
|
import { Node } from '../../../cartography/models/node';
|
||||||
import { Project } from '../../../models/project';
|
import { Project } from '../../../models/project';
|
||||||
@ -51,7 +51,29 @@ export class NewTemplateDialogComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sortData(sort: Sort) {
|
||||||
|
if (!sort.active || sort.direction === '') return;
|
||||||
|
|
||||||
|
let appliances = this.appliances.slice();
|
||||||
|
this.appliances = appliances.sort((a, b) => {
|
||||||
|
const isAsc = sort.direction === 'asc';
|
||||||
|
if (sort.active === 'name') {
|
||||||
|
return compareNames(a.name, b.name, isAsc);
|
||||||
|
} else if (sort.active === 'emulator') {
|
||||||
|
return compareNames(a.emulator, b.emulator, isAsc);
|
||||||
|
} else if (sort.active === 'vendor') {
|
||||||
|
return compareNames(a.vendor_name, b.vendor_name, isAsc);
|
||||||
|
} else return 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
onCloseClick() {
|
onCloseClick() {
|
||||||
this.dialogRef.close();
|
this.dialogRef.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function compareNames(a: string, b: string, isAsc: boolean) {
|
||||||
|
a = a.toLowerCase();
|
||||||
|
b = b.toLowerCase();
|
||||||
|
return (a < b ? -1 : 1) * (isAsc ? 1 : -1);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user