Skip to content
This repository has been archived by the owner on Mar 25, 2023. It is now read-only.

Commit

Permalink
feat(service offering): default service offering
Browse files Browse the repository at this point in the history
Fixes #201
  • Loading branch information
wowshakhov committed Aug 4, 2017
1 parent f01514f commit 6238d1e
Show file tree
Hide file tree
Showing 25 changed files with 1,248 additions and 132 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
export interface CustomOfferingRestriction {
min: number;
max: number;
min?: number;
max?: number;
}

interface ICustomOfferingRestrictions {
cpuNumber: CustomOfferingRestriction;
cpuSpeed: CustomOfferingRestriction;
memory: CustomOfferingRestriction;
export interface ICustomOfferingRestrictionsByZone {
[zone: string]: ICustomOfferingRestrictions;
}

export interface ICustomOfferingRestrictions {
cpuNumber?: CustomOfferingRestriction;
cpuSpeed?: CustomOfferingRestriction;
memory?: CustomOfferingRestriction;
}

export class CustomOfferingRestrictions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { TranslateService } from '@ngx-translate/core';
import { MdlDialogReference } from '../../dialog/dialog-module';
import { ServiceOffering } from '../../shared/models';
import { CustomServiceOffering } from './custom-service-offering';
import { CustomOfferingRestrictions } from './custom-offering-restrictions';
import { CustomOfferingRestrictions, ICustomOfferingRestrictions } from './custom-offering-restrictions';


@Component({
Expand All @@ -14,21 +14,16 @@ import { CustomOfferingRestrictions } from './custom-offering-restrictions';
styleUrls: ['custom-service-offering.component.scss']
})
export class CustomServiceOfferingComponent implements OnInit {
public restrictions: CustomOfferingRestrictions;

constructor(
@Inject('offering') public offering: ServiceOffering,
@Inject('restrictions') public restrictions: ICustomOfferingRestrictions,
@Inject('zoneId') public zoneId: string,
public dialog: MdlDialogReference,
private configService: ConfigService,
private translateService: TranslateService
) {}

public ngOnInit(): void {
if (this.zoneId == null) { throw new Error('Attribute \'zoneId\' is required'); }
this.loadCustomOfferingRestrictions().subscribe(() => {
this.initOffering();
});
}

public errorMessage(lowerLimit: any, upperLimit: any): Observable<string> {
Expand All @@ -53,24 +48,4 @@ export class CustomServiceOfferingComponent implements OnInit {
public onCancel(): void {
this.dialog.hide();
}

private loadCustomOfferingRestrictions(): Observable<void> {
return this.configService.get('customOfferingRestrictions')
.map(restrictions => {
try {
this.restrictions = new CustomOfferingRestrictions(restrictions[this.zoneId]);
} catch (e) {
throw new Error('Custom offering settings must be specified. Contact your administrator.');
}
});
}

private initOffering(): void {
this.offering = new CustomServiceOffering({
cpuNumber: this.restrictions.cpuNumber.min,
cpuSpeed: this.restrictions.cpuSpeed.min,
memory: this.restrictions.memory.min,
serviceOffering: this.offering
});
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { ServiceOffering } from '../../shared/models';


export class CustomServiceOffering extends ServiceOffering {
export interface ICustomServiceOffering {
cpuNumber?: number;
cpuSpeed?: number;
memory?: number;
}

export class CustomServiceOffering extends ServiceOffering implements ICustomServiceOffering {
public cpuNumber: number;
public cpuSpeed: number;
public memory: number;
Expand Down
Loading

0 comments on commit 6238d1e

Please sign in to comment.