Simple Domain Object Model for the Primo new UI
Watch my EPUG-UKI AGM 2017 presentation to get an idea of what it is and what it can do.
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
This package will extend the newUI through a “Template Package” or “Central Package”.
primo-explore-devenv/primo-explore/customYOUR_VIEW_CODEpackage.json file inside your package directorycd YOUR_VIEW_CODEnpm init -ynpm install primo-explore-dom --save-devgulp run --view YOUR_VIEW_CODE --proxy http://my.primo.comPS: YOUR_VIEW_CODE must be replaced with the code you use for your view.

//enable debug information. Wait for the screen to reload.angular.reloadWithDebugInfo();//When screen is reloaded//Get a pointer to AngularJs and angularLoadvar appInjector = angular.injector(['ng','angularLoad']);//Get a reference to angularLoadvar angularLoad = appInjector.get('angularLoad');//Load the script;angularLoad.loadScript('https://npmcdn.com/primo-explore-dom/js/primo-explore-dom.js').then(function(){console.log('script loaded');});
If you are using this library to understand the newUI always load debug info first.
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)
Primo.isDebugEnabled()
Primo.isPrimoAvailable()
Primo.version
Primo.user returns a promise
Primo.user.then(user => console.log(user.id));
Primo.user.then(user => console.log(user.name));
Primo.user.then(user => console.log(user.email));
Primo.user.then(user => console.log(user.isLoggedIn()));
Primo.user.then(user => console.log(user.isOnCampus()));
Primo.user.then(user => console.log(user.fines.length));
Primo.user.then(user => console.log(user.fines.map(f => parseFloat(f.finesum)).reduce((p,c)=> p+c)))
Primo.user.then(user => console.log(user.loans.length))
Primo.view returns a promise
Primo.view.then(view => console.log(view.code));
Primo.view.then(view => console.log(view.institution.code));
Primo.view.then(view => console.log(view.institution.name));
Primo.view.then(view => console.log(view.interfaceLanguage));
Primo.view.then(view => console.log(view.ip.address));
Primo.records returns a promise
This is a pointer to the new UI result set
Primo.records.then(records => console.log(records));
Primo.records.then(records => console.log(records.map((m) => m.pnx.control.recordid[0])));
Primo.facets returns a promise
This is a pointer to the new UI facet set
Primo.facets.then(facets => console.log(facets));
Primo.facets.then(facets => console.log(facets[0].name));
Primo.facets.then(facets => console.log(facets[0].count));
Primo.facets.then(facets => console.log(facets[0].values));
The components list changes over time. Some components are only available in certain situations
Primo.explore.components.keys();
var prmIcons = Primo.explore.components.get('prm-icon');
primIcons[0].name
primIcons[0].element
primIcons[0].cssPath
primIcons[0].scope()
primIcons[0].ctrl()
primIcons[0].blink()
Primo.explore.helper.isDebugEnabled();
Primo.explore.helper.isPrimoAvailable();
Primo.explore.helper.componentNames
Primo.explore.helper.querySelectorAll(selector)
Primo.explore.helper.injector()
Primo.explore.helper.http
Primo.explore.helper.loadScript()
Primo.explore.helper.rootScope()
Primo.explore.helper.userSessionManagerService()
Primo.explore.helper.jwtData()
Primo.explore.helper.userDetails()Primo.explore.helper.userDetailsHTTP()
Primo.explore.helper.userFinesHTTP()
Primo.explore.helper.userLoansHTTP()
Primo.explore.helper.blink(component, numberOfBlinks = 4)
Primo.explore.ui.toggle()

app.component('prmLogoAfter', {bindings: {parentCtrl : '<'},template: '<div>{{$ctrl.user}}</div>',controller: function(){let ctrl = this;ctrl.user = '';Primo.user.then(u => ctrl.user = u.name);}});