Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

Commit

Permalink
Merge pull request #472 from jstrachan/malarkey
Browse files Browse the repository at this point in the history
more polish and fixes for the environments detail view
  • Loading branch information
jstrachan authored May 15, 2017
2 parents 35bb498 + 240d176 commit 0be1d3a
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 32 deletions.
3 changes: 2 additions & 1 deletion src/app/kubernetes/model/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ export var resourceKindToCollectionName = {
};

export var resourceKindToOpenShiftConsoleCollectionName = {
"DeploymentConfig": "dc",
"BuildConfig": "pipelines",
"DeploymentConfig": "dc",
"ReplicationController": "rc",
};

/**
Expand Down
11 changes: 9 additions & 2 deletions src/app/kubernetes/model/kubernetesresource.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,17 @@ export class KubernetesResource implements BaseEntity {
this.labels = metadata.labels || new Map<string, string>();
this.annotations = metadata.annotations || new Map<string, string>();
this.version = this.labels["version"] || "";
this.icon = this.annotations['fabric8.io/iconUrl'] || this.defaultIconUrl();

// for Replicas we need to also look in the spec.template.metadata.annotations
let spec = resource.spec || {};
let template = spec.template || {};
let templateMetadata = template.metadata || {};
let templateAnnotations = templateMetadata.annotations || new Map<string, string>();

this.icon = this.annotations['fabric8.io/iconUrl'] || templateAnnotations['fabric8.io/iconUrl'] || this.defaultIconUrl();

// TODO any other annotations we should look for?
this.description = this.annotations['description'] || '';
this.description = this.annotations['description'] || templateAnnotations['description'] || '';

this.openShiftConsoleUrl = openShiftBrowseResourceUrl(this, currentOAuthConfig());
}
Expand Down
8 changes: 7 additions & 1 deletion src/app/kubernetes/service/devnamespace.scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ export class DevNamespaceScope extends NamespaceScope {
}

protected getNamespace(params) {
return params['space'] || params['namespace'] || this.defaultNamespace();
return params['space'] || this.getRouteParams('space') ||
params['namespace'] || this.getRouteParams('namespace');
}


currentNamespace(): any {
return this.findParamsFor(this.router.routerState.snapshot.root, "space") || super.currentNamespace();
}
}
55 changes: 32 additions & 23 deletions src/app/kubernetes/service/namespace.scope.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,58 @@
import { Injectable } from '@angular/core';
import { ActivatedRoute, Router, NavigationEnd } from "@angular/router";
import { Observable } from 'rxjs';
import { merge } from 'lodash';
import {Injectable} from "@angular/core";
import {ActivatedRoute, Router, NavigationEnd} from "@angular/router";
import {Observable} from "rxjs";

@Injectable()
export class NamespaceScope {
public namespace: Observable<string>;

constructor(private activatedRoute: ActivatedRoute, private router: Router) {
constructor(protected activatedRoute: ActivatedRoute, protected router: Router) {
this.namespace = this.router.events
.filter(event => event instanceof NavigationEnd)
.map(() => this.activatedRoute)
.map(route => {
while (route.firstChild) route = route.firstChild;
return route;
})
.map(
route => {
while (route.firstChild) route = route.firstChild;
return route;
})
.filter(route => route.outlet === 'primary')
.mergeMap(route => route.params).map(params => this.getNamespace(params)).distinctUntilChanged();
.mergeMap(route => route.params).map(params => this.getNamespace(params)).filter(n => n).distinctUntilChanged();
}

protected getNamespace(params) {
return this.getRouteParams()['namespace'] || this.defaultNamespace();
return params['namespace'] || this.getRouteParams('namespace');
}

defaultNamespace(): string {
// TODO use some other mechanism to return the default?
return 'default';
}

private getRouteParams(): any {
protected getRouteParams(key): any {
if (
this.router &&
this.router.routerState &&
this.router.routerState.snapshot &&
this.router.routerState.snapshot.root
) {
let firstChild = this.router.routerState.snapshot.root.firstChild;
let res = {};
while (firstChild) {
res = merge(res, firstChild.params);
firstChild = firstChild.firstChild;
return this.findParamsFor(this.router.routerState.snapshot.root, key);
}
return null;
}

protected findParamsFor(route, key): any {
let children = route.children;
for (let child of children) {
let params = child.params;
if (params) {
let answer = params[key];
if (!answer) {
answer = this.findParamsFor(child, key);
}
if (answer) {
return answer;
}
}
return res;
}
return null;
}

currentNamespace() {
return this.findParamsFor(this.router.routerState.snapshot.root, "namespace");
}
}
4 changes: 2 additions & 2 deletions src/app/kubernetes/service/namespaced.resource.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export abstract class NamespacedResourceService<T extends KubernetesResource, L
private urlPrefix: string = '/api/v1/namespaces/',
) {
super(kubernetesRestangular, watcherFactory);
this.namespace = namespaceScope.defaultNamespace();
this.namespace = namespaceScope.currentNamespace();

if (this.namespaceScope) {
this.namespaceSubscription = this.namespaceScope.namespace.subscribe(
Expand Down Expand Up @@ -51,7 +51,7 @@ export abstract class NamespacedResourceService<T extends KubernetesResource, L
}

set namespace(namespace: string) {
if (namespace != this._namespace) {
if (namespace && namespace != this._namespace) {
this._namespace = namespace;
this._serviceUrl = null;
this.onNamespaceChanged();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {pathJoin} from "../../../model/utils";
import {ReplicationControllerService} from "../../../service/replicationcontroller.service";
import {RouteService} from "../../../service/route.service";
import {AbstractWatchComponent} from "../../../support/abstract-watch.component";
import {currentOAuthConfig} from "../../../store/oauth-config-store";


export let KINDS: Kind[] = [
Expand Down Expand Up @@ -246,6 +247,12 @@ export class EnvironmentListPageComponent extends AbstractWatchComponent impleme

export function environmentOpenShiftConoleUrl(environment: Environment): string {
let openshiftConsoleUrl = process.env.OPENSHIFT_CONSOLE_URL;
if (!openshiftConsoleUrl) {
let config = currentOAuthConfig();
if (config != null) {
openshiftConsoleUrl = config.openshiftConsoleUrl;
}
}
let namespace = environment.namespaceName;
if (namespace) {
return pathJoin(openshiftConsoleUrl, "/project", namespace, "/overview")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="col-md-4">
<h2 *ngIf="!e.openshiftConsoleUrl">{{e.environment.name}}</h2>
<h2 *ngIf="e.openshiftConsoleUrl">
<a [href]="e.openshiftConsoleUrl" title="View this environment in the OpenShift console">
<a [href]="e.openshiftConsoleUrl" target="openshift" title="View this environment in the OpenShift console">
{{e.environment.name}}
</a>
</h2>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Component, OnInit} from "@angular/core";
import {Observable} from "rxjs/Observable";
import {ReplicaSet} from "../../../model/replicaset.model";
import {ReplicaSetStore} from "../../../store/replicaset.store";
import {AbstractViewWrapperComponent} from "../../../support/abstract-viewwrapper-component";
import {ActivatedRoute} from "@angular/router";
import {CompositeReplicaSetStore} from "../../../store/compositedreplicaset.store";

@Component({
selector: 'fabric8-replicaset-view-wrapper',
Expand All @@ -13,7 +13,7 @@ import {ActivatedRoute} from "@angular/router";
export class ReplicaSetViewWrapperComponent extends AbstractViewWrapperComponent implements OnInit {
replicaset: Observable<ReplicaSet>;

constructor(private store: ReplicaSetStore, route: ActivatedRoute) {
constructor(private store: CompositeReplicaSetStore, route: ActivatedRoute) {
super(route);
}

Expand Down

0 comments on commit 0be1d3a

Please sign in to comment.