Skip to content

Commit

Permalink
Merge branch 'v2.0-sandbox' into sp-collection-card
Browse files Browse the repository at this point in the history
  • Loading branch information
spelkey-ucd committed Mar 11, 2021
2 parents 49d3356 + eb3e195 commit 2bfa626
Show file tree
Hide file tree
Showing 12 changed files with 477 additions and 11 deletions.
14 changes: 13 additions & 1 deletion services/ucd-lib-client/client/public/elements/fin-app.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<style include="shared-styles">
:host {
display: block;
background: var(--default-primary-color);
/* background: var(--default-primary-color); */
}

#loading {
Expand Down Expand Up @@ -138,6 +138,18 @@ <h1 class="dot one">.</h1><h1 class="dot two">.</h1><h1 class="dot three">.</h1>
<app-record id="record"></app-record>
<app-about id="about"></app-about>
<app-collections id="collections"></app-collections>
<app-browse-by id="subject"
label="Subject"
facet-query-name="abouts.raw">
</app-browse-by>
<app-browse-by id="creator"
label="Creator"
facet-query-name="creators">
</app-browse-by>
<app-browse-by id="format"
label="Format"
facet-query-name="fileFormats">
</app-browse-by>
<app-components id="components"></app-components>
</iron-pages>
<div class="footer">
Expand Down
10 changes: 8 additions & 2 deletions services/ucd-lib-client/client/public/elements/fin-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import "./auth/app-auth-footer";
import "./components/site/ucdlib-site-footer";
import "./components/site/ucdlib-site-footer-column";
import "./utils/app-header-colorbar";
import "./utils/app-browse-by";


import AppStateInterface from "./interfaces/AppStateInterface";
Expand Down Expand Up @@ -142,9 +143,14 @@ export class FinApp extends Mixin(PolymerElement)
this.page = 'loading';
this.loadedPages[page] = this.loadPage(page);
}
console.log(this.loadedPages[page]);
await this.loadedPages[page];

// handle browse by pages
if( page === 'browse' && e.location.path.length > 1 ) {
page = e.location.path[1];
}


this.page = page;
}

