From ec38754297a121d70782325615227e8044632165 Mon Sep 17 00:00:00 2001 From: kunw Date: Mon, 5 Jun 2017 19:18:08 +0800 Subject: [PATCH] Update for shareable replication component. --- src/ui_ng/lib/src/index.ts | 1 + .../list-replication-rule.component.html.ts | 12 ++-- .../list-replication-rule.component.ts | 55 +++++++++++++++++-- .../replication/replication.component.html.ts | 8 +-- .../src/replication/replication.component.ts | 53 +++++++----------- src/ui_ng/lib/src/utils.ts | 2 +- 6 files changed, 80 insertions(+), 51 deletions(-) diff --git a/src/ui_ng/lib/src/index.ts b/src/ui_ng/lib/src/index.ts index 5deef7dea..fd466aa56 100644 --- a/src/ui_ng/lib/src/index.ts +++ b/src/ui_ng/lib/src/index.ts @@ -9,5 +9,6 @@ export * from './endpoint/index'; export * from './repository/index'; export * from './repository-stackview/index'; export * from './tag/index'; +export * from './list-replication-rule/index'; export * from './replication/index'; export * from './vulnerability-scanning/index'; \ No newline at end of file diff --git a/src/ui_ng/lib/src/list-replication-rule/list-replication-rule.component.html.ts b/src/ui_ng/lib/src/list-replication-rule/list-replication-rule.component.html.ts index 35efcab9c..83e5df4eb 100644 --- a/src/ui_ng/lib/src/list-replication-rule/list-replication-rule.component.html.ts +++ b/src/ui_ng/lib/src/list-replication-rule/list-replication-rule.component.html.ts @@ -3,26 +3,26 @@ export const LIST_REPLICATION_RULE_TEMPLATE: string = ` {{'REPLICATION.NAME' | translate}} - {{'REPLICATION.PROJECT' | translate}} + {{'REPLICATION.PROJECT' | translate}} {{'REPLICATION.DESCRIPTION' | translate}} {{'REPLICATION.DESTINATION_NAME' | translate}} {{'REPLICATION.LAST_START_TIME' | translate}} {{'REPLICATION.ACTIVATION' | translate}} - + - - {{p.name}} + + {{p.name}} - + {{p.name}} - {{p.project_name}} + {{p.project_name}} {{p.description ? p.description : '-'}} {{p.target_name}} diff --git a/src/ui_ng/lib/src/list-replication-rule/list-replication-rule.component.ts b/src/ui_ng/lib/src/list-replication-rule/list-replication-rule.component.ts index aa5e6c363..b543a0556 100644 --- a/src/ui_ng/lib/src/list-replication-rule/list-replication-rule.component.ts +++ b/src/ui_ng/lib/src/list-replication-rule/list-replication-rule.component.ts @@ -11,7 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -import { Component, Input, Output, EventEmitter, ViewChild, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core'; +import { Component, Input, Output, OnInit, EventEmitter, ViewChild, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core'; import { ReplicationService } from '../service/replication.service'; import { ReplicationRule } from '../service/interface'; @@ -32,17 +32,17 @@ import { State, Comparator } from 'clarity-angular'; import { LIST_REPLICATION_RULE_TEMPLATE } from './list-replication-rule.component.html'; @Component({ - selector: 'list-replication-rule', + selector: 'hbr-list-replication-rule', template: LIST_REPLICATION_RULE_TEMPLATE, changeDetection: ChangeDetectionStrategy.OnPush }) -export class ListReplicationRuleComponent { +export class ListReplicationRuleComponent implements OnInit { nullTime: string = '0001-01-01T00:00:00Z'; - - @Input() rules: ReplicationRule[]; - @Input() projectless: boolean; + + @Input() projectId: number; @Input() selectedId: number | string; + @Input() withReplicationJob: boolean; @Input() loading: boolean = false; @@ -50,6 +50,13 @@ export class ListReplicationRuleComponent { @Output() selectOne = new EventEmitter(); @Output() editOne = new EventEmitter(); @Output() toggleOne = new EventEmitter(); + @Output() redirect = new EventEmitter(); + + projectScope: boolean; + + rules: ReplicationRule[]; + changedRules: ReplicationRule[]; + ruleName: string; @ViewChild('toggleConfirmDialog') toggleConfirmDialog: ConfirmationDialogComponent; @@ -68,6 +75,38 @@ export class ListReplicationRuleComponent { setInterval(()=>ref.markForCheck(), 500); } + ngOnInit(): void { + this.projectScope = (!this.projectId); + this.retrieveRules(); + } + + retrieveRules(ruleName: string = ''): void { + this.loading = true; + toPromise(this.replicationService + .getReplicationRules(this.projectId, ruleName)) + .then(rules=>{ + this.rules = rules || []; + if(this.rules && this.rules.length > 0) { + this.selectedId = this.rules[0].id || ''; + this.selectOne.emit(this.rules[0]); + } + this.changedRules = this.rules; + this.loading = false; + } + ).catch(error=>{ + this.errorHandler.error(error); + this.loading = false; + }); + } + + filterRuleStatus(status: string) { + if(status === 'all') { + this.changedRules = this.rules; + } else { + this.changedRules = this.rules.filter(policy=>policy.enabled === +status); + } + } + toggleConfirm(message: ConfirmationAcknowledgement) { if(message && message.source === ConfirmationTargets.TOGGLE_CONFIRM && @@ -112,6 +151,10 @@ export class ListReplicationRuleComponent { this.selectOne.emit(rule); } + redirectTo(rule: ReplicationRule): void { + this.redirect.emit(rule); + } + editRule(rule: ReplicationRule) { this.editOne.emit(rule); } diff --git a/src/ui_ng/lib/src/replication/replication.component.html.ts b/src/ui_ng/lib/src/replication/replication.component.html.ts index b74186907..e37406d78 100644 --- a/src/ui_ng/lib/src/replication/replication.component.html.ts +++ b/src/ui_ng/lib/src/replication/replication.component.html.ts @@ -3,7 +3,7 @@ export const REPLICATION_TEMPLATE: string = `
- +
@@ -20,9 +20,9 @@ export const REPLICATION_TEMPLATE: string = `
- +
-
+
{{'REPLICATION.REPLICATION_JOBS' | translate}}
@@ -45,7 +45,7 @@ export const REPLICATION_TEMPLATE: string = `
-
+
{{'REPLICATION.NAME' | translate}} {{'REPLICATION.STATUS' | translate}} diff --git a/src/ui_ng/lib/src/replication/replication.component.ts b/src/ui_ng/lib/src/replication/replication.component.ts index 5b355612b..e09447d64 100644 --- a/src/ui_ng/lib/src/replication/replication.component.ts +++ b/src/ui_ng/lib/src/replication/replication.component.ts @@ -11,12 +11,13 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -import { Component, OnInit, ViewChild, Input } from '@angular/core'; +import { Component, OnInit, ViewChild, Input, Output, EventEmitter } from '@angular/core'; import { ResponseOptions, RequestOptions } from '@angular/http'; import { NgModel } from '@angular/forms'; import { TranslateService } from '@ngx-translate/core'; +import { ListReplicationRuleComponent} from '../list-replication-rule/list-replication-rule.component'; import { CreateEditRuleComponent } from '../create-edit-rule/create-edit-rule.component'; import { ErrorHandler } from '../error-handler/error-handler'; @@ -71,6 +72,9 @@ export class SearchOption { export class ReplicationComponent implements OnInit { @Input() projectId: number | string; + @Input() withReplicationJob: boolean; + + @Output() redirect = new EventEmitter(); search: SearchOption = new SearchOption(); @@ -94,6 +98,9 @@ export class ReplicationComponent implements OnInit { toggleJobSearchOption = optionalSearch; currentJobSearchOption: number; + @ViewChild(ListReplicationRuleComponent) + listReplicationRule: ListReplicationRuleComponent; + @ViewChild(CreateEditRuleComponent) createEditPolicyComponent: CreateEditRuleComponent; @@ -113,32 +120,8 @@ export class ReplicationComponent implements OnInit { this.currentRuleStatus = this.ruleStatus[0]; this.currentJobStatus = this.jobStatus[0]; this.currentJobSearchOption = 0; - - this.retrieveRules(); } - retrieveRules(): void { - this.loading = true; - toPromise(this.replicationService - .getReplicationRules(this.projectId, this.search.ruleName)) - .then(response=>{ - this.changedRules = response || []; - if(this.changedRules && this.changedRules.length > 0) { - this.initSelectedId = this.changedRules[0].id || ''; - } - this.rules = this.changedRules; - if(this.changedRules && this.changedRules.length > 0) { - this.search.ruleId = this.changedRules[0].id || ''; - this.fetchReplicationJobs(); - } - this.loading = false; - } - ).catch(error=>{ - this.errorHandler.error(error); - this.loading = false; - }); - } - openModal(): void { this.createEditPolicyComponent.openCreateEditRule(true); } @@ -177,37 +160,39 @@ export class ReplicationComponent implements OnInit { this.search.repoName = ''; this.search.status = ''; this.currentJobSearchOption = 0; - this.currentJobStatus = { 'key': 'all', 'description': 'REPLICATION.ALL' }; + this.currentJobStatus = { 'key': 'all', 'description': 'REPLICATION.ALL' }; this.fetchReplicationJobs(); } } + + customRedirect(rule: ReplicationRule) { + this.redirect.emit(rule); + } doSearchRules(ruleName: string) { this.search.ruleName = ruleName; - this.retrieveRules(); + this.listReplicationRule.retrieveRules(ruleName); } doFilterRuleStatus($event: any) { if ($event && $event.target && $event.target["value"]) { let status = $event.target["value"]; this.currentRuleStatus = this.ruleStatus.find((r: any)=>r.key === status); - if(this.currentRuleStatus.key === 'all') { - this.changedRules = this.rules; - } else { - this.changedRules = this.rules.filter(policy=>policy.enabled === +this.currentRuleStatus.key); - } + this.listReplicationRule.filterRuleStatus(this.currentRuleStatus.key); } } doFilterJobStatus($event: any) { if ($event && $event.target && $event.target["value"]) { let status = $event.target["value"]; + this.currentJobStatus = this.jobStatus.find((r: any)=>r.key === status); if(this.currentJobStatus.key === 'all') { status = ''; } this.search.status = status; this.doSearchJobs(this.search.repoName); + } } @@ -219,12 +204,12 @@ export class ReplicationComponent implements OnInit { reloadRules(isReady: boolean) { if(isReady) { this.search.ruleName = ''; - this.retrieveRules(); + this.listReplicationRule.retrieveRules(this.search.ruleName); } } refreshRules() { - this.retrieveRules(); + this.listReplicationRule.retrieveRules(); } refreshJobs() { diff --git a/src/ui_ng/lib/src/utils.ts b/src/ui_ng/lib/src/utils.ts index fcdf10dd0..3c5fb9add 100644 --- a/src/ui_ng/lib/src/utils.ts +++ b/src/ui_ng/lib/src/utils.ts @@ -104,7 +104,7 @@ export class CustomComparator implements Comparator { compare(a: {[key: string]: any| any[]}, b: {[key: string]: any| any[]}) { let comp = 0; - if(a && b && a[this.fieldName] && b[this.fieldName]) { + if(a && b) { let fieldA = a[this.fieldName]; let fieldB = b[this.fieldName]; switch(this.type) {