Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add card view to endpoint list #3422

Merged
merged 23 commits into from
Mar 14, 2019
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions src/frontend/packages/core/assets/endpoint-icons/metrics.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions src/frontend/packages/core/src/core/core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { BytesToHumanSize, MegaBytesToHumanSize } from './byte-formatters.pipe';
import { ClickStopPropagationDirective } from './click-stop-propagation.directive';
import { CurrentUserPermissionsService } from './current-user-permissions.service';
import { Customizations } from './customizations.types';
import { DisableRouterLinkDirective } from './disable-router-link.directive';
import { DotContentComponent } from './dot-content/dot-content.component';
import { EndpointsService } from './endpoints.service';
import { EntityFavoriteStarComponent } from './entity-favorite-star/entity-favorite-star.component';
Expand Down Expand Up @@ -51,7 +52,8 @@ import { WindowRef } from './window-ref/window-ref.service';
ButtonBlurOnClickDirective,
PageNotFoundComponentComponent,
EntityFavoriteStarComponent,
RecentEntitiesComponent
RecentEntitiesComponent,
DisableRouterLinkDirective
],
providers: [
AuthGuardService,
Expand All @@ -78,7 +80,8 @@ import { WindowRef } from './window-ref/window-ref.service';
ButtonBlurOnClickDirective,
PageNotFoundComponentComponent,
EntityFavoriteStarComponent,
RecentEntitiesComponent
RecentEntitiesComponent,
DisableRouterLinkDirective
],
entryComponents: [
LogOutDialogComponent
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Directive, Input, Optional } from '@angular/core';
import { RouterLink, RouterLinkWithHref } from '@angular/router';

@Directive({
selector: '[routerLink][appDisableRouterLink]'
})
export class DisableRouterLinkDirective {

@Input() appDisableRouterLink: boolean;

constructor(
// Inject routerLink
@Optional() routerLink: RouterLink,
@Optional() routerLinkWithHref: RouterLinkWithHref
) {

const link = routerLink || routerLinkWithHref;

// Save original method
const onClick = link.onClick;

// Replace method
link.onClick = (...args) => {
if (this.appDisableRouterLink) {
return routerLinkWithHref ? false : true;
} else {
return onClick.apply(link, args);
}
};
}

}
13 changes: 12 additions & 1 deletion src/frontend/packages/core/src/core/endpoints.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { UserService } from './user.service';
import { AuthState } from '../../../store/src/reducers/auth.reducer';
import { RouterNav } from '../../../store/src/actions/router.actions';
import { endpointHealthChecks, EndpointHealthCheck } from '../../endpoints-health-checks';
import { getEndpointTypes } from '../features/endpoints/endpoint-helpers';


@Injectable()
Expand All @@ -25,6 +26,17 @@ export class EndpointsService implements CanActivate {
haveRegistered$: Observable<boolean>;
haveConnected$: Observable<boolean>;

static getLinkForEndpoint(endpoint: EndpointModel): string {
if (!endpoint) {
return '';
}
const ext = getEndpointTypes().find(ep => ep.value === endpoint.cnsi_type);
if (ext && ext.homeLink) {
return ext.homeLink(endpoint.guid).join('/');
}
return '';
}

constructor(
private store: Store<AppState>,
private userService: UserService
Expand Down Expand Up @@ -101,5 +113,4 @@ export class EndpointsService implements CanActivate {
);
}


}
18 changes: 15 additions & 3 deletions src/frontend/packages/core/src/core/extension/extension-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { Type } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { Schema, schema } from 'normalizr';

import { EndpointModel } from '../../../../store/src/types/endpoint.types';
import { TableCellCustom } from '../../shared/components/list/list.types';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intent with the extensions folder/package was that it should not import anything else in the Stratos code base - thus it could be a separate package and extensions would only need to import the extensions package - they would not need to import anything else.

Is there a way to loosen the typing on listDetailsComponent and check it at runtime for compatibility?


// Allowable endpoint types
export type EndpointType = 'cf' | 'metrics' | string;

Expand All @@ -12,11 +15,20 @@ export interface EndpointTypeConfig {
allowTokenSharing?: boolean;
icon?: string;
iconFont?: string;
imagePath?: string;
authTypes?: string[];
// Get the link to the home page for the given endpoint GUID
homeLink?: (link: string) => string[];
// Schema keys associated with this endpoint type (used when clearing pagination)
/**
* Get the link to the home page for the given endpoint GUID
*/
homeLink?: (s) => string[];
/**
* Schema keys associated with this endpoint type (used when clearing pagination)
*/
entitySchemaKeys?: string[];
/**
* Show custom content in the endpoints list
*/
listDetailsComponent?: Type<TableCellCustom<EndpointModel>>;
}

