Skip to content
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

Dev 169 3 #29

Merged
merged 5 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions src/app/pages/server-compare/server-compare.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,15 @@ <h1 class="text-white font-bold text-3xl">Server Comparison</h1>
</div>
</td>
</tr>
<tr *ngIf="!item.collapsed" >
<td></td>
<ng-container *ngFor="let scoreList of item.scores">
<ng-container *ngIf="!item.collapsed" >
<tr *ngFor="let config of item.configs">
<td>
<div class="flex flex-col">
<div *ngFor="let scoreItem of scoreList">
{{scoreItem.score}} {{serializeConfig(scoreItem.config)}}
</div>
</div>
<div [innerHTML]="serializeConfig(config.config)" ></div></td>
<td *ngFor="let value of config.values">
{{value}}
</td>
</ng-container>
</tr>
</tr>
</ng-container>
</ng-container>
<tr>
<td>View Server</td>
Expand Down
58 changes: 37 additions & 21 deletions src/app/pages/server-compare/server-compare.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ export class ServerCompareComponent implements OnInit {
}
});


/*
this.benchmarkMeta = data[1].body
?.filter((benchmark: any) => {
let found = false;
Expand All @@ -123,18 +121,40 @@ export class ServerCompareComponent implements OnInit {
return {
...b,
collapsed: true,
scores: this.servers.map((s: any) => {
return s.benchmark_scores?.filter((score: any) => score.benchmark_id === b.benchmark_id).sort((a: any, b: any) => {
if(a.config && b.config) {
return JSON.stringify(a).localeCompare(JSON.stringify(b));
configs: []
}
});

this.benchmarkMeta.forEach((benchmark: any) => {
this.servers.forEach((server: any) => {
const scores = server.benchmark_scores?.filter((s: any) => s.benchmark_id === benchmark.benchmark_id);
if(scores) {
scores.forEach((score: any) => {
const config = benchmark.configs.find((c: any) => {
return JSON.stringify(c.config) === JSON.stringify(score.config);
});
if(!config) {
benchmark.configs.push({
config: score.config,
values: []
});
}
return 0;
});
})
}
}
});
});
*/

this.benchmarkMeta.forEach((benchmark: any) => {
benchmark.configs.forEach((config: any) => {
this.servers.forEach((server: any) => {
const score = server.benchmark_scores
?.find((s: any) => s.benchmark_id === benchmark.benchmark_id && JSON.stringify(s.config) === JSON.stringify(config.config));
config.values.push(
score ? score.score : '-'
);
});
});
});

this.isLoading = false;
}).catch((err) => {
Expand Down Expand Up @@ -327,7 +347,8 @@ export class ServerCompareComponent implements OnInit {

getBestPrice(server: ServerPKsWithPrices, allocation: Allocation = Allocation.Ondemand) {
if(server.prices?.find((p) => p.allocation === allocation)){
return `${server.prices.filter(x => x.allocation === allocation).sort((a,b) => a.price - b.price)[0].price}$`;
let best = server.prices.filter(x => x.allocation === allocation).sort((a,b) => a.price - b.price)[0];
return `${best.price} ${best.currency}`;
} else {
return '-';
}
Expand All @@ -338,18 +359,13 @@ export class ServerCompareComponent implements OnInit {
}

serializeConfig(config: any) {
let result = '';
let result = '<ul>';
Object.keys(config).forEach((key) => {
if(result.length > 0) {
result += ', ';
} else {
result += ' (';
}
result += `${key.replace('_', ' ')}: ${config[key]} `;
result += `<li>${key.replace('_', ' ')}: ${config[key]} </li>`;
});
if(result.length > 0) {
result += ')';
}

result += '</ul>';

Comment on lines +380 to +386
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated serializeConfig to generate an HTML list instead of a comma-separated string.

This change improves the readability of the configuration data in the UI. However, consider escaping HTML special characters to prevent potential XSS vulnerabilities.

- result += `<li>${key.replace('_', ' ')}: ${config[key]} </li>`;
+ result += `<li>${key.replace('_', ' ')}: ${escapeHtml(config[key])} </li>`;

Here, escapeHtml is a hypothetical function that you would need to implement to escape HTML special characters.

Committable suggestion was skipped due to low confidence.

return result;
}

Expand Down
12 changes: 8 additions & 4 deletions src/app/pages/server-details/server-details.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,20 @@ export class ServerDetailsComponent implements OnInit {
question: `What is ${this.serverDetails.display_name}?`,
answer: this.description
},
{
question: `How much does the ${this.serverDetails.display_name} server cost?`,
answer: `The pricing for ${this.serverDetails.display_name} servers starts at $${this.serverDetails.prices[0].price} per hour, but the actual price depends on the selected region, zone and server allocation method (e.g. on-demand versus spot pricing options). Currently, the maximum price stands at $${this.serverDetails.prices.slice(-1)[0].price}.`
},
{
question: `What are the specs of the ${this.serverDetails.display_name} server?`,
answer: `The ${this.serverDetails.display_name} server is equipped with ${this.serverDetails.vcpus || this.serverDetails.cpu_cores} vCPU(s), ${this.getMemory()} of memory, ${this.getStorage()} of storage, and ${this.serverDetails.gpu_count} GPU(s). Additional block storage can be attached as needed.`
}
];

if(this.serverDetails.prices[0]) {
this.faqs.push(
{
question: `How much does the ${this.serverDetails.display_name} server cost?`,
answer: `The pricing for ${this.serverDetails.display_name} servers starts at $${this.serverDetails.prices[0].price} per hour, but the actual price depends on the selected region, zone and server allocation method (e.g. on-demand versus spot pricing options). Currently, the maximum price stands at $${this.serverDetails.prices.slice(-1)[0].price}.`
});
}

const keywords = this.title + ', ' + this.serverDetails.server_id + ', ' + this.serverDetails.vendor.vendor_id;

this.SEOHandler.updateTitleAndMetaTags(this.title, this.description, keywords);
Expand Down