Expand All @@ -169,7 +175,7 @@ export class FinApp extends Mixin(PolymerElement)
} else if( page === 'components' ) {
return import(/* webpackChunkName: "page-components" */ "./pages/components/app-components");
}
return import(/* webpackChunkName: "page-home" */ "./pages/home/app-home");
return page;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,46 @@ return html`
</div>
<div id="options">
<app-icons id="option" icon="iron-archive" theme-color='secondary' size-icon-svg='extralg' size="extralg"><div slot="icon-text">Collections</div></app-icons>
<app-icons id="option" icon="iron-dashboard" theme-color='secondary' size-icon-svg='extralg' size="extralg"><div slot="icon-text">All Items</div></app-icons>
<app-icons id="option" icon="iron-account-box" theme-color='secondary' size-icon-svg='extralg' size="extralg"><div slot="icon-text">Creators</div></app-icons>
<app-icons id="option" icon="iron-create" theme-color='secondary' size-icon-svg='extralg' size="extralg"><div slot="icon-text">Formats</div></app-icons>
<app-icons id="option" icon="fin-search" theme-color='secondary' size-icon-svg='extralg' size="extralg"><div slot="icon-text">Subjects</div></app-icons>
<a href="/search">
<app-icons id="option"
icon="iron-dashboard"
theme-color='secondary'
size-icon-svg='extralg'
size="extralg">
<div slot="icon-text">All Items</div>
</app-icons>
</a>
<a href="/browse/creator">
<app-icons id="option"
icon="iron-account-box"
theme-color='secondary'
size-icon-svg='extralg'
size="extralg">
<div slot="icon-text">Creators</div>
</app-icons>
</a>
<a href="/browse/format">
<app-icons id="option"
icon="iron-create"
theme-color='secondary'
size-icon-svg='extralg'
size="extralg">
<div slot="icon-text">Formats</div>
</app-icons>
</a>
<a href="/browse/subject">
<app-icons id="option"
icon="fin-search"
theme-color='secondary'
size-icon-svg='extralg'
size="extralg">
<div slot="icon-text">Subjects</div>
</app-icons>
</a>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ document.head.appendChild(dmEle);
*
* @returns Css string
*/
export function styles() {
export default function styles() {
return `${ucdCss + damsCss}`;
}

160 changes: 160 additions & 0 deletions services/ucd-lib-client/client/public/elements/utils/app-browse-by.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import { LitElement } from 'lit-element';
import render from "./app-browse-by.tpl.js";

import "@ucd-lib/cork-pagination";

/**
* @class AppBrowseBy
* @description base class for the browse by [facet] page elements
*
* Bound to app-state-update, rendering when the url matches /browse/[id] where
* element id is. You must provide facet-query-name and label as well.
*
* Three slots are available for images; 'header-icon', 'left-image' and 'right-image'
*
* @property {String} id required so page is rendered on correct app-state-update event
* @property {String} facet-query-name the record property to be queried on
* @property {String} label nice label text for query facet
* @property {Array} sortByOptions override this property to change the default sorts
*/
export default class AppBrowseBy extends Mixin(LitElement)
.with(LitCorkUtils) {

static get properties() {
return {
facetQueryName : {type: String, attribute: 'facet-query-name'},
label : {type: String},
sortByOptions : {type: Array},
results : {type: Array},
totalResults : {type: Number},
resultsPerPage : {type: Number},
currentIndex : {type: Number}
};
}

constructor() {
super();
this.render = render.bind(this);

this.sortByOptions = [
{label : 'A-Z', type: 'key', dir : 'asc', selected: true},
{label : 'Item Quantity', dir : 'dsc', type: 'count'}
];

this.reset();

this._injectModel('BrowseByModel', 'AppStateModel', 'RecordModel');
}

/**
* @method reset
* @description reset search properties
*/
reset() {
this.results = [];
this.totalResults = 0;
this.resultsPerPage = 20;
this.currentIndex = 0;
this.label = '';
}

/**
* @method _onAppStateUpdate
* @description bound to AppStateModel app-state-update event
*
* @param {Object} e
* @returns {Promise}
*/
async _onAppStateUpdate(e) {
if( e.location.page !== 'browse' ) return;
if( e.location.path.length < 2 ) return;
if( e.location.path[1] !== this.id ) return; // the page

if( this.totalResults === 0 ) {
this.loading = true;
this.allResults = await this.BrowseByModel.getFacets(this.facetQueryName);
this.totalResults = this.allResults.payload.length;
this.loading = false;
}

if( e.location.path.length > 2 ) {
this.currentIndex = parseInt(e.location.path[2]);
} else {
this.currentIndex = 0;
}

let sort = 0;
if( e.location.path.length > 2 ) {
sort = parseInt(e.location.path[2]);
}
this.sortByOptions.forEach((item, index) => item.selected = (sort === index));

this._renderResults();
}

/**
* @method _renderResults
* @description render the results array based on currentPage and sort
* params
*/
_renderResults() {
let sort = this.sortByOptions.find(item => item.selected);

if( this.sortedAs !== sort.type ) {
this.allResults.payload.sort((a, b) => {
if( a[sort.type] > b[sort.type] ) return (sort.dir === 'asc') ? 1 : -1;
if( a[sort.type] < b[sort.type] ) return (sort.dir === 'asc') ? -1 : 1;
return 0;
});
this.sortedAs = sort.type;
}

this.results = this.allResults.payload.slice(
this.currentIndex,
this.currentIndex + this.resultsPerPage
);

this.requestUpdate();
}

/**
* @method _onPaginationNav
* @description bound to cork-pagination nav event
*
* @param {Object} e
*/
_onPaginationNav(e) {
this.currentIndex = (e.detail.page-1) * this.resultsPerPage;
this._renderResults();
}

/**
* @method _onSortChange
* @description bound to sort radio button change events
*
* @param {Object} e
*/
_onSortChange(e) {
let sortIndex = parseInt(e.currentTarget.getAttribute('index'));
this.sortByOptions.forEach((item, index) => item.selected = (index === sortIndex));
this.currentIndex = 0;
this._renderResults();
}

/**
* @method getFilterUrl
* @description used by UI to create anchor tag urls for search queries
* based on given facet
*
* @param {Object} item facet result item
* @returns {String}
*/
getFilterUrl(item) {
let searchDocument = this.RecordModel.emptySearchDocument();
this.RecordModel.appendKeywordFilter(searchDocument, this.facetQueryName, item.key);
return '/search/'+this.RecordModel.searchDocumentToUrl(searchDocument);
}

}

customElements.define('app-browse-by', AppBrowseBy);
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { html } from 'lit-element';

export default function render() {
return html`
<style>
:host {
display: block;
}
.header {
display: flex;
justify-content : center;
}
.sort {
display: flex;
align-items: center;
}
.body {
display: flex;
}
.results {
width: 100%;
box-sizing: border-box;
max-width: 400px;
}
.results > * {
display: flex;
box-sizing: border-box;
width: 100%;
}
.results > * > *:first-child {
flex: 1;
}
</style>
<div class="header">
<div>
<div><slot name="header-icon"></slot></div>
<div>
<h1>Browse <span>${this.label}s</span></h1>
</div>
<div class="sort">
<div>Sort By:</div>
${this.sortByOptions.map((item, index) => html`
<div>
<input type="radio"
id="browse-by-${this.facetQueryName}-${item.label}"
name="browse-by-${this.facetQueryName}"
index="${index}"
.checked="${item.selected}"
@change="${this._onSortChange}" />
<label for="browse-by-${this.facetQueryName}-${item.label}">${item.label}</label>
</div>
`)}
</div>
</div>
</div>
<div class="body">
<div style="flex: 1">
<slot name="left-image"></slot>
</div>
<div class="results">
<h5>
<div>${this.label}</div>
<div>Items</div>
</h5>
${this.results.map(item => html`
<div>
<div><a href="${this.getFilterUrl(item)}">${item.key}</a></div>
<div>${item.count}</div>
</div>
`)}
</div>
<div style="flex: 1">
<slot name="right-image"></slot>
</div>
</div>
<cork-pagination
total-results="${this.totalResults}"
items-per-page="${this.resultsPerPage}"
current-index="${this.currentIndex}"
@nav="${this._onPaginationNav}">
</cork-pagination>
`;}
3 changes: 2 additions & 1 deletion services/ucd-lib-client/client/public/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ module.exports = {
CitationModel : require('./models/CitationsModel'),
SeoModel : require('./models/SeoModel'),
FiltersModel : require('./models/FiltersModel'),
FcAppConfigModel : require('./models/FcAppConfigModel')
FcAppConfigModel : require('./models/FcAppConfigModel'),
BrowseByModel : require('./models/BrowseByModel')
};
Loading

0 comments on commit 2bfa626

Please sign in to comment.