项目作者: mehmetc

项目描述 :
Simple Domain Object Model for the Primo new UI
高级语言: JavaScript
项目地址: git://github.com/mehmetc/primo-explore-dom.git
创建时间: 2017-04-03T11:19:11Z
项目社区:https://github.com/mehmetc/primo-explore-dom

开源协议:

下载


This is a pre-release: you can help us make it better.

Current version 0.0.10

  • can retrieve controller without scope()

Current version 0.0.9

  • extracted ui to its own project primo-explore-dom-ui
  • added user.loans
  • add Helper.loadScript()
  • Primo.version now displays library version and Primo version & hot fix
  • Possibility to drill down on a service in the UI
  • Better check if reloadWithDebugInfo() was ran
  • explorer UI pops up automatically when Primo UI is loaded with angular.reloadWithDebugInfo()
  • some general refactoring
  • fixed an issue that would prevent explore.ui.toggle() from running twice

version 0.0.8

  • refactoring of ui
  • better component ctrl discovery
  • ui component property display
  • unhandle promise

version 0.0.7

  • user fines
  • better ctrl discovery
  • removed angularLoad reference

version 0.0.5

  • refactored: user, view, records, facets, ui
  • added user.email
  • added view.interfaceLanguage
  • user, view, records, facets returns a promise
  • removed Primo.explore.session.id

Watch my EPUG-UKI AGM 2017 presentation to get an idea of what it is and what it can do.

Why do we need a Domain Object Model?

A domain object model according to Tim Howard is a logical container of domain information. You might assume that a model is present in every component and that is kind of true. When you examine a component you get a long list of context(component) specific information and there is no obvious way to access the most common(session, user, record, facet) information from within this component. And if you use an newUI service Ex Libris does not garentee that this service will still be present in the next newUI release.

I’m not saying that we need an SDK but we definitely need something that will withstand the test of time and maybe even is AngularJS agnostic. Currently the newUI is written using AngularJS 1 but plans are in place to upgrade to a future AngularJS and when this happens everybody who has written custom newUI code has to rewrite it for that AngularJS version.

TODO:write more documentation

Install

This package will extend the newUI through a “Template Package” or “Central Package”.

  1. Install and configure primo-explore-devenv
  2. Download a “Template Package” or “Central Package” from the Primo Back Office
  3. Extract the downloaded package to primo-explore-devenv/primo-explore/custom
  4. Rename the “Template Package” directory to reflect your view code for example to YOUR_VIEW_CODE
  5. Create a package.json file inside your package directory
    • cd YOUR_VIEW_CODE
    • npm init -y
  6. Install and store a reference to this package
    • npm install primo-explore-dom --save-dev
  7. Test.

PS: YOUR_VIEW_CODE must be replaced with the code you use for your view.

install PRIMO Domain Object Model

If you haven’t installed primo-explore-devenv but do want to explore you can load primo-explore-dom from your web browser console.

  1. //enable debug information. Wait for the screen to reload.
  2. angular.reloadWithDebugInfo();
  3. //When screen is reloaded
  4. //Get a pointer to AngularJs and angularLoad
  5. var appInjector = angular.injector(['ng','angularLoad']);
  6. //Get a reference to angularLoad
  7. var angularLoad = appInjector.get('angularLoad');
  8. //Load the script;
  9. angularLoad.loadScript('https://npmcdn.com/primo-explore-dom/js/primo-explore-dom.js').then(function(){
  10. console.log('script loaded');
  11. });

Quick links

" class="reference-link">General

If you are using this library to understand the newUI always load debug info first.

  1. angular.reloadWithDebugInfo();

For now it is not possible to access the $scope and $ctrl without the debug info. The library will throw an error if this is the case and try an alternative method but this does not work for component access.
(± will mark methods that absolutely need $scope access)

Check if the library is loaded with debug info enabled

  1. Primo.isDebugEnabled()

This is an artifact. Should not be used!

  1. Primo.isPrimoAvailable()

Get the library version

  1. Primo.version

" class="reference-link">User

Primo.user returns a promise

Get user ID

  1. Primo.user.then(user => console.log(user.id));

Get user name

  1. Primo.user.then(user => console.log(user.name));

Get user email

  1. Primo.user.then(user => console.log(user.email));

