-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added /compare page and compare selector to /servers #22
Changes from 1 commit
400a7ea
cb6e926
17fbd3e
a994e79
e7f7f3c
c37c5dc
d7d222b
27f155a
f2f9887
403a12f
46fca54
1b8857b
0c86fc7
e6629cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<!-- eslint-disable @angular-eslint/template/interactive-supports-focus --> | ||
<div class="w-full bg-primary min-h-screen"> | ||
<div class="content pt-16 pb-16"> | ||
<app-breadcrumbs [segments]="breadcrumbs"></app-breadcrumbs> | ||
|
||
<div class="flex flex-col gap-4 my-8"> | ||
<h1 class="text-white font-bold text-3xl">Instance Compare</h1> | ||
<div class="text-white text-xl pr-16"> | ||
Compare the configuration of your instances to identify differences. | ||
</div> | ||
</div> | ||
|
||
<div class="w-full overflow-x-auto relative" style="padding-left: 1px;"> | ||
<div *ngIf="isLoading" class="absolute top-0 left-0 w-full h-full" style="background-color: rgba(0,0,0,0.2);" > | ||
<div class="flex justify-center mt-16 opacity-100" role="status"> | ||
<svg aria-hidden="true" class="inline w-12 h-12 text-gray-200 animate-spin fill-emerald-400" viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
<path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/> | ||
<path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/> | ||
</svg> | ||
<span class="sr-only">Loading...</span> | ||
</div> | ||
</div> | ||
<table class="items_table"> | ||
<thead> | ||
<tr> | ||
<th></th> | ||
<th *ngFor="let item of servers"> | ||
{{item.display_name}} | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr *ngFor="let item of fields; let i = index" > | ||
<td> | ||
{{item.name}} | ||
</td> | ||
<ng-container *ngFor="let column of servers"> | ||
<td> | ||
{{column.server_id}} | ||
</td> | ||
|
||
</ng-container> | ||
|
||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
|
||
</div> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.items_table { | ||
@apply w-full text-white; | ||
|
||
thead { | ||
@apply border-b border-gray-200 border-solid bg-secondary; | ||
th { | ||
@apply text-left px-5 py-3 font-normal text-xs; | ||
|
||
} | ||
} | ||
|
||
tbody { | ||
tr:nth-child(2n+1) { | ||
@apply bg-primary; | ||
} | ||
tr:nth-child(2n) { | ||
@apply bg-secondary; | ||
} | ||
|
||
tr { | ||
@apply hover:border hover:border-emerald-400 hover:border-solid cursor-pointer; | ||
td { | ||
@apply px-5 py-3 text-left text-sm; | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { ServerCompareComponent } from './server-compare.component'; | ||
|
||
describe('ServerCompareComponent', () => { | ||
let component: ServerCompareComponent; | ||
let fixture: ComponentFixture<ServerCompareComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [ServerCompareComponent] | ||
}) | ||
.compileComponents(); | ||
|
||
fixture = TestBed.createComponent(ServerCompareComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,72 @@ | ||||||||||||||||||||||
/* eslint-disable prefer-const */ | ||||||||||||||||||||||
import { Component, OnInit } from '@angular/core'; | ||||||||||||||||||||||
import { KeeperAPIService } from '../../services/keeper-api.service'; | ||||||||||||||||||||||
import { ActivatedRoute } from '@angular/router'; | ||||||||||||||||||||||
import { BreadcrumbSegment, BreadcrumbsComponent } from '../../components/breadcrumbs/breadcrumbs.component'; | ||||||||||||||||||||||
import { LucideAngularModule } from 'lucide-angular'; | ||||||||||||||||||||||
import { CommonModule } from '@angular/common'; | ||||||||||||||||||||||
import { FormsModule } from '@angular/forms'; | ||||||||||||||||||||||
import { ServerPKsWithPrices } from '../../../../sdk/data-contracts'; | ||||||||||||||||||||||
import { SeoHandlerService } from '../../services/seo-handler.service'; | ||||||||||||||||||||||
|
||||||||||||||||||||||
@Component({ | ||||||||||||||||||||||
selector: 'app-server-compare', | ||||||||||||||||||||||
standalone: true, | ||||||||||||||||||||||
imports: [BreadcrumbsComponent, LucideAngularModule, CommonModule, FormsModule], | ||||||||||||||||||||||
templateUrl: './server-compare.component.html', | ||||||||||||||||||||||
styleUrl: './server-compare.component.scss' | ||||||||||||||||||||||
}) | ||||||||||||||||||||||
export class ServerCompareComponent implements OnInit { | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
breadcrumbs: BreadcrumbSegment[] = [ | ||||||||||||||||||||||
{ name: 'Home', url: '/' }, | ||||||||||||||||||||||
{ name: 'Compare Instances', url: '/compare' } | ||||||||||||||||||||||
]; | ||||||||||||||||||||||
|
||||||||||||||||||||||
isLoading = true; | ||||||||||||||||||||||
|
||||||||||||||||||||||
servers: ServerPKsWithPrices[] = []; | ||||||||||||||||||||||
|
||||||||||||||||||||||
fields: any[] = [ | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace - fields: any[] = [
+ fields: { name: string; key: string; }[] = [ Committable suggestion
Suggested change
ToolsBiome
|
||||||||||||||||||||||
{ name: 'CPU', key: 'cpu' }, | ||||||||||||||||||||||
{ name: 'RAM', key: 'ram' }, | ||||||||||||||||||||||
{ name: 'Storage', key: 'storage' }, | ||||||||||||||||||||||
{ name: 'Network', key: 'network' }, | ||||||||||||||||||||||
{ name: 'Price', key: 'price' } | ||||||||||||||||||||||
]; | ||||||||||||||||||||||
|
||||||||||||||||||||||
constructor( | ||||||||||||||||||||||
private keeperAPI: KeeperAPIService, | ||||||||||||||||||||||
private seoHandler: SeoHandlerService, | ||||||||||||||||||||||
private route: ActivatedRoute) { } | ||||||||||||||||||||||
|
||||||||||||||||||||||
ngOnInit() { | ||||||||||||||||||||||
|
||||||||||||||||||||||
const title = 'Compare Servers'; | ||||||||||||||||||||||
const description = 'Compare servers to find the best one for your needs'; | ||||||||||||||||||||||
const keywords = 'compare, servers, server, hosting, cloud, vps, dedicated, comparison'; | ||||||||||||||||||||||
|
||||||||||||||||||||||
this.seoHandler.updateTitleAndMetaTags(title, description, keywords); | ||||||||||||||||||||||
|
||||||||||||||||||||||
this.route.queryParams.subscribe(params => { | ||||||||||||||||||||||
const param = params['instances']; | ||||||||||||||||||||||
if(param){ | ||||||||||||||||||||||
const decodedParams = JSON.parse(atob(param)); | ||||||||||||||||||||||
let promises: Promise<any>[] = []; | ||||||||||||||||||||||
decodedParams?.forEach((instance: any) => { | ||||||||||||||||||||||
promises.push( | ||||||||||||||||||||||
this.keeperAPI.getServer(instance.vendor, instance.server) | ||||||||||||||||||||||
); | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
Comment on lines
+61
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace - decodedParams?.forEach((instance: any) => {
- promises.push(this.keeperAPI.getServer(instance.vendor, instance.server));
- });
+ for (const instance of decodedParams) {
+ promises.push(this.keeperAPI.getServer(instance.vendor, instance.server));
+ } Committable suggestion
Suggested change
ToolsBiome
|
||||||||||||||||||||||
Promise.all(promises).then((data) => { | ||||||||||||||||||||||
data?.forEach((server: any) => { | ||||||||||||||||||||||
this.servers.push(server.body); | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
this.isLoading = false; | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -399,7 +399,10 @@ export class ServerListingComponent implements OnInit { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
this.keeperAPI.searchServers(queryObject).then(servers => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
this.servers = servers?.body; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
this.servers = servers?.body.map((item: any) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return {...item, selected: false}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if(updateTotalCount) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
this.totalPages = Math.ceil(parseInt(servers?.headers?.get('x-total-count') || '0') / this.limit); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -730,4 +733,28 @@ export class ServerListingComponent implements OnInit { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
this.valueChanged(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
compareCount() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return this.servers?.filter((server) => server.selected).length; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
openCompare() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const selectedServers = this.servers.filter((server) => server.selected); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if(selectedServers.length < 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
alert('Please select at least two servers to compare'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const serverIds = selectedServers.map((server) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return {vendor: server.vendor_id, server: server.server_id} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// encode atob to avoid issues with special characters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const encoded = btoa(JSON.stringify(serverIds)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
console.log(encoded); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
this.router.navigateByUrl('/compare?instances=' + encoded); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Consider using early returns to reduce nesting and improve readability. - if(selectedServers.length < 2) {
- alert('Please select at least two servers to compare');
- return;
- }
+ if(selectedServers.length >= 2) {
+ const serverIds = selectedServers.map(server => ({ vendor: server.vendor_id, server: server.server_id }));
+ const encoded = btoa(JSON.stringify(serverIds));
+ console.log(encoded);
+ this.router.navigateByUrl('/compare?instances=' + encoded);
+ } else {
+ alert('Please select at least two servers to compare');
+ } Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use TypeScript's type import syntax for imports only used as types.
Committable suggestion