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

Commit

Permalink
Merge pull request #3422 from cloudfoundry-incubator/endpoint-list-cards
Browse files Browse the repository at this point in the history
Add card view to endpoint list
  • Loading branch information
nwmac committed Mar 14, 2019
2 parents 5abcde5 + 2083cc8 commit b8a83c2
Show file tree
Hide file tree
Showing 67 changed files with 1,005 additions and 585 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"test": "run-s test-frontend:* --continue-on-error",
"test-frontend:core": "ng test core --code-coverage --watch=false",
"test-frontend:store": "ng test store --code-coverage --watch=false",
"test-frontend:cloud-foundry": "ng test cloud-foundry --code-coverage --watch=false",
"posttest": "istanbul report json && node build/combine-coverage.js",
"codecov": "codecov -f coverage/coverage-final.json",
"lint": "ng lint --format stylish",
Expand Down
28 changes: 28 additions & 0 deletions src/frontend/packages/cloud-foundry/src/cloud-foundry.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { NgModule } from '@angular/core';

import { StratosExtension } from '../../core/src/core/extension/extension-service';
import { EndpointTypeConfig } from '../../core/src/core/extension/extension-types';
import { urlValidationExpression } from '../../core/src/core/utils.service';
import { CfEndpointDetailsComponent } from './shared/components/cf-endpoint-details/cf-endpoint-details.component';
import { CloudFoundryComponentsModule } from './shared/components/components.module';

const cloudFoundryEndpointTypes: EndpointTypeConfig[] = [{
value: 'cf',
label: 'Cloud Foundry',
urlValidation: urlValidationExpression,
icon: 'cloud_foundry',
iconFont: 'stratos-icons',
imagePath: '/core/assets/endpoint-icons/cloudfoundry.png',
homeLink: (guid) => ['/cloud-foundry', guid],
listDetailsComponent: CfEndpointDetailsComponent
}];

@StratosExtension({
endpointTypes: cloudFoundryEndpointTypes,
})
@NgModule({
imports: [
CloudFoundryComponentsModule
],
})
export class CloudFoundryModule { }
2 changes: 1 addition & 1 deletion src/frontend/packages/cloud-foundry/src/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
* Public API Surface of cloud-foundry
*/

export * from './lib/cloud-foundry.service';
// export * from './lib/cloud-foundry.service';
export * from './lib/cloud-foundry.component';
export * from './lib/cloud-foundry.module';
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div class="cf-details" *ngIf="row?.user as user else noUser">
<div class="cf-details__line">
<span class="cf-details__icon">
<mat-icon matTooltip="Username">person</mat-icon>
</span>
{{ user.name}} <ng-container *ngIf="user.admin">(Administrator)</ng-container>
</div>
</div>
<ng-template #noUser>-</ng-template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.cf-details {
display: flex;
flex-direction: column;

&__line {
align-items: center;
display: flex;
}

