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

Commit

Permalink
#49 implement recurring snapshot actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Shakhov committed Jul 17, 2017
1 parent 9242225 commit 44aac2b
Show file tree
Hide file tree
Showing 27 changed files with 537 additions and 166 deletions.
14 changes: 10 additions & 4 deletions src/app/shared/services/base-backend.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ export abstract class BaseBackendService<M extends BaseModel> {
return result;
}

public create(params?: {}): Observable<any> {
return this.sendCommand('create', params)
public create(params?: {}, customApiFormat?: ApiFormat): Observable<any> {
const command = customApiFormat && customApiFormat.command || 'create';
const _entity = customApiFormat && customApiFormat.entity;

return this.sendCommand('create', params, _entity)
.map(response => {
const entity = this.entity.toLowerCase();
if (entity === 'tag' || entity === 'affinitygroup') {
Expand All @@ -62,8 +65,11 @@ export abstract class BaseBackendService<M extends BaseModel> {
});
}

public remove(params?: {}): Observable<any> {
return this.sendCommand('delete', params);
public remove(params?: {}, customApiFormat?: ApiFormat): Observable<any> {
const command = customApiFormat && customApiFormat.command || 'delete';
const entity = customApiFormat && customApiFormat.entity;

return this.sendCommand(command, params, entity);
}

protected prepareModel(res, entityModel?): M {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, forwardRef, Input, OnInit } from '@angular/core';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import { LangChangeEvent, TranslateService } from '@ngx-translate/core';
import { TranslateService } from '@ngx-translate/core';
import { Observable } from 'rxjs/Observable';
import { LanguageService } from '../../../shared/services';
import { DayOfWeek } from '../../../shared/types/day-of-week';
Expand All @@ -11,6 +11,7 @@ export interface DayOfWeekName {
name: string
}


@Component({
selector: 'cs-day-of-week',
templateUrl: 'day-of-week.component.html',
Expand All @@ -27,16 +28,6 @@ export class DayOfWeekComponent implements OnInit {
public _dayOfWeek: DayOfWeek;
public daysOfWeek: Array<DayOfWeekName>;

private _daysOfWeek = [
{ value: DayOfWeek.Sunday, name: 'SUNDAY'},
{ value: DayOfWeek.Monday, name: 'MONDAY'},
{ value: DayOfWeek.Tuesday, name: 'TUESDAY'},
{ value: DayOfWeek.Wednesday, name: 'WEDNESDAY'},
{ value: DayOfWeek.Thursday, name: 'THURSDAY'},
{ value: DayOfWeek.Friday, name: 'FRIDAY'},
{ value: DayOfWeek.Saturday, name: 'SATURDAY'},
];

constructor(
private languageService: LanguageService,
private translateService: TranslateService
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MdlTextFieldComponent } from '@angular-mdl/core';
import { AfterViewInit, Component, forwardRef, Input, OnInit, ViewChild } from '@angular/core';
import { AfterViewInit, ChangeDetectorRef, Component, forwardRef, Input, ViewChild } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { TranslateService } from '@ngx-translate/core';
import { Observable } from 'rxjs/Observable';
Expand All @@ -20,7 +20,7 @@ export interface HourlyPolicy {
}
]
})
export class HourlyPolicyComponent implements ControlValueAccessor {
export class HourlyPolicyComponent implements ControlValueAccessor, AfterViewInit {
@ViewChild('minuteField') public minuteField: MdlTextFieldComponent;
public _policy: HourlyPolicy;

Expand All @@ -30,6 +30,12 @@ export class HourlyPolicyComponent implements ControlValueAccessor {

constructor(private translateService: TranslateService) {}

public ngAfterViewInit(): void {
if (!this.policy) {
this.writeValue(this.policy);
}
}

public get errorMessage(): Observable<string> {
return this.translateService.get('BETWEEN', {
lowerLimit: this.minValue,
Expand All @@ -46,7 +52,7 @@ export class HourlyPolicyComponent implements ControlValueAccessor {
}

public updateMinute(value: number): void {
if (!value) {
if (value == null) {
return;
}

Expand All @@ -67,7 +73,7 @@ export class HourlyPolicyComponent implements ControlValueAccessor {
this.minute = newValue;
this.minuteField.inputEl.nativeElement.value = this.minute;
this.minuteField.writeValue(this.minute);
this.writeValue(this.minute);
this.writeValue(this.policy);
}

public propagateChange: any = () => {};
Expand All @@ -80,8 +86,9 @@ export class HourlyPolicyComponent implements ControlValueAccessor {
}

public set policy(value) {
if (value) {
if (value != null) {
this._policy = value;
this.minute = value.minute.toString();
this.propagateChange(this.policy);
}
}
Expand All @@ -93,7 +100,7 @@ export class HourlyPolicyComponent implements ControlValueAccessor {
public registerOnTouched(): void { }

public writeValue(value: any): void {
if (value) {
if (value != null) {
this.policy = value;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,3 @@
{{ 'SAVE' | translate }}
</button>
</div>

Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { PolicyMode } from '../recurring-snapshots.component';
import { PolicyType } from '../recurring-snapshots.component';
import { TimeZone } from '../time-zone/time-zone.service';
import { DailyPolicy } from './daily/daily-policy.component';
import { HourlyPolicy } from './hourly/hourly-policy.component';
import { MonthlyPolicy } from './monthly/monthly-policy.component';
import { WeeklyPolicy } from './weekly/weekly-policy.component';


export type TimePolicy = HourlyPolicy | DailyPolicy | WeeklyPolicy | MonthlyPolicy;
export type TimePolicy = HourlyPolicy & DailyPolicy & WeeklyPolicy & MonthlyPolicy;

export interface Policy {
timePolicy: TimePolicy;
timeZone: TimeZone;
export interface Policy<T> {
id?: string;
storedSnapshots: number;
timePolicy: T;
timeZone: TimeZone;
type?: PolicyType
}

@Component({
Expand All @@ -21,17 +23,18 @@ export interface Policy {
styleUrls: ['policy-editor.component.scss']
})
export class PolicyEditorComponent {
@Input() policyMode: PolicyMode;
@Output() onPolicySave: EventEmitter<Policy>;
@Input() policyMode: PolicyType;
@Output() onPolicySave: EventEmitter<Policy<TimePolicy>>;

public Policies = PolicyMode;
public Policies = PolicyType;

public policy: TimePolicy;

public timeZone: TimeZone;
public storedSnapshots = 1;

constructor() {
this.onPolicySave = new EventEmitter<Policy>();
this.onPolicySave = new EventEmitter<Policy<TimePolicy>>();
}

public save(): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
<p>
policy-list works!
</p>
<table class="mdl-data-table">
<thead>
<tr>
<th>{{ 'TIME' | translate }}</th>
<th></th>
<th>{{ 'TIME_ZONE' | translate }}</th>
<th>{{ 'KEEP' | translate }}</th>
<th></th>
</tr>
</thead>
<tbody>
<tr *ngFor="let p of policies">
<td>
{{ p.timeToken | translate:{ value: p.timeValue } }}
</td>
<td>
{{ p.periodToken | translate: { value: p.periodValue } }}
</td>
<td>
{{ p.timeZone }}
</td>
<td>
{{ p.keep }}
</td>
<td>
<button
(click)="deletePolicy(p)"
[mdl-tooltip]="'DELETE' | translate"
mdl-tooltip-position="bottom"
mdl-button
mdl-button-type="icon"
mdl-ripple
>
<mdl-icon>delete</mdl-icon>
</button>
</td>
</tr>
</tbody>
</table>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
table {
width: 100%;
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,108 @@
import { Component, Input, OnInit } from '@angular/core';
import { Policy } from '../policy-editor/policy-editor.component';
import { Component, EventEmitter, Input, OnChanges, Output } from '@angular/core';
import { DayOfWeek } from '../../../shared/types/day-of-week';
import { DailyPolicy } from '../policy-editor/daily/daily-policy.component';
import { HourlyPolicy } from '../policy-editor/hourly/hourly-policy.component';
import { MonthlyPolicy } from '../policy-editor/monthly/monthly-policy.component';
import { Policy, TimePolicy } from '../policy-editor/policy-editor.component';
import { WeeklyPolicy } from '../policy-editor/weekly/weekly-policy.component';
import { PolicyType } from '../recurring-snapshots.component';
import { Time } from '../time-picker/time-picker.component';


interface PolicyView {
id: string;
type: PolicyType;
timeToken: string;
timeValue: string;
periodToken: string;
periodValue: string;
timeZone: string;
keep: string;
}

@Component({
selector: 'cs-policy-list',
templateUrl: 'policy-list.component.html',
styleUrls: ['policy-list.component.scss']
})
export class PolicyListComponent implements OnInit {
@Input() public policies: Array<Policy>;
export class PolicyListComponent implements OnChanges {
@Input() hourlyPolicy: Policy<HourlyPolicy>;
@Input() dailyPolicy: Policy<DailyPolicy>;
@Input() weeklyPolicy: Policy<WeeklyPolicy>;
@Input() monthlyPolicy: Policy<MonthlyPolicy>;
@Output() onPolicyDelete: EventEmitter<Policy<TimePolicy>>;

public policies: Array<PolicyView>;

constructor() { }
constructor() {
this.onPolicyDelete = new EventEmitter<Policy<TimePolicy>>();
}

public ngOnChanges(): void {
this.updatePolicies();
}

public deletePolicy(policy: Policy<TimePolicy>): void {
this.onPolicyDelete.next(policy);
}

public updatePolicies(): void {
const daysOfWeek = [
{ value: DayOfWeek.Sunday, name: 'SUNDAY'},
{ value: DayOfWeek.Monday, name: 'MONDAY'},
{ value: DayOfWeek.Tuesday, name: 'TUESDAY'},
{ value: DayOfWeek.Wednesday, name: 'WEDNESDAY'},
{ value: DayOfWeek.Thursday, name: 'THURSDAY'},
{ value: DayOfWeek.Friday, name: 'FRIDAY'},
{ value: DayOfWeek.Saturday, name: 'SATURDAY'},
];

this.policies = [
...(this.hourlyPolicy ? [{
id: this.hourlyPolicy.id,
type: PolicyType.Hourly,
timeToken: 'POLICY_HOURLY_TIME',
timeValue: this.hourlyPolicy.timePolicy.minute.toString(),
periodToken: '',
periodValue: '',
timeZone: this.hourlyPolicy.timeZone.zone,
keep: this.hourlyPolicy.storedSnapshots.toString()
}] : []),
...(this.dailyPolicy ? [{
id: this.dailyPolicy.id,
type: PolicyType.Daily,
timeToken: 'POLICY_DAILY_TIME',
timeValue: this.getTimeString(this.dailyPolicy.timePolicy),
periodToken: '',
periodValue: '',
timeZone: this.dailyPolicy.timeZone.zone,
keep: this.dailyPolicy.storedSnapshots.toString()
}] : []),
...(this.weeklyPolicy ? [{
id: this.weeklyPolicy.id,
type: PolicyType.Weekly,
timeToken: 'POLICY_WEEKLY_TIME',
timeValue: this.getTimeString(this.weeklyPolicy.timePolicy),
periodToken: 'POLICY_WEEKLY_PERIOD',
periodValue: daysOfWeek.find(_ => _.value === this.weeklyPolicy.timePolicy.dayOfWeek).name,
timeZone: this.weeklyPolicy.timeZone.zone,
keep: this.weeklyPolicy.storedSnapshots.toString()
}] : []),
...(this.monthlyPolicy ? [{
id: this.monthlyPolicy.id,
type: PolicyType.Monthly,
timeToken: 'POLICY_MONTHLY_TIME',
timeValue: this.getTimeString(this.monthlyPolicy.timePolicy),
periodToken: 'POLICY_MONTHLY_PERIOD',
periodValue: this.monthlyPolicy.timePolicy.dayOfMonth.toString(),
timeZone: this.monthlyPolicy.timeZone.zone,
keep: this.monthlyPolicy.storedSnapshots.toString()
}] : [])
];
}

public ngOnInit(): void {
private getTimeString(time: Time): string {
// todo am/pm
return `${time.hour}:${time.minute} ${time.period}`;
}
}
Empty file.
Empty file.
17 changes: 0 additions & 17 deletions src/app/snapshot/recurring-snapshots/policy/policy.component.ts

This file was deleted.

Loading

0 comments on commit 44aac2b

Please sign in to comment.