export interface EndpointAuthTypeConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { CustomImportModule } from '../../custom-import.module';
import {
CFEndpointsListConfigService,
} from '../../shared/components/list/list-types/cf-endpoints/cf-endpoints-list-config.service';
import { EndpointListHelper } from '../../shared/components/list/list-types/endpoint/endpoint-list.helpers';
import { EndpointsListConfigService } from '../../shared/components/list/list-types/endpoint/endpoints-list-config.service';
import { SharedModule } from '../../shared/shared.module';
import { AddOrganizationComponent } from './add-organization/add-organization.component';
Expand Down Expand Up @@ -162,6 +163,7 @@ import { UsersRolesComponent } from './users/manage-users/manage-users.component
CfAdminAddUserWarningComponent,
],
providers: [
EndpointListHelper,
CFEndpointsListConfigService,
EndpointsListConfigService,
{
Expand All @@ -176,7 +178,7 @@ import { UsersRolesComponent } from './users/manage-users/manage-users.component
CloudFoundryEndpointService,
CfRolesService,
CloudFoundryCellService,
UserInviteService,
UserInviteService
],
entryComponents: [
UserInviteConfigurationDialogComponent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import { Type } from '@angular/core';
import { Validators } from '@angular/forms';
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs';
import { first, map } from 'rxjs/operators';
import { Validators } from '@angular/forms';

import { urlValidationExpression } from '../../core/utils.service';
import { EndpointModel } from '../../../../store/src/types/endpoint.types';
import { EndpointTypeConfig, EndpointAuthTypeConfig, EndpointType } from '../../core/extension/extension-types';

import { AppState } from '../../../../store/src/app-state';
import { selectEntities } from '../../../../store/src/selectors/api.selectors';
import { endpointSchemaKey } from '../../../../store/src/helpers/entity-factory';
import { selectEntities } from '../../../../store/src/selectors/api.selectors';
import { EndpointModel } from '../../../../store/src/types/endpoint.types';
import { ExtensionService } from '../../core/extension/extension-service';
import { EndpointAuthTypeConfig, EndpointType, EndpointTypeConfig } from '../../core/extension/extension-types';
import { urlValidationExpression } from '../../core/utils.service';
import {
CfEndpointDetailsComponent,
} from '../../shared/components/list/list-types/endpoint/cf-endpoint-details/cf-endpoint-details.component';
import { TableCellCustom } from '../../shared/components/list/list.types';
import { CredentialsAuthFormComponent } from './connect-endpoint-dialog/auth-forms/credentials-auth-form.component';
import { SSOAuthFormComponent } from './connect-endpoint-dialog/auth-forms/sso-auth-form.component';
import { NoneAuthFormComponent } from './connect-endpoint-dialog/auth-forms/none-auth-form.component';
import { SSOAuthFormComponent } from './connect-endpoint-dialog/auth-forms/sso-auth-form.component';

export function getFullEndpointApiUrl(endpoint: EndpointModel) {
return endpoint && endpoint.api_endpoint ? `${endpoint.api_endpoint.Scheme}://${endpoint.api_endpoint.Host}` : 'Unknown';
Expand All @@ -37,12 +41,15 @@ const endpointTypes: EndpointTypeConfig[] = [
urlValidation: urlValidationExpression,
icon: 'cloud_foundry',
iconFont: 'stratos-icons',
homeLink: (guid) => ['/cloud-foundry', guid]
imagePath: '/core/assets/endpoint-icons/cloudfoundry.png',
homeLink: (guid) => ['/cloud-foundry', guid],
listDetailsComponent: CfEndpointDetailsComponent
},
{
value: 'metrics',
label: 'Metrics',
allowTokenSharing: true,
imagePath: '/core/assets/endpoint-icons/metrics.svg',
homeLink: (guid) => ['/endpoints/metrics', guid]
},
];
Expand Down Expand Up @@ -76,6 +83,8 @@ let endpointAuthTypes: EndpointAuthTypeConfig[] = [

const endpointTypesMap = {};

export const endpointListDetailsComponents: Type<TableCellCustom<EndpointModel>>[] = [CfEndpointDetailsComponent];

export function initEndpointTypes(epTypes: EndpointTypeConfig[]) {
epTypes.forEach(epType => {
endpointTypes.push(epType);
Expand All @@ -89,6 +98,10 @@ export function initEndpointTypes(epTypes: EndpointTypeConfig[]) {
}
});
}

if (epType.listDetailsComponent) {
endpointListDetailsComponents.push(epType.listDetailsComponent);
}
});

endpointTypes.forEach(ept => {
Expand All @@ -114,6 +127,10 @@ export function getEndpointTypes() {
return endpointTypes;
}

export function getEndpointType(type: string): EndpointTypeConfig {
return getEndpointTypes().find(ep => ep.value === type);
}

export function getIconForEndpoint(type: string): EndpointIcon {
const icon = {
name: 'settings_ethernet',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
EndpointsListConfigService,
} from '../../../shared/components/list/list-types/endpoint/endpoints-list-config.service';
import { ListConfig } from '../../../shared/components/list/list.component.types';
import { EndpointListHelper } from '../../../shared/components/list/list-types/endpoint/endpoint-list.helpers';

@Component({
selector: 'app-endpoints-page',
Expand All @@ -25,7 +26,7 @@ import { ListConfig } from '../../../shared/components/list/list.component.types
providers: [{
provide: ListConfig,
useClass: EndpointsListConfigService,
}]
}, EndpointListHelper]
})

export class EndpointsPageComponent implements OnDestroy, OnInit {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,35 @@ import {
} from '@angular/core';

import { IListDataSource } from '../../data-sources-controllers/list-data-source-types';

import { CardCell } from '../../list.types';
import {
AppServiceBindingCardComponent,
} from '../../list-types/app-sevice-bindings/app-service-binding-card/app-service-binding-card.component';
import { CardAppComponent } from '../../list-types/app/card/card-app.component';
import { EndpointCardComponent } from '../../list-types/cf-endpoints/cf-endpoint-card/endpoint-card.component';
import { CfOrgCardComponent } from '../../list-types/cf-orgs/cf-org-card/cf-org-card.component';
import { CfSpaceCardComponent } from '../../list-types/cf-spaces/cf-space-card/cf-space-card.component';
import { CfBuildpackCardComponent } from '../../list-types/cf-buildpacks/cf-buildpack-card/cf-buildpack-card.component';
import { CfOrgCardComponent } from '../../list-types/cf-orgs/cf-org-card/cf-org-card.component';
import {
CfSecurityGroupsCardComponent
CfSecurityGroupsCardComponent,
} from '../../list-types/cf-security-groups/cf-security-groups-card/cf-security-groups-card.component';
import { CfStacksCardComponent } from '../../list-types/cf-stacks/cf-stacks-card/cf-stacks-card.component';
import { CfServiceCardComponent } from '../../list-types/cf-services/cf-service-card/cf-service-card.component';
import { CfSpaceCardComponent } from '../../list-types/cf-spaces/cf-space-card/cf-space-card.component';
import { CfStacksCardComponent } from '../../list-types/cf-stacks/cf-stacks-card/cf-stacks-card.component';
import { EndpointCardComponent } from '../../list-types/endpoint/endpoint-card/endpoint-card.component';
import {
AppServiceBindingCardComponent
} from '../../list-types/app-sevice-bindings/app-service-binding-card/app-service-binding-card.component';
import { ServiceInstanceCardComponent } from '../../list-types/services-wall/service-instance-card/service-instance-card.component';
ServiceInstanceCardComponent,
} from '../../list-types/services-wall/service-instance-card/service-instance-card.component';
import { CardCell } from '../../list.types';

export const listCards = [
CardAppComponent,
EndpointCardComponent,
CfOrgCardComponent,
CfSpaceCardComponent,
CfBuildpackCardComponent,
CfSecurityGroupsCardComponent,
CfStacksCardComponent,
CfServiceCardComponent,
AppServiceBindingCardComponent,
ServiceInstanceCardComponent
ServiceInstanceCardComponent,
EndpointCardComponent
];
@Component({
selector: 'app-card',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
<ng-content *ngTemplateOutlet="value.content"></ng-content>
</div>
</div>
</ng-template>
</ng-template>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, Component, ContentChild, OnInit, TemplateRef, ViewChild, Input } from '@angular/core';
import { ChangeDetectionStrategy, Component, ContentChild, Input, OnInit, TemplateRef, ViewChild } from '@angular/core';

import { MetaCardKeyComponent } from '../meta-card-key/meta-card-key.component';
import { MetaCardValueComponent } from '../meta-card-value/meta-card-value.component';
Expand Down Expand Up @@ -29,9 +29,6 @@ export class MetaCardItemComponent implements OnInit {

@Input() customStyle = 'row';

constructor() {
}

ngOnInit() {
this.itemStyle = this.styles[this.customStyle];
}
Expand Down
Loading