&__icon {
align-items: center;
display: flex;
justify-content: center;
width: 32px;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { CoreModule } from '../../../../../core/src/core/core.module';
import { SharedModule } from '../../../../../core/src/shared/shared.module';
import { CfEndpointDetailsComponent } from './cf-endpoint-details.component';

describe('CfEndpointDetailsComponent', () => {
let component: CfEndpointDetailsComponent;
let fixture: ComponentFixture<CfEndpointDetailsComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [CfEndpointDetailsComponent],
imports: [
CoreModule,
SharedModule
]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(CfEndpointDetailsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Component } from '@angular/core';

import {
EndpointListDetailsComponent,
} from '../../../../../core/src/shared/components/list/list-types/endpoint/endpoint-list.helpers';


@Component({
selector: 'lib-cf-endpoint-details',
templateUrl: './cf-endpoint-details.component.html',
styleUrls: ['./cf-endpoint-details.component.scss']
})
export class CfEndpointDetailsComponent extends EndpointListDetailsComponent { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { NgModule } from '@angular/core';

import { CoreModule } from '../../../../core/src/core/core.module';
import { CfEndpointDetailsComponent } from './cf-endpoint-details/cf-endpoint-details.component';

@NgModule({
imports: [
CoreModule
],
declarations: [
CfEndpointDetailsComponent
],
exports: [
CfEndpointDetailsComponent
],
entryComponents: [
CfEndpointDetailsComponent
]
})
export class CloudFoundryComponentsModule { }
9 changes: 3 additions & 6 deletions src/frontend/packages/cloud-foundry/src/test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import 'zone.js/dist/long-stack-trace-zone';
import 'zone.js/dist/proxy';
import 'zone.js/dist/sync-test';
import 'zone.js/dist/jasmine-patch';
import 'zone.js/dist/async-test';
import 'zone.js/dist/fake-async-test';
import 'core-js/es7/reflect';
import 'zone.js/dist/zone';
import 'zone.js/dist/zone-testing';

import { APP_BASE_HREF } from '@angular/common';
import { getTestBed } from '@angular/core/testing';
Expand Down
7 changes: 4 additions & 3 deletions src/frontend/packages/cloud-foundry/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
"extends": "../../../tsconfig.spec.json",
"compilerOptions": {
"outDir": "../../../../out-tsc/spec",
"types": [
"jasmine",
"node"
]
},
"files": [
"src/test.ts"
],
"include": [
"**/*.spec.ts",
"**/*.d.ts"
],
"exclude": [
"**/node_modules/**"
]
}
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.
6 changes: 4 additions & 2 deletions src/frontend/packages/core/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { RouterStateSerializer, StoreRouterConnectingModule } from '@ngrx/router
import { Store } from '@ngrx/store';
import { debounceTime, withLatestFrom } from 'rxjs/operators';

import { CloudFoundryModule } from '../../cloud-foundry/src/cloud-foundry.module';
import { GetAllEndpoints } from '../../store/src/actions/endpoint.actions';
import { GetOrganization } from '../../store/src/actions/organization.actions';
import { SetRecentlyVisitedEntityAction } from '../../store/src/actions/recently-visited.actions';
Expand Down Expand Up @@ -38,6 +39,7 @@ import { CurrentUserPermissionsService } from './core/current-user-permissions.s
import { DynamicExtensionRoutes } from './core/extension/dynamic-extension-routes';
import { ExtensionService } from './core/extension/extension-service';
import { getGitHubAPIURL, GITHUB_API_URL } from './core/github.helpers';
import { LoggerService } from './core/logger.service';
import { UserFavoriteManager } from './core/user-favorite-manager';
import { CustomImportModule } from './custom-import.module';
import { AboutModule } from './features/about/about.module';
Expand All @@ -56,7 +58,6 @@ import { ApplicationStateService } from './shared/components/application-state/a
import { favoritesConfigMapper } from './shared/components/favorites-meta-card/favorite-config-mapper';
import { SharedModule } from './shared/shared.module';
import { XSRFModule } from './xsrf.module';
import { LoggerService } from './core/logger.service';

// Create action for router navigation. See
// - https://github.com/ngrx/platform/issues/68
Expand Down Expand Up @@ -113,6 +114,7 @@ export class CustomRouterStateSerializer
AboutModule,
CustomImportModule,
XSRFModule,
CloudFoundryModule
],
providers: [
LoggedInService,
Expand All @@ -138,7 +140,7 @@ export class AppModule {
initEndpointExtensions(ext);
// Once the CF modules become an extension point, these should be moved to a CF specific module
this.registerCfFavoriteMappers();
this.userFavoriteManager = new UserFavoriteManager(store, logger);
this.userFavoriteManager = new UserFavoriteManager(store, logger);
const allFavs$ = this.userFavoriteManager.getAllFavorites();
const recents$ = this.store.select(recentlyVisitedSelector);
const debouncedApiRequestData$ = this.store.select(getAPIRequestDataState).pipe(debounceTime(2000));
Expand Down
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 {
);
}


}
15 changes: 12 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 @@ -12,11 +12,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. Should be Type<EndpointListDetailsComponent>
*/
listDetailsComponent?: any;
}

export interface EndpointAuthTypeConfig {
Expand Down
Loading

0 comments on commit b8a83c2

Please sign in to comment.