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

Commit

Permalink
#705-template-from-snap - create group through template creation
Browse files Browse the repository at this point in the history
  • Loading branch information
ksendart committed Nov 30, 2017
1 parent 8ceee7b commit cc3687e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
8 changes: 6 additions & 2 deletions src/app/shared/models/account.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { AccountUser } from './account-user.model';

export const enum AccountType {
User = 0,
Admin,
DomainAdmin
RootAdmin = 1,
DomainAdmin = 2
}

export const AccountState = {
Expand Down Expand Up @@ -88,4 +88,8 @@ export class Account extends BaseModel {
public get isAdmin() {
return this.accounttype !== AccountType.User;
}

public get isRootAdmin() {
return this.accounttype === AccountType.RootAdmin;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { Component, Inject } from '@angular/core';
import {
Component,
Inject
} from '@angular/core';
import { State } from '../../../reducers/index';
import { Store } from '@ngrx/store';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material';
import {
MAT_DIALOG_DATA,
MatDialogRef
} from '@angular/material';
import { Snapshot } from '../../../shared/models/snapshot.model';

import * as fromTemplates from '../../redux/template.reducers';
import * as fromOsTypes from '../../redux/ostype.reducers';
import * as fromTemplateGroups from '../../redux/template-group.reducers';
import * as fromZones from '../../redux/zone.reducers';
import * as fromAuth from '../../../reducers/auth/redux/auth.reducers';
import * as templateActions from '../../redux/template.actions';
import * as osTypeActions from '../../redux/ostype.actions';
import * as zoneActions from '../../redux/zone.actions';
Expand All @@ -23,11 +30,13 @@ import * as templateGroupActions from '../../redux/template-group.actions';
[isLoading]="loading$ | async"
[groups]="groups$ | async"
[snapshot]="snapshot"
[account]="account$ | async"
(onCreateTemplate)="onCreate($event)"
></cs-template-creation>`
})
export class TemplateCreationContainerComponent {
readonly viewMode$ = this.store.select(fromTemplates.filterSelectedViewMode);
readonly account$ = this.store.select(fromAuth.getUserAccount);
readonly osTypes$ = this.store.select(fromOsTypes.selectAll);
readonly zones$ = this.store.select(fromZones.selectAll);
readonly loading$ = this.store.select(fromTemplates.isLoading);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,21 +178,22 @@ <h3 class="mat-dialog-title">{{ modeTranslationToken | translate }}</h3>
<mat-checkbox
name="public"
[(ngModel)]="isPublic"
*ngIf="isRootAdmin()"
>
{{ 'TEMPLATE_PAGE.TEMPLATE_CREATION.IS_PUBLIC' | translate }}
</mat-checkbox>
<mat-checkbox
name="feature"
[(ngModel)]="isFeatured"
*ngIf="isAdmin()"
*ngIf="isRootAdmin()"
>
{{ 'TEMPLATE_PAGE.TEMPLATE_CREATION.IS_FEATURED' | translate }}
</mat-checkbox>

<mat-checkbox
name="routing"
[(ngModel)]="isRouting"
*ngIf="isAdmin()"
*ngIf="isRootAdmin()"
>
{{ 'TEMPLATE_PAGE.TEMPLATE_CREATION.IS_ROUTING' | translate }}
</mat-checkbox>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import {
} from '../../shared';
import { Snapshot } from '../../shared/models/snapshot.model';
import { HypervisorService } from '../../shared/services/hypervisor.service';
import { AuthService } from '../../shared/services/auth.service';
import { TemplateGroup } from '../../shared/models/template-group.model';
import { TranslateService } from '@ngx-translate/core';
import { Language } from '../../shared/services/language.service';
import { TemplateResourceType } from '../shared/base-template.service';
import { Account } from '../../shared/models/account.model';

interface TemplateFormat {
name: string;
Expand All @@ -30,6 +30,7 @@ interface TemplateFormat {
})
export class TemplateCreationComponent implements OnInit {
@Input() public mode: string;
@Input() public account: Account;
@Input() public osTypes: Array<OsType>;
@Input() public zones: Array<Zone>;
@Input() public isLoading: boolean;
Expand Down Expand Up @@ -83,7 +84,6 @@ export class TemplateCreationComponent implements OnInit {

constructor(
private hypervisorService: HypervisorService,
private authService: AuthService,
private translate: TranslateService,
) {
this.visibleFormats = this.formats;
Expand Down Expand Up @@ -150,18 +150,18 @@ export class TemplateCreationComponent implements OnInit {
params['bootable'] = this.bootable;
params['format'] = this.format;
params['requireshvm'] = this.requiresHvm;
params['ispublic'] = this.isPublic;
params['hypervisor'] = this.hypervisor;
if (this.isAdmin()) {
if (this.isRootAdmin()) {
params['isrouting'] = this.isRouting;
params['isfeatured'] = this.isFeatured;
params['ispublic'] = this.isPublic;
}
}

this.onCreateTemplate.emit(params);
}

public isAdmin(): boolean {
return this.authService.isAdmin();
public isRootAdmin(): boolean {
return this.account.isRootAdmin;
}
}

0 comments on commit cc3687e

Please sign in to comment.