Is user logged in

  1. Primo.user.then(user => console.log(user.isLoggedIn()));

is user on campus

  1. Primo.user.then(user => console.log(user.isOnCampus()));

Print number of fines for user

  1. Primo.user.then(user => console.log(user.fines.length));

Print total of all fines

  1. Primo.user.then(user => console.log(user.fines.map(f => parseFloat(f.finesum)).reduce((p,c)=> p+c)))

Print number of loans for user

  1. Primo.user.then(user => console.log(user.loans.length))

" class="reference-link">view

Primo.view returns a promise

Get VID

  1. Primo.view.then(view => console.log(view.code));

Get institution code

  1. Primo.view.then(view => console.log(view.institution.code));

Get institution name

  1. Primo.view.then(view => console.log(view.institution.name));

Get interface language

  1. Primo.view.then(view => console.log(view.interfaceLanguage));

ip

Get IP address of your Primo view

  1. Primo.view.then(view => console.log(view.ip.address));

" class="reference-link">Records

Primo.records returns a promise
This is a pointer to the new UI result set

Getting access to all records

  1. Primo.records.then(records => console.log(records));

Mapping all recordid’s into a list

  1. Primo.records.then(records => console.log(records.map((m) => m.pnx.control.recordid[0])));

This is just a glimpse of what can be done.

" class="reference-link">Facets

Primo.facets returns a promise
This is a pointer to the new UI facet set

Getting access to all facets

  1. Primo.facets.then(facets => console.log(facets));

Examining a facet

Getting the facet name

  1. Primo.facets.then(facets => console.log(facets[0].name));

Getting facet count

  1. Primo.facets.then(facets => console.log(facets[0].count));

Getting facet values

  1. Primo.facets.then(facets => console.log(facets[0].values));

This is just a glimpse of what can be done.

" class="reference-link">Components

Getting available components

The components list changes over time. Some components are only available in certain situations

  1. Primo.explore.components.keys();

Getting the ‘prm-icon’ component

  1. var prmIcons = Primo.explore.components.get('prm-icon');

Examining the prmIcon component

Get component name

  1. primIcons[0].name

Get DOM element

  1. primIcons[0].element

Find out css path to component

  1. primIcons[0].cssPath

Get $scope for component (±)

  1. primIcons[0].scope()

Get $ctrl form component (±)

  1. primIcons[0].ctrl()
  1. primIcons[0].blink()

" class="reference-link">Helper

Same as Primo.isDebugEnabled()

  1. Primo.explore.helper.isDebugEnabled();

Same as Primo.isPrimoAvailable()

  1. Primo.explore.helper.isPrimoAvailable();

Get all rendered components

  1. Primo.explore.helper.componentNames

Same as document.querySelectorAll but return an Array instead of a NodeList

  1. Primo.explore.helper.querySelectorAll(selector)

PrimoExplore injector

  1. Primo.explore.helper.injector()

Reference to AngularJS $http

  1. Primo.explore.helper.http

Reference to angular-load. Returns a promise

  1. Primo.explore.helper.loadScript()

Reference to PrimoExplore rootScope

  1. Primo.explore.helper.rootScope()

Reference to userSessionManagerService

  1. Primo.explore.helper.userSessionManagerService()

Reference to json web token data

  1. Primo.explore.helper.jwtData()

Returns a promise to userDetails

  1. Primo.explore.helper.userDetails()
  2. Primo.explore.helper.userDetailsHTTP()

Returns a promise to userFines

  1. Primo.explore.helper.userFinesHTTP()

Returns a promise to userLoans

  1. Primo.explore.helper.userLoansHTTP()
  1. Primo.explore.helper.blink(component, numberOfBlinks = 4)

" class="reference-link">UI

Activate the UI

  1. Primo.explore.ui.toggle()

PRIMO Domain Object Model UI

" class="reference-link">Examples

  1. app.component('prmLogoAfter', {
  2. bindings: {
  3. parentCtrl : '<'
  4. },
  5. template: '<div>{{$ctrl.user}}</div>',
  6. controller: function(){
  7. let ctrl = this;
  8. ctrl.user = '';
  9. Primo.user.then(u => ctrl.user = u.name);
  10. }
  11. });