ensure @Input bindings are not undefined before executing trigger logic

This commit is contained in:
alecmerdler 2017-05-26 11:50:11 -07:00
parent 4750d1c5ef
commit d5e35156e0
6 changed files with 64 additions and 53 deletions

View file

@ -1,4 +1,4 @@
import { Input, Output, Component, Inject, EventEmitter, OnInit } from 'ng-metadata/core';
import { Input, Output, Component, Inject, EventEmitter, OnChanges, SimpleChanges } from 'ng-metadata/core';
import * as moment from 'moment';
import { Local, Trigger, TriggerConfig, Repository, Namespace } from '../../../types/common.types';
import { ContextChangeEvent } from '../context-path-select/context-path-select.component';
@ -12,7 +12,7 @@ import { PathChangeEvent } from '../dockerfile-path-select/dockerfile-path-selec
selector: 'manage-trigger',
templateUrl: '/static/js/directives/ui/manage-trigger/manage-trigger.component.html'
})
export class ManageTriggerComponent implements OnInit {
export class ManageTriggerComponent implements OnChanges {
@Input('<') public githost: string = 'custom-git';
@Input('<') public repository: Repository;
@ -43,26 +43,28 @@ export class ManageTriggerComponent implements OnInit {
}
public ngOnInit(): void {
this.config = this.trigger.config || {};
this.namespaceTitle = 'organization';
this.local.selectedNamespace = null;
if (this.githost != 'custom-git') {
this.loadNamespaces();
}
public ngOnChanges(changes: SimpleChanges): void {
if (this.githost && this.repository && this.trigger) {
this.config = this.trigger.config || {};
this.namespaceTitle = 'organization';
this.local.selectedNamespace = null;
if (this.githost != 'custom-git') {
this.loadNamespaces();
}
// FIXME: Need to have watchers here because cor-table doesn't have ng-change functionality yet
this.$scope.$watch(() => this.local.selectedNamespace, (namespace: Namespace) => {
if (namespace) {
this.loadRepositories(namespace);
}
});
this.$scope.$watch(() => this.local.selectedRepository, (selectedRepository: Repository) => {
if (selectedRepository && this.githost != 'custom-git') {
this.loadRepositoryRefs(selectedRepository);
this.loadDockerfileLocations(selectedRepository);
}
});
// FIXME (Alec 5/26/17): Need to have watchers here because cor-table doesn't have ng-change functionality yet
this.$scope.$watch(() => this.local.selectedNamespace, (namespace: Namespace) => {
if (namespace) {
this.loadRepositories(namespace);
}
});
this.$scope.$watch(() => this.local.selectedRepository, (selectedRepository: Repository) => {
if (selectedRepository && this.githost != 'custom-git') {
this.loadRepositoryRefs(selectedRepository);
this.loadDockerfileLocations(selectedRepository);
}
});
}
}
public getTriggerIcon(): any {
@ -120,20 +122,21 @@ export class ManageTriggerComponent implements OnInit {
return this.apiService.getRobots(this.repository.namespace, null, {'permissions': true});
} else {
this.local.triggerAnalysis = Object.assign({}, resp);
this.buildOrderedRobotAccounts();
}
})
.catch((error) => {
this.apiService.errorDisplay('Could not analyze trigger');
})
.then((resp) => {
this.local.triggerAnalysis = {
status: 'publicbase',
is_admin: true,
robots: resp.robots,
name: this.repository.name,
namespace: this.repository.namespace
};
if (resp) {
this.local.triggerAnalysis = {
status: 'publicbase',
is_admin: true,
robots: resp.robots,
name: this.repository.name,
namespace: this.repository.namespace
};
}
this.buildOrderedRobotAccounts();
})
.catch((error) => {