-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tiles widgets for api products and products list (#1162)
- Loading branch information
Showing
22 changed files
with
448 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
<!-- ko if: layout() === 'list' --> | ||
<product-apis-runtime data-bind="attr: { params: runtimeConfig }"></product-apis-runtime> | ||
<!-- /ko --> | ||
|
||
<!-- ko if: layout() === 'tiles' --> | ||
<product-apis-tiles-runtime data-bind="attr: { params: runtimeConfig }"></product-apis-tiles-runtime> | ||
<!-- /ko --> |
3 changes: 2 additions & 1 deletion
3
src/components/products/product-apis/ko/productApisEditor.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import { IInjectorModule, IInjector } from "@paperbits/common/injection"; | ||
import { ProductApisHandlers } from "../productApisHandlers"; | ||
import { ProductApisHandlers, ProductApisTilesHandlers } from "../productApisHandlers"; | ||
import { ProductApisEditor } from "./productApisEditor"; | ||
|
||
export class ProductApisEditorModule implements IInjectorModule { | ||
public register(injector: IInjector): void { | ||
injector.bind("productApisEditor", ProductApisEditor); | ||
injector.bindToCollection("widgetHandlers", ProductApisHandlers, "productApisHandlers"); | ||
injector.bindToCollection("widgetHandlers", ProductApisTilesHandlers, "productApisTilesHandlers"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/components/products/product-apis/ko/runtime/product-apis-tiles.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<div class="form-inline search-input"> | ||
<div class="input-group"> | ||
<input type="search" role="searchbox" aria-label="Search" placeholder="Search APIs" spellcheck="false" | ||
data-bind="textInput: pattern" /> | ||
<button type="button" class="search-button" aria-label="Search products"> | ||
<i class="icon-emb icon-emb-magnifier"></i> | ||
</button> | ||
</div> | ||
</div> | ||
|
||
<div class="cards"> | ||
<!-- ko if: working --> | ||
<div class="cards-body"> | ||
<spinner class="fit"></spinner> | ||
</div> | ||
<!-- /ko --> | ||
|
||
<!-- ko ifnot: working --> | ||
<div class="cards-body animation-fade-in"> | ||
|
||
<!-- ko foreach: { data: apis, as: 'item' } --> | ||
<a href="#" data-bind="attr: { href: $component.getReferenceUrl(item) }"> | ||
<div class="card item-tile"> | ||
<h3> | ||
<span data-bind="text: item.displayName"></span> | ||
<!-- ko if: item.type === 'soap' --> | ||
<span class="badge badge-soap">SOAP</span> | ||
<!-- /ko --> | ||
<!-- ko if: item.apiVersion --> | ||
- <span data-bind="text: item.apiVersion"></span> | ||
<!-- /ko --> | ||
</h3> | ||
<div class="tile line-clamp"> | ||
<p class="tile-content" data-bind="markdown: { source: item.description, truncateAt: 250 }"></p> | ||
</div> | ||
</div> | ||
</a> | ||
<!-- /ko --> | ||
|
||
<!-- ko if: apis().length === 0 --> | ||
<p>This product doesn't have APIs.</p> | ||
<!-- /ko --> | ||
|
||
</div> | ||
<!-- /ko --> | ||
|
||
<div class="cards-footer"> | ||
<!-- ko if: hasPager --> | ||
<ul class="pagination" role="navigation" aria-label="Pagination"> | ||
<!-- ko if: hasPrevPage --> | ||
<li class="page-item"> | ||
<a href="#" class="page-link" role="button" aria-label="Previous page" | ||
data-bind="click: prevPage, enable: hasPrevPage"> | ||
<i class="icon-emb icon-emb-chevron-left"></i> | ||
</a> | ||
</li> | ||
<!-- /ko --> | ||
<li class="page-item"> | ||
<span class="page-link" data-bind="text: page"></span> | ||
</li> | ||
<!-- ko if: hasNextPage --> | ||
<li class="page-item"> | ||
<a href="#" class="page-link" role="button" aria-label="Next page" | ||
data-bind="click: nextPage, enable: hasNextPage"> | ||
<i class="icon-emb icon-emb-chevron-right"></i> | ||
</a> | ||
</li> | ||
<!-- /ko --> | ||
</ul> | ||
<!-- /ko --> | ||
</div> | ||
</div> |
120 changes: 120 additions & 0 deletions
120
src/components/products/product-apis/ko/runtime/product-apis-tiles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import * as ko from "knockout"; | ||
import * as Constants from "../../../../../constants"; | ||
import template from "./product-apis-tiles.html"; | ||
import { Component, RuntimeComponent, OnMounted, OnDestroyed, Param } from "@paperbits/common/ko/decorators"; | ||
import { Router } from "@paperbits/common/routing"; | ||
import { ApiService } from "../../../../../services/apiService"; | ||
import { Api } from "../../../../../models/api"; | ||
import { SearchQuery } from "../../../../../contracts/searchQuery"; | ||
import { RouteHelper } from "../../../../../routing/routeHelper"; | ||
|
||
|
||
@RuntimeComponent({ | ||
selector: "product-apis-tiles-runtime" | ||
}) | ||
@Component({ | ||
selector: "product-apis-tiles-runtime", | ||
template: template | ||
}) | ||
export class ProductApisTiles { | ||
public readonly apis: ko.ObservableArray<Api>; | ||
public readonly working: ko.Observable<boolean>; | ||
public readonly pattern: ko.Observable<string>; | ||
public readonly page: ko.Observable<number>; | ||
public readonly hasPager: ko.Computed<boolean>; | ||
public readonly hasPrevPage: ko.Observable<boolean>; | ||
public readonly hasNextPage: ko.Observable<boolean>; | ||
|
||
constructor( | ||
private readonly apiService: ApiService, | ||
private readonly router: Router, | ||
private readonly routeHelper: RouteHelper | ||
) { | ||
this.detailsPageUrl = ko.observable(); | ||
this.apis = ko.observableArray([]); | ||
this.working = ko.observable(); | ||
this.pattern = ko.observable(); | ||
this.page = ko.observable(1); | ||
this.hasPrevPage = ko.observable(); | ||
this.hasNextPage = ko.observable(); | ||
this.hasPager = ko.computed(() => this.hasPrevPage() || this.hasNextPage()); | ||
} | ||
|
||
@Param() | ||
public detailsPageUrl: ko.Observable<string>; | ||
|
||
@OnMounted() | ||
public async initialize(): Promise<void> { | ||
await this.searchApis(); | ||
|
||
this.router.addRouteChangeListener(this.searchApis); | ||
|
||
this.pattern | ||
.extend({ rateLimit: { timeout: Constants.defaultInputDelayMs, method: "notifyWhenChangesStop" } }) | ||
.subscribe(this.searchApis); | ||
} | ||
|
||
/** | ||
* Initiates searching APIs. | ||
*/ | ||
public async searchApis(): Promise<void> { | ||
this.page(1); | ||
this.loadPageOfApis(); | ||
} | ||
|
||
/** | ||
* Loads page of APIs. | ||
*/ | ||
public async loadPageOfApis(): Promise<void> { | ||
const productName = this.routeHelper.getProductName(); | ||
|
||
if (!productName) { | ||
return; | ||
} | ||
|
||
try { | ||
this.working(true); | ||
|
||
const pageNumber = this.page() - 1; | ||
|
||
const query: SearchQuery = { | ||
pattern: this.pattern(), | ||
skip: pageNumber * Constants.defaultPageSize, | ||
take: Constants.defaultPageSize | ||
}; | ||
|
||
const pageOfApis = await this.apiService.getProductApis(`products/${productName}`, query); | ||
this.apis(pageOfApis.value); | ||
|
||
const nextLink = pageOfApis.nextLink; | ||
|
||
this.hasPrevPage(pageNumber > 0); | ||
this.hasNextPage(!!nextLink); | ||
} | ||
catch (error) { | ||
throw new Error(`Unable to load APIs. Error: ${error.message}`); | ||
} | ||
finally { | ||
this.working(false); | ||
} | ||
} | ||
|
||
public getReferenceUrl(api: Api): string { | ||
return this.routeHelper.getApiReferenceUrl(api.name, this.detailsPageUrl()); | ||
} | ||
|
||
public prevPage(): void { | ||
this.page(this.page() - 1); | ||
this.loadPageOfApis(); | ||
} | ||
|
||
public nextPage(): void { | ||
this.page(this.page() + 1); | ||
this.loadPageOfApis(); | ||
} | ||
|
||
@OnDestroyed() | ||
public dispose(): void { | ||
this.router.removeRouteChangeListener(this.searchApis); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/components/products/product-list/ko/productListEditor.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import { IInjectorModule, IInjector } from "@paperbits/common/injection"; | ||
import { ProductListHandlers, ProductListDropdownHandlers } from "../productListHandlers"; | ||
import { ProductListHandlers, ProductListDropdownHandlers, ProductListTilesHandlers } from "../productListHandlers"; | ||
import { ProductListEditor } from "./productListEditor"; | ||
|
||
export class ProductListEditorModule implements IInjectorModule { | ||
public register(injector: IInjector): void { | ||
injector.bind("productListEditor", ProductListEditor); | ||
injector.bindToCollection("widgetHandlers", ProductListHandlers, "productListHandlers"); | ||
injector.bindToCollection("widgetHandlers", ProductListDropdownHandlers, "productListDropdownHandlers"); | ||
injector.bindToCollection("widgetHandlers", ProductListTilesHandlers, "productListTilesHandlers"); | ||
} | ||
} |
Oops, something went wrong.